Followup to my previous sysctl commit.  When modifying kern.geom.debugflags is
not necessary, this avoids the third sysctlbyname() call (and allocating "flags"
into the stack ;)).

2006-04-21  Robert Millan  <[EMAIL PROTECTED]>

        * grub/asmstub.c (get_diskinfo): Optimize sysctl routine.

Index: grub/asmstub.c
===================================================================
RCS file: /sources/grub/grub/grub/asmstub.c,v
retrieving revision 1.85
diff -u -r1.85 asmstub.c
--- grub/asmstub.c      20 Apr 2006 13:46:45 -0000      1.85
+++ grub/asmstub.c      21 Apr 2006 12:28:17 -0000
@@ -785,7 +785,7 @@
 /* By default, kernel of FreeBSD does not allow overwriting MBR */
 #if defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
 #define GEOM_SYSCTL    "kern.geom.debugflags"
-         int old_flags, flags;
+         int old_flags;
          size_t sizeof_int = sizeof (int);
 
          if (sysctlbyname (GEOM_SYSCTL, &old_flags, &sizeof_int, NULL, 0) != 0)
@@ -794,7 +794,7 @@
          if ((old_flags & 0x10) == 0)
            {
              /* "allow foot shooting", see geom(4) */
-             flags = old_flags | 0x10;
+             int flags = old_flags | 0x10;
 
              if (sysctlbyname (GEOM_SYSCTL, NULL, NULL, &flags, sizeof (int)) 
!= 0)
                grub_printf ("failed to set " GEOM_SYSCTL "sysctl: %s\n", 
strerror (errno));
@@ -802,7 +802,7 @@
 #endif
          disks[drive].flags = open (devname, O_RDWR);
 #if defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
-         if (flags != old_flags)
+         if ((old_flags & 0x10) == 0)
            {
              if (sysctlbyname (GEOM_SYSCTL, NULL, NULL, &old_flags, sizeof 
(int)) != 0)
                grub_printf ("failed to set " GEOM_SYSCTL "sysctl: %s\n", 
strerror (errno));

-- 
Robert Millan


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to