From: "Grégoire Sutre" <gregoire.sutre@gmail.com>
To: The development of GNU GRUB <grub-devel@gnu.org>
Subject: [PATCH] NetBSD disk wedge support
Date: Fri, 03 Feb 2012 11:48:18 +0100 [thread overview]
Message-ID: <4F2BBB72.2060507@gmail.com> (raw)
[-- 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.
next reply other threads:[~2012-02-03 10:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-03 10:48 Grégoire Sutre [this message]
2012-02-03 11:18 ` [PATCH] NetBSD disk wedge support Vladimir 'φ-coder/phcoder' Serbinenko
2012-02-03 11:46 ` Grégoire Sutre
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4F2BBB72.2060507@gmail.com \
--to=gregoire.sutre@gmail.com \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.