Skip to contentSkip to conversation

Fix grub-probe with userland partition support

PATCH In review Samuel Thibault 2 participants 38 messages Apr 22, 2012 – May 3, 2012 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix grub-probe with userland partition support

Hello,

GNU/Hurd is moving to userland partition support, i.e. /dev/hd0s* slices are actually served by userland translators which use libparted. The grub probe code needs to be fixed for that, here is a proposed patch.

The principle is that it gets the store translator behind the file being probed for, and compares the storage area there with what grub detects itself. That is why it makes use of the map array, which I preferred to rename to hostdisk_map (thus big but trivial changes in hostdisk.c):
even if it was already an external symbol, it's preferrable to prefix it.

Samuel

=== modified file 'Makefile.util.def'

Makefile.util.def +4 -4
@@ -170,7 +170,7 @@
   ldadd = libgrubgcry.a;
   ldadd = libgrubkern.a;
   ldadd = grub-core/gnulib/libgnu.a;
-  ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)';
+  ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM) $(LIBSTORE)';
 };
 
 program = {
@@ -300,7 +300,7 @@
   ldadd = libgrubgcry.a;
   ldadd = libgrubkern.a;
   ldadd = grub-core/gnulib/libgnu.a;
-  ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)';
+  ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM) $(LIBSTORE)';
 };
 
 program = {
@@ -316,7 +316,7 @@
   ldadd = libgrubkern.a;
   ldadd = libgrubgcry.a;
   ldadd = grub-core/gnulib/libgnu.a;
-  ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)';
+  ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM) $(LIBSTORE)';
   cppflags = '-DGRUB_SETUP_BIOS=1';
 };
 
@@ -334,7 +334,7 @@
   ldadd = libgrubkern.a;
   ldadd = libgrubgcry.a;
   ldadd = grub-core/gnulib/libgnu.a;
-  ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)';
+  ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM) $(LIBSTORE)';
   cppflags = '-DGRUB_SETUP_SPARC64=1';
 };
 

=== modified file 'configure.ac'

configure.ac +12 -0
@@ -341,6 +341,18 @@
 ])
 AC_SUBST([LIBUTIL])
 
+# On Hurd we need libstore for util/getroot.c
+case "$host_kernel" in 
+  hurd)
+    AC_CHECK_HEADER([hurd/store.h], [], [AC_MSG_ERROR([hurd/store.h is needed])])
+    AC_CHECK_LIB([store], [store_create], [], [AC_MSG_ERROR([libstore is needed])])
+    LIBSTORE="-lstore"
+    ;;
+  *)
+    ;;
+esac
+AC_SUBST([LIBSTORE])
+
 #
 # Check for host and build compilers.
 #

=== modified file 'grub-core/kern/emu/hostdisk.c'

kern/emu/hostdisk.c +53 -58

278 lines not on this page · raw message

=== modified file 'include/grub/emu/hostdisk.h'

grub/emu/hostdisk.h +9 -0
@@ -24,6 +24,15 @@
 #include <grub/partition.h>
 #include <sys/types.h>
 
+struct hostdisk_map
+{
+  char *drive;
+  char *device;
+  int device_map;
+};
+
+extern struct hostdisk_map hostdisk_map[256];
+
 void grub_util_biosdisk_init (const char *dev_map);
 void grub_util_biosdisk_fini (void);
 char *grub_util_biosdisk_get_grub_dev (const char *os_dev);

=== modified file 'util/getroot.c'

getroot.c +153 -60

243 lines not on this page · raw message

#1 lore raw
Quoted 6 lines · Samuel Thibault

Hello,

GNU/Hurd is moving to userland partition support, i.e. /dev/hd0s* slices are actually served by userland translators which use libparted. The grub probe code needs to be fixed for that, here is a proposed patch.

Quoted 6 lines

The principle is that it gets the store translator behind the file being probed for, and compares the storage area there with what grub detects itself. That is why it makes use of the map array, which I preferred to rename to hostdisk_map (thus big but trivial changes in hostdisk.c):
even if it was already an external symbol, it's preferrable to prefix it.

map was never intended to be globally visible. At most perhaps "semi-local" due to difficulties of split between getroot.c and hostdisk.c Moreover the behaviour of find_root_device must be independent of what is already in map since we don't rely anymore at map being populated at all and at entries only on as-needed basis.
Additional problems include:

+ if (disk->dev->id != GRUB_DISK_DEVICE_BIOSDISK_ID && disk->dev->id != GRUB_DISK_DEVICE_HOSTDISK_ID)
+ {
No need to check for BIOSDISK. It's not used for hostdisk.
+ store_offset_t start = partition->start * GRUB_DISK_SECTOR_SIZE,
+ length = partition->len * GRUB_DISK_SECTOR_SIZE,
This is both stylistically incorrect and wrong.
Stylistically at declaration we repeat type on every line.
Additionally partition->start is only relative to container, not whole disk. You have to use grub_disk_partition_get_start for this.

Quoted 8 lines

Samuel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#2 lore raw
Quoted 5 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Mon 23 Apr 2012 10:52:09 +0200, a…

map was never intended to be globally visible. At most perhaps "semi-local" due to difficulties of split between getroot.c and hostdisk.c Moreover the behaviour of find_root_device must be independent of what is already in map since we don't rely anymore at map being populated at all and at entries only on as-needed basis.

How can I get the same information, then? (the unix path corresponding to a disk opened with grub_disk_open())

Samuel

#3 lore raw
Quoted 8 lines · Samuel Thibault
Quoted 5 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Mon 23 Apr 2012 10:52:09 +0200, a…

map was never intended to be globally visible. At most perhaps "semi-local" due to difficulties of split between getroot.c and hostdisk.c Moreover the behaviour of find_root_device must be independent of what is already in map since we don't rely anymore at map being populated at all and at entries only on as-needed basis.

How can I get the same information, then? (the unix path corresponding to a disk opened with grub_disk_open())

The problem is bigger than just getting the device from a disk. The problem is that you assume that grub_disk_dev_iterate will go through the disk in question which isn't necessarily true.

Quoted 6 lines

Samuel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#4 lore raw
Quoted 7 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Mon 23 Apr 2012 12:45:09 +0200, a…
Quoted 6 lines · Samuel Thibault
Quoted 5 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Mon 23 Apr 2012 10:52:09 +0200, a…

map was never intended to be globally visible. At most perhaps "semi-local" due to difficulties of split between getroot.c and hostdisk.c Moreover the behaviour of find_root_device must be independent of what is already in map since we don't rely anymore at map being populated at all and at entries only on as-needed basis.

Quoted 5 lines
Quoted 2 lines

How can I get the same information, then? (the unix path corresponding to a disk opened with grub_disk_open())

The problem is bigger than just getting the device from a disk. The problem is that you assume that grub_disk_dev_iterate will go through the disk in question which isn't necessarily true.

And so?

Our need is to iterate over all disks that GRUB sees, to match that with where the file resides.

Samuel

#5 lore raw
Quoted 10 lines · Samuel Thibault
Quoted 9 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Mon 23 Apr 2012 12:45:09 +0200, a…
Quoted 8 lines · Samuel Thibault
Quoted 5 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Mon 23 Apr 2012 10:52:09 +0200, a…

map was never intended to be globally visible. At most perhaps "semi-local" due to difficulties of split between getroot.c and hostdisk.c Moreover the behaviour of find_root_device must be independent of what is already in map since we don't rely anymore at map being populated at all and at entries only on as-needed basis.

How can I get the same information, then? (the unix path corresponding to a disk opened with grub_disk_open())

Quoted 7 lines
Quoted 3 lines

The problem is bigger than just getting the device from a disk. The problem is that you assume that grub_disk_dev_iterate will go through the disk in question which isn't necessarily true.

And so?

Our need is to iterate over all disks that GRUB sees, to match that with where the file resides.

It looks like you have missed some of 2.00 developement. We auto-add the device to map if necessary right after find_root_devices so at find_root_devices the disk won't be seen yet but find_root_devices has to work nevertheless.
This function has nothing to do with the rest of GRUB. It could be a standalone program with syntax like
find_root_devices DIR
Output:
/dev/sda1 /dev/sdb2
Any of GRUB context is irrelevant. (and actually so is the GRUB partition view, but you can use partition functions as they are stateless but beware that their view is likely to be different from GRUB's one).

Quoted 6 lines

Samuel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#6 lore raw
Quoted 4 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Mon 23 Apr 2012 13:17:15 +0200, a…
Quoted 2 lines · Samuel Thibault

Our need is to iterate over all disks that GRUB sees, to match that with where the file resides.

It looks like you have missed some of 2.00 developement.

I don't really follow GRUB development.

Quoted 1 line

This function has nothing to do with the rest of GRUB.

Right. That's not how we were considering things due to more possibilites on the Hurd, but I won't try to fight against that, I have other things to spend time on :)

Samuel

#7 lore raw

Here is a revamped patch.

Samuel

=== modified file 'Makefile.util.def'

Makefile.util.def +4 -4
@@ -170,7 +170,7 @@
   ldadd = libgrubgcry.a;
   ldadd = libgrubkern.a;
   ldadd = grub-core/gnulib/libgnu.a;
-  ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)';
+  ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM) $(LIBSTORE)';
 };
 
 program = {
@@ -300,7 +300,7 @@
   ldadd = libgrubgcry.a;
   ldadd = libgrubkern.a;
   ldadd = grub-core/gnulib/libgnu.a;
-  ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)';
+  ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM) $(LIBSTORE)';
 };
 
 program = {
@@ -316,7 +316,7 @@
   ldadd = libgrubkern.a;
   ldadd = libgrubgcry.a;
   ldadd = grub-core/gnulib/libgnu.a;
-  ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)';
+  ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM) $(LIBSTORE)';
   cppflags = '-DGRUB_SETUP_BIOS=1';
 };
 
