Skip to contentSkip to conversation

Fix GNU/Hurd partition number

PATCH In review Samuel Thibault 2 participants 7 messages Nov 2, 2009 – Nov 21, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix GNU/Hurd partition number

Hello,

This patch fixes partition number translation on GNU/Hurd.

Samuel

2009-11-02 Samuel Thibault <[email protected]>

* util/hostdisk.c (grub_util_biosdisk_get_grub_dev): Subtract 1 from GNU partition number to get internal grub DOS partition number.

hostdisk.c +1 -1
Index: util/hostdisk.c
===================================================================
@@ -1057,7 +1057,7 @@
 	n = strtol (p, &q, 10);
 	if (p != q && n != GRUB_LONG_MIN && n != GRUB_LONG_MAX)
 	  {
-	    dos_part = (int) n;
+	    dos_part = (int) n - 1;
 
 	    if (*q >= 'a' && *q <= 'g')
 	      bsd_part = *q - 'a';
#1 lore raw

PATCH 1/1 Fix 10_hurd for separate /boot case.

Hello,

This patch fixes the 10_hurd script in the case where /boot is in a separate partition.

Samuel

2009-11-02 Samuel Thibault <[email protected]>

* util/grub.d/10_hurd.in: Call prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} before loading /boot kernel.

grub.d/10_hurd.in +4 -1
Index: util/grub.d/10_hurd.in
===================================================================
@@ -71,9 +71,12 @@
 cat << EOF
 menuentry "${OS}" {
 EOF
+prepare_grub_to_access_device ${GRUB_DEVICE_BOOT} | sed -e "s/^/\t/"
+cat << EOF
+	multiboot ${kernel} root=device:${GRUB_DEVICE}
+EOF
 prepare_grub_to_access_device ${GRUB_DEVICE} | sed -e "s/^/\t/"
 cat << EOF
-	multiboot ${kernel} root=device:${GRUB_DEVICE}
 	module /hurd/${hurd_fs}.static ${hurd_fs} --readonly \\
 			--multiboot-command-line='\${kernel-command-line}' \\
 			--host-priv-port='\${host-port}' \\
#2 lore raw

Re: [PATCH,HURD] Fix 10_hurd for separate /boot case.

Quoted 4 lines · Samuel Thibault

Hello,

This patch fixes the 10_hurd script in the case where /boot is in a separate partition.

Committed, thanks.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#3 lore raw
In reply to Samuel Thibault
Quoted 10 lines · Samuel Thibault

Hello,

This patch fixes partition number translation on GNU/Hurd.

Samuel

2009-11-02 Samuel Thibault <[email protected]>

* util/hostdisk.c (grub_util_biosdisk_get_grub_dev): Subtract 1 from GNU partition number to get internal grub DOS partition number.

Are you sure this is needed? We use the same numbering scheme as GNU/Hurd.

(hd0,1) means first partition, so does /dev/hd0s1.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#4 lore raw
Quoted 6 lines · Robert Millan, le Mon 02 Nov 2009 14:52:02 +0100, a écrit :
Quoted 2 lines · Samuel Thibault

* util/hostdisk.c (grub_util_biosdisk_get_grub_dev): Subtract 1 from GNU partition number to get internal grub DOS partition number.

Are you sure this is needed? We use the same numbering scheme as GNU/Hurd. (hd0,1) means first partition, so does /dev/hd0s1.

Externally, yes.
Internally, no, cf make_device_name:

if (dos_part >= 0)

    sprintf (p + strlen (p), ",%d", dos_part + 1);

so from hd0s1 I need to provide dos_part==0 in order to get (hd0,1).

Samuel

#5 lore raw
Quoted 8 lines · Samuel Thibault
Quoted 6 lines · Robert Millan, le Mon 02 Nov 2009 14:52:02 +0100, a écrit :
Quoted 2 lines · Samuel Thibault

* util/hostdisk.c (grub_util_biosdisk_get_grub_dev): Subtract 1 from GNU partition number to get internal grub DOS partition number.

Are you sure this is needed? We use the same numbering scheme as GNU/Hurd. (hd0,1) means first partition, so does /dev/hd0s1.

Quoted 7 lines

Externally, yes.
Internally, no, cf make_device_name:

if (dos_part >= 0)

    sprintf (p + strlen (p), ",%d", dos_part + 1);

so from hd0s1 I need to provide dos_part==0 in order to get (hd0,1).

Oh, ok.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
#6 lore raw

PATCH 1/1 Make grub-probe work on GNU/Hurd

In reply to Samuel Thibault

Hello,

After discussions between Hurd developers, here is a patch to implement grub_guess_root_device() natively by directly asking the fs translator. This is the last bit needed to get grub-install working.

Samuel

2009-11-21 Samuel Thibault <[email protected]>

* util/getroot.c: [__GNU__] Include <hurd.h>, <hurd/lookup.h>, and <hurd/fs.h>
(grub_guess_root_device): [__GNU__] Call file_name_lookup and file_get_storage_info to implement grub_guess_root_device.

getroot.c +65 -1
Index: util/getroot.c
===================================================================
@@ -30,6 +30,12 @@
 # define DEV_CYGDRIVE_MAJOR 98
 #endif
 
+#ifdef __GNU__
+#include <hurd.h>
+#include <hurd/lookup.h>
+#include <hurd/fs.h>
+#endif
+
 #include <grub/util/misc.h>
 #include <grub/util/hostdisk.h>
 #include <grub/util/getroot.h>
@@ -378,9 +384,66 @@
 char *
 grub_guess_root_device (const char *dir)
 {
-  struct stat st;
   char *os_dev;
+#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 (strlen ("/dev/") + data_len);
+  memcpy (os_dev, "/dev/", strlen ("/dev/"));
+  memcpy (os_dev + strlen ("/dev/"), data, data_len);
+
+  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__ */
+  struct stat st;
+
   if (stat (dir, &st) < 0)
     grub_util_error ("Cannot stat `%s'", dir);
 
@@ -393,6 +456,7 @@
   /* This might be truly slow, but is there any better way?  */
   os_dev = find_root_device ("/dev", st.st_dev);
 #endif
+#endif /* !__GNU__ */
 
   return os_dev;
 }