2005-07-10 07:57:49 +00:00
|
|
|
/* grub-mkdevicemap.c - make a device map file automatically */
|
|
|
|
/*
|
|
|
|
* GRUB -- GRand Unified Bootloader
|
2010-01-01 20:32:30 +00:00
|
|
|
* Copyright (C) 1999,2000,2001,2002,2003,2004,2005,2007,2008,2009,2010 Free Software Foundation, Inc.
|
2005-07-10 07:57:49 +00:00
|
|
|
*
|
2007-07-21 23:32:33 +00:00
|
|
|
* GRUB is free software: you can redistribute it and/or modify
|
2005-07-10 07:57:49 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2007-07-21 23:32:33 +00:00
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
2005-07-10 07:57:49 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2007-07-21 23:32:33 +00:00
|
|
|
* GRUB is distributed in the hope that it will be useful,
|
2005-07-10 07:57:49 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2007-07-21 23:32:33 +00:00
|
|
|
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
2005-07-10 07:57:49 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
#include <grub/util/misc.h>
|
2009-04-22 09:57:39 +00:00
|
|
|
#include <grub/util/deviceiter.h>
|
2009-11-25 23:10:02 +00:00
|
|
|
#include <grub/i18n.h>
|
2005-07-10 07:57:49 +00:00
|
|
|
|
|
|
|
#define _GNU_SOURCE 1
|
|
|
|
#include <getopt.h>
|
|
|
|
|
2009-11-25 23:10:02 +00:00
|
|
|
#include "progname.h"
|
|
|
|
|
2008-05-07 20:46:57 +00:00
|
|
|
static void
|
2009-04-22 09:57:39 +00:00
|
|
|
make_device_map (const char *device_map, int floppy_disks)
|
2005-07-10 07:57:49 +00:00
|
|
|
{
|
2009-04-22 09:57:39 +00:00
|
|
|
int num_hd = 0;
|
|
|
|
int num_fd = 0;
|
2005-07-10 07:57:49 +00:00
|
|
|
FILE *fp;
|
|
|
|
|
2009-04-26 08:44:36 +00:00
|
|
|
auto int NESTED_FUNC_ATTR process_device (const char *name, int is_floppy);
|
2005-07-10 07:57:49 +00:00
|
|
|
|
2009-04-26 08:44:36 +00:00
|
|
|
int NESTED_FUNC_ATTR process_device (const char *name, int is_floppy)
|
2009-04-22 09:57:39 +00:00
|
|
|
{
|
|
|
|
grub_util_emit_devicemap_entry (fp, (char *) name,
|
|
|
|
is_floppy, &num_fd, &num_hd);
|
2005-07-10 07:57:49 +00:00
|
|
|
return 0;
|
2009-04-22 09:57:39 +00:00
|
|
|
}
|
2005-07-10 07:57:49 +00:00
|
|
|
|
|
|
|
if (strcmp (device_map, "-") == 0)
|
|
|
|
fp = stdout;
|
|
|
|
else
|
|
|
|
fp = fopen (device_map, "w");
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-07-10 07:57:49 +00:00
|
|
|
if (! fp)
|
|
|
|
grub_util_error ("cannot open %s", device_map);
|
|
|
|
|
2009-04-22 09:57:39 +00:00
|
|
|
grub_util_iterate_devices (process_device, floppy_disks);
|
2008-05-05 20:58:53 +00:00
|
|
|
|
2005-07-10 07:57:49 +00:00
|
|
|
if (fp != stdout)
|
|
|
|
fclose (fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct option options[] =
|
|
|
|
{
|
|
|
|
{"device-map", required_argument, 0, 'm'},
|
|
|
|
{"probe-second-floppy", no_argument, 0, 's'},
|
|
|
|
{"no-floppy", no_argument, 0, 'n'},
|
|
|
|
{"help", no_argument, 0, 'h'},
|
|
|
|
{"version", no_argument, 0, 'V'},
|
|
|
|
{"verbose", no_argument, 0, 'v'},
|
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage (int status)
|
|
|
|
{
|
|
|
|
if (status)
|
|
|
|
fprintf (stderr,
|
2009-11-25 23:10:02 +00:00
|
|
|
"Try ``%s --help'' for more information.\n", program_name);
|
2005-07-10 07:57:49 +00:00
|
|
|
else
|
|
|
|
printf ("\
|
2009-11-25 23:10:02 +00:00
|
|
|
Usage: %s [OPTION]...\n\
|
2005-07-10 07:57:49 +00:00
|
|
|
\n\
|
|
|
|
Generate a device map file automatically.\n\
|
|
|
|
\n\
|
|
|
|
-n, --no-floppy do not probe any floppy drive\n\
|
|
|
|
-s, --probe-second-floppy probe the second floppy drive\n\
|
|
|
|
-m, --device-map=FILE use FILE as the device map [default=%s]\n\
|
|
|
|
-h, --help display this message and exit\n\
|
|
|
|
-V, --version print version information and exit\n\
|
|
|
|
-v, --verbose print verbose messages\n\
|
|
|
|
\n\
|
|
|
|
Report bugs to <%s>.\n\
|
2009-11-25 23:10:02 +00:00
|
|
|
", program_name,
|
2005-07-24 18:16:26 +00:00
|
|
|
DEFAULT_DEVICE_MAP, PACKAGE_BUGREPORT);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-07-10 07:57:49 +00:00
|
|
|
exit (status);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
char *dev_map = 0;
|
|
|
|
int floppy_disks = 1;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2009-11-25 23:10:02 +00:00
|
|
|
set_program_name (argv[0]);
|
2010-01-01 20:32:30 +00:00
|
|
|
|
|
|
|
grub_util_init_nls ();
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-07-10 07:57:49 +00:00
|
|
|
/* Check for options. */
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
int c = getopt_long (argc, argv, "snm:r:hVv", options, 0);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-07-10 07:57:49 +00:00
|
|
|
if (c == -1)
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case 'm':
|
|
|
|
if (dev_map)
|
|
|
|
free (dev_map);
|
|
|
|
|
|
|
|
dev_map = xstrdup (optarg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'n':
|
|
|
|
floppy_disks = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 's':
|
|
|
|
floppy_disks = 2;
|
|
|
|
break;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-07-10 07:57:49 +00:00
|
|
|
case 'h':
|
|
|
|
usage (0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'V':
|
2009-11-25 23:10:02 +00:00
|
|
|
printf ("%s (%s) %s\n", program_name, PACKAGE_NAME, PACKAGE_VERSION);
|
2005-07-10 07:57:49 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case 'v':
|
|
|
|
verbosity++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
usage (1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
make_device_map (dev_map ? : DEFAULT_DEVICE_MAP, floppy_disks);
|
|
|
|
|
|
|
|
free (dev_map);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-07-10 07:57:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|