@@ -334,7 +334,7 @@
   ldadd = libgrubkern.a;
   ldadd = libgrubgcry.a;
   ldadd = grub-core/gnulib/libgnu.a;
-  ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM)';
+  ldadd = '$(LIBINTL) $(LIBDEVMAPPER) $(LIBUTIL) $(LIBZFS) $(LIBNVPAIR) $(LIBGEOM) $(LIBSTORE)';
   cppflags = '-DGRUB_SETUP_SPARC64=1';
 };
 

=== modified file 'configure.ac'

configure.ac +12 -0
@@ -341,6 +341,18 @@
 ])
 AC_SUBST([LIBUTIL])
 
+# On Hurd we need libstore for kern/emu/getroot.c
+case "$host_kernel" in 
+  hurd)
+    AC_CHECK_HEADER([hurd/store.h], [], [AC_MSG_ERROR([hurd/store.h is needed])])
+    AC_CHECK_LIB([store], [store_create], [], [AC_MSG_ERROR([libstore is needed])])
+    LIBSTORE="-lstore"
+    ;;
+  *)
+    ;;
+esac
+AC_SUBST([LIBSTORE])
+
 #
 # Check for host and build compilers.
 #

=== modified file 'util/getroot.c'

getroot.c +118 -60

216 lines not on this page · raw message

#8 lore raw

Review

