From: Felix Zielcke <fzielcke@z-51.de>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: [PATCH] use UUID to map system devices to grub devices
Date: Sun, 26 Jul 2009 16:05:31 +0200 [thread overview]
Message-ID: <1248617131.25072.13.camel@fz.local> (raw)
[-- Attachment #1: Type: text/plain, Size: 768 bytes --]
As requested by Robert on IRC, this is a split from my dmraid patch.
On dmraid devices HDIO_GETGEO returns 0 for all fields, so the current
way of grub_util_biosdisk_get_grub_dev just can't work.
So I use blkid to get the UUID of the device and then a new nested
function to find out the grub device like search does.
I think this is with intent from the kernel that it just returns 0's.
Maybe it just can't distinguish between a device mapper setup which goes
over multiple partitions or harddisks of different size not from one
which goes only over complete harddisks with same size like in dmraid
Hm but even if, I think it wouldn't help in case of RAID != 1. Sector
count could be > then last sector of one disk or not?
--
Felix Zielcke
Proud Debian Maintainer
[-- Attachment #2: find_by_uuid.patch --]
[-- Type: text/x-patch, Size: 3543 bytes --]
2009-07-26 Felix Zielcke <fzielcke@z-51.de>
* util/hostdisk.c: Include <grub/file.h>.
(grub_util_biosdisk_get_grub_dev): Use new nested function
find_partition_by_uuid in the case that the HD_GETGEO ioctl
returns 0 for the sectors count, to get the value of dos_part.
diff --git a/util/hostdisk.c b/util/hostdisk.c
index 5842698..843bfb4 100644
--- a/util/hostdisk.c
+++ b/util/hostdisk.c
@@ -25,6 +25,7 @@
#include <grub/util/misc.h>
#include <grub/util/hostdisk.h>
#include <grub/misc.h>
+#include <grub/file.h>
#include <stdio.h>
#include <stdlib.h>
@@ -925,7 +926,7 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
does not count the extended partition and missing primary
partitions. Use same method as on Linux here. */
{
- char *name;
+ char *name, *os_dev_uuid;
grub_disk_t disk;
int fd;
struct hd_geometry hdg;
@@ -975,7 +976,46 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
return 0;
}
+ auto int find_partition_by_uuid (const char *name);
+ int find_partition_by_uuid (const char *name)
+ {
+ grub_device_t dev;
+
+ if (name[0] == 'f' && name[1] == 'd'
+ && name[2] >= '0' && name[2] <= '9')
+ return 0;
+
+ dev = grub_device_open (name);
+ if (dev)
+ {
+ grub_fs_t fs;
+
+ fs = grub_fs_probe (dev);
+
+ if (fs && fs->uuid)
+ {
+ char *uuid, *p;
+
+ (fs->uuid) (dev, &uuid);
+ if (grub_errno == GRUB_ERR_NONE && uuid)
+ {
+ if (grub_strcasecmp (uuid, os_dev_uuid) == 0)
+ {
+ p = strchr (name, ',');
+ dos_part = atoi (p);
+ if (strchr (p, ','))
+ grub_util_error ("BSD partitions not yet supported");
+ free (uuid);
+ return 1;
+ }
+ free (uuid);
+ }
+ }
+ grub_device_close (dev);
+ }
+ return 0;
+ }
name = make_device_name (drive, -1, -1);
if (MAJOR (st.st_rdev) == FLOPPY_MAJOR)
@@ -1005,28 +1045,61 @@ grub_util_biosdisk_get_grub_dev (const char *os_dev)
if (hdg.start == 0 && device_is_wholedisk (os_dev))
return name;
- grub_util_info ("opening the device %s", name);
- disk = grub_disk_open (name);
- free (name);
-
- if (! disk)
- return 0;
- grub_partition_iterate (disk, find_partition);
- if (grub_errno != GRUB_ERR_NONE)
+ if (hdg.sectors == 0)
{
- grub_disk_close (disk);
- return 0;
+ FILE *fp;
+ char *free_ptr, *p, *q;
+ int len = 512;
+
+ p = xmalloc (strlen (os_dev) + strlen ("blkid ") + 1);
+ strcpy (p, "blkid ");
+ strcat (p, os_dev);
+ fp = popen (p, "r");
+ free (p);
+ do {
+ p = xmalloc (len);
+ p = fgets (p, len, fp);
+ if (! p)
+ return 0;
+ len *= 2;
+ } while (! strchr (p, '\n'));
+ free_ptr = p;
+ p = strstr (p , "UUID=");
+ if (! p)
+ return 0;
+ p += strlen ("UUID=\"");
+ q = strchr (p, '\"');
+ if (q)
+ *q = '\0';
+ os_dev_uuid = p;
+ pclose (fp);
+ grub_device_iterate (find_partition_by_uuid);
+ free (free_ptr);
}
+ else
+ {
+ grub_util_info ("opening the device %s", name);
+ disk = grub_disk_open (name);
+ free (name);
+ if (! disk)
+ return 0;
+ grub_partition_iterate (disk, find_partition);
+ if (grub_errno != GRUB_ERR_NONE)
+ {
+ grub_disk_close (disk);
+ return 0;
+ }
+ if (dos_part < 0)
+ grub_disk_close (disk);
+ }
if (dos_part < 0)
{
- grub_disk_close (disk);
grub_error (GRUB_ERR_BAD_DEVICE,
"cannot find the partition of `%s'", os_dev);
return 0;
}
-
return make_device_name (drive, dos_part, bsd_part);
}
next reply other threads:[~2009-07-26 14:04 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-26 14:05 Felix Zielcke [this message]
2009-07-28 18:12 ` [PATCH] use UUID to map system devices to grub devices Robert Millan
2009-07-29 8:43 ` Felix Zielcke
2009-07-31 16:05 ` Robert Millan
2009-07-31 16:26 ` Felix Zielcke
2009-08-04 21:19 ` Robert Millan
2009-08-05 6:18 ` Felix Zielcke
2009-08-05 10:50 ` Vladimir 'phcoder' Serbinenko
2009-08-05 11:01 ` Felix Zielcke
2009-08-07 11:27 ` Robert Millan
2009-08-07 14:29 ` Felix Zielcke
2009-08-07 19:22 ` Robert Millan
2009-08-08 5:13 ` Felix Zielcke
2009-08-10 11:31 ` Robert Millan
2009-08-10 12:46 ` Felix Zielcke
2009-08-10 12:58 ` Felix Zielcke
2009-08-10 15:29 ` Robert Millan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1248617131.25072.13.camel@fz.local \
--to=fzielcke@z-51.de \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.