Skip to contentSkip to conversation

GRUB2: *BSD and more patch

PATCH Sergey Matveychuk 5 participants 31 messages Mar 18, 2004 – Jan 11, 2005

lore
Share & tools
lore
#0 lore raw

Here is a patch with *BSD stuff.

Also I've moved pupa_util_biosdisk_init() above pupa_guess_root_device() in util/pupa-emu.c because of pupa_guess_root_device() use parsed device.map but reading and parsing do in pupa_util_biosdisk_init().

I've tested the patch buth FreeBSD 4.x and 5.x. It should be tested on NetBSD and OpenBSD also.

Signature · 1 line
Sem.
ChangeLog +14 -0
diff -ruN grub2/ChangeLog grub2.devel/ChangeLog
@@ -1,3 +1,17 @@
+2004-03-15  Sergey Matveychuk  <[email protected]>
+
+	* util/i386/pc/biosdisk.c: Add *BSD stuff.
+	(get_os_disk): Change strchr() with strrchr() to fix working with
+	sd* disk names.
+	* grub2/util/i386/pc/getroot.c: Update copyright.
+	(find_root_device) [__FreeBSD__]: Do not check for a block device.
+	* util/misc.c [__FreeBSD__]: Do not include malloc.h.
+	Change memalign() with malloc().
+	* util/pupa-emu.c:
+	[__FreeBSD__]: Do not include malloc.h.
+	(main): Move pupa_util_biosdisk_init() above pupa_guess_root_device().
+	* util/pupa-setup.c [__FreeBSD__]: Do not include malloc.h.
+
 2004-03-14  Jeroen Dekkers  <[email protected]>
 
 	* Makefile.in: Update copyright.
util/i386/pc/biosdisk.c +79 -5

118 lines not on this page · raw message

util/i386/pc/getroot.c +6 -2
diff -ruN grub2/util/i386/pc/getroot.c grub2.devel/util/i386/pc/getroot.c
@@ -1,7 +1,7 @@
 /* getroot.c - Get root device */
 /*
  *  PUPA  --  Preliminary Universal Programming Architecture for GRUB
- *  Copyright (C) 1999,2000,2001,2002,2003  Free Software Foundation, Inc.
+ *  Copyright (C) 1999,2000,2001,2002,2003,2004  Free Software Foundation, Inc.
  *
  *  PUPA is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -177,8 +177,12 @@
 	      return res;
 	    }
 	}
-
+      /* On last FreeBSDs there are no block devices */
+#if !defined(__FreeBSD__)
       if (S_ISBLK (st.st_mode) && st.st_rdev == dev)
