* [patch] search for partition using GPT GUID
@ 2010-02-12 18:21 George Buranov
2010-02-18 7:13 ` gburanov
0 siblings, 1 reply; 7+ messages in thread
From: George Buranov @ 2010-02-12 18:21 UTC (permalink / raw)
To: The development of GNU GRUB
[-- Attachment #1.1: Type: text/plain, Size: 525 bytes --]
Hello everybody.
I have just implemented support for GPT GUID search and I am really
interested in providing this patch for integration.Who is in chief here, we
can discuss details =)
Patch is included. The syntax is now the following
# Entry 1 - Chainload another bootloader
menuentry "Chainload LILO"
{
search --no-floppy --gpt-guid --set a97fa026-fa15-8244-b272-5bff98b1c522
chainloader /boot/elilo.efi
}
As I said before, search over GPT GUIDs is much safer then in FS UUID (see
topic below)
Regards,
Georgy
[-- Attachment #1.2: Type: text/html, Size: 608 bytes --]
[-- Attachment #2: gpt_guid.diff --]
[-- Type: application/octet-stream, Size: 10268 bytes --]
=== modified file 'ChangeLog'
--- ChangeLog 2010-02-10 19:27:12 +0000
+++ ChangeLog 2010-02-12 14:14:46 +0000
@@ -1,3 +1,8 @@
+2010-02-12 Georgy Buranov <gburanov@gmail.com>
+
+ * disk/efi/efidisk.c (grub_efidisk_get_device_name): Fix bug obtaining device name of the whole disk
+ * fs/iso9660.c (grub_iso9660_iterate_dir): Remove file versions from ISO9660&Joliet file names
+
2010-02-10 Vladimir Serbinenko <phcoder@gmail.com>
Pass SIMPLE framebuffer size in bytes and not 64K blocks.
=== modified file 'commands/search.c'
--- commands/search.c 2010-01-20 08:12:47 +0000
+++ commands/search.c 2010-02-12 18:10:03 +0000
@@ -23,6 +23,9 @@
#include <grub/err.h>
#include <grub/dl.h>
#include <grub/device.h>
+#include <grub/disk.h>
+#include <grub/gpt_partition.h>
+#include <grub/partition.h>
#include <grub/file.h>
#include <grub/env.h>
#include <grub/command.h>
@@ -62,6 +65,58 @@
}
grub_free (buf);
}
+#elif defined (DO_SEARCH_GPT_GUID)
+ {
+ /* type is SEARCH_GPT_GUID. Obtaining device by GPT GUID */
+ grub_device_t dev = grub_device_open (name);
+ if (dev)
+ {
+ const char * dest_partmap = 0;
+
+ auto int identify_partmap (grub_disk_t /*disk*/, const grub_partition_t p);
+ int identify_partmap (grub_disk_t disk __attribute__((unused)), const grub_partition_t p)
+ {
+ dest_partmap = p->partmap->name;
+ return 1;
+ }
+
+ dest_partmap = 0;
+ grub_partition_iterate (dev->disk, identify_partmap);
+ if (grub_strcmp (dest_partmap, "part_gpt") == 0)
+ {
+ auto void identify_gpt_partition(grub_gpt_partentry_t partition);
+
+ void identify_gpt_partition(grub_gpt_partentry_t partition)
+ {
+ int i = 0;
+ char guid[37];
+ char* pguid = (char*)guid;
+ grub_memset(pguid, 0, 37);
+
+ for (; i < 16; ++i)
+ {
+ if (i == 4 || i == 6 || i == 8 || i == 10)
+ {
+ grub_snprintf(pguid, 37 - i, "-");
+ ++pguid;
+ }
+ grub_snprintf(pguid, 37 - i, "%02x", partition->guid[i]);
+ pguid += 2;
+ }
+ // For debug
+ grub_printf("Compare %s and %s\n", guid, key);
+ if (grub_strcmp(guid, key) == 0)
+ {
+ found = 1;
+ }
+ return;
+ }
+
+ // this is gpt disk.
+ gpt_partition_map_gpt_iterate(dev->disk, identify_gpt_partition);
+ }
+ }
+ }
#else
{
/* SEARCH_FS_UUID or SEARCH_LABEL */
@@ -152,6 +207,8 @@
GRUB_MOD_INIT(search_file)
#elif defined (DO_SEARCH_FS_UUID)
GRUB_MOD_INIT(search_fs_uuid)
+#elif defined (DO_SEARCH_GPT_GUID)
+GRUB_MOD_INIT(search_gpt_guid)
#else
GRUB_MOD_INIT(search_fs_label)
#endif
@@ -166,6 +223,8 @@
GRUB_MOD_FINI(search_file)
#elif defined (DO_SEARCH_FS_UUID)
GRUB_MOD_FINI(search_fs_uuid)
+#elif defined (DO_SEARCH_GPT_GUID)
+GRUB_MOD_FINI(search_gpt_guid)
#else
GRUB_MOD_FINI(search_fs_label)
#endif
=== modified file 'commands/search_wrap.c'
--- commands/search_wrap.c 2009-12-25 22:06:52 +0000
+++ commands/search_wrap.c 2010-02-12 17:06:50 +0000
@@ -34,6 +34,8 @@
0, 0},
{"fs-uuid", 'u', 0, N_("Search devices by a filesystem UUID."),
0, 0},
+ {"gpt-guid", 'g', 0, N_("Search devices by GPT GUID."),
+ 0, 0},
{"set", 's', GRUB_ARG_OPTION_OPTIONAL,
N_("Set a variable to the first device found."), "VAR", ARG_TYPE_STRING},
{"no-floppy", 'n', 0, N_("Do not probe any floppy drive."), 0, 0},
@@ -45,6 +47,7 @@
SEARCH_FILE,
SEARCH_LABEL,
SEARCH_FS_UUID,
+ SEARCH_GPT_GUID,
SEARCH_SET,
SEARCH_NO_FLOPPY,
};
@@ -67,6 +70,8 @@
grub_search_fs_uuid (args[0], var, state[SEARCH_NO_FLOPPY].set);
else if (state[SEARCH_FILE].set)
grub_search_fs_file (args[0], var, state[SEARCH_NO_FLOPPY].set);
+ else if (state[SEARCH_GPT_GUID].set)
+ grub_search_gpt_guid (args[0], var, state[SEARCH_NO_FLOPPY].set);
else
return grub_error (GRUB_ERR_INVALID_COMMAND, "unspecified search type");
@@ -80,9 +85,9 @@
cmd =
grub_register_extcmd ("search", grub_cmd_search,
GRUB_COMMAND_FLAG_BOTH,
- N_("search [-f|-l|-u|-s|-n] NAME"),
+ N_("search [-f|-l|-u|-g|-s|-n] NAME"),
N_("Search devices by file, filesystem label"
- " or filesystem UUID."
+ " ,filesystem UUID or GPT GUID."
" If --set is specified, the first device found is"
" set to a variable. If no variable name is"
" specified, \"root\" is used."),
=== modified file 'conf/any-emu.rmk'
--- conf/any-emu.rmk 2010-02-03 00:24:07 +0000
+++ conf/any-emu.rmk 2010-02-12 16:46:14 +0000
@@ -10,6 +10,7 @@
commands/handler.c commands/ls.c commands/test.c \
commands/search_wrap.c commands/search_file.c \
commands/search_label.c commands/search_uuid.c \
+ commands/search_guid.c \
commands/blocklist.c commands/hexdump.c \
lib/hexdump.c commands/halt.c commands/reboot.c \
lib/envblk.c commands/loadenv.c \
=== modified file 'conf/common.rmk'
--- conf/common.rmk 2010-02-06 14:37:23 +0000
+++ conf/common.rmk 2010-02-12 17:05:18 +0000
@@ -519,7 +519,7 @@
search_mod_CFLAGS = $(COMMON_CFLAGS)
search_mod_LDFLAGS = $(COMMON_LDFLAGS)
-pkglib_MODULES += search_fs_file.mod search_fs_uuid.mod search_label.mod
+pkglib_MODULES += search_fs_file.mod search_fs_uuid.mod search_label.mod search_gpt_guid.mod
# For search.mod.
search_fs_file_mod_SOURCES = commands/search_file.c
@@ -536,6 +536,11 @@
search_fs_uuid_mod_CFLAGS = $(COMMON_CFLAGS)
search_fs_uuid_mod_LDFLAGS = $(COMMON_LDFLAGS)
+# For search.mod.
+search_gpt_guid_mod_SOURCES = commands/search_guid.c
+search_gpt_guid_mod_CFLAGS = $(COMMON_CFLAGS)
+search_gpt_guid_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
# For test.mod.
test_mod_SOURCES = commands/test.c
test_mod_CFLAGS = $(COMMON_CFLAGS)
=== modified file 'disk/efi/efidisk.c'
--- disk/efi/efidisk.c 2010-01-20 08:12:47 +0000
+++ disk/efi/efidisk.c 2010-02-12 14:05:23 +0000
@@ -825,7 +825,7 @@
if (! disk)
return 1;
- if (disk->id == GRUB_DISK_DEVICE_EFIDISK_ID)
+ if (disk->dev->id == GRUB_DISK_DEVICE_EFIDISK_ID)
{
struct grub_efidisk_data *d;
=== modified file 'fs/iso9660.c'
--- fs/iso9660.c 2010-01-27 03:11:20 +0000
+++ fs/iso9660.c 2010-02-12 14:13:01 +0000
@@ -615,9 +615,6 @@
if (!filename)
{
name[dirent.namelen] = '\0';
- filename = grub_strrchr (name, ';');
- if (filename)
- *filename = '\0';
if (dirent.namelen == 1 && name[0] == 0)
filename = ".";
@@ -640,6 +637,14 @@
filename_alloc = 1;
}
+
+ if (!dir->data->rockridge)
+ {
+ // On simple ISO 9660 disks and on joliet, we need to remove file version, if any
+ char* lastSymbol = grub_strrchr (filename, ';');
+ if (lastSymbol)
+ *lastSymbol = '\0';
+ }
if (hook (filename, type, node))
{
=== modified file 'include/grub/gpt_partition.h'
--- include/grub/gpt_partition.h 2009-04-19 20:38:46 +0000
+++ include/grub/gpt_partition.h 2010-02-12 17:21:00 +0000
@@ -20,6 +20,9 @@
#define GRUB_GPT_PARTITION_HEADER 1
#include <grub/types.h>
+#include <grub/err.h>
+#include <grub/disk.h>
+#include <grub/partition.h>
struct grub_gpt_part_type
{
@@ -67,5 +70,9 @@
grub_uint64_t attrib;
char name[72];
} __attribute__ ((packed));
+typedef struct grub_gpt_partentry *grub_gpt_partentry_t;
+
+grub_err_t
+gpt_partition_map_gpt_iterate(grub_disk_t disk, void (*hook) (grub_gpt_partentry_t entry));
#endif /* ! GRUB_GPT_PARTITION_HEADER */
=== modified file 'include/grub/search.h'
--- include/grub/search.h 2009-11-23 20:15:44 +0000
+++ include/grub/search.h 2010-02-12 17:05:39 +0000
@@ -22,5 +22,6 @@
void grub_search_fs_file (const char *key, const char *var, int no_floppy);
void grub_search_fs_uuid (const char *key, const char *var, int no_floppy);
void grub_search_label (const char *key, const char *var, int no_floppy);
+void grub_search_gpt_guid (const char *key, const char *var, int no_floppy);
#endif
=== modified file 'partmap/gpt.c'
--- partmap/gpt.c 2010-01-20 08:12:47 +0000
+++ partmap/gpt.c 2010-02-12 17:30:09 +0000
@@ -34,12 +34,15 @@
static struct grub_partition_map grub_gpt_partition_map;
-\f
-
-static grub_err_t
-gpt_partition_map_iterate (grub_disk_t disk,
- int (*hook) (grub_disk_t disk,
- const grub_partition_t partition))
+/*
+* Both gpt_partition_map_gpt_iterate and gpt_partition_map_iterate are using this func internally
+* to obtain grub_gpt_partentry_t and grub_partition_t of every partition
+*/
+static
+grub_err_t
+gpt_partition_map_iterate_internal(grub_disk_t disk,
+ int (*hook) (grub_disk_t disk, const grub_partition_t partition,
+ grub_gpt_partentry_t entry))
{
struct grub_partition part;
struct grub_gpt_header gpt;
@@ -98,7 +101,7 @@
(unsigned long long) part.start,
(unsigned long long) part.len);
- if (hook (disk, &part))
+ if (hook (disk, &part, &entry))
return 1;
}
@@ -110,7 +113,39 @@
}
}
- return 0;
+ return 0;
+}
+
+grub_err_t
+gpt_partition_map_gpt_iterate(grub_disk_t disk, void (*hook) (grub_gpt_partentry_t entry))
+{
+ auto int hook_func(grub_disk_t hook_disk, const grub_partition_t partition, grub_gpt_partentry_t entry);
+
+ int hook_func(grub_disk_t hook_disk, const grub_partition_t partition, grub_gpt_partentry_t entry)
+ {
+ if (hook_disk->partition->index == partition->index)
+ {
+ hook(entry);
+ }
+ return 0;
+ }
+
+ return gpt_partition_map_iterate_internal(disk, hook_func);
+}
+
+static grub_err_t
+gpt_partition_map_iterate (grub_disk_t disk,
+ int (*hook) (grub_disk_t disk,
+ const grub_partition_t partition))
+{
+ auto int hook_func(grub_disk_t hook_disk, const grub_partition_t partition, grub_gpt_partentry_t entry);
+ int hook_func(grub_disk_t hook_disk, const grub_partition_t partition, grub_gpt_partentry_t entry)
+ {
+ if (entry->guid)
+ return hook(hook_disk, partition);
+ }
+
+ return gpt_partition_map_iterate_internal(disk, hook_func);
}
=== modified file 'po/POTFILES'
--- po/POTFILES 2010-01-21 08:04:49 +0000
+++ po/POTFILES 2010-02-12 16:48:29 +0000
@@ -40,6 +40,7 @@
commands/search_file.c
commands/search_label.c
commands/search_uuid.c
+commands/search_guid.c
commands/sleep.c
commands/test.c
commands/true.c
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [patch] search for partition using GPT GUID
2010-02-12 18:21 [patch] search for partition using GPT GUID George Buranov
@ 2010-02-18 7:13 ` gburanov
2010-02-20 11:05 ` Vladimir 'φ-coder/phcoder' Serbinenko
0 siblings, 1 reply; 7+ messages in thread
From: gburanov @ 2010-02-18 7:13 UTC (permalink / raw)
To: grub-devel
What about this patch? It is possible to integrate it, at least in the experimental branch?
--
This message was sent on behalf of gburanov@gmail.com at openSubscriber.com
http://www.opensubscriber.com/message/grub-devel@gnu.org/13421616.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [patch] search for partition using GPT GUID
2010-02-18 7:13 ` gburanov
@ 2010-02-20 11:05 ` Vladimir 'φ-coder/phcoder' Serbinenko
2010-02-21 12:32 ` Michal Suchanek
2010-02-25 6:59 ` gburanov
0 siblings, 2 replies; 7+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2010-02-20 11:05 UTC (permalink / raw)
To: The development of GNU GRUB
[-- Attachment #1: Type: text/plain, Size: 641 bytes --]
gburanov@gmail.com wrote:
> What about this patch? It is possible to integrate it, at least in the experimental branch?
>
>
I asked you for at least a usecase when it makes a difference but till
now I've read only about theoretical advantages.
> --
> This message was sent on behalf of gburanov@gmail.com at openSubscriber.com
> http://www.opensubscriber.com/message/grub-devel@gnu.org/13421616.html
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>
>
--
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 293 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [patch] search for partition using GPT GUID
2010-02-20 11:05 ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2010-02-21 12:32 ` Michal Suchanek
2010-02-21 13:27 ` Colin Watson
2010-02-25 6:59 ` gburanov
1 sibling, 1 reply; 7+ messages in thread
From: Michal Suchanek @ 2010-02-21 12:32 UTC (permalink / raw)
To: The development of GNU GRUB
2010/2/20 Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com>:
> gburanov@gmail.com wrote:
>> What about this patch? It is possible to integrate it, at least in the experimental branch?
>>
>>
> I asked you for at least a usecase when it makes a difference but till
> now I've read only about theoretical advantages.
It has been explained that using the NTFS UUID is about equivalent of
using the volume label. If it is sufficient why are we using UUIDs at
all? We can use the much more readable labels everywhere and get rid
of those long and impractical UUIDs completely.
Thanks
Michal
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [patch] search for partition using GPT GUID
2010-02-21 12:32 ` Michal Suchanek
@ 2010-02-21 13:27 ` Colin Watson
0 siblings, 0 replies; 7+ messages in thread
From: Colin Watson @ 2010-02-21 13:27 UTC (permalink / raw)
To: grub-devel
On Sun, Feb 21, 2010 at 01:32:15PM +0100, Michal Suchanek wrote:
> It has been explained that using the NTFS UUID is about equivalent of
> using the volume label. If it is sufficient why are we using UUIDs at
> all? We can use the much more readable labels everywhere and get rid
> of those long and impractical UUIDs completely.
Volume labels (in the general case; I don't know specifically about
NTFS) are set by system administrators by hand. GRUB cannot assume that
any filesystem has a volume label, or that they don't clash. (For
example, Red Hat's installer used to have the unwise policy of setting
labels to match the mount point; thus two Red Hat installations on the
same machine would produce label collisions.)
The appropriate policy for use of labels is to permit them to be used
when requested by the system administrator, but not to use them by
default.
I posted an analysis of all the generic available methods for filesystem
identification to debian-boot a while back:
http://lists.debian.org/debian-boot/2008/12/msg00338.html
--
Colin Watson [cjwatson@ubuntu.com]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Re: [patch] search for partition using GPT GUID
2010-02-20 11:05 ` Vladimir 'φ-coder/phcoder' Serbinenko
2010-02-21 12:32 ` Michal Suchanek
@ 2010-02-25 6:59 ` gburanov
2010-04-02 20:01 ` Vladimir 'φ-coder/phcoder' Serbinenko
1 sibling, 1 reply; 7+ messages in thread
From: gburanov @ 2010-02-25 6:59 UTC (permalink / raw)
To: grub-devel
> I asked you for at least a usecase when it makes a difference but till
> now I've read only about theoretical advantages.
Ok, my usecase is the following:
We are installing grub to EFI system partition and on the next load it must load itself (rmadisk&kernel) from Windows partiton (where our main product is installed). It need however to find the NTFS partition with our product, the only ways is GPT GUID.
Out of Linux world FS UUID is nothing, our main product works on Windows, and the only way to identify the partition correctly - GUID. UEFI spec also use GPT GUIDs in it's "device path", same as Windows.
grub2 is not for Linux load only.
--
This message was sent on behalf of gburanov@gmail.com at openSubscriber.com
http://www.opensubscriber.com/message/grub-devel@gnu.org/13458994.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [patch] search for partition using GPT GUID
2010-02-25 6:59 ` gburanov
@ 2010-04-02 20:01 ` Vladimir 'φ-coder/phcoder' Serbinenko
0 siblings, 0 replies; 7+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2010-04-02 20:01 UTC (permalink / raw)
To: The development of GNU GRUB
[-- Attachment #1: Type: text/plain, Size: 1596 bytes --]
gburanov@gmail.com wrote:
>> I asked you for at least a usecase when it makes a difference but till
>> now I've read only about theoretical advantages.
>>
>
> Ok, my usecase is the following:
> We are installing grub to EFI system partition and on the next load it must load itself (rmadisk&kernel) from Windows partiton (where our main product is installed). It need however to find the NTFS partition with our product, the only ways is GPT GUID.
>
> Out of Linux world FS UUID is nothing, our main product works on Windows, and the only way to identify the partition correctly - GUID. UEFI spec also use GPT GUIDs in it's "device path", same as Windows.
>
> grub2 is not for Linux load only.
>
>
I thought about this and decided that it's ok to have this functionality
as long as it's implemented cleanly. In particular:
- It shouldn't be named "GPT GUID" but something like PARTITION GUID. If
partition is GPT then GPT UUIDs are used, if it's msdos then nt-like
UUIDs should be used and so on. You don't have to implement non-GPT but
arcitecture must be clean
- It must not give any size increase of basic modules
- grub-probe must support it (trivial)
- Not used by default
> --
> This message was sent on behalf of gburanov@gmail.com at openSubscriber.com
> http://www.opensubscriber.com/message/grub-devel@gnu.org/13458994.html
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> http://lists.gnu.org/mailman/listinfo/grub-devel
>
>
--
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 293 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2010-04-02 20:01 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-12 18:21 [patch] search for partition using GPT GUID George Buranov
2010-02-18 7:13 ` gburanov
2010-02-20 11:05 ` Vladimir 'φ-coder/phcoder' Serbinenko
2010-02-21 12:32 ` Michal Suchanek
2010-02-21 13:27 ` Colin Watson
2010-02-25 6:59 ` gburanov
2010-04-02 20:01 ` Vladimir 'φ-coder/phcoder' Serbinenko
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.