fix grub-setup on kfreebsd by adding 0x10 to the sysctl ("kern.geom.debugflags") flags
PATCH 1/1 fix grub-setup on kfreebsd by adding 0x10 to the sysctl ("kern.geom.debugflags") flags
Here's a patch to fix grub-setup on Debian GNU/kFreeBSD. Without it, it fails always with grub-setup: error: cannot open /dev/da0' in open_device()'
With it, it works fine.
Signature · 1 line
Felix Zielcke
Am Montag, den 13.04.2009, 15:32 +0200 schrieb Felix Zielcke:
Quoted 4 lines
Here's a patch to fix grub-setup on Debian GNU/kFreeBSD. Without it, it fails always with
grub-setup: error: cannot open/dev/da0' inopen_device()'
With it, it works fine.
Args there should be a patch attached. Fixed.
Signature · 1 line
Felix Zielcke
2009-04-13 Felix Zielcke <[email protected]>
util/hostdisk.c [__FreeBSD_kernel]: Include <sys/param.h> and <sys/sysctl.h> (open_device) [__FreeBSD_kernel_]: Use sysctlgetbyname() to add 0x10 to `kern.geom.debugflags', before opening the device and reset them afterwards.
hostdisk.c +22 -0
@@ -90,6 +90,11 @@ struct hd_geometry# include <sys/disk.h> /* DIOCGMEDIASIZE */ #endif +#ifdef __FreeBSD_kernel__ +#include <sys/param.h> +#include <sys/sysctl.h> +#endif +struct {char *drive;
@@ -340,7 +345,24 @@ open_device (const grub_disk_t disk, gru sector -= disk->partition->start; }#else /* ! __linux__ */ +#if defined __FreeBSD_kernel__ +int sysctl_flags, sysctl_oldflags; +size_t sysctl_size =sizeof (sysctl_flags); + +if (sysctlbyname ("kern.geom.debugflags" , &sysctl_oldflags, &sysctl_size,NULL ,0 )) +grub_util_error ("cannot get current flags of sysctl kern.geom.debugflags" ); + sysctl_flags = sysctl_oldflags |=0x10 ; +if (sysctlbyname ("kern.geom.debugflags" ,NULL ,0 , &sysctl_flags, sysctl_size)) +grub_util_error ("cannot set flags of sysctl kern.geom.debugflags" ); +#endif + fd =open (map[disk->id].device, flags); + +#if defined __FreeBSD_kernel__ +if (sysctlbyname ("kern.geom.debugflags" ,NULL ,0 , &sysctl_oldflags, sysctl_size)) +grub_util_error ("cannot set flags back to the old value for sysctl kern.geom.debugflags" ); +#endif +if (fd <0 ) {grub_error (GRUB_ERR_BAD_DEVICE ,"cannot open `%s' in open_device()" , map[disk->id].device);
Quoted 1 line · Felix Zielcke
+#ifdef
__FreeBSD_kernel__
Unfortunately FreeBSD doesn't define __FreeBSD_kernel__, so we need to check for both macros.
hostdisk.c open_device (const grub_disk_t disk, gru · line 350
Quoted 3 lines
hostdisk.c +3
-0+#if defined __FreeBSD_kernel__ +int sysctl_flags, sysctl_oldflags; +size_t sysctl_size =sizeof (sysctl_flags);
You can add a `const' on this one.
Quoted 1 line
+
sysctl_flags=sysctl_oldflags|=0x10;
Shouldn't this be "sysctl_oldflags | 0x10" ?
Btw you can avoid the two subsequent calls if sysctl_flags == sysctl_oldflags.
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."
Am Montag, den 13.04.2009, 16:49 +0200 schrieb Robert Millan:
Thanks for reviewing.
Quoted 5 lines · Felix Zielcke
Quoted 1 line
+#ifdef
__FreeBSD_kernel__Unfortunately FreeBSD doesn't define
__FreeBSD_kernel__, so we need to check for both macros.
Oh right.
Quoted 9 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+#if defined __FreeBSD_kernel__ + int sysctl_flags, sysctl_oldflags; + size_t sysctl_size = sizeof (sysctl_flags);You can add a `const' on this one.
Quoted 1 line
+
sysctl_flags=sysctl_oldflags|=0x10;Shouldn't this be "
sysctl_oldflags|0x10" ?
Yes.
Quoted 1 line
Btw you can avoid the two subsequent calls if
sysctl_flags==sysctl_oldflags.
Right and actually it can be even avoided if 0x10 is already set.
Is it correct that I used now `[__FreeBSD__]: Likewise.' in the Changelog?
The GCS unfortunately doestn't tell anything about the case that a change applies to 2 or more marcros and I couldn't find an example in the existing Changelog for this.
Signature · 1 line
Felix Zielcke
2009-04-13 Felix Zielcke <[email protected]>
util/hostdisk.c [__FreeBSD_kernel]: Include <sys/param.h> and <sys/sysctl.h>. [__FreeBSD__]: Likewise. (open_device) [__FreeBSD_kernel_]: Use sysctlgetbyname() to add 0x10 to `kern.geom.debugflags' if it's not already set, before opening the device and reset them afterwards. [__FreeBSD__]: Likewise.
hostdisk.c +19 -0
@@ -88,6 +88,8 @@ struct hd_geometry#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)# include <sys/disk.h> /* DIOCGMEDIASIZE */ +# include <sys/param.h> +# include <sys/sysctl.h> #endif struct
@@ -340,7 +342,24 @@ open_device (const grub_disk_t disk, gru sector -= disk->partition->start; }#else /* ! __linux__ */ +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +int sysctl_flags, sysctl_oldflags; +const size_t sysctl_size =sizeof (sysctl_flags); + +if (sysctlbyname ("kern.geom.debugflags" , &sysctl_oldflags, &sysctl_size,NULL ,0 )) +grub_util_error ("cannot get current flags of sysctl kern.geom.debugflags" ); + sysctl_flags = sysctl_oldflags |0x10 ; +if (! sysctl_oldflags &0x10 &&sysctlbyname ("kern.geom.debugflags" ,NULL ,0 , &sysctl_flags, sysctl_size)) +grub_util_error ("cannot set flags of sysctl kern.geom.debugflags" ); +#endif + fd =open (map[disk->id].device, flags); + +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +if (! sysctl_oldflags &0x10 &&sysctlbyname ("kern.geom.debugflags" ,NULL ,0 , &sysctl_oldflags, sysctl_size)) +grub_util_error ("cannot set flags back to the old value for sysctl kern.geom.debugflags" ); +#endif +if (fd <0 ) {grub_error (GRUB_ERR_BAD_DEVICE ,"cannot open `%s' in open_device()" , map[disk->id].device);
Quoted 3 lines · Felix Zielcke
Quoted 1 line
Btw you can avoid the two subsequent calls if
sysctl_flags==sysctl_oldflags.Right and actually it can be even avoided if
0x10is already set.
It's the same thing (if and only if 0x10 was set, old and new flags will be the same). I'm not sure which check is cheaper, but it doesn't matter much anyway.
Quoted 5 lines
Is it correct that I used now `[__FreeBSD__]: Likewise.' in the Changelog?
The GCS unfortunately doestn't tell anything about the case that a change applies to 2 or more marcros and I couldn't find an example in the existing Changelog for this.
How about [__FreeBSD__ || __FreeBSD_kernel__] ?
hostdisk.c open_device (const grub_disk_t disk, gru · line 350
Quoted 2 lines
hostdisk.c +2
-0+if (sysctlbyname ("kern.geom.debugflags" , &sysctl_oldflags, &sysctl_size,NULL ,0 )) +grub_util_error ("cannot get current flags of sysctl kern.geom.debugflags" );
I'd just return grub_error instead. Otherwise we abort the program even if failure to read a drive is not critical (e.g. lvm.mod scannning all drives, grub-emu, etc).
hostdisk.c open_device (const grub_disk_t disk, gru · line 353
Quoted 2 lines
hostdisk.c +2
-0+if (! sysctl_oldflags &0x10 &&sysctlbyname ("kern.geom.debugflags" ,NULL ,0 , &sysctl_flags, sysctl_size)) +grub_util_error ("cannot set flags of sysctl kern.geom.debugflags" );
Just a matter of taste, I'd suggest nested ifs to make it more readable.
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."
Am Montag, den 13.04.2009, 21:11 +0200 schrieb Robert Millan:
Quoted 1 line
How about [
__FreeBSD__||__FreeBSD_kernel__] ?
Ok.
Quoted 6 lines
hostdisk.c open_device (const grub_disk_t disk, gru · line 350
Quoted 2 lines
hostdisk.c +2
-0+if (sysctlbyname ("kern.geom.debugflags" , &sysctl_oldflags, &sysctl_size,NULL ,0 )) +grub_util_error ("cannot get current flags of sysctl kern.geom.debugflags" );I'd just return
grub_errorinstead. Otherwise we abort the program even if failure to read a drive is not critical (e.g. lvm.mod scannning all drives, grub-emu, etc).
Ok.
Quoted 4 lines
hostdisk.c open_device (const grub_disk_t disk, gru · line 353
Quoted 2 lines
hostdisk.c +2
-0+if (! sysctl_oldflags &0x10 &&sysctlbyname ("kern.geom.debugflags" ,NULL ,0 , &sysctl_flags, sysctl_size)) +grub_util_error ("cannot set flags of sysctl kern.geom.debugflags" );Just a matter of taste, I'd suggest nested ifs to make it more readable.
Changed too.
I commited this now.
Signature · 1 line
Felix Zielcke