]> git.ozlabs.org Git - petitboot/blob - devices/parser-test.c
Include limits.h
[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 #include "paths.h"
11
12 void pb_log(const char *fmt, ...)
13 {
14         va_list ap;
15
16         va_start(ap, fmt);
17         vfprintf(stderr, fmt, ap);
18         va_end(ap);
19 }
20
21 int mount_device(const char *dev_path)
22 {
23         printf("[mount] %s\n", dev_path);
24         return 0;
25 }
26
27 static int device_idx;
28 static int option_idx;
29
30 int add_device(const struct device *dev)
31 {
32         printf("[dev %2d] id: %s\n", device_idx, dev->id);
33         printf("[dev %2d] name: %s\n", device_idx, dev->name);
34         printf("[dev %2d] description: %s\n", device_idx, dev->description);
35         printf("[dev %2d] boot_image: %s\n", device_idx, dev->icon_file);
36
37         device_idx++;
38         option_idx = 0;
39         return 0;
40 }
41
42
43 int add_boot_option(const struct boot_option *opt)
44 {
45         if (!device_idx) {
46                 fprintf(stderr, "Option (%s) added before device\n",
47                                 opt->name);
48                 exit(EXIT_FAILURE);
49         }
50
51         printf("[opt %2d] name: %s\n", option_idx, opt->name);
52         printf("[opt %2d] description: %s\n", option_idx, opt->description);
53         printf("[opt %2d] boot_image: %s\n", option_idx, opt->boot_image_file);
54         printf("[opt %2d] initrd: %s\n", option_idx, opt->initrd_file);
55         printf("[opt %2d] boot_args: %s\n", option_idx, opt->boot_args);
56
57         option_idx++;
58
59         return 0;
60 }
61
62 enum generic_icon_type guess_device_type(void)
63 {
64         return ICON_TYPE_UNKNOWN;
65 }
66
67 int main(int argc, char **argv)
68 {
69         char *mountpoint, *dev;
70
71         if (argc != 3) {
72                 fprintf(stderr, "usage: %s <basedir> <devname>\n", argv[0]);
73                 return EXIT_FAILURE;
74         }
75
76         mountpoint = argv[1];
77         dev = argv[2];
78
79         set_mount_base(mountpoint);
80
81         iterate_parsers(dev, mountpoint);
82
83
84         return EXIT_SUCCESS;
85 }