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