Skip to contentSkip to conversation

hurd: Support device entries with @/dev/disk: qualifier

PATCH Superseded Samuel Thibault 2 participants 6 messages Feb 22, 2022 – May 17, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hurd: Support device entries with @/dev/disk: qualifier

Those are used with non-bootstrap disk drivers, for which libstore has to open /dev/disk before calling device_open on it instead of on the device master port. Normally in that case all /dev/ entries also have the @/dev/disk:
qualifier, so we can just drop it.

grub-core/osdep/hurd/getroot.c +32 -5
Index: grub2-2.06/grub-core/osdep/hurd/getroot.c
===================================================================
@@ -112,11 +112,23 @@ grub_util_find_hurd_root_device (const c
   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));
+
+      if (dev_name[0] == '@')
+        {
+          /* non-bootstrap disk driver, the /dev/ entry is normally set up with
+             the same @.  */
+          char *next_name = strchr (dev_name, ':');
+          if (next_name)
+            dev_name = next_name + 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);
@@ -166,12 +178,27 @@ grub_util_part_to_disk (const char *os_d
 		    || strncmp ("/dev/hd", os_dev, 7) == 0)))
     {
       *is_part = !is_fulldisk (path, os_dev);
+
+      if (path[0] == '@')
+        {
+          /* non-bootstrap disk driver, the /dev/ entry is normally set up with
+             the same @.  */
+          char *next_path = strchr (path, ':');
+          if (next_path)
+            {
+              char *n = strdup (next_path + 1);
+              free (path);
+              path = n;
+            }
+        }
+
       if (path[0] != '/')
 	{
 	  char *n = xasprintf ("/dev/%s", path);
 	  free (path);
 	  path = n;
 	}
+
       return path;
     }
   free (path);
#1 lore raw

PATCH v2 1/1 hurd: Support device entries with @/dev/disk: qualifier

Those are used with non-bootstrap disk drivers, for which libstore has to open /dev/disk before calling device_open on it instead of on the device master port. Normally in that case all /dev/ entries also have the @/dev/disk:
qualifier, so we can just drop it.

---
Difference with v1: better drop the @/dev/disk: qualifier right from grub_util_hurd_get_disk_info so it benefits alls the callees and not only grub_util_part_to_disk.

grub-core/osdep/hurd/getroot.c +17 -5
Index: grub2-2.06/grub-core/osdep/hurd/getroot.c
===================================================================
@@ -112,11 +112,23 @@ grub_util_find_hurd_root_device (const c
   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));
+
+      if (dev_name[0] == '@')
+        {
+          /* non-bootstrap disk driver, the /dev/ entry is normally set up with
+             the same @.  */
+          char *next_name = strchr (dev_name, ':');
+          if (next_name)
+            dev_name = next_name + 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);
grub-core/osdep/hurd/hostdisk.c +13 -0
Index: grub2-2.06/grub-core/osdep/hurd/hostdisk.c
===================================================================
@@ -87,6 +87,19 @@ grub_util_hurd_get_disk_info (const char
 	  *parent = xmalloc (len+1);
 	  memcpy (*parent, data, len);
 	  (*parent)[len] = '\0';
+
+	  if ((*parent)[0] == '@')
+	    {
+	      /* non-bootstrap disk driver, the /dev/ entry is normally set up with
+		 the same @.  */
+	      char *next_path = strchr (*parent, ':');
+	      if (next_path)
+		{
+		  char *n = strdup (next_path + 1);
+		  free (*parent);
+		  *parent = n;
+		}
+	    }
 	}
     }
   if (offset)
#2 lore raw

Sorry for late reply but I am busy...

Quoted 20 lines · Samuel Thibault

Those are used with non-bootstrap disk drivers, for which libstore has to open /dev/disk before calling device_open on it instead of on the device master port. Normally in that case all /dev/ entries also have the @/dev/disk:
qualifier, so we can just drop it.

