All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] NetBSD disk wedge support
@ 2012-02-03 10:48 Grégoire Sutre
  2012-02-03 11:18 ` Vladimir 'φ-coder/phcoder' Serbinenko
  0 siblings, 1 reply; 3+ messages in thread
From: Grégoire Sutre @ 2012-02-03 10:48 UTC (permalink / raw)
  To: The development of GNU GRUB

[-- Attachment #1: Type: text/plain, Size: 254 bytes --]

The attached patch makes it possible to install GRUB from NetBSD
on a GPT partition.  Those are available as so-called disk wedges
on NetBSD (see [1]).  Tested under NetBSD -current.

Grégoire

[1] http://netbsd.gw.com/cgi-bin/man-cgi?dk++NetBSD-current

[-- Attachment #2: patch-wedge.diff --]
[-- Type: text/x-patch, Size: 4693 bytes --]

=== modified file 'grub-core/kern/emu/hostdisk.c'
--- grub-core/kern/emu/hostdisk.c	2012-01-29 20:49:44 +0000
+++ grub-core/kern/emu/hostdisk.c	2012-02-03 09:37:01 +0000
@@ -98,10 +98,11 @@ struct hd_geometry
 
 #if defined(__NetBSD__)
 # define HAVE_DIOCGDINFO
 # include <sys/ioctl.h>
 # include <sys/disklabel.h>    /* struct disklabel */
+# include <sys/disk.h>    /* struct dkwedge_info */
 #else /* !defined(__NetBSD__) && !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) */
 # undef HAVE_DIOCGDINFO
 #endif /* defined(__NetBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) */
 
 #if defined(__NetBSD__)
@@ -481,10 +482,13 @@ grub_hostdisk_find_partition_start (cons
 #ifdef __sun__
   struct extpart_info pinfo;
 # elif !defined(HAVE_DIOCGDINFO)
   struct hd_geometry hdg;
 # else /* defined(HAVE_DIOCGDINFO) */
+#  if defined(__NetBSD__)
+  struct dkwedge_info dkw;
+#  endif /* defined(__NetBSD__) */
   struct disklabel label;
   int p_index;
 # endif /* !defined(HAVE_DIOCGDINFO) */
 
 # ifdef HAVE_DEVICE_MAPPER
@@ -572,10 +576,16 @@ devmapper_fail:
 # elif !defined(HAVE_DIOCGDINFO)
   if (ioctl (fd, HDIO_GETGEO, &hdg))
 # else /* defined(HAVE_DIOCGDINFO) */
 #  if defined(__NetBSD__)
   configure_device_driver (fd);
+  /* First handle the case of disk wedges.  */
+  if (ioctl (fd, DIOCGWEDGEINFO, &dkw) == 0)
+    {
+      close (fd);
+      return (grub_disk_addr_t) dkw.dkw_offset;
+    }
 #  endif /* defined(__NetBSD__) */
   if (ioctl (fd, DIOCGDINFO, &label) == -1)
 # endif /* !defined(HAVE_DIOCGDINFO) */
     {
       grub_error (GRUB_ERR_BAD_DEVICE,

=== modified file 'util/getroot.c'
--- util/getroot.c	2012-02-03 10:02:06 +0000
+++ util/getroot.c	2012-02-03 10:25:17 +0000
@@ -122,10 +122,11 @@
 
 #if defined(__NetBSD__)
 # define HAVE_DIOCGDINFO
 # include <sys/ioctl.h>
 # include <sys/disklabel.h>    /* struct disklabel */
+# include <sys/disk.h>    /* struct dkwedge_info */
 #else /* !defined(__NetBSD__) && !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) */
 # undef HAVE_DIOCGDINFO
 #endif /* defined(__NetBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) */
 
 #if defined(__NetBSD__)
@@ -1712,35 +1713,64 @@ devmapper_out:
           }
     }
   return path;
 
 #elif defined(__NetBSD__)
-  /* NetBSD uses "/dev/r[a-z]+[0-9][a-z]".  */
-  char *path = xstrdup (os_dev);
-  if (strncmp ("/dev/r", path, sizeof("/dev/r") - 1) == 0 &&
-      (path[sizeof("/dev/r") - 1] >= 'a' && path[sizeof("/dev/r") - 1] <= 'z') &&
-      strncmp ("fd", path + sizeof("/dev/r") - 1, sizeof("fd") - 1) != 0)    /* not a floppy device name */
+  int rawpart = -1;
+# ifdef HAVE_GETRAWPARTITION
+  rawpart = getrawpartition();
+# endif /* HAVE_GETRAWPARTITION */
+  if (rawpart < 0)
+    return xstrdup (os_dev);
+
+  /* NetBSD disk wedges are of the form "/dev/rdk.*".  */
+  if (strncmp ("/dev/rdk", os_dev, sizeof("/dev/rdk") - 1) == 0)
+    {
+      struct dkwedge_info dkw;
+      int fd;
+
+      fd = open (os_dev, O_RDONLY);
+      if (fd == -1)
+	{
+	  grub_error (GRUB_ERR_BAD_DEVICE,
+		      "cannot open `%s' while attempting to get disk wedge info", os_dev);
+	  return xstrdup (os_dev);
+	}
+      /* We don't call configure_device_driver since this isn't a floppy device name.  */
+      if (ioctl (fd, DIOCGWEDGEINFO, &dkw) == -1)
+	{
+	  grub_error (GRUB_ERR_BAD_DEVICE,
+		      "cannot get disk wedge info of `%s'", os_dev);
+	  close (fd);
+	  return xstrdup (os_dev);
+	}
+      close (fd);
+      return xasprintf ("/dev/r%s%c", dkw.dkw_parent, 'a' + rawpart);
+    }
+
+  /* NetBSD (disk label) partitions are of the form "/dev/r[a-z]+[0-9][a-z]".  */
+  if (strncmp ("/dev/r", os_dev, sizeof("/dev/r") - 1) == 0 &&
+      (os_dev[sizeof("/dev/r") - 1] >= 'a' && os_dev[sizeof("/dev/r") - 1] <= 'z') &&
+      strncmp ("fd", os_dev + sizeof("/dev/r") - 1, sizeof("fd") - 1) != 0)    /* not a floppy device name */
     {
+      char *path = xstrdup (os_dev);
       char *p;
       for (p = path + sizeof("/dev/r"); *p >= 'a' && *p <= 'z'; p++);
       if (grub_isdigit(*p))
 	{
 	  p++;
 	  if ((*p >= 'a' && *p <= 'z') && (*(p+1) == '\0'))
 	    {
 	      /* path matches the required regular expression and
 		 p points to its last character.  */
-	      int rawpart = -1;
-# ifdef HAVE_GETRAWPARTITION
-	      rawpart = getrawpartition();
-# endif /* HAVE_GETRAWPARTITION */
-	      if (rawpart >= 0)
-		*p = 'a' + rawpart;
+	      *p = 'a' + rawpart;
 	    }
-        }
+	}
+      return path;
     }
