On Fri, Sep 22, 2006 at 06:33:13PM +0200, Robert Millan wrote:
>
> This would be very useful to get rid of ugly kludges in Debian, such as this
> one:
>
> http://svn.debian.org/wsvn/pkg-grub/grub2/trunk/debian/update-grub?op=file&rev=0&sc=0
> (look for convert() here)
>
> Fortunately grub-probefs is already doing what we need, we just need a way to
> tell it to print the information.
Uhm it seems I need the system device name as well. Please look at this new
patch with an additional option (I had to rework the grub_guess_root_device
interface to get the info yet unprocessed by grub_util_biosdisk_get_grub_dev).
2006-09-22 Robert Millan <[EMAIL PROTECTED]>
* util/i386/pc/getroot.c (grub_guess_root_device): Stop using
grub_util_biosdisk_get_grub_dev to convert system device to GRUB device.
* util/grub-emu.c: Use grub_util_biosdisk_get_grub_dev with the string
returned by grub_guess_root_device.
* util/i386/pc/grub-setup.c: Ditto.
* util/i386/pc/grub-probefs.c: Ditto.
* util/i386/pc/grub-probefs.c: Add two options (--grub-root-device and
--root-device) to print GRUB or system device and exit.
--
Robert Millan
My spam trap is [EMAIL PROTECTED] Note: this address is only intended for
spam harvesters. Writing to it will get you added to my black list.
2006-09-22 Robert Millan <[EMAIL PROTECTED]>
* util/i386/pc/getroot.c (grub_guess_root_device): Stop using
grub_util_biosdisk_get_grub_dev to convert system device to GRUB device.
* util/grub-emu.c: Use grub_util_biosdisk_get_grub_dev with the string
returned by grub_guess_root_device.
* util/i386/pc/grub-setup.c: Ditto.
* util/i386/pc/grub-probefs.c: Ditto.
* util/i386/pc/grub-probefs.c: Add two options (--grub-root-device and
--root-device) to print GRUB or system device and exit.
Index: util/grub-emu.c
===================================================================
RCS file: /sources/grub/grub2/util/grub-emu.c,v
retrieving revision 1.30
diff -u -r1.30 grub-emu.c
--- util/grub-emu.c 13 Jun 2006 22:50:01 -0000 1.30
+++ util/grub-emu.c 22 Sep 2006 21:00:09 -0000
@@ -185,7 +185,7 @@
/* Make sure that there is a root device. */
if (! args.root_dev)
{
- args.root_dev = grub_guess_root_device (args.dir ? : DEFAULT_DIRECTORY);
+ args.root_dev = grub_util_biosdisk_get_grub_dev (grub_guess_root_device
(args.dir ? : DEFAULT_DIRECTORY));
if (! args.root_dev)
{
grub_util_info ("guessing the root device failed, because of `%s'",
Index: util/i386/pc/getroot.c
===================================================================
RCS file: /sources/grub/grub2/util/i386/pc/getroot.c,v
retrieving revision 1.5
diff -u -r1.5 getroot.c
--- util/i386/pc/getroot.c 14 Sep 2006 18:52:50 -0000 1.5
+++ util/i386/pc/getroot.c 22 Sep 2006 21:00:09 -0000
@@ -223,5 +223,5 @@
if (! os_dev)
return 0;
- return grub_util_biosdisk_get_grub_dev (os_dev);
+ return os_dev;
}
Index: util/i386/pc/grub-probefs.c
===================================================================
RCS file: /sources/grub/grub2/util/i386/pc/grub-probefs.c,v
retrieving revision 1.3
diff -u -r1.3 grub-probefs.c
--- util/i386/pc/grub-probefs.c 23 Apr 2006 13:37:36 -0000 1.3
+++ util/i386/pc/grub-probefs.c 22 Sep 2006 21:00:09 -0000
@@ -47,6 +47,9 @@
#define DEFAULT_DEVICE_MAP DEFAULT_DIRECTORY "/device.map"
+int print_root = 0;
+int print_grub_root = 0;
+
void
grub_putchar (int c)
{
@@ -74,13 +77,33 @@
probe (const char *path)
{
char *device_name;
+ char *grub_device_name;
grub_device_t dev;
grub_fs_t fs;
device_name = grub_guess_root_device (path);
if (! device_name)
{
- fprintf (stderr, "cannot find a GRUB device for %s.\n", path);
+ fprintf (stderr, "cannot find a device for %s.\n", path);
+ return;
+ }
+
+ grub_device_name = grub_util_biosdisk_get_grub_dev (device_name);
+ if (! grub_device_name)
+ {
+ fprintf (stderr, "cannot find a GRUB device for %s.\n", device_name);
+ return;
+ }
+
+ if (print_root)
+ {
+ printf ("%s\n", device_name);
+ return;
+ }
+
+ if (print_grub_root)
+ {
+ printf ("(%s)\n", grub_device_name);
return;
}
@@ -102,6 +125,8 @@
static struct option options[] =
{
{"device-map", required_argument, 0, 'm'},
+ {"root-device", no_argument, 0, 'r'},
+ {"grub-root-device", no_argument, 0, 'g'},
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
{"verbose", no_argument, 0, 'v'},
@@ -121,6 +146,8 @@
Probe a filesystem module for a given path.\n\
\n\
-m, --device-map=FILE use FILE as the device map [default=%s]\n\
+ -r, --root-device print guessed root device and exit\n\
+ -g, --grub-root-device print guessed GRUB root device and exit\n\
-h, --help display this message and exit\n\
-V, --version print version information and exit\n\
-v, --verbose print verbose messages\n\
@@ -143,7 +170,7 @@
/* Check for options. */
while (1)
{
- int c = getopt_long (argc, argv, "m:hVv", options, 0);
+ int c = getopt_long (argc, argv, "m:rghVv", options, 0);
if (c == -1)
break;
@@ -157,6 +184,14 @@
dev_map = xstrdup (optarg);
break;
+ case 'r':
+ print_root=1;
+ break;
+
+ case 'g':
+ print_grub_root=1;
+ break;
+
case 'h':
usage (0);
break;
Index: util/i386/pc/grub-setup.c
===================================================================
RCS file: /sources/grub/grub2/util/i386/pc/grub-setup.c,v
retrieving revision 1.18
diff -u -r1.18 grub-setup.c
--- util/i386/pc/grub-setup.c 4 Jun 2006 15:56:55 -0000 1.18
+++ util/i386/pc/grub-setup.c 22 Sep 2006 21:00:09 -0000
@@ -669,7 +669,7 @@
}
else
{
- root_dev = grub_guess_root_device (dir ? : DEFAULT_DIRECTORY);
+ root_dev = grub_util_biosdisk_get_grub_dev (grub_guess_root_device (dir
? : DEFAULT_DIRECTORY));
if (! root_dev)
{
grub_util_info ("guessing the root device failed, because of `%s'",
_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel