]> git.ozlabs.org Git - petitboot/blob - devices/parser-test.c
Remove completed items from TODO
[petitboot] / devices / parser-test.c
1 #define _GNU_SOURCE
2
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <stdarg.h>
6 #include <unistd.h>
7 #include <string.h>
8
9 #include "parser.h"
10
11 void pb_log(const char *fmt, ...)
12 {
13         va_list ap;
14
15         va_start(ap, fmt);
16         vfprintf(stderr, fmt, ap);
17         va_end(ap);
18 }
19
20 int mount_device(const char *dev_path)
21 {
22         printf("[mount] %s\n", dev_path);
23         return 0;
24 }
25
26 static int device_idx;
27 static int option_idx;
28
29 int add_device(const struct device *dev)
30 {
31         printf("[dev %2d] id: %s\n", device_idx, dev->id);
32         printf("[dev %2d] name: %s\n", device_idx, dev->name);
33         printf("[dev %2d] description: %s\n", device_idx, dev->description);
34         printf("[dev %2d] boot_image: %s\n", device_idx, dev->icon_file);
35
36         device_idx++;
37         option_idx = 0;
38         return 0;
39 }
40
41
42 int add_boot_option(const struct boot_option *opt)
43 {
44         if (!device_idx) {
45                 fprintf(stderr, "Option (%s) added before device\n",
46                                 opt->name);
47                 exit(EXIT_FAILURE);
48         }
49
50         printf("[opt %2d] name: %s\n", option_idx, opt->name);
51         printf("[opt %2d] description: %s\n", option_idx, opt->description);
52         printf("[opt %2d] boot_image: %s\n", option_idx, opt->boot_image_file);
53         printf("[opt %2d] initrd: %s\n", option_idx, opt->initrd_file);
54         printf("[opt %2d] boot_args: %s\n", option_idx, opt->boot_args);
55
56         option_idx++;
57
58         return 0;
59 }
60
61 enum generic_icon_type guess_device_type(void)
62 {
63         return ICON_TYPE_UNKNOWN;
64 }
65
66 static char *mountpoint;
67
68 /* pretend that all devices are mounted at our original mountpoint */
69 const char *mountpoint_for_device(const char *dev_path)
70 {
71         return mountpoint;
72 }
73
74 char *resolve_path(const char *path, const char *default_mountpoint)
75 {
76         char *sep, *ret;
77         const char *devpath;
78
79         sep = strchr(path, ':');
80         if (!sep) {
81                 devpath = default_mountpoint;
82                 asprintf(&ret, "%s/%s", devpath, path);
83         } else {
84                 char *tmp = strndup(path, sep - path);
85                 devpath = mountpoint_for_device(path);
86                 asprintf(&ret, "%s/%s", devpath, sep + 1);
87                 free(tmp);
88         }
89
90         return ret;
91 }
92
93 int main(int argc, char **argv)
94 {
95         const char *dev = "sda1";
96
97         if (argc != 2) {
98                 fprintf(stderr, "usage: %s <fake-mountpoint>\n", argv[0]);
99                 return EXIT_FAILURE;
100         }
101
102         mountpoint = argv[1];
103
104         iterate_parsers(dev, mountpoint);
105
106         return EXIT_SUCCESS;
107 }