NetBSD disk wedge support.

This commit is contained in:
Grégoire Sutre 2012-02-03 12:32:21 +01:00
parent 055f856f71
commit dc87d45a7a
3 changed files with 62 additions and 13 deletions

View file

@ -1,3 +1,12 @@
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.
2012-02-03 Mark Wooding <mdw@distorted.org.uk> 2012-02-03 Mark Wooding <mdw@distorted.org.uk>
* util/grub-mkconfig.in: Use umask rather than chmod to create * util/grub-mkconfig.in: Use umask rather than chmod to create

View file

@ -100,6 +100,7 @@ struct hd_geometry
# define HAVE_DIOCGDINFO # define HAVE_DIOCGDINFO
# include <sys/ioctl.h> # include <sys/ioctl.h>
# include <sys/disklabel.h> /* struct disklabel */ # include <sys/disklabel.h> /* struct disklabel */
# include <sys/disk.h> /* struct dkwedge_info */
#else /* !defined(__NetBSD__) && !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) */ #else /* !defined(__NetBSD__) && !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) */
# undef HAVE_DIOCGDINFO # undef HAVE_DIOCGDINFO
#endif /* defined(__NetBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) */ #endif /* defined(__NetBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) */
@ -483,6 +484,9 @@ grub_hostdisk_find_partition_start (const char *dev)
# elif !defined(HAVE_DIOCGDINFO) # elif !defined(HAVE_DIOCGDINFO)
struct hd_geometry hdg; struct hd_geometry hdg;
# else /* defined(HAVE_DIOCGDINFO) */ # else /* defined(HAVE_DIOCGDINFO) */
# if defined(__NetBSD__)
struct dkwedge_info dkw;
# endif /* defined(__NetBSD__) */
struct disklabel label; struct disklabel label;
int p_index; int p_index;
# endif /* !defined(HAVE_DIOCGDINFO) */ # endif /* !defined(HAVE_DIOCGDINFO) */
@ -574,6 +578,12 @@ devmapper_fail:
# else /* defined(HAVE_DIOCGDINFO) */ # else /* defined(HAVE_DIOCGDINFO) */
# if defined(__NetBSD__) # if defined(__NetBSD__)
configure_device_driver (fd); 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__) */ # endif /* defined(__NetBSD__) */
if (ioctl (fd, DIOCGDINFO, &label) == -1) if (ioctl (fd, DIOCGDINFO, &label) == -1)
# endif /* !defined(HAVE_DIOCGDINFO) */ # endif /* !defined(HAVE_DIOCGDINFO) */

View file

@ -124,6 +124,7 @@
# define HAVE_DIOCGDINFO # define HAVE_DIOCGDINFO
# include <sys/ioctl.h> # include <sys/ioctl.h>
# include <sys/disklabel.h> /* struct disklabel */ # include <sys/disklabel.h> /* struct disklabel */
# include <sys/disk.h> /* struct dkwedge_info */
#else /* !defined(__NetBSD__) && !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) */ #else /* !defined(__NetBSD__) && !defined(__FreeBSD__) && !defined(__FreeBSD_kernel__) */
# undef HAVE_DIOCGDINFO # undef HAVE_DIOCGDINFO
#endif /* defined(__NetBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) */ #endif /* defined(__NetBSD__) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__) */
@ -1714,12 +1715,44 @@ devmapper_out:
return path; return path;
#elif defined(__NetBSD__) #elif defined(__NetBSD__)
/* NetBSD uses "/dev/r[a-z]+[0-9][a-z]". */ int rawpart = -1;
char *path = xstrdup (os_dev); # ifdef HAVE_GETRAWPARTITION
if (strncmp ("/dev/r", path, sizeof("/dev/r") - 1) == 0 && rawpart = getrawpartition();
(path[sizeof("/dev/r") - 1] >= 'a' && path[sizeof("/dev/r") - 1] <= 'z') && # endif /* HAVE_GETRAWPARTITION */
strncmp ("fd", path + sizeof("/dev/r") - 1, sizeof("fd") - 1) != 0) /* not a floppy device name */ 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; char *p;
for (p = path + sizeof("/dev/r"); *p >= 'a' && *p <= 'z'; p++); for (p = path + sizeof("/dev/r"); *p >= 'a' && *p <= 'z'; p++);
if (grub_isdigit(*p)) if (grub_isdigit(*p))
@ -1729,16 +1762,13 @@ devmapper_out:
{ {
/* path matches the required regular expression and /* path matches the required regular expression and
p points to its last character. */ p points to its last character. */
int rawpart = -1; *p = 'a' + rawpart;
# ifdef HAVE_GETRAWPARTITION
rawpart = getrawpartition();
# endif /* HAVE_GETRAWPARTITION */
if (rawpart >= 0)
*p = 'a' + rawpart;
} }
} }
return path;
} }
return path;
return xstrdup (os_dev);
#elif defined (__sun__) #elif defined (__sun__)
char *colon = grub_strrchr (os_dev, ':'); char *colon = grub_strrchr (os_dev, ':');