Ensure all lines that should be omitted from public includes are marked
[AROS.git] / arch / all-pc / boot / grub2-aros / util / grub-mkdevicemap.c
blobbdecae4a35586945bf6a9e0f8784a32e6d9cf935
1 /* grub-mkdevicemap.c - make a device map file automatically */
2 /*
3 * GRUB -- GRand Unified Bootloader
4 * Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008,2009,2010 Free Software Foundation, Inc.
6 * GRUB is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * GRUB is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
20 #include <config.h>
22 #include <stdio.h>
23 #include <unistd.h>
24 #include <string.h>
25 #include <stdlib.h>
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <errno.h>
29 #include <fcntl.h>
30 #include <limits.h>
32 #include <grub/emu/misc.h>
33 #include <grub/util/misc.h>
34 #include <grub/util/deviceiter.h>
35 #include <grub/env.h>
36 #include <grub/i18n.h>
38 #define _GNU_SOURCE 1
39 #include <getopt.h>
41 #include "progname.h"
43 static void
44 make_device_map (const char *device_map, int floppy_disks)
46 int num_hd = 0;
47 int num_fd = 0;
48 FILE *fp;
50 auto int NESTED_FUNC_ATTR process_device (const char *name, int is_floppy);
52 int NESTED_FUNC_ATTR process_device (const char *name, int is_floppy)
54 grub_util_emit_devicemap_entry (fp, (char *) name,
55 is_floppy, &num_fd, &num_hd);
56 return 0;
59 if (strcmp (device_map, "-") == 0)
60 fp = stdout;
61 else
62 fp = fopen (device_map, "w");
64 if (! fp)
65 grub_util_error ("cannot open %s", device_map);
67 grub_util_iterate_devices (process_device, floppy_disks);
69 if (fp != stdout)
70 fclose (fp);
73 static struct option options[] =
75 {"device-map", required_argument, 0, 'm'},
76 {"probe-second-floppy", no_argument, 0, 's'},
77 {"no-floppy", no_argument, 0, 'n'},
78 {"help", no_argument, 0, 'h'},
79 {"version", no_argument, 0, 'V'},
80 {"verbose", no_argument, 0, 'v'},
81 {0, 0, 0, 0}
84 static void
85 usage (int status)
87 if (status)
88 fprintf (stderr,
89 "Try `%s --help' for more information.\n", program_name);
90 else
91 printf ("\
92 Usage: %s [OPTION]...\n\
93 \n\
94 Generate a device map file automatically.\n\
95 \n\
96 -n, --no-floppy do not probe any floppy drive\n\
97 -s, --probe-second-floppy probe the second floppy drive\n\
98 -m, --device-map=FILE use FILE as the device map [default=%s]\n\
99 -h, --help display this message and exit\n\
100 -V, --version print version information and exit\n\
101 -v, --verbose print verbose messages\n\
103 Report bugs to <%s>.\n\
104 ", program_name,
105 DEFAULT_DEVICE_MAP, PACKAGE_BUGREPORT);
107 exit (status);
111 main (int argc, char *argv[])
113 char *dev_map = 0;
114 int floppy_disks = 1;
116 set_program_name (argv[0]);
118 grub_util_init_nls ();
120 /* Check for options. */
121 while (1)
123 int c = getopt_long (argc, argv, "snm:r:hVv", options, 0);
125 if (c == -1)
126 break;
127 else
128 switch (c)
130 case 'm':
131 if (dev_map)
132 free (dev_map);
134 dev_map = xstrdup (optarg);
135 break;
137 case 'n':
138 floppy_disks = 0;
139 break;
141 case 's':
142 floppy_disks = 2;
143 break;
145 case 'h':
146 usage (0);
147 break;
149 case 'V':
150 printf ("%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
151 return 0;
153 case 'v':
154 verbosity++;
155 break;
157 default:
158 usage (1);
159 break;
163 if (verbosity > 1)
164 grub_env_set ("debug", "all");
166 make_device_map (dev_map ? : DEFAULT_DEVICE_MAP, floppy_disks);
168 free (dev_map);
170 return 0;