Quoted 2 lines · Samuel Thibault
(quoted diff) +2 -0
+	  if (errno == ENOENT && part >= 5)
+	    {

This introduces an assumption that if part >=5 is missing then there are no additional partitions. While this is true for msdos, it's false for GPT, where such config is common after deleting a partition. Moreover, APM (apple) partitions often start at 8.

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#9 lore raw
Quoted 7 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Tue 24 Apr 2012 10:55:21 +0200, a…

Review

Quoted 2 lines · Samuel Thibault
(quoted diff) +2 -0
+	  if (errno == ENOENT && part >= 5)
+	    {

This introduces an assumption that if part >=5 is missing then there are no additional partitions. While this is true for msdos, it's false for GPT, where such config is common after deleting a partition. Moreover, APM (apple) partitions often start at 8.

Ok, but what do you suggest? By the very nature of parted-based translators, there is no way to know how many partitions there are.

Samuel

#10 lore raw
Quoted 10 lines · Samuel Thibault
Quoted 7 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Tue 24 Apr 2012 10:55:21 +0200, a…

Review

Quoted 2 lines · Samuel Thibault
(quoted diff) +2 -0
+	  if (errno == ENOENT && part >= 5)
+	    {

This introduces an assumption that if part >=5 is missing then there are no additional partitions. While this is true for msdos, it's false for GPT, where such config is common after deleting a partition. Moreover, APM (apple) partitions often start at 8.

Ok, but what do you suggest? By the very nature of parted-based translators, there is no way to know how many partitions there are.

Can we know whether given device is partition? If we know that it is we can iterate as long as we can, adding some restriction like your 1000 and issuing error if it's hit since it should never happen.

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#11 lore raw
Quoted 9 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Tue 24 Apr 2012 11:12:11 +0200, a…
Quoted 8 lines · Samuel Thibault
Quoted 7 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Tue 24 Apr 2012 10:55:21 +0200, a…

Review

Quoted 2 lines · Samuel Thibault
(quoted diff) +2 -0
+	  if (errno == ENOENT && part >= 5)
+	    {

This introduces an assumption that if part >=5 is missing then there are no additional partitions. While this is true for msdos, it's false for GPT, where such config is common after deleting a partition. Moreover, APM (apple) partitions often start at 8.

Quoted 5 lines
Quoted 2 lines

Ok, but what do you suggest? By the very nature of parted-based translators, there is no way to know how many partitions there are.

Can we know whether given device is partition? If we know that it is we can iterate as long as we can, adding some restriction like your 1000 and issuing error if it's hit since it should never happen.

I don't see how knowing whether the device is partition will help to know where to stop. A user could very well have all partition nodes in /dev up to 100, they'll all be partitions. Whether they actually exist is another story, but as you say, you can't assume anything with the absence of a partition.

Samuel

#12 lore raw
Quoted 12 lines · Samuel Thibault
Quoted 11 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Tue 24 Apr 2012 11:12:11 +0200, a…
Quoted 10 lines · Samuel Thibault
Quoted 7 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Tue 24 Apr 2012 10:55:21 +0200, a…

Review

Quoted 2 lines · Samuel Thibault
(quoted diff) +2 -0
+	  if (errno == ENOENT && part >= 5)
+	    {

This introduces an assumption that if part >=5 is missing then there are no additional partitions. While this is true for msdos, it's false for GPT, where such config is common after deleting a partition. Moreover, APM (apple) partitions often start at 8.

Ok, but what do you suggest? By the very nature of parted-based translators, there is no way to know how many partitions there are.

Quoted 8 lines
Quoted 3 lines

Can we know whether given device is partition? If we know that it is we can iterate as long as we can, adding some restriction like your 1000 and issuing error if it's hit since it should never happen.

I don't see how knowing whether the device is partition will help to know where to stop. A user could very well have all partition nodes in /dev up to 100, they'll all be partitions. Whether they actually exist is another story, but as you say, you can't assume anything with the absence of a partition.

Theoretically you shouldn't stop until you find the partition if you know that your device is partition since it means that Hurd knows the partition in question.

Quoted 7 lines

Samuel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#13 lore raw
Quoted 2 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Tue 24 Apr 2012 11:26:46 +0200, a…

Theoretically you shouldn't stop until you find the partition if you know that your device is partition

What do you precisely mean by "device"?

What we don't know is whether the root storage for the file is partitioned or not.

Samuel

#14 lore raw
Quoted 5 lines · Samuel Thibault, le Tue 24 Apr 2012 11:36:27 +0200, a écrit :
Quoted 2 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Tue 24 Apr 2012 11:26:46 +0200, a…

Theoretically you shouldn't stop until you find the partition if you know that your device is partition

What do you precisely mean by "device"?

I mean "your device", not device in general: what variable are you talking about in the source.

Samuel

#15 lore raw
Quoted 7 lines · Samuel Thibault
Quoted 4 lines · Samuel Thibault, le Tue 24 Apr 2012 11:36:27 +0200, a écrit :
Quoted 2 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Tue 24 Apr 2012 11:26:46 +0200, a…

Theoretically you shouldn't stop until you find the partition if you know that your device is partition

What do you precisely mean by "device"?

I mean "your device", not device in general: what variable are you talking about in the source.

I meant: if we know that /boot/grub/grub.cfg resides on a partition then we can iterate as long as we need to.

Quoted 6 lines

Samuel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#16 lore raw
Quoted 10 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Tue 24 Apr 2012 11:44:35 +0200, a…
Quoted 7 lines · Samuel Thibault
Quoted 4 lines · Samuel Thibault, le Tue 24 Apr 2012 11:36:27 +0200, a écrit :
Quoted 2 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Tue 24 Apr 2012 11:26:46 +0200, a…

Theoretically you shouldn't stop until you find the partition if you know that your device is partition

What do you precisely mean by "device"?

I mean "your device", not device in general: what variable are you talking about in the source.

I meant: if we know that /boot/grub/grub.cfg resides on a partition then we can iterate as long as we need to.

We don't know whether grub.cfg resides on a partition.

Samuel

#17 lore raw
In reply to Samuel Thibault
Quoted 7 lines · Samuel Thibault
getroot.c +7 -0
+/* Retrieve the storage information for PATH, and search which partitions
+ * contains its start.  */
+static char *
+find_hurd_root_device (const char *path)
+{
+  struct store *path_store, *part_store;
+  char *devpath = NULL;

getroot.c line 744

Quoted 10 lines
getroot.c +10 -0
+  const char *prefix;
+  size_t len, prefix_len;
+  store_offset_t path_start;
+  int part;
+
+  path_store = storeinfo_store (path);
+  if (! path_store)
+    grub_util_error ("Could not retrieve storage information for `%s'", path);
+  if (! path_store->name)
+    grub_util_error ("No storage name associated with `%s'", path);

grub_util_error messages should be marked for translation. And probably have a TRANSLATORS comment about the context.

getroot.c line 756

Quoted 12 lines
getroot.c +12 -0
+
+  grub_util_info ("Storage is %s, type %d",
+      path_store->name, path_store->class->id);
+
+  if (path_store->class->id == STORAGE_DEVICE)
+    prefix = "/dev/";
+  else
+    prefix = "";
+
+  prefix_len = strlen (prefix);
+  len = strlen (path_store->name);
+  devpath = xmalloc (prefix_len + len + 4 + 1);

It's better to have an explicit sizeof ("s999") rather than 4 + 1

Review

Quoted 2 lines
(quoted diff) +2 -0
+	  if (errno == ENOENT && part >= 5)
+	    {

Said in previous mail

getroot.c line 790

Quoted 2 lines
getroot.c +2 -0
+      if (first_run->start * part_store->block_size <= path_start &&
+	  (last_run->start + last_run->length) * part_store->block_size > path_start) {

Why this weird check rather than just check that start is the same? Some partitions may contain more partitions, like logical container contains logical partitions.

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#18 lore raw
Quoted 12 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Tue 24 Apr 2012 11:04:46 +0200, a…
Quoted 11 lines · Samuel Thibault
getroot.c +11 -0
+/* Retrieve the storage information for PATH, and search which partitions
+ * contains its start.  */
+static char *
+find_hurd_root_device (const char *path)
+{
+  struct store *path_store, *part_store;
+  char *devpath = NULL;
+  const char *prefix;
+  size_t len, prefix_len;
+  store_offset_t path_start;
+  int part;
Quoted 8 lines

getroot.c line 744

Quoted 6 lines
getroot.c +6 -0
+
+  path_store = storeinfo_store (path);
+  if (! path_store)
+    grub_util_error ("Could not retrieve storage information for `%s'", path);
+  if (! path_store->name)
+    grub_util_error ("No storage name associated with `%s'", path);

grub_util_error messages should be marked for translation. And probably have a TRANSLATORS comment about the context.

Ah, I had only had a look at the existing grub_util_info calls, which are not marked for translation.

Quoted 3 lines

getroot.c line 790

Quoted 2 lines
getroot.c +2 -0
+      if (first_run->start * part_store->block_size <= path_start &&
+	  (last_run->start + last_run->length) * part_store->block_size > path_start) {

Why this weird check rather than just check that start is the same?

Because path_start is the start of the file, not of the partition containing the file.

Quoted 2 lines

Some partitions may contain more partitions, like logical container contains logical partitions.

Yes, but we do not have defined /dev namings for these yet, so we don't know how to look for them grom GRUB yet.

Samuel

#19 lore raw
Quoted 7 lines · Samuel Thibault

Because path_start is the start of the file, not of the partition containing the file.

Quoted 2 lines
Quoted 2 lines

Some partitions may contain more partitions, like logical container contains logical partitions.

Yes, but we do not have defined /dev namings for these yet, so we don't know how to look for them grom GRUB yet.

That 2 comments together open the can of worms. Second one would imply we should take the smallest partition containing the given file. E.g. One could have
hd0s1 containing hd0s5 and hd0s6. In this case we want hd0s5 and not hd0s1. On the other hand a file may reside in partition but be part of a filesystem spanning through the whole disk. This is common for all kinds of hybrid CDROMs, including the ones created by grub-mkrescue. They have iso9660 spanning through the whole disk but all of the disk other than the first sector is in some kind of partition table to avoid it being accidentally overwritten. So even though the file itself is inside a partition, we want the whole disk.
Also if file is 0-sized, sparse, compressed or encrypted it won't have blocklist and this approach would fail, possibly even with out-of-range array access.
I'm surprised that Hurd doesn't offer a way to just ask "What does this filesystem translator consume?"

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#20 lore raw
Quoted 1 line · Vladimir 'φ-coder/phcoder' Serbinenko, le Tue 24 Apr 2012 11:55:33 +0200, a…

One could have hd0s1 containing hd0s5 and hd0s6.

Argl, I forgot that case indeed. It's funny how that contracts the very word "partition"...

Quoted 8 lines

In this case we want hd0s5 and not hd0s1. On the other hand a file may reside in partition but be part of a filesystem spanning through the whole disk. This is common for all kinds of hybrid CDROMs, including the ones created by grub-mkrescue. They have iso9660 spanning through the whole disk but all of the disk other than the first sector is in some kind of partition table to avoid it being accidentally overwritten. So even though the file itself is inside a partition, we want the whole disk.

The partition itself can not be mounted?

Quoted 3 lines

Also if file is 0-sized, sparse, compressed or encrypted it won't have blocklist and this approach would fail, possibly even with out-of-range array access.

Other than 0-sized would work, the eventual storage would still be on the partition.

0-sized indeed poses problems.

Quoted 2 lines

I'm surprised that Hurd doesn't offer a way to just ask "What does this filesystem translator consume?"

Because the whole point of the Hurd is to let the user have access to more powerful ways. A file can reside inside an iso file, which is stored in an ext2fs, which is stored in a file, using the user's own translator with no constraint on the naming convention, etc. etc. That's why it generally does not make sense to know where a file comes from, because you would not know how to parse the result. The proper way would be asking the FS, which may tell you

/hurd/ext2fs --writable --no-inherit-dir-group /dev/hd0s1

or

ext2fs --writable --no-atime --no-inherit-dir-group --store-type=typed device:hd1

But we generally don't want to impose any syntax here, it could actually be

/opt/my/own/translator xyz

I guess we'll have to impose some syntax anyway for whatever contains /boot, so that grub can open it itself.

Samuel

#21 lore raw
Quoted 13 lines · Samuel Thibault
Quoted 1 line · Vladimir 'φ-coder/phcoder' Serbinenko, le Tue 24 Apr 2012 11:55:33 +0200, a…

One could have hd0s1 containing hd0s5 and hd0s6.

Argl, I forgot that case indeed. It's funny how that contracts the very word "partition"...

Quoted 8 lines

In this case we want hd0s5 and not hd0s1. On the other hand a file may reside in partition but be part of a filesystem spanning through the whole disk. This is common for all kinds of hybrid CDROMs, including the ones created by grub-mkrescue. They have iso9660 spanning through the whole disk but all of the disk other than the first sector is in some kind of partition table to avoid it being accidentally overwritten. So even though the file itself is inside a partition, we want the whole disk.

Quoted 1 line

The partition itself can not be mounted?

No, since it contains FS structures at wrong offset.

Quoted 5 lines
Quoted 3 lines

Also if file is 0-sized, sparse, compressed or encrypted it won't have blocklist and this approach would fail, possibly even with out-of-range array access.

Other than 0-sized would work, the eventual storage would still be on the partition.

completely sparse just has a size and not backed by any storage.

Quoted 7 lines

0-sized indeed poses problems.

Quoted 2 lines

I'm surprised that Hurd doesn't offer a way to just ask "What does this filesystem translator consume?"

Because the whole point of the Hurd is to let the user have access to more powerful ways. A file can reside inside an iso file, which is stored in an ext2fs, which is stored in a file,

So much GRUB can handle. We don't handle loopback automatically right now since it's not clear whether it's a loopback for VM or loopback used on host.

Quoted 2 lines

using the user's
own translator with no constraint on the naming convention, etc. etc.

For these ones we're limited at what GRUB can. grub-probe is used for 2 purposes:
1) Determining the device for root, its FS and UUID
2) Determining the GRUB environment on boot.
The first is used in grub-mkconfig and if Hurd is so much more flexible 10_hurd.in may need to be adjusted accordingly.
As for the second, we're limited to what GRUB can do and so it won't be possible to have /boot on translator from hyperspace. grub-probe should error-out if it reaches a translator which can't be handled by GRUB.

Quoted 10 lines

That's why it generally does not make sense to know where a file comes from, because you would not know how to parse the result. The proper way would be asking the FS, which may tell you

/hurd/ext2fs --writable --no-inherit-dir-group /dev/hd0s1

or

ext2fs --writable --no-atime --no-inherit-dir-group --store-type=typed device:hd1

Quoted 7 lines

But we generally don't want to impose any syntax here, it could actually be

/opt/my/own/translator xyz

I guess we'll have to impose some syntax anyway for whatever contains /boot, so that grub can open it itself.

There should be a standartised way to get this information for any conventional FS, otherwise it makes porting programs which use this information much more difficult and in most cases results in dirty workarounds.

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#22 lore raw
Quoted 9 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Tue 24 Apr 2012 15:19:25 +0200, a…
Quoted 7 lines · Samuel Thibault
Quoted 5 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Tue 24 Apr 2012 11:55:33 +0200, a…

They have iso9660 spanning through
the whole disk but all of the disk other than the first sector is in some kind of partition table to avoid it being accidentally overwritten. So even though the file itself is inside a partition, we want the whole disk.

The partition itself can not be mounted?

No, since it contains FS structures at wrong offset.

Ok.

Quoted 6 lines
Quoted 5 lines
Quoted 3 lines

Also if file is 0-sized, sparse, compressed or encrypted it won't have blocklist and this approach would fail, possibly even with out-of-range array access.

Other than 0-sized would work, the eventual storage would still be on the partition.

completely sparse just has a size and not backed by any storage.

That's included in "0-size" in my head :)

Quoted 8 lines
Quoted 7 lines

0-sized indeed poses problems.

Quoted 2 lines

I'm surprised that Hurd doesn't offer a way to just ask "What does this filesystem translator consume?"

Because the whole point of the Hurd is to let the user have access to more powerful ways. A file can reside inside an iso file, which is stored in an ext2fs, which is stored in a file,

So much GRUB can handle.

But how to express that to GRUB? grub_guess_root_devices only returns a series of alternative paths. See below.

Quoted 2 lines

We don't handle loopback automatically right now since it's not clear whether it's a loopback for VM or loopback used on host.

You'd need to know which files to open anyway. You don't want to browse all filesystems for that :) So the OS-specific function has to tell you.

Quoted 8 lines
Quoted 2 lines

using the user's
own translator with no constraint on the naming convention, etc. etc.

For these ones we're limited at what GRUB can. grub-probe is used for 2 purposes:
1) Determining the device for root, its FS and UUID
2) Determining the GRUB environment on boot.
The first is used in grub-mkconfig and if Hurd is so much more flexible 10_hurd.in may need to be adjusted accordingly.

Sure.

Quoted 2 lines

As for the second, we're limited to what GRUB can do and so it won't be possible to have /boot on translator from hyperspace.

Sure. But it can be something expressed in a complex way by the user, which can actually be reached by GRUB. That said, as I said earlier, we can ask the user to refrain himself when it's about /boot.

Quoted 11 lines
Quoted 7 lines

But we generally don't want to impose any syntax here, it could actually be

/opt/my/own/translator xyz

I guess we'll have to impose some syntax anyway for whatever contains /boot, so that grub can open it itself.

There should be a standartised way to get this information for any conventional FS, otherwise it makes porting programs which use this information much more difficult and in most cases results in dirty workarounds.

So far, I've mostly seen GRUB really needing that information.

Samuel

#23 lore raw
Quoted 11 lines · Samuel Thibault
Quoted 9 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Tue 24 Apr 2012 15:19:25 +0200, a…
Quoted 7 lines · Samuel Thibault
Quoted 5 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Tue 24 Apr 2012 11:55:33 +0200, a…

They have iso9660 spanning through
the whole disk but all of the disk other than the first sector is in some kind of partition table to avoid it being accidentally overwritten. So even though the file itself is inside a partition, we want the whole disk.

The partition itself can not be mounted?

No, since it contains FS structures at wrong offset.

Ok.

BTW sometimes partition can be mounted but contains another FS which references the same file by another name or not at all.

Quoted 10 lines
Quoted 8 lines
Quoted 7 lines

0-sized indeed poses problems.

Quoted 2 lines

I'm surprised that Hurd doesn't offer a way to just ask "What does this filesystem translator consume?"

Because the whole point of the Hurd is to let the user have access to more powerful ways. A file can reside inside an iso file, which is stored in an ext2fs, which is stored in a file,

So much GRUB can handle.

But how to express that to GRUB? grub_guess_root_devices only returns a series of alternative paths. See below.

By just giving the file in question.
But it currently always suppose that the file will be for VM and not host use.

Quoted 4 lines
Quoted 2 lines

We don't handle loopback automatically right now since it's not clear whether it's a loopback for VM or loopback used on host.

You'd need to know which files to open anyway. You don't want to browse all filesystems for that :) So the OS-specific function has to tell you.

Yes.

Quoted 5 lines
Quoted 2 lines

As for the second, we're limited to what GRUB can do and so it won't be possible to have /boot on translator from hyperspace.

Sure. But it can be something expressed in a complex way by the user, which can actually be reached by GRUB. That said, as I said earlier, we can ask the user to refrain himself when it's about /boot.

We can add more translators handling as-needed. But this problem isn't Hurd-specific. A simple GNU/Linux example is unionfs: currently we can't traverse it even if it refers to something easy. Trouble is that unionfs/translator reference "foo" can point to different files depending on circumstances and we need to follow this changes if they happen behind the grub-mkconfig back (e.g. if unionfs had kernel just in branch1 and then it was moved to branch2 we would need to handle this change without rerunning grub-mkconfig).

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

But we generally don't want to impose any syntax here, it could actually be

/opt/my/own/translator xyz

Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

I guess we'll have to impose some syntax anyway for whatever contains /boot, so that grub can open it itself.

There should be a standartised way to get this information for any conventional FS, otherwise it makes porting programs which use this information much more difficult and in most cases results in dirty workarounds.

So far, I've mostly seen GRUB really needing that information.

I suppose that databases would want to know this for optimisations.

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#24 lore raw
Quoted 7 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Tue 24 Apr 2012 22:14:33 +0200, a…
Quoted 6 lines · Samuel Thibault
Quoted 5 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Tue 24 Apr 2012 15:19:25 +0200, a…
Quoted 4 lines · Samuel Thibault

0-sized indeed poses problems.

Quoted 2 lines

I'm surprised that Hurd doesn't offer a way to just ask "What does this filesystem translator consume?"

Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines

Because the whole point of the Hurd is to let the user have access to more powerful ways. A file can reside inside an iso file, which is stored in an ext2fs, which is stored in a file,

So much GRUB can handle.

But how to express that to GRUB? grub_guess_root_devices only returns a series of alternative paths. See below.

By just giving the file in question.

That will not tell you which image has to be mounted to find it.

Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

As for the second, we're limited to what GRUB can do and so it won't be possible to have /boot on translator from hyperspace.

Sure. But it can be something expressed in a complex way by the user, which can actually be reached by GRUB. That said, as I said earlier, we can ask the user to refrain himself when it's about /boot.

We can add more translators handling as-needed.

So would it be acceptable for now as a horrible-but-works solution to use the output of sysopts:

ext2fs --writable --no-atime --no-inherit-dir-group --store-type=typed device:hd1

and

/hurd/ext2fs --writable --no-inherit-dir-group /dev/hd0s1

Drop the first parameter (translator path), -* options, and that leaves only the device, with additional s_device:_/dev/_ mangling.

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

But we generally don't want to impose any syntax here, it could actually be

/opt/my/own/translator xyz

Quoted 8 lines
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

I guess we'll have to impose some syntax anyway for whatever contains /boot, so that grub can open it itself.

There should be a standartised way to get this information for any conventional FS, otherwise it makes porting programs which use this information much more difficult and in most cases results in dirty workarounds.

So far, I've mostly seen GRUB really needing that information.

I suppose that databases would want to know this for optimisations.

libstore does provide the best thing for that: the actual area on the disk, which is what was used in the very first patch already, and which is used for swap, etc. But that reveals to be actually too precise for GRUB.

Samuel

#25 lore raw
Quoted 8 lines · Samuel Thibault
Quoted 7 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Tue 24 Apr 2012 22:14:33 +0200, a…
Quoted 6 lines · Samuel Thibault
Quoted 5 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Tue 24 Apr 2012 15:19:25 +0200, a…
Quoted 4 lines · Samuel Thibault

0-sized indeed poses problems.

Quoted 2 lines

I'm surprised that Hurd doesn't offer a way to just ask "What does this filesystem translator consume?"

Quoted 8 lines
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines

Because the whole point of the Hurd is to let the user have access to more powerful ways. A file can reside inside an iso file, which is stored in an ext2fs, which is stored in a file,

So much GRUB can handle.

But how to express that to GRUB? grub_guess_root_devices only returns a series of alternative paths. See below.

By just giving the file in question.

That will not tell you which image has to be mounted to find it.

As I said: currently we assume that image is for VM use, so nothing needs to be specifically mounted. Just return image filename. When the adssumption is lifted mounting would be handled in prepare_grub_to_access_device

Quoted 9 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines

As for the second, we're limited to what GRUB can do and so it won't be possible to have /boot on translator from hyperspace.

Sure. But it can be something expressed in a complex way by the user, which can actually be reached by GRUB. That said, as I said earlier, we can ask the user to refrain himself when it's about /boot.

We can add more translators handling as-needed.

So would it be acceptable for now as a horrible-but-works solution to use the output of sysopts:

Quoted 8 lines

ext2fs --writable --no-atime --no-inherit-dir-group --store-type=typed device:hd1

and

/hurd/ext2fs --writable --no-inherit-dir-group /dev/hd0s1

Drop the first parameter (translator path), -* options, and that leaves only the device, with additional s_device:_/dev/_ mangling.

Yes it will, just we need comprehensive error messages on failure and a comment in code that it's not complete solution.

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 7 lines

But we generally don't want to impose any syntax here, it could actually be

/opt/my/own/translator xyz

I guess we'll have to impose some syntax anyway for whatever contains /boot, so that grub can open it itself.

There should be a standartised way to get this information for any conventional FS, otherwise it makes porting programs which use this information much more difficult and in most cases results in dirty workarounds.

Quoted 6 lines
Quoted 2 lines
Quoted 1 line

So far, I've mostly seen GRUB really needing that information.

I suppose that databases would want to know this for optimisations.

libstore does provide the best thing for that: the actual area on the disk, which is what was used in the very first patch already, and which is used for swap, etc. But that reveals to be actually too precise for GRUB.

It's more of it not being stable. You could access all the files by blocklists but it would fail very quickly

Quoted 6 lines

Samuel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#26 lore raw
Quoted 9 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Wed 25 Apr 2012 00:31:26 +0200, a…
Quoted 8 lines · Samuel Thibault
Quoted 7 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Tue 24 Apr 2012 22:14:33 +0200, a…
Quoted 6 lines · Samuel Thibault
Quoted 5 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Tue 24 Apr 2012 15:19:25 +0200, a…
Quoted 4 lines · Samuel Thibault
Quoted 2 lines

I'm surprised that Hurd doesn't offer a way to just ask "What does this filesystem translator consume?"

A file can reside inside an iso file, which is stored in an ext2fs, which is stored in a file,

Quoted 7 lines
Quoted 5 lines
Quoted 4 lines
Quoted 3 lines
Quoted 1 line

So much GRUB can handle.

But how to express that to GRUB? grub_guess_root_devices only returns a series of alternative paths. See below.

By just giving the file in question.

That will not tell you which image has to be mounted to find it.

As I said: currently we assume that image is for VM use, so nothing needs to be specifically mounted. Just return image filename.

That would work with only one layer. See my example above, it has several layers, and you'd have to know the image filename at each layer.

I'm not saying that GRUB should implement all these layers. I'm just explaining why the "what does this translator consume?" is not a trivial question at all in the Hurd, and thus does not have any interface for it, and we have to define one that would only work for the trivial cases.

Quoted 5 lines
Quoted 5 lines

So would it be acceptable for now as a horrible-but-works solution to use the output of sysopts:

ext2fs --writable --no-atime --no-inherit-dir-group --store-type=typed device:hd1

Quoted 8 lines
Quoted 6 lines

and

/hurd/ext2fs --writable --no-inherit-dir-group /dev/hd0s1

Drop the first parameter (translator path), -* options, and that leaves only the device, with additional s_device:_/dev/_ mangling.

Yes it will, just we need comprehensive error messages on failure and a comment in code that it's not complete solution.

Sure.

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 7 lines

But we generally don't want to impose any syntax here, it could actually be

/opt/my/own/translator xyz

I guess we'll have to impose some syntax anyway for whatever contains /boot, so that grub can open it itself.

There should be a standartised way to get this information for any conventional FS, otherwise it makes porting programs which use this information much more difficult and in most cases results in dirty workarounds.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Quoted 1 line

So far, I've mostly seen GRUB really needing that information.

I suppose that databases would want to know this for optimisations.

libstore does provide the best thing for that: the actual area on the disk, which is what was used in the very first patch already, and which is used for swap, etc. But that reveals to be actually too precise for GRUB.

It's more of it not being stable. You could access all the files by blocklists but it would fail very quickly

Yes, because it's too precise, and thus not stable.

Samuel

#27 lore raw
Quoted 11 lines · Samuel Thibault
Quoted 10 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Wed 25 Apr 2012 00:31:26 +0200, a…
Quoted 9 lines · Samuel Thibault
Quoted 8 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Tue 24 Apr 2012 22:14:33 +0200, a…
Quoted 7 lines · Samuel Thibault
Quoted 6 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Tue 24 Apr 2012 15:19:25 +0200, a…
Quoted 4 lines · Samuel Thibault
Quoted 2 lines

I'm surprised that Hurd doesn't offer a way to just ask "What does this filesystem translator consume?"

A file can reside inside an iso file, which is stored in an ext2fs, which is stored in a file,

So much GRUB can handle.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines

But how to express that to GRUB? grub_guess_root_devices only returns a series of alternative paths. See below.

By just giving the file in question.

That will not tell you which image has to be mounted to find it.

As I said: currently we assume that image is for VM use, so nothing needs to be specifically mounted. Just return image filename.

That would work with only one layer. See my example above, it has several layers, and you'd have to know the image filename at each layer.

Right now we assume only one layer (VM use), more layers is for the future.

Quoted 5 lines

I'm not saying that GRUB should implement all these layers. I'm just explaining why the "what does this translator consume?" is not a trivial question at all in the Hurd, and thus does not have any interface for it, and we have to define one that would only work for the trivial cases.

We just need to traverse one layer: the FS, and only the case when it's an FS.

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#28 lore raw
In reply to Vladimir 'φ-coder/phcoder' Serbinenko

Here is an updated patch.

Samuel

=== modified file 'util/getroot.c'

getroot.c +69 -60
@@ -700,6 +700,69 @@
 
 #elif defined (__GNU__)
 
+static char *
+find_hurd_root_device (const char *path)
+{
+  file_t file;
+  error_t err;
+  char *argz = NULL, *name = NULL, *ret;
+  size_t argz_len = 0;
+  int i;
+
+  file = file_name_lookup (path, 0, 0);
+  if (file == MACH_PORT_NULL)
+    grub_util_error (_("Could not open path `%s'"), path);
+
+  /* This returns catenated 0-terminated strings.  */
+  err = file_get_fs_options (file, &argz, &argz_len);
+  if (err)
+    grub_util_error (_("Could not get filesystem options "
+                       "for path `%s': %s"), path, strerror(err));
+
+  /* Make sure the string is terminated.  */
+  argz[argz_len-1] = 0;
+
+  /* Skip first word (translator path) and options.  */
+  for (i = strlen (&argz[0]) + 1; i < argz_len; i += strlen (&argz[i]) + 1)
+    {
+      if (argz[i] != '-')
+        {
+          /* Non-option.  Only accept one, assumed to be the FS path.  */
+          /* XXX: this should be replaced by an RPC to the translator.  */
+          if (name)
+            /* TRANSLATORS: we expect to get something like
+               /hurd/foobar --option1 --option2=baz /dev/something
+             */
+            grub_util_error (_("Translator `%s' for path `%s' has several "
+                               "non-option words, at least `%s' and `%s'"),
+                               &argz[0], path, name, &argz[i]);
+          name = &argz[i];
+        }
+    }
+
+  if (!name)
+    /* TRANSLATORS: we expect to get something like
+       /hurd/foobar --option1 --option2=baz /dev/something
+     */
+    grub_util_error (_("Translator `%s' for path `%s' is given only options, "
+                       "could not find device part"), &argz[0], path);
+
+  if (!strncmp (name, "device:", strlen ("device:")))
+    {
+      char *dev_name = name + strlen ("device:");
+      size_t size = strlen ("/dev/") + strlen (dev_name) + 1;
+      ret = malloc (size);
+      snprintf (ret, size, "/dev/%s", dev_name);
+    }
+  else if (!strncmp (name, "file:", strlen ("file:")))
+    ret = strdup (name + strlen ("file:"));
+  else
+    ret = strdup (name);
+
+  munmap (argz, argz_len);
+  return ret;
+}
+
 #elif ! defined(__CYGWIN__)
 
 char *
@@ -930,65 +993,7 @@
 grub_guess_root_devices (const char *dir)
 {
   char **os_dev = NULL;
-#ifdef __GNU__
-  file_t file;
-  mach_port_t *ports;
-  int *ints;
-  loff_t *offsets;
-  char *data;
-  error_t err;
-  mach_msg_type_number_t num_ports = 0, num_ints = 0, num_offsets = 0, data_len = 0;
-  size_t name_len;
-
-  file = file_name_lookup (dir, 0, 0);
-  if (file == MACH_PORT_NULL)
-    return 0;
-
-  err = file_get_storage_info (file,
-			       &ports, &num_ports,
-			       &ints, &num_ints,
-			       &offsets, &num_offsets,
-			       &data, &data_len);
-
-  if (num_ints < 1)
-    grub_util_error (_("Storage info for `%s' does not include type"), dir);
-  if (ints[0] != STORAGE_DEVICE)
-    grub_util_error (_("Filesystem of `%s' is not stored on local disk"), dir);
-
-  if (num_ints < 5)
-    grub_util_error (_("Storage info for `%s' does not include name"), dir);
-  name_len = ints[4];
-  if (name_len < data_len)
-    grub_util_error (_("Bogus name length for storage info for `%s'"), dir);
-  if (data[name_len - 1] != '\0')
-    grub_util_error (_("Storage name for `%s' not NUL-terminated"), dir);
-
-  os_dev = xmalloc (2 * sizeof (os_dev[0]));
-  os_dev[0] = xmalloc (sizeof ("/dev/") - 1 + data_len);
-  memcpy (os_dev[0], "/dev/", sizeof ("/dev/") - 1);
-  memcpy (os_dev[0] + sizeof ("/dev/") - 1, data, data_len);
-  os_dev[1] = 0;
-
-  if (ports && num_ports > 0)
-    {
-      mach_msg_type_number_t i;
-      for (i = 0; i < num_ports; i++)
-        {
-	  mach_port_t port = ports[i];
-	  if (port != MACH_PORT_NULL)
-	    mach_port_deallocate (mach_task_self(), port);
-        }
-      munmap ((caddr_t) ports, num_ports * sizeof (*ports));
-    }
-
-  if (ints && num_ints > 0)
-    munmap ((caddr_t) ints, num_ints * sizeof (*ints));
-  if (offsets && num_offsets > 0)
-    munmap ((caddr_t) offsets, num_offsets * sizeof (*offsets));
-  if (data && data_len > 0)
-    munmap (data, data_len);
-  mach_port_deallocate (mach_task_self (), file);
-#else /* !__GNU__ */
+#ifndef __GNU__
   struct stat st;
   dev_t dev;
 
@@ -1035,6 +1040,7 @@
     grub_util_error (_("cannot stat `%s': %s"), dir, strerror (errno));
 
   dev = st.st_dev;
+#endif /* !__GNU__ */
 
   os_dev = xmalloc (2 * sizeof (os_dev[0]));
   
@@ -1042,6 +1048,10 @@
   /* Cygwin specific function.  */
   os_dev[0] = grub_find_device (dir, dev);
 
+#elif defined __GNU__
+  /* GNU/Hurd specific function.  */
+  os_dev[0] = find_hurd_root_device (dir);
+
 #else
 
   /* This might be truly slow, but is there any better way?  */
@@ -1054,7 +1064,6 @@
     }
 
   os_dev[1] = 0;
-#endif /* !__GNU__ */
 
   return os_dev;
 }
#29 lore raw
Quoted 1 line · Samuel Thibault

+ grub_util_error (_("Could not open path `%s'"), path);

This one should be unified with other similar messages. It would also have advantage of giving strerror. strerror should be given on all lib errors.

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#30 lore raw
Quoted 3 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Wed 25 Apr 2012 01:57:54 +0200, a…
Quoted 1 line · Samuel Thibault

+ grub_util_error (_("Could not open path `%s'"), path);

This one should be unified with other similar messages.

Err, in the file I can see various ways: "Unable to", "cannot", "failed to", "couldn't", "can't". Which one should be used.

Quoted 1 line

It would also have advantage of giving strerror.

Oops, indeed.

Samuel

#31 lore raw
Quoted 6 lines · Samuel Thibault
Quoted 3 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Wed 25 Apr 2012 01:57:54 +0200, a…
Quoted 1 line · Samuel Thibault

+ grub_util_error (_("Could not open path `%s'"), path);

This one should be unified with other similar messages.

Err, in the file I can see various ways: "Unable to", "cannot", "failed to", "couldn't", "can't". Which one should be used.

Where? For open we always use:
msgid "cannot open `%s': %s"

Quoted 10 lines
Quoted 2 lines

It would also have advantage of giving strerror.

Oops, indeed.

Samuel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#32 lore raw
Quoted 8 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Wed 25 Apr 2012 10:36:59 +0200, a…
Quoted 6 lines · Samuel Thibault
Quoted 3 lines · Vladimir 'φ-coder/phcoder' Serbinenko, le Wed 25 Apr 2012 01:57:54 +0200, a…
Quoted 1 line · Samuel Thibault

+ grub_util_error (_("Could not open path `%s'"), path);

This one should be unified with other similar messages.

Err, in the file I can see various ways: "Unable to", "cannot", "failed to", "couldn't", "can't". Which one should be used.

Where?

The util/getroot.c file, the various error conditions.

Quoted 1 line

For open we always use: msgid "cannot open `%s': %s"

So be it, here is an updated patch.

Samuel

=== modified file 'util/getroot.c'

getroot.c +69 -60
@@ -700,6 +700,69 @@
 
 #elif defined (__GNU__)
 
+static char *
+find_hurd_root_device (const char *path)
+{
+  file_t file;
+  error_t err;
+  char *argz = NULL, *name = NULL, *ret;
+  size_t argz_len = 0;
+  int i;
+
+  file = file_name_lookup (path, 0, 0);
+  if (file == MACH_PORT_NULL)
+    grub_util_error (_("cannot open `%s': %s"), path, strerror (errno));
+
+  /* This returns catenated 0-terminated strings.  */
+  err = file_get_fs_options (file, &argz, &argz_len);
+  if (err)
+    grub_util_error (_("cannot get filesystem options "
+                       "for path `%s': %s"), path, strerror(err));
+
+  /* Make sure the string is terminated.  */
+  argz[argz_len-1] = 0;
+
+  /* Skip first word (translator path) and options.  */
+  for (i = strlen (&argz[0]) + 1; i < argz_len; i += strlen (&argz[i]) + 1)
+    {
+      if (argz[i] != '-')
+        {
+          /* Non-option.  Only accept one, assumed to be the FS path.  */
+          /* XXX: this should be replaced by an RPC to the translator.  */
+          if (name)
+            /* TRANSLATORS: we expect to get something like
+               /hurd/foobar --option1 --option2=baz /dev/something
+             */
+            grub_util_error (_("Translator `%s' for path `%s' has several "
+                               "non-option words, at least `%s' and `%s'"),
+                               &argz[0], path, name, &argz[i]);
+          name = &argz[i];
+        }
+    }
+
+  if (!name)
+    /* TRANSLATORS: we expect to get something like
+       /hurd/foobar --option1 --option2=baz /dev/something
+     */
+    grub_util_error (_("Translator `%s' for path `%s' is given only options, "
+                       "cannot find device part"), &argz[0], path);
+
+  if (!strncmp (name, "device:", strlen ("device:")))
+    {
+      char *dev_name = name + strlen ("device:");
+      size_t size = strlen ("/dev/") + strlen (dev_name) + 1;
+      ret = malloc (size);
+      snprintf (ret, size, "/dev/%s", dev_name);
+    }
+  else if (!strncmp (name, "file:", strlen ("file:")))
+    ret = strdup (name + strlen ("file:"));
+  else
+    ret = strdup (name);
+
+  munmap (argz, argz_len);
+  return ret;
+}
+
 #elif ! defined(__CYGWIN__)
 
 char *
@@ -930,65 +993,7 @@
 grub_guess_root_devices (const char *dir)
 {
   char **os_dev = NULL;
-#ifdef __GNU__
-  file_t file;
-  mach_port_t *ports;
-  int *ints;
-  loff_t *offsets;
-  char *data;
-  error_t err;
-  mach_msg_type_number_t num_ports = 0, num_ints = 0, num_offsets = 0, data_len = 0;
-  size_t name_len;
-
-  file = file_name_lookup (dir, 0, 0);
-  if (file == MACH_PORT_NULL)
-    return 0;
-
-  err = file_get_storage_info (file,
-			       &ports, &num_ports,
-			       &ints, &num_ints,
-			       &offsets, &num_offsets,
-			       &data, &data_len);
-
-  if (num_ints < 1)
-    grub_util_error (_("Storage info for `%s' does not include type"), dir);
-  if (ints[0] != STORAGE_DEVICE)
-    grub_util_error (_("Filesystem of `%s' is not stored on local disk"), dir);
-
-  if (num_ints < 5)
-    grub_util_error (_("Storage info for `%s' does not include name"), dir);
-  name_len = ints[4];
-  if (name_len < data_len)
-    grub_util_error (_("Bogus name length for storage info for `%s'"), dir);
-  if (data[name_len - 1] != '\0')
-    grub_util_error (_("Storage name for `%s' not NUL-terminated"), dir);
-
-  os_dev = xmalloc (2 * sizeof (os_dev[0]));
-  os_dev[0] = xmalloc (sizeof ("/dev/") - 1 + data_len);
-  memcpy (os_dev[0], "/dev/", sizeof ("/dev/") - 1);
-  memcpy (os_dev[0] + sizeof ("/dev/") - 1, data, data_len);
-  os_dev[1] = 0;
-
-  if (ports && num_ports > 0)
-    {
-      mach_msg_type_number_t i;
-      for (i = 0; i < num_ports; i++)
-        {
-	  mach_port_t port = ports[i];
-	  if (port != MACH_PORT_NULL)
-	    mach_port_deallocate (mach_task_self(), port);
-        }
-      munmap ((caddr_t) ports, num_ports * sizeof (*ports));
-    }
-
-  if (ints && num_ints > 0)
-    munmap ((caddr_t) ints, num_ints * sizeof (*ints));
-  if (offsets && num_offsets > 0)
-    munmap ((caddr_t) offsets, num_offsets * sizeof (*offsets));
-  if (data && data_len > 0)
-    munmap (data, data_len);
-  mach_port_deallocate (mach_task_self (), file);
-#else /* !__GNU__ */
+#ifndef __GNU__
   struct stat st;
   dev_t dev;
 
@@ -1035,6 +1040,7 @@
     grub_util_error (_("cannot stat `%s': %s"), dir, strerror (errno));
 
   dev = st.st_dev;
+#endif /* !__GNU__ */
 
   os_dev = xmalloc (2 * sizeof (os_dev[0]));
   
@@ -1042,6 +1048,10 @@
   /* Cygwin specific function.  */
   os_dev[0] = grub_find_device (dir, dev);
 
+#elif defined __GNU__
+  /* GNU/Hurd specific function.  */
+  os_dev[0] = find_hurd_root_device (dir);
+
 #else
 
   /* This might be truly slow, but is there any better way?  */
@@ -1054,7 +1064,6 @@
     }
 
   os_dev[1] = 0;
-#endif /* !__GNU__ */
 
   return os_dev;
 }
#33 lore raw

getroot.c line 723

Quoted 2 lines · Samuel Thibault
getroot.c +2 -0
+  /* Make sure the string is terminated.  */
+  argz[argz_len-1] = 0;

This would fail if argz_len == 0. You have to check this case.

getroot.c line 727

Quoted 4 lines
getroot.c +4 -0
+
+  /* Skip first word (translator path) and options.  */
+  for (i = strlen (&argz[0]) + 1; i < argz_len; i += strlen (&argz[i]) + 1)
+    {

please use argz and argz + i

getroot.c line 739

Quoted 12 lines
getroot.c +12 -0
+      if (argz[i] != '-')
+        {
+          /* Non-option.  Only accept one, assumed to be the FS path.  */
+          /* XXX: this should be replaced by an RPC to the translator.  */
+          if (name)
+            /* TRANSLATORS: we expect to get something like
+               /hurd/foobar --option1 --option2=baz /dev/something
+             */
+            grub_util_error (_("Translator `%s' for path `%s' has several "
+                               "non-option words, at least `%s' and `%s'"),
+                               &argz[0], path, name, &argz[i]);
+          name = &argz[i];

ditto

getroot.c line 750

Quoted 11 lines
getroot.c +11 -0
+        }
+    }
+
+  if (!name)
+    /* TRANSLATORS: we expect to get something like
+       /hurd/foobar --option1 --option2=baz /dev/something
+     */
+    grub_util_error (_("Translator `%s' for path `%s' is given only options, "
+                       "cannot find device part"), &argz[0], path);
+
+  if (!strncmp (name, "device:", strlen ("device:")))

Please use explicit == 0 and use sizeof ("...")-1 instead of strlen on const string.

getroot.c line 755

Quoted 5 lines
getroot.c +5 -0
+    {
+      char *dev_name = name + strlen ("device:");
+      size_t size = strlen ("/dev/") + strlen (dev_name) + 1;
+      ret = malloc (size);
+      snprintf (ret, size, "/dev/%s", dev_name);

stpcpy is more appropriate than snprintf here.

Quoted 8 lines
getroot.c +8 -0
+    }
+  else if (!strncmp (name, "file:", strlen ("file:")))
+    ret = strdup (name + strlen ("file:"));
+  else
+    ret = strdup (name);
+
+  munmap (argz, argz_len);
+  return ret;
Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko
#34 lore raw

Here is an updated patch.

Samuel

=== modified file 'util/getroot.c'

getroot.c +75 -60
@@ -700,6 +700,75 @@
 
 #elif defined (__GNU__)
 
+static char *
+find_hurd_root_device (const char *path)
+{
+  file_t file;
+  error_t err;
+  char *argz = NULL, *name = NULL, *ret;
+  size_t argz_len = 0;
+  int i;
+
+  file = file_name_lookup (path, 0, 0);
+  if (file == MACH_PORT_NULL)
+    grub_util_error (_("cannot open `%s': %s"), path, strerror (errno));
+
+  /* This returns catenated 0-terminated strings.  */
+  err = file_get_fs_options (file, &argz, &argz_len);
+  if (err)
+    grub_util_error (_("cannot get filesystem options "
+                       "for path `%s': %s"), path, strerror(err));
+  if (argz_len == 0)
+    /* TRANSLATORS: a "translator" is similar to a filesystem, but handled by a
+     * userland daemon.  */
+    grub_util_error (_("translator is empty for path `%s'"), path);
+
+  /* Make sure the string is terminated.  */
+  argz[argz_len-1] = 0;
+
+  /* Skip first word (translator path) and options.  */
+  for (i = strlen (argz) + 1; i < argz_len; i += strlen (argz + i) + 1)
+    {
+      if (argz[i] != '-')
+        {
+          /* Non-option.  Only accept one, assumed to be the FS path.  */
+          /* XXX: this should be replaced by an RPC to the translator.  */
+          if (name)
+            /* TRANSLATORS: we expect to get something like
+               /hurd/foobar --option1 --option2=baz /dev/something
+             */
+            grub_util_error (_("translator `%s' for path `%s' has several "
+                               "non-option words, at least `%s' and `%s'"),
+                               argz, path, name, argz + i);
+          name = argz + i;
+        }
+    }
+
+  if (!name)
+    /* TRANSLATORS: we expect to get something like
+       /hurd/foobar --option1 --option2=baz /dev/something
+     */
+    grub_util_error (_("translator `%s' for path `%s' is given only options, "
+                       "cannot find device part"), argz, path);
+
+  if (strncmp (name, "device:", sizeof ("device:") - 1) == 0)
+    {
+      char *dev_name = name + sizeof ("device:") - 1;
+      size_t size = sizeof ("/dev/") - 1 + strlen (dev_name) + 1;
+      char *next;
+      ret = malloc (size);
+      next = stpncpy (ret, "/dev/", size);
+      stpncpy (next, dev_name, size - (next - ret));
+    }
+  else if (!strncmp (name, "file:", sizeof ("file:") - 1))
+    ret = strdup (name + sizeof ("file:") - 1);
+  else
+    ret = strdup (name);
+
+  munmap (argz, argz_len);
+  return ret;
+}
+
 #elif ! defined(__CYGWIN__)
 
 char *
@@ -930,65 +999,7 @@
 grub_guess_root_devices (const char *dir)
 {
   char **os_dev = NULL;
-#ifdef __GNU__
-  file_t file;
-  mach_port_t *ports;
-  int *ints;
-  loff_t *offsets;
-  char *data;
-  error_t err;
-  mach_msg_type_number_t num_ports = 0, num_ints = 0, num_offsets = 0, data_len = 0;
-  size_t name_len;
-
-  file = file_name_lookup (dir, 0, 0);
-  if (file == MACH_PORT_NULL)
-    return 0;
-
-  err = file_get_storage_info (file,
-			       &ports, &num_ports,
-			       &ints, &num_ints,
-			       &offsets, &num_offsets,
-			       &data, &data_len);
-
-  if (num_ints < 1)
-    grub_util_error (_("Storage info for `%s' does not include type"), dir);
-  if (ints[0] != STORAGE_DEVICE)
-    grub_util_error (_("Filesystem of `%s' is not stored on local disk"), dir);
-
-  if (num_ints < 5)
-    grub_util_error (_("Storage info for `%s' does not include name"), dir);
-  name_len = ints[4];
-  if (name_len < data_len)
-    grub_util_error (_("Bogus name length for storage info for `%s'"), dir);
-  if (data[name_len - 1] != '\0')
-    grub_util_error (_("Storage name for `%s' not NUL-terminated"), dir);
-
-  os_dev = xmalloc (2 * sizeof (os_dev[0]));
-  os_dev[0] = xmalloc (sizeof ("/dev/") - 1 + data_len);
-  memcpy (os_dev[0], "/dev/", sizeof ("/dev/") - 1);
-  memcpy (os_dev[0] + sizeof ("/dev/") - 1, data, data_len);
-  os_dev[1] = 0;
-
-  if (ports && num_ports > 0)
-    {
-      mach_msg_type_number_t i;
-      for (i = 0; i < num_ports; i++)
-        {
-	  mach_port_t port = ports[i];
-	  if (port != MACH_PORT_NULL)
-	    mach_port_deallocate (mach_task_self(), port);
-        }
-      munmap ((caddr_t) ports, num_ports * sizeof (*ports));
-    }
-
-  if (ints && num_ints > 0)
-    munmap ((caddr_t) ints, num_ints * sizeof (*ints));
-  if (offsets && num_offsets > 0)
-    munmap ((caddr_t) offsets, num_offsets * sizeof (*offsets));
-  if (data && data_len > 0)
-    munmap (data, data_len);
-  mach_port_deallocate (mach_task_self (), file);
-#else /* !__GNU__ */
+#ifndef __GNU__
   struct stat st;
   dev_t dev;
 
@@ -1035,6 +1046,7 @@
     grub_util_error (_("cannot stat `%s': %s"), dir, strerror (errno));
 
   dev = st.st_dev;
+#endif /* !__GNU__ */
 
   os_dev = xmalloc (2 * sizeof (os_dev[0]));
   
@@ -1042,6 +1054,10 @@
   /* Cygwin specific function.  */
   os_dev[0] = grub_find_device (dir, dev);
 
+#elif defined __GNU__
+  /* GNU/Hurd specific function.  */
+  os_dev[0] = find_hurd_root_device (dir);
+
 #else
 
   /* This might be truly slow, but is there any better way?  */
@@ -1054,7 +1070,6 @@
     }
 
   os_dev[1] = 0;
-#endif /* !__GNU__ */
 
   return os_dev;
 }
#37 lore raw
In reply to Samuel Thibault

Review

Quoted 2 lines · Samuel Thibault
(quoted diff) +2 -0
+	sprintf (devpath + strlen (devpath), "s%d", winner_part + 1);
+    }

Also:
- It's probably wrong to assume that Hurd partition numbering is the same as GRUB's, especially if several partmaps are present.
- Don't use x + strlen (x), keep pointer instead, you can easily do it if you replace strcpy with stpcpy
- sprintf is banned in GRUB code. Use snprintf

Signature · 2 lines
Regards
Vladimir 'φ-coder/phcoder' Serbinenko