-  return path;
+
+  return xstrdup (os_dev);
 
 #elif defined (__sun__)
   char *colon = grub_strrchr (os_dev, ':');
   if (grub_memcmp (os_dev, "/devices", sizeof ("/devices") - 1) == 0
       && colon)


[-- Attachment #3: ChangeLog.wedge --]
[-- Type: text/plain, Size: 283 bytes --]

2012-02-03  Grégoire Sutre  <gregoire.sutre@gmail.com>

	NetBSD disk wedge support.

	* grub-core/kern/emu/hostdisk.c (grub_hostdisk_find_partition_start)
	[__NetBSD__]: Handle NetBSD disk wedges.
	* util/getroot.c (convert_system_partition_to_system_disk)
	[__NetBSD__]: Likewise.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] NetBSD disk wedge support
  2012-02-03 10:48 [PATCH] NetBSD disk wedge support Grégoire Sutre
@ 2012-02-03 11:18 ` Vladimir 'φ-coder/phcoder' Serbinenko
  2012-02-03 11:46   ` Grégoire Sutre
  0 siblings, 1 reply; 3+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2012-02-03 11:18 UTC (permalink / raw)
  To: The development of GNU GRUB

Go ahead.

On 03.02.2012 11:48, Grégoire Sutre wrote:
> The attached patch makes it possible to install GRUB from NetBSD
> on a GPT partition.  Those are available as so-called disk wedges
> on NetBSD (see [1]).  Tested under NetBSD -current.
>
> Grégoire
>
> [1] http://netbsd.gw.com/cgi-bin/man-cgi?dk++NetBSD-current
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel


-- 
Regards
Vladimir 'φ-coder/phcoder' Serbinenko



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] NetBSD disk wedge support
  2012-02-03 11:18 ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2012-02-03 11:46   ` Grégoire Sutre
  0 siblings, 0 replies; 3+ messages in thread
From: Grégoire Sutre @ 2012-02-03 11:46 UTC (permalink / raw)
  To: The development of GNU GRUB

On 02/03/2012 12:18 PM, Vladimir 'φ-coder/phcoder' Serbinenko wrote:
> Go ahead.

Done, thanks.

Grégoire

> On 03.02.2012 11:48, Grégoire Sutre wrote:
>> The attached patch makes it possible to install GRUB from NetBSD
>> on a GPT partition. Those are available as so-called disk wedges
>> on NetBSD (see [1]). Tested under NetBSD -current.
>>
>> Grégoire
>>
>> [1] http://netbsd.gw.com/cgi-bin/man-cgi?dk++NetBSD-current
>>
>>
>> _______________________________________________
>> Grub-devel mailing list
>> Grub-devel@gnu.org
>> https://lists.gnu.org/mailman/listinfo/grub-devel
>
>



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-02-03 11:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-03 10:48 [PATCH] NetBSD disk wedge support Grégoire Sutre
2012-02-03 11:18 ` Vladimir 'φ-coder/phcoder' Serbinenko
2012-02-03 11:46   ` Grégoire Sutre

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.