---
Difference with v1: better drop the @/dev/disk: qualifier right from grub_util_hurd_get_disk_info so it benefits alls the callees and not only grub_util_part_to_disk.

Index: grub2-2.06/grub-core/osdep/hurd/getroot.c
===================================================================

grub-core/osdep/hurd/getroot.c +0 -0
@@ -112,11 +112,23 @@ grub_util_find_hurd_root_device (const c
   if (strncmp (name, "device:", sizeof ("device:") - 1) == 0)
     {
       char *dev_name = name + sizeof ("device:") - 1;

grub-core/osdep/hurd/getroot.c grub_util_find_hurd_root_device (const c · line 119

Quoted 10 lines
grub-core/osdep/hurd/getroot.c +5 -5
-      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));
+
+      if (dev_name[0] == '@')
+        {
+          /* non-bootstrap disk driver, the /dev/ entry is normally set up with
+             the same @.  */

Please format comments according to this [1].

grub-core/osdep/hurd/getroot.c grub_util_find_hurd_root_device (const c · line 120

Quoted 1 line
grub-core/osdep/hurd/getroot.c +1 -0
+          char *next_name = strchr (dev_name, ':');

Could you put empty line here?

grub-core/osdep/hurd/getroot.c grub_util_find_hurd_root_device (const c · line 127

Quoted 7 lines
grub-core/osdep/hurd/getroot.c +7 -0
+          if (next_name)
+            dev_name = next_name + 1;
+        }
+
+      {
+        size_t size = sizeof ("/dev/") - 1 + strlen (dev_name) + 1;
+        char *next;

I would prefer if you leave variable definitions above and put code without {} here.

grub-core/osdep/hurd/getroot.c grub_util_find_hurd_root_device (const c · line 128

Quoted 1 line
grub-core/osdep/hurd/getroot.c +1 -0
+        ret = malloc (size);

I think this should be xmalloc() call instead of malloc() one. Or you should check ret != NULL before use.

Quoted 11 lines
grub-core/osdep/hurd/getroot.c +3 -0
+        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);

Index: grub2-2.06/grub-core/osdep/hurd/hostdisk.c
===================================================================

grub-core/osdep/hurd/hostdisk.c grub_util_hurd_get_disk_info (const char · line 94

Quoted 8 lines
grub-core/osdep/hurd/hostdisk.c +5 -0
@@ -87,6 +87,19 @@ grub_util_hurd_get_disk_info (const char
 	  *parent = xmalloc (len+1);
 	  memcpy (*parent, data, len);
 	  (*parent)[len] = '\0';
+
+	  if ((*parent)[0] == '@')
+	    {
+	      /* non-bootstrap disk driver, the /dev/ entry is normally set up with
+		 the same @.  */

Please fix this comment too.

grub-core/osdep/hurd/hostdisk.c grub_util_hurd_get_disk_info (const char · line 95

Quoted 1 line
grub-core/osdep/hurd/hostdisk.c +1 -0
+	      char *next_path = strchr (*parent, ':');

Please add empty line here.

grub-core/osdep/hurd/hostdisk.c grub_util_hurd_get_disk_info (const char · line 98

Quoted 3 lines
grub-core/osdep/hurd/hostdisk.c +3 -0
+	      if (next_path)
+		{
+		  char *n = strdup (next_path + 1);

Ditto.

grub-core/osdep/hurd/hostdisk.c grub_util_hurd_get_disk_info (const char · line 105

Quoted 7 lines
grub-core/osdep/hurd/hostdisk.c +4 -0
+		  free (*parent);
+		  *parent = n;
+		}
+	    }
 	}
     }
   if (offset)

[1] https://www.gnu.org/software/grub/manual/grub-dev/grub-dev.html#Comments

Daniel

#3 lore raw

PATCH v3 1/1 hurd: Support device entries with @/dev/disk: qualifier

Those are used with non-bootstrap disk drivers, for which libstore has to open /dev/disk before calling device_open on it instead of on the device master port. Normally in that case all /dev/ entries also have the @/dev/disk:
qualifier, so we can just drop it.

Message-Id: <20220223233413.wkk66pxp5p2q2wrf@begin>

---
Difference with v2: formatting, using xmalloc instead of malloc.

Difference with v1: better drop the @/dev/disk: qualifier right from grub_util_hurd_get_disk_info so it benefits alls the callees and not only grub_util_part_to_disk.

grub-core/osdep/hurd/getroot.c +14 -2
index c66b206fa..5f0e366d1 100644
@@ -112,9 +112,21 @@ grub_util_find_hurd_root_device (const char *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;
+      size_t size;
       char *next;
-      ret = malloc (size);
+
+      if (dev_name[0] == '@')
+        {
+          /* non-bootstrap disk driver, the /dev/ entry is normally set up with
+           * the same @. */
+          char *next_name = strchr (dev_name, ':');
+
+          if (next_name)
+            dev_name = next_name + 1;
+        }
+
+      size = sizeof ("/dev/") - 1 + strlen (dev_name) + 1;
+      ret = xmalloc (size);
       next = stpncpy (ret, "/dev/", size);
       stpncpy (next, dev_name, size - (next - ret));
     }
grub-core/osdep/hurd/hostdisk.c +15 -0
index c47b5a5ea..73c442ae5 100644
@@ -87,6 +87,21 @@ grub_util_hurd_get_disk_info (const char *dev, grub_uint32_t *secsize, grub_disk
 	  *parent = xmalloc (len+1);
 	  memcpy (*parent, data, len);
 	  (*parent)[len] = '\0';
+
+	  if ((*parent)[0] == '@')
+	    {
+	      /* non-bootstrap disk driver, the /dev/ entry is normally set up with
+	       * the same @. */
+	      char *next_path = strchr (*parent, ':');
+
+	      if (next_path)
+		{
+		  char *n = strdup (next_path + 1);
+
+		  free (*parent);
+		  *parent = n;
+		}
+	    }
 	}
     }
   if (offset)
#4 lore raw
Quoted 52 lines · Samuel Thibault

Those are used with non-bootstrap disk drivers, for which libstore has to open /dev/disk before calling device_open on it instead of on the device master port. Normally in that case all /dev/ entries also have the @/dev/disk:
qualifier, so we can just drop it.

Message-Id: <20220223233413.wkk66pxp5p2q2wrf@begin>

---
Difference with v2: formatting, using xmalloc instead of malloc.

Difference with v1: better drop the @/dev/disk: qualifier right from grub_util_hurd_get_disk_info so it benefits alls the callees and not only grub_util_part_to_disk.

grub-core/osdep/hurd/getroot.c +14 -2
index c66b206fa..5f0e366d1 100644
@@ -112,9 +112,21 @@ grub_util_find_hurd_root_device (const char *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;
+      size_t size;
       char *next;
-      ret = malloc (size);
+
+      if (dev_name[0] == '@')
+        {
+          /* non-bootstrap disk driver, the /dev/ entry is normally set up with
+           * the same @. */
+          char *next_name = strchr (dev_name, ':');
+
+          if (next_name)
+            dev_name = next_name + 1;
+        }
+
+      size = sizeof ("/dev/") - 1 + strlen (dev_name) + 1;
+      ret = xmalloc (size);
       next = stpncpy (ret, "/dev/", size);
       stpncpy (next, dev_name, size - (next - ret));
     }
grub-core/osdep/hurd/hostdisk.c +0 -0
index c47b5a5ea..73c442ae5 100644
@@ -87,6 +87,21 @@ grub_util_hurd_get_disk_info (const char *dev, grub_uint32_t *secsize, grub_disk
 	  *parent = xmalloc (len+1);
 	  memcpy (*parent, data, len);
 	  (*parent)[len] = '\0';

grub-core/osdep/hurd/hostdisk.c grub_util_hurd_get_disk_info (const char *dev, grub_uint32_t *secsize, grub_disk · line 99

Quoted 10 lines
grub-core/osdep/hurd/hostdisk.c +10 -0
+
+	  if ((*parent)[0] == '@')
+	    {
+	      /* non-bootstrap disk driver, the /dev/ entry is normally set up with
+	       * the same @. */
+	      char *next_path = strchr (*parent, ':');
+
+	      if (next_path)
+		{
+		  char *n = strdup (next_path + 1);

I think this should be xstrdup() instead of strdup(). I can fix this for you before push.

Otherwise Reviewed-by: Daniel Kiper <[email protected]>

Daniel

Quoted 7 lines
grub-core/osdep/hurd/hostdisk.c +4 -0
+		  free (*parent);
+		  *parent = n;
+		}
+	    }
 	}
     }
   if (offset)
#5 lore raw

Daniel Kiper, le mar. 17 mai 2022 16:22:10 +0200, a ecrit:

Quoted 58 lines · Samuel Thibault
Quoted 57 lines

Those are used with non-bootstrap disk drivers, for which libstore has to open /dev/disk before calling device_open on it instead of on the device master port. Normally in that case all /dev/ entries also have the @/dev/disk:
qualifier, so we can just drop it.

Message-Id: <20220223233413.wkk66pxp5p2q2wrf@begin>

---
Difference with v2: formatting, using xmalloc instead of malloc.

Difference with v1: better drop the @/dev/disk: qualifier right from grub_util_hurd_get_disk_info so it benefits alls the callees and not only grub_util_part_to_disk.

grub-core/osdep/hurd/getroot.c +14 -2
index c66b206fa..5f0e366d1 100644
@@ -112,9 +112,21 @@ grub_util_find_hurd_root_device (const char *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;
+      size_t size;
       char *next;
-      ret = malloc (size);
+
+      if (dev_name[0] == '@')
+        {
+          /* non-bootstrap disk driver, the /dev/ entry is normally set up with
+           * the same @. */
+          char *next_name = strchr (dev_name, ':');
+
+          if (next_name)
+            dev_name = next_name + 1;
+        }
+
+      size = sizeof ("/dev/") - 1 + strlen (dev_name) + 1;
+      ret = xmalloc (size);
       next = stpncpy (ret, "/dev/", size);
       stpncpy (next, dev_name, size - (next - ret));
     }
grub-core/osdep/hurd/hostdisk.c +5 -0
index c47b5a5ea..73c442ae5 100644
@@ -87,6 +87,21 @@ grub_util_hurd_get_disk_info (const char *dev, grub_uint32_t *secsize, grub_disk
 	  *parent = xmalloc (len+1);
 	  memcpy (*parent, data, len);
 	  (*parent)[len] = '\0';
+
+	  if ((*parent)[0] == '@')
+	    {
+	      /* non-bootstrap disk driver, the /dev/ entry is normally set up with
+	       * the same @. */
Quoted 8 lines

grub-core/osdep/hurd/hostdisk.c grub_util_hurd_get_disk_info (const char *dev, grub_uint32_t *secsize, grub_disk · line 99

Quoted 5 lines
grub-core/osdep/hurd/hostdisk.c +5 -0
+	      char *next_path = strchr (*parent, ':');
+
+	      if (next_path)
+		{
+		  char *n = strdup (next_path + 1);

I think this should be xstrdup() instead of strdup(). I can fix this for you before push.

Ok, please do so :)

Samuel

Quoted 12 lines

Otherwise Reviewed-by: Daniel Kiper <[email protected]>

Daniel

Quoted 7 lines
grub-core/osdep/hurd/hostdisk.c +4 -0
+		  free (*parent);
+		  *parent = n;
+		}
+	    }
 	}
     }
   if (offset)