+#else
+      if (st.st_rdev == dev)
+#endif
 	{
 	  /* Found!  */
 	  char *res;
util/i386/pc/pupa-setup.c +1 -1
diff -ruN grub2/util/i386/pc/pupa-setup.c grub2.devel/util/i386/pc/pupa-setup.c
@@ -1,7 +1,7 @@
 /* pupa-setup.c - make PUPA usable */
 /*
  *  PUPA  --  Preliminary Universal Programming Architecture for GRUB
- *  Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
+ *  Copyright (C) 1999,2000,2001,2002,2003,2004  Free Software Foundation, Inc.
  *
  *  PUPA is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
util/misc.c +6 -0
diff -ruN grub2/util/misc.c grub2.devel/util/misc.c
@@ -24,7 +24,9 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/times.h>
+#if !defined(__FreeBSD__)
 #include <malloc.h>
+#endif
 
 #include <pupa/util/misc.h>
 #include <pupa/mm.h>
@@ -194,7 +196,11 @@
 {
   void *p;
   
+#if !defined(__FreeBSD__)
   p = memalign (align, size);
+#else
+  p = malloc(size);
+#endif
   if (! p)
     pupa_util_error ("out of memory");
   
util/pupa-emu.c +4 -3
diff -ruN grub2/util/pupa-emu.c grub2.devel/util/pupa-emu.c
@@ -18,7 +18,9 @@
  */
 
 #include <stdlib.h>
+#if !defined(__FreeBSD__)
 #include <malloc.h>
+#endif
 #include <sys/stat.h>
 #include <argp.h>
 #include <string.h>
@@ -135,6 +137,8 @@
 
   argp_parse (&argp, argc, argv, 0, 0, &args);
 
+  /* XXX: This is a bit unportable.  */
+  pupa_util_biosdisk_init (args.dev_map);
   /* More sure there is a root device.  */
   if (! args.root_dev)
     {
@@ -152,9 +156,6 @@
 
   pupa_env_set ("prefix", rootprefix);
   
-  /* XXX: This is a bit unportable.  */
-  pupa_util_biosdisk_init (args.dev_map);
-
   /* Initialize the default modules.  */
   pupa_fat_init ();
   pupa_ext2_init ();
#1 lore raw
Quoted 1 line · Sergey Matveychuk

diff -ruN grub2/util/i386/pc/biosdisk.c

grub2.devel/util/i386/pc/biosdisk.c

util/i386/pc/biosdisk.c Tue Mar 16 04:25:21 2004 line 40

Quoted 7 lines
util/i386/pc/biosdisk.c Tue Mar 16 04:25:21 2004 renamed from util/i386/pc/biosdisk.c Tue Mar 16 02:24:00 2004 +1 -0
@@ -37,6 +37,17 @@
 #include <errno.h>
 #include <limits.h>
 
+#if defined(__FreeBSD__) || defined(__NetBSD__) || 

defined(__OpenBSD__)

util/i386/pc/biosdisk.c Tue Mar 16 04:25:21 2004 line 50

Quoted 10 lines
util/i386/pc/biosdisk.c Tue Mar 16 04:25:21 2004 renamed from util/i386/pc/biosdisk.c Tue Mar 16 02:24:00 2004 +10 -0
+# include <sys/ioctl.h>                /* ioctl */
+# include <sys/disklabel.h>
+#if defined(__FreeBSD__)
+#include <sys/param.h>
+#if __FreeBSD_version >= 500040
+#include <sys/disk.h>
+#endif
+#endif
+#endif /* __FreeBSD__ || __NetBSD__ || __OpenBSD__ */
+

This part should be indented appropriately, according to the GNU Coding Standards. Please take a look at how I applied your patch to GRUB legacy.

util/i386/pc/biosdisk.c Tue Mar 16 04:25:21 2004

Quoted 5 lines
util/i386/pc/biosdisk.c Tue Mar 16 04:25:21 2004 renamed from util/i386/pc/biosdisk.c Tue Mar 16 02:24:00 2004 +5 -0
+#if !defined(__FreeBSD__)
+    if (fstat (fd, &st) < 0 || ! S_ISBLK (st.st_mode))
+#else
+    if (fstat (fd, &st) < 0)
+#endif

I think this part can omit the check using S_ISBLK regardless of the OS.

Quoted 25 lines
util/i386/pc/biosdisk.c Tue Mar 16 04:25:21 2004 renamed from util/i386/pc/biosdisk.c Tue Mar 16 02:24:00 2004 +25 -0
+#if !defined(__FreeBSD__) || __FreeBSD_version < 500040
+    if (ioctl (fd, DIOCGDINFO, &hdg))
+      goto fail;
+    
+    disk->total_sectors = hdg.d_secperunit;
+#else
+    u_int    u, secsize;
+    off_t    mediasize;
+
+    if(ioctl(fd, DIOCGSECTORSIZE, &secsize) != 0)
+       secsize = 512;
+
+    if (ioctl(fd, DIOCGMEDIASIZE, &mediasize) != 0)
+       goto fail;
+
+    hdg.d_secperunit = mediasize / secsize;
+
+    if (ioctl(fd, DIOCGFWSECTORS, &u) == 0)
+           hdg.d_nsectors = u;
+    else
+           hdg.d_nsectors = 63;
+    if (ioctl(fd, DIOCGFWHEADS, &u) == 0)
+           hdg.d_ntracks = u;
+    else if (hdg.d_secperunit <= 63*1*1024)
+           hdg.d_ntracks = 1;

util/i386/pc/biosdisk.c Tue Mar 16 04:25:21 2004

Quoted 10 lines
util/i386/pc/biosdisk.c Tue Mar 16 04:25:21 2004 renamed from util/i386/pc/biosdisk.c Tue Mar 16 02:24:00 2004 +10 -0
+    else if (hdg.d_secperunit <= 63*16*1024)
+           hdg.d_ntracks = 16;
+    else
+           hdg.d_ntracks = 255;
+    hdg.d_secpercyl = hdg.d_ntracks * hdg.d_nsectors;
+    hdg.d_ncylinders = hdg.d_secperunit / hdg.d_secpercyl;
+
+    disk->total_sectors = hdg.d_secperunit;
+
+#endif

I prefer not using hdg here. Again, look at my way in GRUB legacy.

Quoted 1 line

diff -ruN grub2/util/i386/pc/getroot.c

grub2.devel/util/i386/pc/getroot.c

util/i386/pc/getroot.c Tue Mar 16 03:20:05 2004 line 4

Quoted 7 lines
util/i386/pc/getroot.c Tue Mar 16 03:20:05 2004 renamed from util/i386/pc/getroot.c Sun Mar 14 05:44:20 2004 +0 -1
@@ -1,7 +1,7 @@
 /* getroot.c - Get root device */
 /*
  *  PUPA  --  Preliminary Universal Programming Architecture for GRUB
- *  Copyright (C) 1999,2000,2001,2002,2003  Free Software Foundation, 

Inc.

util/i386/pc/getroot.c Tue Mar 16 03:20:05 2004 line 4

Quoted 1 line
util/i386/pc/getroot.c Tue Mar 16 03:20:05 2004 renamed from util/i386/pc/getroot.c Sun Mar 14 05:44:20 2004 +1 -0
+ *  Copyright (C) 1999,2000,2001,2002,2003,2004  Free Software 

Foundation, Inc.

util/i386/pc/getroot.c Tue Mar 16 03:20:05 2004 line 7

Quoted 3 lines
util/i386/pc/getroot.c Tue Mar 16 03:20:05 2004 renamed from util/i386/pc/getroot.c Sun Mar 14 05:44:20 2004 +0 -0
  *
  *  PUPA is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published 

by

util/i386/pc/getroot.c Tue Mar 16 03:20:05 2004 line 185

Quoted 11 lines
util/i386/pc/getroot.c Tue Mar 16 03:20:05 2004 renamed from util/i386/pc/getroot.c Sun Mar 14 05:44:20 2004 +5 -1
@@ -177,8 +177,12 @@
              return res;
            }
        }
-
+      /* On last FreeBSDs there are no block devices */
+#if !defined(__FreeBSD__)
       if (S_ISBLK (st.st_mode) && st.st_rdev == dev)
+#else
+      if (st.st_rdev == dev)
+#endif

I think this can be generic, too. The check for a block device is not very important.

util/misc.c Mon Mar 15 20:14:40 2004 line 29

Quoted 10 lines

diff -ruN grub2/util/misc.c grub2.devel/util/misc.c

util/misc.c Mon Mar 15 20:14:40 2004 renamed from util/misc.c Sun Mar 14 05:44:20 2004 +2 -0
@@ -24,7 +24,9 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/times.h>
+#if !defined(__FreeBSD__)
 #include <malloc.h>
+#endif

I think this should be probed by the configure script.

util/misc.c Mon Mar 15 20:14:40 2004

Quoted 5 lines
util/misc.c Mon Mar 15 20:14:40 2004 renamed from util/misc.c Sun Mar 14 05:44:20 2004 +4 -0
+#if !defined(__FreeBSD__)
   p = memalign (align, size);
+#else
+  p = malloc(size);
+#endif

Hmm, FreeBSD doesn't have memalign? Since memalign is different from malloc, it is not good to just replace memalign with malloc.

BTW, have you signed a copyright assignment for GRUB? I'm sorry, but I don't remember well. If not, I'd like you to do that.

Regards,
Okuji

#2 lore raw
Quoted 1 line · Yoshinori K. Okuji

This part should be indented appropriately, according to the GNU Coding Standards. Please take a look at how I applied your patch to GRUB legacy.

Done.

Quoted 1 line

I think this part can omit the check using S_ISBLK regardless of the OS.

Done.

Quoted 2 lines

I prefer not using hdg here. Again, look at my way in GRUB legacy.

Done.

Quoted 1 line

I think this should be probed by the configure script.

Done. I don't include configure script in the patch. So create it from configure.ac please.

Quoted 10 lines

Review

Quoted 7 lines
(quoted diff) +4 -0
+#if !defined(__FreeBSD__)
  p = memalign (align, size);
+#else
+  p = malloc(size);
+#endif

Hmm, FreeBSD doesn't have memalign? Since memalign is different from malloc, it is not good to just replace memalign with malloc.

I told with Marco and Jeroen on IRC and we descide it not so important. But I open for your offers.

Quoted 2 lines

BTW, have you signed a copyright assignment for GRUB? I'm sorry, but I don't remember well. If not, I'd like you to do that.

A new patch with a few fixes for inherited from fsys_ffs.c bugs is testing now. I publish it within a few days.

Signature · 1 line
Sem.
ChangeLog +12 -0
diff -ruN grub2/ChangeLog grub2.devel/ChangeLog
@@ -1,3 +1,15 @@
+2004-03-15  Sergey Matveychuk  <[email protected]>
+
+	* util/i386/pc/biosdisk.c: Add *BSD stuff.
+	(get_os_disk): Change strchr() with strrchr() to fix working with
+	sd* disk names.
+	* util/i386/pc/getroot.c: Update copyright.
+	(find_root_device): Do not check for a block device.
+	* util/misc.c: Include malloc.h only if it's needed.
+	[__FreeBSD__]: Change memalign() with malloc().
+	* util/pupa-emu.c: Include malloc.h only if it's needed.
+	(main): Move pupa_util_biosdisk_init() above pupa_guess_root_device().
+
 2004-03-14  Jeroen Dekkers  <[email protected]>
 
 	* Makefile.in: Update copyright.
config.h.in +3 -0
diff -ruN grub2/config.h.in grub2.devel/config.h.in
@@ -28,6 +28,9 @@
 /* Define to 1 if you have the <memory.h> header file. */
 #undef HAVE_MEMORY_H
 
+/* Define to 1 if you have the <malloc.h> header file. */
+#undef HAVE_MALLOC_H
+
 /* Define to 1 if you have the <stdint.h> header file. */
 #undef HAVE_STDINT_H
 
configure.ac +2 -0
diff -ruN grub2/configure.ac grub2.devel/configure.ac
@@ -78,6 +78,8 @@
 fi
 AC_SUBST(CFLAGS)
 
+AC_CHECK_HEADER(malloc.h)
+
 # Defined in aclocal.m4.
 pupa_ASM_USCORE
 pupa_CHECK_START_SYMBOL
util/i386/pc/biosdisk.c +61 -6

107 lines not on this page · raw message

util/i386/pc/getroot.c +2 -3
diff -ruN grub2/util/i386/pc/getroot.c grub2.devel/util/i386/pc/getroot.c
@@ -1,7 +1,7 @@
 /* getroot.c - Get root device */
 /*
  *  PUPA  --  Preliminary Universal Programming Architecture for GRUB
- *  Copyright (C) 1999,2000,2001,2002,2003  Free Software Foundation, Inc.
+ *  Copyright (C) 1999,2000,2001,2002,2003,2004  Free Software Foundation, Inc.
  *
  *  PUPA is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -177,8 +177,7 @@
 	      return res;
 	    }
 	}
-
-      if (S_ISBLK (st.st_mode) && st.st_rdev == dev)
+      if (st.st_rdev == dev)
 	{
 	  /* Found!  */
 	  char *res;
util/misc.c +7 -0
diff -ruN grub2/util/misc.c grub2.devel/util/misc.c
@@ -17,6 +17,7 @@
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
+#include <config.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
@@ -24,7 +25,9 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/times.h>
+#if HAVE_MALLOC_H
 #include <malloc.h>
+#endif
 
 #include <pupa/util/misc.h>
 #include <pupa/mm.h>
@@ -194,7 +197,11 @@
 {
   void *p;
   
+#if !defined(__FreeBSD__)
   p = memalign (align, size);
+#else
+  p = malloc(size);
+#endif
   if (! p)
     pupa_util_error ("out of memory");
   
util/pupa-emu.c +4 -3
diff -ruN grub2/util/pupa-emu.c grub2.devel/util/pupa-emu.c
@@ -18,7 +18,9 @@
  */
 
 #include <stdlib.h>
+#if !defined(__FreeBSD__)
 #include <malloc.h>
+#endif
 #include <sys/stat.h>
 #include <argp.h>
 #include <string.h>
@@ -135,6 +137,8 @@
 
   argp_parse (&argp, argc, argv, 0, 0, &args);
 
+  /* XXX: This is a bit unportable.  */
+  pupa_util_biosdisk_init (args.dev_map);
   /* More sure there is a root device.  */
   if (! args.root_dev)
     {
@@ -152,9 +156,6 @@
 
   pupa_env_set ("prefix", rootprefix);
   
-  /* XXX: This is a bit unportable.  */
-  pupa_util_biosdisk_init (args.dev_map);
-
   /* Initialize the default modules.  */
   pupa_fat_init ();
   pupa_ext2_init ();
#3 lore raw

Sergey Matveychuk <[email protected]> wrote:

: -  if (strncmp ("/dev/sd", path, 7) == 0 || strncmp ("/dev/hd", path, 7) == 0)
: +  if (strncmp ("/dev/sd", path, 7) == 0 || strncmp ("/dev/hd", path, 7) == 0 ||
: +      strncmp ("/dev/ad", path, 7) == 0 || strncmp ("/dev/wd", path, 7) == 0)

Doesn't the GCS say that lines should be broken before operators? Not a biggie, but anway.

Signature · 4 lines
Johan Rydberg, Free Software Developer, Sweden
http://rtmk.sf.net | http://www.nongnu.org/guss/

Playing A Perfect Circle - Lullaby
#4 lore raw
In reply to Sergey Matveychuk
Quoted 2 lines · Sergey Matveychuk

I told with Marco and Jeroen on IRC and we descide it not so important. But I open for your offers.

It seems it is used as a fix by many people (I found this using google). But at the moment pupa_memalign is not used anywhere in PUPA. And AFAIK it does not even matter for the currently code if it is supported.

If you want to fix it this way, it would be better to check for the existence of memalign using autoconf IMHO.

Quoted 5 lines
Quoted 2 lines

BTW, have you signed a copyright assignment for GRUB? I'm sorry, but I don't remember well. If not, I'd like you to do that.

A new patch with a few fixes for inherited from fsys_ffs.c bugs is testing now. I publish it within a few days.

Do you mean for GRUB 2? Please keep us up-to-date what you are doing to prevent people from doing double work.

Quoted 1 line

diff -ruN grub2/ChangeLog grub2.devel/ChangeLog

Can you please make a patch using the -p argument as well? In that case it is visible which function was changed.

ChangeLog line 3

Quoted 6 lines
ChangeLog +3 -0
@@ -1,3 +1,15 @@
+2004-03-15  Sergey Matveychuk  <[email protected]>
+
+	* util/i386/pc/biosdisk.c: Add *BSD stuff.

Can you please be more clear here? It would be better to notice everything you changed and added.

--
Marco

#5 lore raw
Quoted 2 lines · Marco Gerards

If you want to fix it this way, it would be better to check for the existence of memalign using autoconf IMHO.

Hmm. OK :)

Quoted 11 lines
Quoted 7 lines
Quoted 4 lines

BTW, have you signed a copyright assignment for GRUB? I'm sorry, but I don't remember well. If not, I'd like you to do that.

A new patch with a few fixes for inherited from fsys_ffs.c bugs is testing now. I publish it within a few days.

Do you mean for GRUB 2? Please keep us up-to-date what you are doing to prevent people from doing double work.

No. Okuji means GRUB1 UFS2 patch I think. Okiji, am I right? :)

Quoted 7 lines
Quoted 3 lines

diff -ruN grub2/ChangeLog grub2.devel/ChangeLog

Can you please make a patch using the -p argument as well? In that case it is visible which function was changed.

OK.

Quoted 5 lines

ChangeLog line 3

Quoted 1 line
ChangeLog +1 -0
+	* util/i386/pc/biosdisk.c: Add *BSD stuff.

Can you please be more clear here? It would be better to notice everything you changed and added.

I'll do it.

Quoted 6 lines · Johan Rydberg
: +  if (strncmp ("/dev/sd", path, 7) == 0 || strncmp ("/dev/hd", path, 7) == 0 ||
: +      strncmp ("/dev/ad", path, 7) == 0 || strncmp ("/dev/wd", path, 7) == 0)

Doesn't the GCS say that lines should be broken before operators? Not a biggie, but anway.

Are you agree with it?

Signature · 1 line
Sem.
#6 lore raw
Quoted 10 lines · Sergey Matveychuk
Quoted 1 line

: + if (strncmp ("/dev/sd", path, 7) == 0 || strncmp ("/dev/hd",

path, 7) == 0 ||

Quoted 1 line

: + strncmp ("/dev/ad", path, 7) == 0 || strncmp ("/dev/wd",

path, 7) == 0)

Quoted 4 lines

Doesn't the GCS say that lines should be broken before operators? Not a biggie, but anway.

Are you agree with it?

Please do it as it is explained in the GCS. The same goes for the changelog.

Thanks,
Marco

#7 lore raw

Here is a third version.

Signature · 1 line
Sem.
ChangeLog +16 -0
diff -ruNp grub2/ChangeLog grub2.test/ChangeLog
@@ -1,3 +1,19 @@
+2004-03-15  Sergey Matveychuk  <[email protected]>
+
+	* util/i386/pc/biosdisk.c: Added headers for BSD.
+	(pupa_util_biosdisk_open): Added getting a device size for BSD.
+	(get_os_disk): Use code for __GNU__ for BSD too. Add recognizing of
+	'ad' and 'wd' disk names. Change strchr() with strrchr() to fix working
+	with 'sd' disk names.
+	(pupa_util_biosdisk_get_pupa_dev): Do not call
+	make_device_name(drive,-1-1) if not a block device.
+	* util/i386/pc/getroot.c: Update copyright.
+	(find_root_device): Do not check for a block device.
+	* util/misc.c: Include malloc.h only if it's needed.
+	(pupa_memalign): Change memalign() with malloc() where unavailable.
+	* util/pupa-emu.c: Include malloc.h only if it's needed.
+	(main): Move pupa_util_biosdisk_init() above pupa_guess_root_device().
+
 2004-03-14  Jeroen Dekkers  <[email protected]>
 
 	* Makefile.in: Update copyright.
config.h.in +2 -2
diff -ruNp grub2/config.h.in grub2.test/config.h.in
@@ -4,13 +4,13 @@
    prefixed with an asterisk */
 #undef ABSOLUTE_WITHOUT_ASTERISK
 
-/* Define it to \"addr32\" or \"addr32;\" to make GAS happy */
+/* Define it to "addr32" or "addr32;" to make GAS happy */
 #undef ADDR32
 
 /* Define it to one of __bss_start, edata and _edata */
 #undef BSS_START_SYMBOL
 
-/* Define it to \"data32\" or \"data32;\" to make GAS happy */
+/* Define it to "data32" or "data32;" to make GAS happy */
 #undef DATA32
 
 /* Define it to either end or _end */
configure.ac +3 -0
diff -ruNp grub2/configure.ac grub2.test/configure.ac
@@ -78,6 +78,9 @@ if test "x$default_CFLAGS" = xyes; then
 fi
 AC_SUBST(CFLAGS)
 
+AC_CHECK_HEADER(malloc.h)
+AC_CHECK_FUNC(memalign)
+
 # Defined in aclocal.m4.
 pupa_ASM_USCORE
 pupa_CHECK_START_SYMBOL
util/i386/pc/biosdisk.c +60 -5

99 lines not on this page · raw message

util/i386/pc/getroot.c +2 -3
diff -ruNp grub2/util/i386/pc/getroot.c grub2.test/util/i386/pc/getroot.c
@@ -1,7 +1,7 @@
 /* getroot.c - Get root device */
 /*
  *  PUPA  --  Preliminary Universal Programming Architecture for GRUB
- *  Copyright (C) 1999,2000,2001,2002,2003  Free Software Foundation, Inc.
+ *  Copyright (C) 1999,2000,2001,2002,2003,2004  Free Software Foundation, Inc.
  *
  *  PUPA is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -177,8 +177,7 @@ find_root_device (const char *dir, dev_t
 	      return res;
 	    }
 	}
-
-      if (S_ISBLK (st.st_mode) && st.st_rdev == dev)
+      if (st.st_rdev == dev)
 	{
 	  /* Found!  */
 	  char *res;
util/misc.c +7 -0
diff -ruNp grub2/util/misc.c grub2.test/util/misc.c
@@ -17,6 +17,7 @@
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
+#include <config.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
@@ -24,7 +25,9 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/times.h>
+#ifdef HAVE_MALLOC_H
 #include <malloc.h>
+#endif
 
 #include <pupa/util/misc.h>
 #include <pupa/mm.h>
@@ -194,7 +197,11 @@ pupa_memalign (pupa_size_t align, pupa_s
 {
   void *p;
   
+#ifdef HAVE_MEMALIGN
   p = memalign (align, size);
+#else
+  p = malloc(size);
+#endif
   if (! p)
     pupa_util_error ("out of memory");
   
util/pupa-emu.c +4 -3
diff -ruNp grub2/util/pupa-emu.c grub2.test/util/pupa-emu.c
@@ -18,7 +18,9 @@
  */
 
 #include <stdlib.h>
+#ifdef HAVE_MALLOC_H
 #include <malloc.h>
+#endif
 #include <sys/stat.h>
 #include <argp.h>
 #include <string.h>
@@ -135,6 +137,8 @@ main (int argc, char *argv[])
 
   argp_parse (&argp, argc, argv, 0, 0, &args);
 
+  /* XXX: This is a bit unportable.  */
+  pupa_util_biosdisk_init (args.dev_map);
   /* More sure there is a root device.  */
   if (! args.root_dev)
     {
@@ -152,9 +156,6 @@ main (int argc, char *argv[])
 
   pupa_env_set ("prefix", rootprefix);
   
-  /* XXX: This is a bit unportable.  */
-  pupa_util_biosdisk_init (args.dev_map);
-
   /* Initialize the default modules.  */
   pupa_fat_init ();
   pupa_ext2_init ();
#8 lore raw
Quoted 1 line · Sergey Matveychuk

Here is a third version.

Great!

After reading your patch I found some other problems, sorry for not looking good enough the first time. Most problems I found are minor nitpicks.

If it is ok for Okuji I can make the changes I proposed (and have a quick look at the changelog entry) and commit the patch.

ChangeLog line 3

Quoted 9 lines
Signature · 2 lines
Sem.
diff -ruNp grub2/ChangeLog grub2.test/ChangeLog
ChangeLog +3 -0
@@ -1,3 +1,19 @@
+2004-03-15  Sergey Matveychuk  <[email protected]>
+
+	* util/i386/pc/biosdisk.c: Added headers for BSD.

Please say exactly what header files you are including.

ChangeLog line 8

Quoted 1 line
ChangeLog +1 -0
+	(pupa_util_biosdisk_get_pupa_dev): Do not call

Please end a sentence with a ".".

ChangeLog line 10

Quoted 2 lines
ChangeLog +2 -0
+	make_device_name(drive,-1-1) if not a block device.
+	* util/i386/pc/getroot.c: Update copyright.

No need to notice the copyright update when changing years. It is only required when changing the copyright holders (Correct me if I am wrong).

ChangeLog line 15

Quoted 5 lines
ChangeLog +5 -0
+	(find_root_device): Do not check for a block device.
+	* util/misc.c: Include malloc.h only if it's needed.
+	(pupa_memalign): Change memalign() with malloc() where unavailable.
+	* util/pupa-emu.c: Include malloc.h only if it's needed.
+	(main): Move pupa_util_biosdisk_init() above pupa_guess_root_device().

I do not see the configure.ac changes in the changelog entry. Same for including config.h in misc.c.

This is only what I noticed at first. Please make sure the changelog entries are complete.

ChangeLog line 12

Quoted 2 lines
ChangeLog +1 -1
-/* Define it to \"addr32\" or \"addr32;\" to make GAS happy */
+/* Define it to "addr32" or "addr32;" to make GAS happy */

Why are you doing this? I assume this is what the autotools generated?

ChangeLog line 13

Quoted 2 lines
ChangeLog +1 -1
-/* Define it to \"data32\" or \"data32;\" to make GAS happy */
+/* Define it to "data32" or "data32;" to make GAS happy */

Same here.

ChangeLog line 15

Quoted 2 lines
ChangeLog +2 -0
+AC_CHECK_HEADER(malloc.h)
+AC_CHECK_FUNC(memalign)

This is what I meant, great!

ChangeLog

Quoted 4 lines
ChangeLog +2 -0
+#if !defined(__FreeBSD__)
   if (! S_ISBLK (st.st_mode))
     return make_device_name (drive, -1, -1);
+#endif

make_device_name does not have to be called at all?

ChangeLog

Quoted 4 lines
ChangeLog +2 -2
-#elif defined(__GNU__)
-  /* GNU uses "/dev/[hs]d[0-9]+(s[0-9]+[a-z]?)?".  */
+#elif defined(__GNU__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+  /* GNU uses "/dev/[ahsw]d[0-9]+(s[0-9]+[a-z]?)?".  */

Is this comment correct? It says something about GNU, now you changed the regexp. so it matches *BSD as well.

Thanks,
Marco

#9 lore raw
Quoted 4 lines · Marco Gerards

Review

Quoted 1 line
(quoted diff) +1 -0
+	* util/i386/pc/biosdisk.c: Added headers for BSD.

Please say exactly what header files you are including.

OK.

Quoted 6 lines

Review

Quoted 3 lines
(quoted diff) +1 -0
+	(pupa_util_biosdisk_get_pupa_dev): Do not call

Please end a sentence with a ".".

It continue on next line. But I rewrite it anyway.

Quoted 3 lines

No need to notice the copyright update when changing years. It is only required when changing the copyright holders (Correct me if I am wrong).

May be you're right. I've removed it.

Quoted 2 lines

I do not see the configure.ac changes in the changelog entry. Same for including config.h in misc.c.

I've missed it. Fixed.

Quoted 6 lines

Review

Quoted 2 lines
(quoted diff) +1 -1
-/* Define it to \"addr32\" or \"addr32;\" to make GAS happy */
+/* Define it to "addr32" or "addr32;" to make GAS happy */

Why are you doing this? I assume this is what the autotools generated?

Yes, it was autoconf. I've removed it.

Quoted 7 lines

Review

Quoted 4 lines
(quoted diff) +2 -0
+#if !defined(__FreeBSD__)
  if (! S_ISBLK (st.st_mode))
    return make_device_name (drive, -1, -1);
+#endif

make_device_name does not have to be called at all?

As Okuji said checking for a block device make a little sence, I've remove it at all.

Quoted 10 lines

Review

Quoted 6 lines
(quoted diff) +2 -2
-#elif defined(__GNU__)
-  /* GNU uses "/dev/[hs]d[0-9]+(s[0-9]+[a-z]?)?".  */
+#elif defined(__GNU__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+  /* GNU uses "/dev/[ahsw]d[0-9]+(s[0-9]+[a-z]?)?".  */

Is this comment correct? It says something about GNU, now you changed the regexp. so it matches *BSD as well.

Yes. I've missed it too. Fixed.

Signature · 1 line
Sem.
ChangeLog +18 -0
diff -ruNp grub2/ChangeLog grub2.test/ChangeLog
@@ -1,3 +1,21 @@
+2004-03-15  Sergey Matveychuk  <[email protected]>
+
+	* configure.ac:	Added detection of malloc.h and memalign().
+	* util/i386/pc/biosdisk.c: Added sys/ioctl.h, sys/disklabel.h for
+	*BSD, sys/param.h for FreeBSD and sys/disk.h for FreeBSD 5.x.
+	(pupa_util_biosdisk_open): Added getting a device size for BSD.
+	(get_os_disk): Use code for __GNU__ for BSD too. Add recognizing of
+	'ad' and 'wd' disk names. Change strchr() with strrchr() to fix
+	working with 'sd' disk names.
+	(pupa_util_biosdisk_get_pupa_dev): Remove call make_device_name()
+	if file is not a block device.
+	* util/i386/pc/getroot.c (find_root_device): Do not check for a block
+	device.
+	* util/misc.c: Include config.h. Include malloc.h only if it's needed.
+	(pupa_memalign): Change memalign() with malloc() where unavailable.
+	* util/pupa-emu.c: Include malloc.h only if it's needed.
+	(main): Move pupa_util_biosdisk_init() above pupa_guess_root_device().
+
 2004-03-14  Jeroen Dekkers  <[email protected]>
 
 	* Makefile.in: Update copyright.
configure.ac +3 -0
diff -ruNp grub2/configure.ac grub2.test/configure.ac
@@ -78,6 +78,9 @@ if test "x$default_CFLAGS" = xyes; then
 fi
 AC_SUBST(CFLAGS)
 
+AC_CHECK_HEADER(malloc.h)
+AC_CHECK_FUNC(memalign)
+
 # Defined in aclocal.m4.
 pupa_ASM_USCORE
 pupa_CHECK_START_SYMBOL
util/i386/pc/biosdisk.c +58 -7

98 lines not on this page · raw message

util/i386/pc/getroot.c +2 -3
diff -ruNp grub2/util/i386/pc/getroot.c grub2.test/util/i386/pc/getroot.c
@@ -1,7 +1,7 @@
 /* getroot.c - Get root device */
 /*
  *  PUPA  --  Preliminary Universal Programming Architecture for GRUB
- *  Copyright (C) 1999,2000,2001,2002,2003  Free Software Foundation, Inc.
+ *  Copyright (C) 1999,2000,2001,2002,2003,2004  Free Software Foundation, Inc.
  *
  *  PUPA is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -177,8 +177,7 @@ find_root_device (const char *dir, dev_t
 	      return res;
 	    }
 	}
-
-      if (S_ISBLK (st.st_mode) && st.st_rdev == dev)
+      if (st.st_rdev == dev)
 	{
 	  /* Found!  */
 	  char *res;
util/misc.c +7 -0
diff -ruNp grub2/util/misc.c grub2.test/util/misc.c
@@ -17,6 +17,7 @@
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
+#include <config.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
@@ -24,7 +25,9 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/times.h>
+#ifdef HAVE_MALLOC_H
 #include <malloc.h>
+#endif
 
 #include <pupa/util/misc.h>
 #include <pupa/mm.h>
@@ -194,7 +197,11 @@ pupa_memalign (pupa_size_t align, pupa_s
 {
   void *p;
   
+#ifdef HAVE_MEMALIGN
   p = memalign (align, size);
+#else
+  p = malloc(size);
+#endif
   if (! p)
     pupa_util_error ("out of memory");
   
util/pupa-emu.c +4 -3
diff -ruNp grub2/util/pupa-emu.c grub2.test/util/pupa-emu.c
@@ -18,7 +18,9 @@
  */
 
 #include <stdlib.h>
+#ifdev HAVE_MALLOC_H
 #include <malloc.h>
+#endif
 #include <sys/stat.h>
 #include <argp.h>
 #include <string.h>
@@ -135,6 +137,8 @@ main (int argc, char *argv[])
 
   argp_parse (&argp, argc, argv, 0, 0, &args);
 
+  /* XXX: This is a bit unportable.  */
+  pupa_util_biosdisk_init (args.dev_map);
   /* More sure there is a root device.  */
   if (! args.root_dev)
     {
@@ -152,9 +156,6 @@ main (int argc, char *argv[])
 
   pupa_env_set ("prefix", rootprefix);
   
-  /* XXX: This is a bit unportable.  */
-  pupa_util_biosdisk_init (args.dev_map);
-
   /* Initialize the default modules.  */
   pupa_fat_init ();
   pupa_ext2_init ();
#10 lore raw

util/i386/pc/biosdisk.c pupa_util_biosdisk_open (const char *nam · line 246

Quoted 10 lines · Sergey Matveychuk
util/i386/pc/biosdisk.c +8 -0
+#endif
+
+    close (fd);
+  }
+    
+    pupa_util_info ("the size of %s is %lu", name, disk->total_sectors);
+    
+    return PUPA_ERR_NONE;
 
  fail:

You removed the fail: label from the __linux__ code, please add it back.

util/i386/pc/biosdisk.c get_os_disk (const char *os_dev) · line 717

Quoted 10 lines
util/i386/pc/biosdisk.c +3 -2
@@ -659,11 +711,12 @@ get_os_disk (const char *os_dev)
 
   return path;
 
-#elif defined(__GNU__)
+#elif defined(__GNU__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
   path = xstrdup (os_dev);
-  if (strncmp ("/dev/sd", path, 7) == 0 || strncmp ("/dev/hd", path, 7) == 0)
+  if (strncmp ("/dev/sd", path, 7) == 0 || strncmp ("/dev/hd", path, 7) == 0
+   || strncmp ("/dev/ad", path, 7) == 0 || strncmp ("/dev/wd", path, 7) == 0)

This is not correct. GNU doesn't use /dev/ad and /dev/wd. You should do the check for /dev/ad and /dev/wd only when !__GNU__.

util/misc.c pupa_memalign (pupa_size_t align, pupa_s · line 206

Quoted 11 lines
util/misc.c +4 -0
@@ -194,7 +197,11 @@ pupa_memalign (pupa_size_t align, pupa_s
 {
   void *p;
 
+#ifdef HAVE_MEMALIGN
   p = memalign (align, size);
+#else
+  p = malloc(size);
+#endif
   if (! p)
     pupa_util_error ("out of memory");

I think it's better to just use

pupa_util_error ("memalign not available")

instead of malloc(). pupa_memalign() isn't used now, so it's not really a big problem, but when it is used, the memory must be aligned. If the memory isn't aligned when it needs to be that can cause subtle and hard to debug bugs. It is better to fail loudly.

Signature · 1 line
Jeroen Dekkers
#11 lore raw
Quoted 1 line · Jeroen Dekkers

You removed the fail: label from the __linux__ code, please add it back.

Accidently. First I wanted to move it after #endif but after awhile I understood why it was there but forgot to take it back. Fixed.

Quoted 2 lines

This is not correct. GNU doesn't use /dev/ad and /dev/wd. You should do the check for /dev/ad and /dev/wd only when !__GNU__.

You're absolutely right. Fixed.

Quoted 9 lines

I think it's better to just use

pupa_util_error ("memalign not available")

instead of malloc(). pupa_memalign() isn't used now, so it's not really a big problem, but when it is used, the memory must be aligned. If the memory isn't aligned when it needs to be that can cause subtle and hard to debug bugs. It is better to fail loudly.

I'm not sure here. Developer who will add using of pupa_memalign() on linux could never see the message. So he'll silently break utils on some other platforms.

PS. My first patch was quite draft. I was not sure in many details so I wanted to see your comments. I did. Thanks to all. Here is a next patch. (The last one I hope :)

Signature · 1 line
Sem.
ChangeLog +18 -0
diff -ruNp grub2/ChangeLog grub2.test/ChangeLog
@@ -1,3 +1,21 @@
+2004-03-15  Sergey Matveychuk  <[email protected]>
+
+	* configure.ac:	Added detection of malloc.h and memalign().
+	* util/i386/pc/biosdisk.c: Added sys/ioctl.h, sys/disklabel.h for
+	BSD, sys/param.h for FreeBSD and sys/disk.h for FreeBSD 5.x.
+	(pupa_util_biosdisk_open): Added getting a device size for BSD.
+	(get_os_disk): Use code for __GNU__ for BSD too.
+	Change strchr() with strrchr() to fix working with 'sd' disk names.
+	[!__GNU__]: Add recognizing of 'ad' and 'wd' disk names.
+	(pupa_util_biosdisk_get_pupa_dev): Remove call make_device_name()
+	if file is not a block device.
+	* util/i386/pc/getroot.c (find_root_device): Do not check for a block
+	device.
+	* util/misc.c: Include config.h. Include malloc.h only if it's needed.
+	(pupa_memalign): Change memalign() with malloc() where unavailable.
+	* util/pupa-emu.c: Include malloc.h only if it's needed.
+	(main): Move pupa_util_biosdisk_init() above pupa_guess_root_device().
+
 2004-03-14  Jeroen Dekkers  <[email protected]>
 
 	* Makefile.in: Update copyright.
configure.ac +3 -0
diff -ruNp grub2/configure.ac grub2.test/configure.ac
@@ -78,6 +78,9 @@ if test "x$default_CFLAGS" = xyes; then
 fi
 AC_SUBST(CFLAGS)
 
+AC_CHECK_HEADER(malloc.h)
+AC_CHECK_FUNC(memalign)
+
 # Defined in aclocal.m4.
 pupa_ASM_USCORE
 pupa_CHECK_START_SYMBOL
stamp-h +1 -0
diff -ruNp grub2/stamp-h grub2.test/stamp-h
@@ -0,0 +1 @@
+timestamp
util/i386/pc/biosdisk.c +61 -6

101 lines not on this page · raw message

util/i386/pc/getroot.c +2 -2
diff -ruNp grub2/util/i386/pc/getroot.c grub2.test/util/i386/pc/getroot.c
@@ -1,7 +1,7 @@
 /* getroot.c - Get root device */
 /*
  *  PUPA  --  Preliminary Universal Programming Architecture for GRUB
- *  Copyright (C) 1999,2000,2001,2002,2003  Free Software Foundation, Inc.
+ *  Copyright (C) 1999,2000,2001,2002,2003,2004  Free Software Foundation, Inc.
  *
  *  PUPA is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -178,7 +178,7 @@ find_root_device (const char *dir, dev_t
 	    }
 	}
 
-      if (S_ISBLK (st.st_mode) && st.st_rdev == dev)
+      if (st.st_rdev == dev)
 	{
 	  /* Found!  */
 	  char *res;
util/misc.c +7 -0
diff -ruNp grub2/util/misc.c grub2.test/util/misc.c
@@ -17,6 +17,7 @@
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
+#include <config.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
@@ -24,7 +25,9 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/times.h>
+#ifdef HAVE_MALLOC_H
 #include <malloc.h>
+#endif
 
 #include <pupa/util/misc.h>
 #include <pupa/mm.h>
@@ -194,7 +197,11 @@ pupa_memalign (pupa_size_t align, pupa_s
 {
   void *p;
   
+#ifdef HAVE_MEMALIGN
   p = memalign (align, size);
+#else
+  p = malloc(size);
+#endif
   if (! p)
     pupa_util_error ("out of memory");
   
util/pupa-emu.c +4 -3
diff -ruNp grub2/util/pupa-emu.c grub2.test/util/pupa-emu.c
@@ -18,7 +18,9 @@
  */
 
 #include <stdlib.h>
+#ifdev HAVE_MALLOC_H
 #include <malloc.h>
+#endif
 #include <sys/stat.h>
 #include <argp.h>
 #include <string.h>
@@ -135,6 +137,8 @@ main (int argc, char *argv[])
 
   argp_parse (&argp, argc, argv, 0, 0, &args);
 
+  /* XXX: This is a bit unportable.  */
+  pupa_util_biosdisk_init (args.dev_map);
   /* More sure there is a root device.  */
   if (! args.root_dev)
     {
@@ -152,9 +156,6 @@ main (int argc, char *argv[])
 
   pupa_env_set ("prefix", rootprefix);
   
-  /* XXX: This is a bit unportable.  */
-  pupa_util_biosdisk_init (args.dev_map);
-
   /* Initialize the default modules.  */
   pupa_fat_init ();
   pupa_ext2_init ();
#12 lore raw
Quoted 3 lines · Sergey Matveychuk

I'm not sure here. Developer who will add using of pupa_memalign() on linux could never see the message. So he'll silently break utils on some other platforms.

All GRUB hackers know about this issue. If we had a bug tracker we could mention it there somehow.

Quoted 3 lines

PS. My first patch was quite draft. I was not sure in many details so I wanted to see your comments. I did. Thanks to all. Here is a next patch. (The last one I hope :)

Luckily you can handle the comments just as they were meant, constructive. Thanks a lot for your patch!

Does pupa-emu work for you after this patch is applied?

--
Marco

#13 lore raw
Quoted 1 line · Marco Gerards

Does pupa-emu work for you after this patch is applied?

Oops. A little typo in the last patch (#ifdev instead of #ifdef). It's all right now.

Really I still need a little hack for Makefiles to build grub2 on FreeBSD out of box (for -I and -L switches). I guess it should be done with autotools but I don't know how yet. And I'd like to make notice in README file for dd command differs for FreeBSD (may be for all BSD?). So I plan to send once more patch.

Signature · 1 line
Sem.
ChangeLog +18 -0
diff -ruNp grub2/ChangeLog grub2.test/ChangeLog
@@ -1,3 +1,21 @@
+2004-03-15  Sergey Matveychuk  <[email protected]>
+
+	* configure.ac:	Added detection of malloc.h and memalign().
+	* util/i386/pc/biosdisk.c: Added sys/ioctl.h, sys/disklabel.h for
+	BSD, sys/param.h for FreeBSD and sys/disk.h for FreeBSD 5.x.
+	(pupa_util_biosdisk_open): Added getting a device size for BSD.
+	(get_os_disk): Use code for __GNU__ for BSD too.
+	Change strchr() with strrchr() to fix working with 'sd' disk names.
+	[!__GNU__]: Add recognizing of 'ad' and 'wd' disk names.
+	(pupa_util_biosdisk_get_pupa_dev): Remove call make_device_name()
+	if file is not a block device.
+	* util/i386/pc/getroot.c (find_root_device): Do not check for a block
+	device.
+	* util/misc.c: Include config.h. Include malloc.h only if it's needed.
+	(pupa_memalign): Change memalign() with malloc() where unavailable.
+	* util/pupa-emu.c: Include malloc.h only if it's needed.
+	(main): Move pupa_util_biosdisk_init() above pupa_guess_root_device().
+
 2004-03-14  Jeroen Dekkers  <[email protected]>
 
 	* Makefile.in: Update copyright.
configure.ac +3 -0
diff -ruNp grub2/configure.ac grub2.test/configure.ac
@@ -78,6 +78,9 @@ if test "x$default_CFLAGS" = xyes; then
 fi
 AC_SUBST(CFLAGS)
 
+AC_CHECK_HEADER(malloc.h)
+AC_CHECK_FUNC(memalign)
+
 # Defined in aclocal.m4.
 pupa_ASM_USCORE
 pupa_CHECK_START_SYMBOL
stamp-h +1 -0
diff -ruNp grub2/stamp-h grub2.test/stamp-h
@@ -0,0 +1 @@
+timestamp
util/i386/pc/biosdisk.c +61 -6

101 lines not on this page · raw message

util/i386/pc/getroot.c +2 -2
diff -ruNp grub2/util/i386/pc/getroot.c grub2.test/util/i386/pc/getroot.c
@@ -1,7 +1,7 @@
 /* getroot.c - Get root device */
 /*
  *  PUPA  --  Preliminary Universal Programming Architecture for GRUB
- *  Copyright (C) 1999,2000,2001,2002,2003  Free Software Foundation, Inc.
+ *  Copyright (C) 1999,2000,2001,2002,2003,2004  Free Software Foundation, Inc.
  *
  *  PUPA is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -178,7 +178,7 @@ find_root_device (const char *dir, dev_t
 	    }
 	}
 
-      if (S_ISBLK (st.st_mode) && st.st_rdev == dev)
+      if (st.st_rdev == dev)
 	{
 	  /* Found!  */
 	  char *res;
util/misc.c +7 -0
diff -ruNp grub2/util/misc.c grub2.test/util/misc.c
@@ -17,6 +17,7 @@
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
+#include <config.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
@@ -24,7 +25,9 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/times.h>
+#ifdef HAVE_MALLOC_H
 #include <malloc.h>
+#endif
 
 #include <pupa/util/misc.h>
 #include <pupa/mm.h>
@@ -194,7 +197,11 @@ pupa_memalign (pupa_size_t align, pupa_s
 {
   void *p;
   
+#ifdef HAVE_MEMALIGN
   p = memalign (align, size);
+#else
+  p = malloc(size);
+#endif
   if (! p)
     pupa_util_error ("out of memory");
   
util/pupa-emu.c +4 -3
diff -ruNp grub2/util/pupa-emu.c grub2.test/util/pupa-emu.c
@@ -18,7 +18,9 @@
  */
 
 #include <stdlib.h>
+#ifdef HAVE_MALLOC_H
 #include <malloc.h>
+#endif
 #include <sys/stat.h>
 #include <argp.h>
 #include <string.h>
@@ -135,6 +137,8 @@ main (int argc, char *argv[])
 
   argp_parse (&argp, argc, argv, 0, 0, &args);
 
+  /* XXX: This is a bit unportable.  */
+  pupa_util_biosdisk_init (args.dev_map);
   /* More sure there is a root device.  */
   if (! args.root_dev)
     {
@@ -152,9 +156,6 @@ main (int argc, char *argv[])
 
   pupa_env_set ("prefix", rootprefix);
   
-  /* XXX: This is a bit unportable.  */
-  pupa_util_biosdisk_init (args.dev_map);
-
   /* Initialize the default modules.  */
   pupa_fat_init ();
   pupa_ext2_init ();
#14 lore raw
Quoted 6 lines · Sergey Matveychuk
Quoted 1 line · Marco Gerards

Does pupa-emu work for you after this patch is applied?

Oops. A little typo in the last patch (#ifdev instead of #ifdef). It's all right now.

Was that a reply to my question if pupa-emu works or not? :)

Quoted 6 lines

Really I still need a little hack for Makefiles to build grub2 on FreeBSD out of box (for -I and -L switches). I guess it should be done with autotools but I don't know how yet. And I'd like to make notice in README file for dd command differs for FreeBSD (may be for all BSD?).
So I plan to send once more patch.

Yes, I thought about that too. :)

Let's do that later.

--
Marco

#15 lore raw
Quoted 7 lines · Marco Gerards
Quoted 4 lines
Quoted 1 line

Does pupa-emu work for you after this patch is applied?

Oops. A little typo in the last patch (#ifdev instead of #ifdef). It's all right now.

Was that a reply to my question if pupa-emu works or not? :)

:)
What did you mean "works"? Of course it works! Why I would sent patch made pupa-emu does not work. ;)

OK. May be I've checked not all functions. But it runs, does not crashed, right guess a root device, and right detects fat and ext2 FSs. That's all I've fixed. So I guess it works :)

Signature · 1 line
Sem.
#16 lore raw
Quoted 5 lines · Sergey Matveychuk
Quoted 1 line

Was that a reply to my question if pupa-emu works or not? :)

:)
What did you mean "works"? Of course it works! Why I would sent patch made pupa-emu does not work. ;)

Well, you asked a lot about booting GRUB on real hardware and not much about pupa-emu. But I agree, it still was a stupid question, thinking of some files you hacked. :)

And I was just curious how well it works on FreeBSD.

Quoted 4 lines

OK. May be I've checked not all functions. But it runs, does not crashed, right guess a root device, and right detects fat and ext2 FSs. That's all I've fixed.
So I guess it works :)

Great!

Thanks,
Marco

#17 lore raw
In reply to Sergey Matveychuk

util/i386/pc/biosdisk.c pupa_util_biosdisk_get_pupa_dev (const c · line 721

Quoted 7 lines · Sergey Matveychuk
util/i386/pc/biosdisk.c +0 -3
@@ -716,9 +773,6 @@ pupa_util_biosdisk_get_pupa_dev (const c
       return 0;
     }
 
-  if (! S_ISBLK (st.st_mode))
-    return make_device_name (drive, -1, -1);
- 

This part is not good. The problem here is that we want to support installing GRUB into a normal file as well as a device file.

So what I said to you was wrong. The check about a block device is sometimes very important. In FreeBSD, what is the right way to distinguish a device file from a normal file?

util/misc.c pupa_memalign (pupa_size_t align, pupa_s · line 204

Quoted 5 lines
util/misc.c +4 -0
+#ifdef HAVE_MEMALIGN
   p = memalign (align, size);
+#else
+  p = malloc(size);
+#endif

I don't agree on this one. Please implement memalign correctly. It's not so difficult. Probably it can be like this (not tested):

p = malloc((size + align - 1) & ~(align - 1));
if (! p)
return 0;
return (p + align - 1) & ~(align - 1);

It might be possible to find a better implementation, if you see glibc.

BTW, I confirmed that you haven't assigned your copyright on GRUB to the FSF yet. For a GNU project, it is a custom to assign your copyright to the FSF, so that the FSF can fight instead of you in a court when someone claims that our software is illegal. Also, this step of a copyright assignment makes sure that your contribution will be free in freedom forever. So, would you like to sign a copyright assignment for GRUB? If you need more information, don't hesitate to ask me. We can talk privately if you want.

Okuji

#18 lore raw
Quoted 6 lines · Yoshinori K. Okuji

Review

Quoted 3 lines
(quoted diff) +0 -3
-  if (! S_ISBLK (st.st_mode))
-    return make_device_name (drive, -1, -1);
- 

This part is not good. The problem here is that we want to support installing GRUB into a normal file as well as a device file.

OK. I've taken it back.

Quoted 8 lines

I don't agree on this one. Please implement memalign correctly. It's not so difficult. Probably it can be like this (not tested):

p = malloc((size + align - 1) & ~(align - 1));
if (! p)
return 0;
return (p + align - 1) & ~(align - 1);

It might be possible to find a better implementation, if you see glibc.

I'm not sure here. So I did as Jeroen Dekkers offers.

Quoted 2 lines

BTW, I confirmed that you haven't assigned your copyright on GRUB to the FSF yet. For a GNU project, it is a custom to assign your copyright to the FSF, so that the FSF can fight instead of you in a court when someone claims that our software is illegal. Also, this step of a copyright assignment makes sure that your contribution will be free in freedom forever. So, would you like to sign a copyright assignment for GRUB? If you need more information, don't hesitate to ask me. We can talk privately if you want.

Do you mean GRUB1?

Signature · 1 line
Sem.
ChangeLog +18 -0
diff -ruNp grub2/ChangeLog grub2.devel/ChangeLog
@@ -1,3 +1,21 @@
+2004-03-15  Sergey Matveychuk  <[email protected]>
+
+	* configure.ac:	Added detection of malloc.h and memalign().
+	* util/i386/pc/biosdisk.c: Added sys/ioctl.h, sys/disklabel.h for
+	BSD, sys/param.h for FreeBSD and sys/disk.h for FreeBSD 5.x.
+	(pupa_util_biosdisk_open): Added getting a device size for BSD.
+	(get_os_disk): Use code for __GNU__ for BSD too.
+	Change strchr() with strrchr() to fix working with 'sd' disk names.
+	[!__GNU__]: Add recognizing of 'ad' and 'wd' disk names.
+	(pupa_util_biosdisk_get_pupa_dev): Remove call make_device_name()
+	if file is not a block device.
+	* util/i386/pc/getroot.c (find_root_device): Do not check for a block
+	device.
+	* util/misc.c: Include config.h. Include malloc.h only if it's needed.
+	(pupa_memalign): Change memalign() with malloc() where unavailable.
+	* util/pupa-emu.c: Include malloc.h only if it's needed.
+	(main): Move pupa_util_biosdisk_init() above pupa_guess_root_device().
+
 2004-03-14  Jeroen Dekkers  <[email protected]>
 
 	* Makefile.in: Update copyright.
configure.ac +3 -0
diff -ruNp grub2/configure.ac grub2.devel/configure.ac
@@ -78,6 +78,9 @@ if test "x$default_CFLAGS" = xyes; then
 fi
 AC_SUBST(CFLAGS)
 
+AC_CHECK_HEADER(malloc.h)
+AC_CHECK_FUNC(memalign)
+
 # Defined in aclocal.m4.
 pupa_ASM_USCORE
 pupa_CHECK_START_SYMBOL
stamp-h +1 -0
diff -ruNp grub2/stamp-h grub2.devel/stamp-h
@@ -0,0 +1 @@
+timestamp
util/i386/pc/biosdisk.c +64 -4

104 lines not on this page · raw message

util/i386/pc/getroot.c +2 -2
diff -ruNp grub2/util/i386/pc/getroot.c grub2.devel/util/i386/pc/getroot.c
@@ -1,7 +1,7 @@
 /* getroot.c - Get root device */
 /*
  *  PUPA  --  Preliminary Universal Programming Architecture for GRUB
- *  Copyright (C) 1999,2000,2001,2002,2003  Free Software Foundation, Inc.
+ *  Copyright (C) 1999,2000,2001,2002,2003,2004  Free Software Foundation, Inc.
  *
  *  PUPA is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -178,7 +178,7 @@ find_root_device (const char *dir, dev_t
 	    }
 	}
 
-      if (S_ISBLK (st.st_mode) && st.st_rdev == dev)
+      if (st.st_rdev == dev)
 	{
 	  /* Found!  */
 	  char *res;
util/misc.c +7 -0
diff -ruNp grub2/util/misc.c grub2.devel/util/misc.c
@@ -17,6 +17,7 @@
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
+#include <config.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
@@ -24,7 +25,9 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/times.h>
+#ifdef HAVE_MALLOC_H
 #include <malloc.h>
+#endif
 
 #include <pupa/util/misc.h>
 #include <pupa/mm.h>
@@ -194,7 +197,11 @@ pupa_memalign (pupa_size_t align, pupa_s
 {
   void *p;
   
+#ifdef HAVE_MEMALIGN
   p = memalign (align, size);
+#else
+  pupa_util_error ("memalign not available");
+#endif
   if (! p)
     pupa_util_error ("out of memory");
   
util/pupa-emu.c +4 -3
diff -ruNp grub2/util/pupa-emu.c grub2.devel/util/pupa-emu.c
@@ -18,7 +18,9 @@
  */
 
 #include <stdlib.h>
+#ifdef HAVE_MALLOC_H
 #include <malloc.h>
+#endif
 #include <sys/stat.h>
 #include <argp.h>
 #include <string.h>
@@ -135,6 +137,8 @@ main (int argc, char *argv[])
 
   argp_parse (&argp, argc, argv, 0, 0, &args);
 
+  /* XXX: This is a bit unportable.  */
+  pupa_util_biosdisk_init (args.dev_map);
   /* More sure there is a root device.  */
   if (! args.root_dev)
     {
@@ -152,9 +156,6 @@ main (int argc, char *argv[])
 
   pupa_env_set ("prefix", rootprefix);
   
-  /* XXX: This is a bit unportable.  */
-  pupa_util_biosdisk_init (args.dev_map);
-
   /* Initialize the default modules.  */
   pupa_fat_init ();
   pupa_ext2_init ();
#19 lore raw
Quoted 10 lines · Sergey Matveychuk
Quoted 7 lines · Yoshinori K. Okuji

util/pupa-emu.c main (int argc, char *argv[]) · line 157

Quoted 4 lines
util/pupa-emu.c +0 -3
-  if (! S_ISBLK (st.st_mode))
 
-    return make_device_name (drive, -1, -1);
-

This part is not good. The problem here is that we want to support installing GRUB into a normal file as well as a device file.

OK. I've taken it back.

I got an advise from Mr.Soda personally about the block device issue. And, I now think it is better to use S_ISREG rather than S_ISBLK when determining if a file is a disk device or a normal file. That is, use S_ISREG for a normal file, and use ! S_ISREG for a disk device.

So, regardless of your OS, let's use:

if (S_ISREG (st.st_mode))
return make_device_name (drive, -1, -1);

The same applies to other places where S_ISBLK is used.

Quoted 10 lines
Quoted 8 lines

BTW, I confirmed that you haven't assigned your copyright on GRUB to the FSF yet. For a GNU project, it is a custom to assign your copyright to the FSF, so that the FSF can fight instead of you in a court when someone claims that our software is illegal. Also, this step of a copyright assignment makes sure that your contribution will be free in freedom forever. So, would you like to sign a copyright assignment for GRUB? If you need more information, don't hesitate to ask me. We can talk privately if you want.

Do you mean GRUB1?

There is no difference between GRUB 1 and GRUB 2, as far as we talk about the legal issue, since they are the same software from legal point of view. It's GRUB.

util/misc.c pupa_memalign (pupa_size_t align, pupa_s · line 206

Quoted 11 lines
util/misc.c +4 -0
@@ -194,7 +197,11 @@ pupa_memalign (pupa_size_t align, pupa_s
 {
   void *p;
 
+#ifdef HAVE_MEMALIGN
   p = memalign (align, size);
+#else
+  pupa_util_error ("memalign not available");
+#endif
   if (! p)
     pupa_util_error ("out of memory");

This segfaults if pupa_memalign is used actually. It must return a NULL pointer if fails.

Okuji

#20 lore raw
Quoted 5 lines · Yoshinori K. Okuji
Quoted 4 lines · Sergey Matveychuk
util/misc.c +0 -0
@@ -194,7 +197,11 @@ pupa_memalign (pupa_size_t align, pupa_s
 {
   void *p;
 
Quoted 10 lines

util/misc.c pupa_memalign (pupa_size_t align, pupa_s · line 206

Quoted 7 lines
util/misc.c +4 -0
+#ifdef HAVE_MEMALIGN
   p = memalign (align, size);
+#else
+  pupa_util_error ("memalign not available");
+#endif
   if (! p)
     pupa_util_error ("out of memory");

This segfaults if pupa_memalign is used actually. It must return a NULL pointer if fails.

It doesn't return, pupa_util_error() calls exit().

Signature · 1 line
Jeroen Dekkers
#21 lore raw
Quoted 4 lines · Jeroen Dekkers
Quoted 2 lines

This segfaults if pupa_memalign is used actually. It must return a NULL pointer if fails.

It doesn't return, pupa_util_error() calls exit().

Oops! Jeroen, you are right. I'm sorry.

Okuji

#22 lore raw

Here is a new version.

Signature · 1 line
Sem.
ChangeLog +18 -0
diff -ruNp grub2/ChangeLog grub2.devel/ChangeLog
@@ -1,3 +1,21 @@
+2004-03-15  Sergey Matveychuk  <[email protected]>
+
+	* configure.ac:	Added detection of malloc.h and memalign().
+	* util/i386/pc/biosdisk.c: Added sys/ioctl.h, sys/disklabel.h for
+	BSD, sys/param.h for FreeBSD and sys/disk.h for FreeBSD 5.x.
+	(pupa_util_biosdisk_open): Added getting a device size for BSD.
+	(get_os_disk): Use code for __GNU__ for BSD too.
+	Change strchr() with strrchr() to fix working with 'sd' disk names.
+	[!__GNU__]: Add recognizing of 'ad' and 'wd' disk names.
+	(pupa_util_biosdisk_get_pupa_dev): Checking file type against S_ISREG
+	instead of S_ISBLK.
+	* util/i386/pc/getroot.c (find_root_device): Checking file type
+	against S_ISREG instead of S_ISBLK.
+	* util/misc.c: Include config.h. Include malloc.h only if it's needed.
+	(pupa_memalign): Exit with error if memalign() unavailable.
+	* util/pupa-emu.c: Include malloc.h only if it's needed.
+	(main): Move pupa_util_biosdisk_init() above pupa_guess_root_device().
+
 2004-03-14  Jeroen Dekkers  <[email protected]>
 
 	* Makefile.in: Update copyright.
configure.ac +3 -0
diff -ruNp grub2/configure.ac grub2.devel/configure.ac
@@ -78,6 +78,9 @@ if test "x$default_CFLAGS" = xyes; then
 fi
 AC_SUBST(CFLAGS)
 
+AC_CHECK_HEADER(malloc.h)
+AC_CHECK_FUNC(memalign)
+
 # Defined in aclocal.m4.
 pupa_ASM_USCORE
 pupa_CHECK_START_SYMBOL
stamp-h +1 -0
diff -ruNp grub2/stamp-h grub2.devel/stamp-h
@@ -0,0 +1 @@
+timestamp
util/i386/pc/biosdisk.c +62 -4

100 lines not on this page · raw message

util/i386/pc/getroot.c +2 -2
diff -ruNp grub2/util/i386/pc/getroot.c grub2.devel/util/i386/pc/getroot.c
@@ -1,7 +1,7 @@
 /* getroot.c - Get root device */
 /*
  *  PUPA  --  Preliminary Universal Programming Architecture for GRUB
- *  Copyright (C) 1999,2000,2001,2002,2003  Free Software Foundation, Inc.
+ *  Copyright (C) 1999,2000,2001,2002,2003,2004  Free Software Foundation, Inc.
  *
  *  PUPA is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -178,7 +178,7 @@ find_root_device (const char *dir, dev_t
 	    }
 	}
 
-      if (S_ISBLK (st.st_mode) && st.st_rdev == dev)
+      if (S_ISREG (st.st_mode) && st.st_rdev == dev)
 	{
 	  /* Found!  */
 	  char *res;
util/misc.c +7 -0
diff -ruNp grub2/util/misc.c grub2.devel/util/misc.c
@@ -17,6 +17,7 @@
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
+#include <config.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
@@ -24,7 +25,9 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/times.h>
+#ifdef HAVE_MALLOC_H
 #include <malloc.h>
+#endif
 
 #include <pupa/util/misc.h>
 #include <pupa/mm.h>
@@ -194,7 +197,11 @@ pupa_memalign (pupa_size_t align, pupa_s
 {
   void *p;
   
+#ifdef HAVE_MEMALIGN
   p = memalign (align, size);
+#else
+  pupa_util_error ("memalign not available");
+#endif
   if (! p)
     pupa_util_error ("out of memory");
   
util/pupa-emu.c +4 -3
diff -ruNp grub2/util/pupa-emu.c grub2.devel/util/pupa-emu.c
@@ -18,7 +18,9 @@
  */
 
 #include <stdlib.h>
+#ifdef HAVE_MALLOC_H
 #include <malloc.h>
+#endif
 #include <sys/stat.h>
 #include <argp.h>
 #include <string.h>
@@ -135,6 +137,8 @@ main (int argc, char *argv[])
 
   argp_parse (&argp, argc, argv, 0, 0, &args);
 
+  /* XXX: This is a bit unportable.  */
+  pupa_util_biosdisk_init (args.dev_map);
   /* More sure there is a root device.  */
   if (! args.root_dev)
     {
@@ -152,9 +156,6 @@ main (int argc, char *argv[])
 
   pupa_env_set ("prefix", rootprefix);
   
-  /* XXX: This is a bit unportable.  */
-  pupa_util_biosdisk_init (args.dev_map);
-
   /* Initialize the default modules.  */
   pupa_fat_init ();
   pupa_ext2_init ();
#23 lore raw
In reply to Yoshinori K. Okuji
Quoted 6 lines · Yoshinori K. Okuji

So, regardless of your OS, let's use:

if (S_ISREG (st.st_mode))
return make_device_name (drive, -1, -1);

The same applies to other places where S_ISBLK is used.

Oh. I'm sorry. I've just s/S_ISBLK/S_ISREG/. I need to sleep. I'll fix it with my next patch. :(

Signature · 1 line
Sem.
#24 lore raw
In reply to Yoshinori K. Okuji
Quoted 6 lines · Yoshinori K. Okuji

So, regardless of your OS, let's use:

if (S_ISREG (st.st_mode))
return make_device_name (drive, -1, -1);

The same applies to other places where S_ISBLK is used.

It's quite strange in util/i386/pc/getroot.c:
if (!S_ISREG (st.st_mode) && st.st_rdev == dev)

but I've left so.

Signature · 1 line
Sem.
ChangeLog +18 -0
diff -ruNp grub2/ChangeLog grub2.devel/ChangeLog
@@ -1,3 +1,21 @@
+2004-03-15  Sergey Matveychuk  <[email protected]>
+
+	* configure.ac:	Added detection of malloc.h and memalign().
+	* util/i386/pc/biosdisk.c: Added sys/ioctl.h, sys/disklabel.h for
+	BSD, sys/param.h for FreeBSD and sys/disk.h for FreeBSD 5.x.
+	(pupa_util_biosdisk_open): Added getting a device size for BSD.
+	(get_os_disk): Use code for __GNU__ for BSD too.
+	Change strchr() with strrchr() to fix working with 'sd' disk names.
+	[!__GNU__]: Add recognizing of 'ad' and 'wd' disk names.
+	(pupa_util_biosdisk_get_pupa_dev): Checking file type against S_ISREG
+	instead of !S_ISBLK.
+	* util/i386/pc/getroot.c (find_root_device): Checking file type
+	against !S_ISREG instead of S_ISBLK.
+	* util/misc.c: Include config.h. Include malloc.h only if it's needed.
+	(pupa_memalign): Exit with error if memalign() unavailable.
+	* util/pupa-emu.c: Include malloc.h only if it's needed.
+	(main): Move pupa_util_biosdisk_init() above pupa_guess_root_device().
+
 2004-03-14  Jeroen Dekkers  <[email protected]>
 
 	* Makefile.in: Update copyright.
configure.ac +3 -0
diff -ruNp grub2/configure.ac grub2.devel/configure.ac
@@ -78,6 +78,9 @@ if test "x$default_CFLAGS" = xyes; then
 fi
 AC_SUBST(CFLAGS)
 
+AC_CHECK_HEADER(malloc.h)
+AC_CHECK_FUNC(memalign)
+
 # Defined in aclocal.m4.
 pupa_ASM_USCORE
 pupa_CHECK_START_SYMBOL
stamp-h +1 -0
diff -ruNp grub2/stamp-h grub2.devel/stamp-h
@@ -0,0 +1 @@
+timestamp
util/i386/pc/biosdisk.c +62 -4

100 lines not on this page · raw message

util/i386/pc/getroot.c +2 -2
diff -ruNp grub2/util/i386/pc/getroot.c grub2.devel/util/i386/pc/getroot.c
@@ -1,7 +1,7 @@
 /* getroot.c - Get root device */
 /*
  *  PUPA  --  Preliminary Universal Programming Architecture for GRUB
- *  Copyright (C) 1999,2000,2001,2002,2003  Free Software Foundation, Inc.
+ *  Copyright (C) 1999,2000,2001,2002,2003,2004  Free Software Foundation, Inc.
  *
  *  PUPA is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -178,7 +178,7 @@ find_root_device (const char *dir, dev_t
 	    }
 	}
 
-      if (S_ISBLK (st.st_mode) && st.st_rdev == dev)
+      if (!S_ISREG (st.st_mode) && st.st_rdev == dev)
 	{
 	  /* Found!  */
 	  char *res;
util/misc.c +7 -0
diff -ruNp grub2/util/misc.c grub2.devel/util/misc.c
@@ -17,6 +17,7 @@
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
+#include <config.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
@@ -24,7 +25,9 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/times.h>
+#ifdef HAVE_MALLOC_H
 #include <malloc.h>
+#endif
 
 #include <pupa/util/misc.h>
 #include <pupa/mm.h>
@@ -194,7 +197,11 @@ pupa_memalign (pupa_size_t align, pupa_s
 {
   void *p;
   
+#ifdef HAVE_MEMALIGN
   p = memalign (align, size);
+#else
+  pupa_util_error ("memalign not available");
+#endif
   if (! p)
     pupa_util_error ("out of memory");
   
util/pupa-emu.c +4 -3
diff -ruNp grub2/util/pupa-emu.c grub2.devel/util/pupa-emu.c
@@ -18,7 +18,9 @@
  */
 
 #include <stdlib.h>
+#ifdef HAVE_MALLOC_H
 #include <malloc.h>
+#endif
 #include <sys/stat.h>
 #include <argp.h>
 #include <string.h>
@@ -135,6 +137,8 @@ main (int argc, char *argv[])
 
   argp_parse (&argp, argc, argv, 0, 0, &args);
 
+  /* XXX: This is a bit unportable.  */
+  pupa_util_biosdisk_init (args.dev_map);
   /* More sure there is a root device.  */
   if (! args.root_dev)
     {
@@ -152,9 +156,6 @@ main (int argc, char *argv[])
 
   pupa_env_set ("prefix", rootprefix);
   
-  /* XXX: This is a bit unportable.  */
-  pupa_util_biosdisk_init (args.dev_map);
-
   /* Initialize the default modules.  */
   pupa_fat_init ();
   pupa_ext2_init ();
#25 lore raw
Quoted 9 lines · Sergey Matveychuk
Quoted 4 lines · Yoshinori K. Okuji

So, regardless of your OS, let's use:
if (S_ISREG (st.st_mode))
return make_device_name (drive, -1, -1);
The same applies to other places where S_ISBLK is used.

It's quite strange in util/i386/pc/getroot.c:
if (!S_ISREG (st.st_mode) && st.st_rdev == dev)

This patch is still not applied. What are the issues and what needs to be done before it can be committed?

Can't this code be changed like Okuji suggested and be committed?

Thanks,
Marco

#26 lore raw
Quoted 2 lines · Marco Gerards

This patch is still not applied. What are the issues and what needs to be done before it can be committed?

I don't remember. Where is the patch?

Okuji

#29 lore raw
Quoted 6 lines · Yoshinori K. Okuji
Quoted 2 lines · Marco Gerards

Here it is in the mailinglist archives:
http://lists.gnu.org/archive/html/grub-devel/2004-03/msg00060.html

Ah, I see. IIRC, I didn't like the patch, because memalign was not implemented. I accept the patch, once someone writes memalign.

There are, as far as I can see, 3 things we can do:

1) Make grub_memalign return GRUB_ERR_NOT_IMPLEMENTED_YET. grub_memalign is only used by dl.c, which is not important for the utils. When someone adds module loading support to grub-emu, we have to switch to using kern/mm.c anyway.

2) Allocating memory using mmap and managing it with kern/mm.c. That makes it easier to implement module loading.

3) Reserving more memory than required so the alignment can be corrected.

And while we are discussing the memory management. I'd like to add an option to grub-emu so the memory manager (mm.c or POSIX) can be chosen. The mm.c memory manager can be useful to debugging mm.c. The POSIX (malloc) memory manager that is available by default will be useful for debugging for memory leaks with tools like valgrind.

I would prefer solution #1, until we implement more fancy features (choosing the memory manager and module loading) for grub-emu. And even in that case, I think mm.c should be used in grub-emu only and even then configurable like I described above.

Okuji, do you agree with this or do you prefer another solution? Or do you have any other suggestion? It would not be hard to fix this and it is required for FreeBSD. I am willing to work on this.

Thanks,
Marco

#30 lore raw

Hi Marco,

Quoted 4 lines · Marco Gerards

I would prefer solution #1, until we implement more fancy features (choosing the memory manager and module loading) for grub-emu. And even in that case, I think mm.c should be used in grub-emu only and even then configurable like I described above.

I prefer the 3rd one to the first one. Having something is better than nothing.

Okuji