* GRUB2: *BSD and more patch
@ 2004-03-18 8:15 Sergey Matveychuk
2004-03-18 12:31 ` Yoshinori K. Okuji
0 siblings, 1 reply; 31+ messages in thread
From: Sergey Matveychuk @ 2004-03-18 8:15 UTC (permalink / raw)
To: grub-devel
[-- Attachment #1: Type: text/plain, Size: 351 bytes --]
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.
--
Sem.
[-- Attachment #2: grub2-bsd.patch --]
[-- Type: text/plain, Size: 7191 bytes --]
diff -ruN grub2/ChangeLog grub2.devel/ChangeLog
--- grub2/ChangeLog Tue Mar 16 02:23:55 2004
+++ grub2.devel/ChangeLog Thu Mar 18 10:54:14 2004
@@ -1,3 +1,17 @@
+2004-03-15 Sergey Matveychuk <sem@ciam.ru>
+
+ * 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 <jeroen@dekkers.cx>
* Makefile.in: Update copyright.
diff -ruN grub2/util/i386/pc/biosdisk.c grub2.devel/util/i386/pc/biosdisk.c
--- grub2/util/i386/pc/biosdisk.c Tue Mar 16 02:24:00 2004
+++ grub2.devel/util/i386/pc/biosdisk.c Tue Mar 16 04:25:21 2004
@@ -37,6 +37,17 @@
#include <errno.h>
#include <limits.h>
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+# 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__ */
+
#ifdef __linux__
# include <sys/ioctl.h> /* ioctl */
# if !defined(__GLIBC__) || \
@@ -190,6 +201,66 @@
return PUPA_ERR_NONE;
}
+#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+ {
+ int fd;
+ struct disklabel hdg;
+
+ fd = open (map[drive], O_RDONLY);
+ if (fd < 0)
+ return pupa_error (PUPA_ERR_BAD_DEVICE, "cannot open `%s'", map[drive]);
+
+#if !defined(__FreeBSD__)
+ if (fstat (fd, &st) < 0 || ! S_ISBLK (st.st_mode))
+#else
+ if (fstat (fd, &st) < 0)
+#endif
+ {
+ close (fd);
+ goto fail;
+ }
+
+#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;
+ 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
+ close (fd);
+ }
+
+ pupa_util_info ("the size of %s is %lu", name, disk->total_sectors);
+
+ return PUPA_ERR_NONE;
fail:
/* In GNU/Hurd, stat() will return the right size. */
@@ -659,11 +730,12 @@
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)
{
- p = strchr (path, 's');
+ p = strrchr (path, 's');
if (p)
*p = '\0';
}
@@ -716,8 +788,10 @@
return 0;
}
+#if !defined(__FreeBSD__)
if (! S_ISBLK (st.st_mode))
return make_device_name (drive, -1, -1);
+#endif
#if defined(__linux__)
/* Linux counts partitions uniformly, whether a BSD partition or a DOS
@@ -806,8 +880,8 @@
return make_device_name (drive, dos_part, bsd_part);
}
-#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]?)?". */
{
char *p;
int dos_part = -1;
diff -ruN grub2/util/i386/pc/getroot.c grub2.devel/util/i386/pc/getroot.c
--- grub2/util/i386/pc/getroot.c Sun Mar 14 05:44:20 2004
+++ grub2.devel/util/i386/pc/getroot.c Tue Mar 16 03:20:05 2004
@@ -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;
diff -ruN grub2/util/i386/pc/pupa-setup.c grub2.devel/util/i386/pc/pupa-setup.c
--- grub2/util/i386/pc/pupa-setup.c Tue Mar 16 02:24:05 2004
+++ grub2.devel/util/i386/pc/pupa-setup.c Tue Mar 16 03:23:23 2004
@@ -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
diff -ruN grub2/util/misc.c grub2.devel/util/misc.c
--- grub2/util/misc.c Sun Mar 14 05:44:20 2004
+++ grub2.devel/util/misc.c Mon Mar 15 20:14:40 2004
@@ -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");
diff -ruN grub2/util/pupa-emu.c grub2.devel/util/pupa-emu.c
--- grub2/util/pupa-emu.c Tue Mar 16 02:24:00 2004
+++ grub2.devel/util/pupa-emu.c Tue Mar 16 03:24:48 2004
@@ -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 ();
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: GRUB2: *BSD and more patch
2004-03-18 8:15 GRUB2: *BSD and more patch Sergey Matveychuk
@ 2004-03-18 12:31 ` Yoshinori K. Okuji
2004-03-19 21:24 ` Sergey Matveychuk
0 siblings, 1 reply; 31+ messages in thread
From: Yoshinori K. Okuji @ 2004-03-18 12:31 UTC (permalink / raw)
To: The development of GRUB 2
On Thursday 18 March 2004 09:15, Sergey Matveychuk wrote:
> diff -ruN grub2/util/i386/pc/biosdisk.c
grub2.devel/util/i386/pc/biosdisk.c
> --- grub2/util/i386/pc/biosdisk.c Tue Mar 16 02:24:00 2004
> +++ grub2.devel/util/i386/pc/biosdisk.c Tue Mar 16 04:25:21 2004
> @@ -37,6 +37,17 @@
> #include <errno.h>
> #include <limits.h>
>
> +#if defined(__FreeBSD__) || defined(__NetBSD__) ||
defined(__OpenBSD__)
> +# 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.
> +#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.
> +#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;
> + 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.
> diff -ruN grub2/util/i386/pc/getroot.c
grub2.devel/util/i386/pc/getroot.c
> --- grub2/util/i386/pc/getroot.c Sun Mar 14 05:44:20 2004
> +++ grub2.devel/util/i386/pc/getroot.c Tue Mar 16 03:20:05 2004
> @@ -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
I think this can be generic, too. The check for a block device is not
very important.
> diff -ruN grub2/util/misc.c grub2.devel/util/misc.c
> --- grub2/util/misc.c Sun Mar 14 05:44:20 2004
> +++ grub2.devel/util/misc.c Mon Mar 15 20:14:40 2004
> @@ -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.
> +#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
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: GRUB2: *BSD and more patch
2004-03-18 12:31 ` Yoshinori K. Okuji
@ 2004-03-19 21:24 ` Sergey Matveychuk
2004-03-19 21:34 ` Johan Rydberg
2004-03-19 21:42 ` Marco Gerards
0 siblings, 2 replies; 31+ messages in thread
From: Sergey Matveychuk @ 2004-03-19 21:24 UTC (permalink / raw)
To: The development of GRUB 2
[-- Attachment #1: Type: text/plain, Size: 1114 bytes --]
Yoshinori K. Okuji wrote:
> 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.
> I think this part can omit the check using S_ISBLK regardless of the OS.
Done.
>
> I prefer not using hdg here. Again, look at my way in GRUB legacy.
Done.
> 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.
>
>
>>+#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.
>
> 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.
--
Sem.
[-- Attachment #2: grub2-bsd.patch --]
[-- Type: text/plain, Size: 6790 bytes --]
diff -ruN grub2/ChangeLog grub2.devel/ChangeLog
--- grub2/ChangeLog Fri Mar 19 23:55:21 2004
+++ grub2.devel/ChangeLog Fri Mar 19 23:27:37 2004
@@ -1,3 +1,15 @@
+2004-03-15 Sergey Matveychuk <sem@ciam.ru>
+
+ * 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 <jeroen@dekkers.cx>
* Makefile.in: Update copyright.
diff -ruN grub2/config.h.in grub2.devel/config.h.in
--- grub2/config.h.in Fri Mar 19 23:55:22 2004
+++ grub2.devel/config.h.in Fri Mar 19 23:29:57 2004
@@ -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
diff -ruN grub2/configure.ac grub2.devel/configure.ac
--- grub2/configure.ac Fri Mar 19 23:55:24 2004
+++ grub2.devel/configure.ac Fri Mar 19 23:59:27 2004
@@ -78,6 +78,8 @@
fi
AC_SUBST(CFLAGS)
+AC_CHECK_HEADER(malloc.h)
+
# Defined in aclocal.m4.
pupa_ASM_USCORE
pupa_CHECK_START_SYMBOL
diff -ruN grub2/util/i386/pc/biosdisk.c grub2.devel/util/i386/pc/biosdisk.c
--- grub2/util/i386/pc/biosdisk.c Sun Mar 14 20:48:25 2004
+++ grub2.devel/util/i386/pc/biosdisk.c Fri Mar 19 23:26:06 2004
@@ -37,6 +37,17 @@
#include <errno.h>
#include <limits.h>
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+# 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__ */
+
#ifdef __linux__
# include <sys/ioctl.h> /* ioctl */
# if !defined(__GLIBC__) || \
@@ -190,6 +201,47 @@
return PUPA_ERR_NONE;
}
+#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+ {
+ int fd;
+
+ fd = open (map[drive], O_RDONLY);
+ if (fd < 0)
+ return pupa_error (PUPA_ERR_BAD_DEVICE, "cannot open `%s'", map[drive]);
+
+ if (fstat (fd, &st) < 0)
+ {
+ close (fd);
+ goto fail;
+ }
+
+#if !defined(__FreeBSD__) || __FreeBSD_version < 500040
+ {
+ struct disklabel hdg;
+ 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;
+
+ disk->total_sectors = mediasize / secsize;
+#endif
+
+ close (fd);
+ }
+
+ pupa_util_info ("the size of %s is %lu", name, disk->total_sectors);
+
+ return PUPA_ERR_NONE;
fail:
/* In GNU/Hurd, stat() will return the right size. */
@@ -659,11 +711,12 @@
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)
{
- p = strchr (path, 's');
+ p = strrchr (path, 's');
if (p)
*p = '\0';
}
@@ -716,8 +769,10 @@
return 0;
}
+#if !defined(__FreeBSD__)
if (! S_ISBLK (st.st_mode))
return make_device_name (drive, -1, -1);
+#endif
#if defined(__linux__)
/* Linux counts partitions uniformly, whether a BSD partition or a DOS
@@ -806,8 +861,8 @@
return make_device_name (drive, dos_part, bsd_part);
}
-#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]?)?". */
{
char *p;
int dos_part = -1;
@@ -816,7 +871,7 @@
p = strrchr (os_dev, 's');
if (p)
{
- long int n;
+ long n;
char *q;
p++;
diff -ruN grub2/util/i386/pc/getroot.c grub2.devel/util/i386/pc/getroot.c
--- grub2/util/i386/pc/getroot.c Sat Mar 13 16:59:25 2004
+++ grub2.devel/util/i386/pc/getroot.c Fri Mar 19 23:01:22 2004
@@ -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;
diff -ruN grub2/util/misc.c grub2.devel/util/misc.c
--- grub2/util/misc.c Sat Mar 13 16:59:25 2004
+++ grub2.devel/util/misc.c Fri Mar 19 23:19:34 2004
@@ -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");
diff -ruN grub2/util/pupa-emu.c grub2.devel/util/pupa-emu.c
--- grub2/util/pupa-emu.c Sat Mar 13 16:59:25 2004
+++ grub2.devel/util/pupa-emu.c Tue Mar 16 03:24:48 2004
@@ -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 ();
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: GRUB2: *BSD and more patch
2004-03-19 21:24 ` Sergey Matveychuk
@ 2004-03-19 21:34 ` Johan Rydberg
2004-03-19 21:42 ` Marco Gerards
1 sibling, 0 replies; 31+ messages in thread
From: Johan Rydberg @ 2004-03-19 21:34 UTC (permalink / raw)
To: The development of GRUB 2
Sergey Matveychuk <sem@ciam.ru> 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.
--
Johan Rydberg, Free Software Developer, Sweden
http://rtmk.sf.net | http://www.nongnu.org/guss/
Playing A Perfect Circle - Lullaby
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: GRUB2: *BSD and more patch
2004-03-19 21:24 ` Sergey Matveychuk
2004-03-19 21:34 ` Johan Rydberg
@ 2004-03-19 21:42 ` Marco Gerards
2004-03-19 21:56 ` Sergey Matveychuk
1 sibling, 1 reply; 31+ messages in thread
From: Marco Gerards @ 2004-03-19 21:42 UTC (permalink / raw)
To: The development of GRUB 2
Sergey Matveychuk <sem@ciam.ru> writes:
> 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.
>> 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.
> 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.
> --- grub2/ChangeLog Fri Mar 19 23:55:21 2004
> +++ grub2.devel/ChangeLog Fri Mar 19 23:27:37 2004
> @@ -1,3 +1,15 @@
> +2004-03-15 Sergey Matveychuk <sem@ciam.ru>
> +
> + * 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
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: GRUB2: *BSD and more patch
2004-03-19 21:42 ` Marco Gerards
@ 2004-03-19 21:56 ` Sergey Matveychuk
2004-03-19 22:22 ` Marco Gerards
0 siblings, 1 reply; 31+ messages in thread
From: Sergey Matveychuk @ 2004-03-19 21:56 UTC (permalink / raw)
To: The development of GRUB 2
Marco Gerards wrote:
> If you want to fix it this way, it would be better to check for the
> existence of memalign using autoconf IMHO.
Hmm. OK :)
>
>
>>>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? :)
>
>
>>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.
>>+ * 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.
Johan Rydberg wrote:
> : + 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?
--
Sem.
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: GRUB2: *BSD and more patch
2004-03-19 21:56 ` Sergey Matveychuk
@ 2004-03-19 22:22 ` Marco Gerards
2004-03-19 23:24 ` Sergey Matveychuk
0 siblings, 1 reply; 31+ messages in thread
From: Marco Gerards @ 2004-03-19 22:22 UTC (permalink / raw)
To: The development of GRUB 2
Sergey Matveychuk <sem@ciam.ru> writes:
> > : + 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?
Please do it as it is explained in the GCS. The same goes for the
changelog.
Thanks,
Marco
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: GRUB2: *BSD and more patch
2004-03-19 22:22 ` Marco Gerards
@ 2004-03-19 23:24 ` Sergey Matveychuk
2004-03-19 23:55 ` Marco Gerards
0 siblings, 1 reply; 31+ messages in thread
From: Sergey Matveychuk @ 2004-03-19 23:24 UTC (permalink / raw)
To: The development of GRUB 2
[-- Attachment #1: Type: text/plain, Size: 35 bytes --]
Here is a third version.
--
Sem.
[-- Attachment #2: grub2-bsd.patch --]
[-- Type: text/plain, Size: 7518 bytes --]
diff -ruNp grub2/ChangeLog grub2.test/ChangeLog
--- grub2/ChangeLog Fri Mar 19 23:55:21 2004
+++ grub2.test/ChangeLog Sat Mar 20 01:38:47 2004
@@ -1,3 +1,19 @@
+2004-03-15 Sergey Matveychuk <sem@ciam.ru>
+
+ * 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 <jeroen@dekkers.cx>
* Makefile.in: Update copyright.
diff -ruNp grub2/config.h.in grub2.test/config.h.in
--- grub2/config.h.in Fri Mar 19 23:55:22 2004
+++ grub2.test/config.h.in Sat Mar 20 01:26:45 2004
@@ -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 */
diff -ruNp grub2/configure.ac grub2.test/configure.ac
--- grub2/configure.ac Fri Mar 19 23:55:24 2004
+++ grub2.test/configure.ac Sat Mar 20 01:21:36 2004
@@ -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
diff -ruNp grub2/util/i386/pc/biosdisk.c grub2.test/util/i386/pc/biosdisk.c
--- grub2/util/i386/pc/biosdisk.c Sun Mar 14 20:48:25 2004
+++ grub2.test/util/i386/pc/biosdisk.c Sat Mar 20 01:27:40 2004
@@ -37,6 +37,17 @@
#include <errno.h>
#include <limits.h>
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+# 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__ */
+
#ifdef __linux__
# include <sys/ioctl.h> /* ioctl */
# if !defined(__GLIBC__) || \
@@ -190,6 +201,47 @@ pupa_util_biosdisk_open (const char *nam
return PUPA_ERR_NONE;
}
+#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+ {
+ int fd;
+
+ fd = open (map[drive], O_RDONLY);
+ if (fd < 0)
+ return pupa_error (PUPA_ERR_BAD_DEVICE, "cannot open `%s'", map[drive]);
+
+ if (fstat (fd, &st) < 0)
+ {
+ close (fd);
+ goto fail;
+ }
+
+#if !defined(__FreeBSD__) || __FreeBSD_version < 500040
+ {
+ struct disklabel hdg;
+ if (ioctl (fd, DIOCGDINFO, &hdg))
+ goto fail;
+
+ disk->total_sectors = hdg.d_secperunit;
+ }
+#else
+ u_int secsize;
+ off_t mediasize;
+
+ if(ioctl(fd, DIOCGSECTORSIZE, &secsize) != 0)
+ secsize = 512;
+
+ if (ioctl(fd, DIOCGMEDIASIZE, &mediasize) != 0)
+ goto fail;
+
+ disk->total_sectors = mediasize / secsize;
+#endif
+
+ close (fd);
+ }
+
+ pupa_util_info ("the size of %s is %lu", name, disk->total_sectors);
+
+ return PUPA_ERR_NONE;
fail:
/* In GNU/Hurd, stat() will return the right size. */
@@ -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)
{
- p = strchr (path, 's');
+ p = strrchr (path, 's');
if (p)
*p = '\0';
}
@@ -716,8 +769,10 @@ pupa_util_biosdisk_get_pupa_dev (const c
return 0;
}
+#if !defined(__FreeBSD__)
if (! S_ISBLK (st.st_mode))
return make_device_name (drive, -1, -1);
+#endif
#if defined(__linux__)
/* Linux counts partitions uniformly, whether a BSD partition or a DOS
@@ -806,8 +861,8 @@ pupa_util_biosdisk_get_pupa_dev (const c
return make_device_name (drive, dos_part, bsd_part);
}
-#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]?)?". */
{
char *p;
int dos_part = -1;
diff -ruNp grub2/util/i386/pc/getroot.c grub2.test/util/i386/pc/getroot.c
--- grub2/util/i386/pc/getroot.c Sat Mar 13 16:59:25 2004
+++ grub2.test/util/i386/pc/getroot.c Sat Mar 20 00:05:26 2004
@@ -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;
diff -ruNp grub2/util/misc.c grub2.test/util/misc.c
--- grub2/util/misc.c Sat Mar 13 16:59:25 2004
+++ grub2.test/util/misc.c Sat Mar 20 01:25:31 2004
@@ -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");
diff -ruNp grub2/util/pupa-emu.c grub2.test/util/pupa-emu.c
--- grub2/util/pupa-emu.c Sat Mar 13 16:59:25 2004
+++ grub2.test/util/pupa-emu.c Sat Mar 20 01:25:51 2004
@@ -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 ();
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: GRUB2: *BSD and more patch
2004-03-19 23:24 ` Sergey Matveychuk
@ 2004-03-19 23:55 ` Marco Gerards
2004-03-20 0:45 ` Sergey Matveychuk
0 siblings, 1 reply; 31+ messages in thread
From: Marco Gerards @ 2004-03-19 23:55 UTC (permalink / raw)
To: The development of GRUB 2
Sergey Matveychuk <sem@ciam.ru> writes:
> 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.
> --
> Sem.
> diff -ruNp grub2/ChangeLog grub2.test/ChangeLog
> --- grub2/ChangeLog Fri Mar 19 23:55:21 2004
> +++ grub2.test/ChangeLog Sat Mar 20 01:38:47 2004
> @@ -1,3 +1,19 @@
> +2004-03-15 Sergey Matveychuk <sem@ciam.ru>
> +
> + * util/i386/pc/biosdisk.c: Added headers for BSD.
Please say exactly what header files you are including.
> + (pupa_util_biosdisk_get_pupa_dev): Do not call
Please end a sentence with a ".".
> + 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).
> + (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.
> -/* 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?
> -/* Define it to \"data32\" or \"data32;\" to make GAS happy */
> +/* Define it to "data32" or "data32;" to make GAS happy */
Same here.
> +AC_CHECK_HEADER(malloc.h)
> +AC_CHECK_FUNC(memalign)
This is what I meant, great!
> +#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?
> -#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
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: GRUB2: *BSD and more patch
2004-03-19 23:55 ` Marco Gerards
@ 2004-03-20 0:45 ` Sergey Matveychuk
2004-03-20 10:29 ` Jeroen Dekkers
0 siblings, 1 reply; 31+ messages in thread
From: Sergey Matveychuk @ 2004-03-20 0:45 UTC (permalink / raw)
To: The development of GRUB 2
[-- Attachment #1: Type: text/plain, Size: 1549 bytes --]
Marco Gerards wrote:
>>+ * util/i386/pc/biosdisk.c: Added headers for BSD.
>
>
> Please say exactly what header files you are including.
OK.
>
>
>>+ (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.
> 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.
> 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.
>>-/* 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.
>>+#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.
>
>
>>-#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.
--
Sem.
[-- Attachment #2: grub2-bsd.patch --]
[-- Type: text/plain, Size: 7041 bytes --]
diff -ruNp grub2/ChangeLog grub2.test/ChangeLog
--- grub2/ChangeLog Fri Mar 19 23:55:21 2004
+++ grub2.test/ChangeLog Sat Mar 20 03:39:20 2004
@@ -1,3 +1,21 @@
+2004-03-15 Sergey Matveychuk <sem@ciam.ru>
+
+ * 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 <jeroen@dekkers.cx>
* Makefile.in: Update copyright.
diff -ruNp grub2/configure.ac grub2.test/configure.ac
--- grub2/configure.ac Fri Mar 19 23:55:24 2004
+++ grub2.test/configure.ac Sat Mar 20 01:40:52 2004
@@ -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
diff -ruNp grub2/util/i386/pc/biosdisk.c grub2.test/util/i386/pc/biosdisk.c
--- grub2/util/i386/pc/biosdisk.c Sun Mar 14 20:48:25 2004
+++ grub2.test/util/i386/pc/biosdisk.c Sat Mar 20 03:19:49 2004
@@ -37,6 +37,17 @@
#include <errno.h>
#include <limits.h>
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+# 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__ */
+
#ifdef __linux__
# include <sys/ioctl.h> /* ioctl */
# if !defined(__GLIBC__) || \
@@ -190,6 +201,47 @@ pupa_util_biosdisk_open (const char *nam
return PUPA_ERR_NONE;
}
+#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+ {
+ int fd;
+
+ fd = open (map[drive], O_RDONLY);
+ if (fd < 0)
+ return pupa_error (PUPA_ERR_BAD_DEVICE, "cannot open `%s'", map[drive]);
+
+ if (fstat (fd, &st) < 0)
+ {
+ close (fd);
+ goto fail;
+ }
+
+#if !defined(__FreeBSD__) || __FreeBSD_version < 500040
+ {
+ struct disklabel hdg;
+ if (ioctl (fd, DIOCGDINFO, &hdg))
+ goto fail;
+
+ disk->total_sectors = hdg.d_secperunit;
+ }
+#else
+ u_int secsize;
+ off_t mediasize;
+
+ if(ioctl(fd, DIOCGSECTORSIZE, &secsize) != 0)
+ secsize = 512;
+
+ if (ioctl(fd, DIOCGMEDIASIZE, &mediasize) != 0)
+ goto fail;
+
+ disk->total_sectors = mediasize / secsize;
+#endif
+
+ close (fd);
+ }
+
+ pupa_util_info ("the size of %s is %lu", name, disk->total_sectors);
+
+ return PUPA_ERR_NONE;
fail:
/* In GNU/Hurd, stat() will return the right size. */
@@ -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)
{
- p = strchr (path, 's');
+ p = strrchr (path, 's');
if (p)
*p = '\0';
}
@@ -716,9 +769,6 @@ pupa_util_biosdisk_get_pupa_dev (const c
return 0;
}
- if (! S_ISBLK (st.st_mode))
- return make_device_name (drive, -1, -1);
-
#if defined(__linux__)
/* Linux counts partitions uniformly, whether a BSD partition or a DOS
partition, so mapping them to PUPA devices is not trivial.
@@ -806,8 +856,9 @@ pupa_util_biosdisk_get_pupa_dev (const c
return make_device_name (drive, dos_part, bsd_part);
}
-#elif defined(__GNU__)
+#elif defined(__GNU__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
/* GNU uses "/dev/[hs]d[0-9]+(s[0-9]+[a-z]?)?". */
+ /* BSD uses "/dev/[aw]d[0-9]+(s[0-9]+[a-z]?)?". */
{
char *p;
int dos_part = -1;
diff -ruNp grub2/util/i386/pc/getroot.c grub2.test/util/i386/pc/getroot.c
--- grub2/util/i386/pc/getroot.c Sat Mar 13 16:59:25 2004
+++ grub2.test/util/i386/pc/getroot.c Sat Mar 20 01:40:52 2004
@@ -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;
diff -ruNp grub2/util/misc.c grub2.test/util/misc.c
--- grub2/util/misc.c Sat Mar 13 16:59:25 2004
+++ grub2.test/util/misc.c Sat Mar 20 02:23:44 2004
@@ -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");
diff -ruNp grub2/util/pupa-emu.c grub2.test/util/pupa-emu.c
--- grub2/util/pupa-emu.c Sat Mar 13 16:59:25 2004
+++ grub2.test/util/pupa-emu.c Sat Mar 20 02:23:52 2004
@@ -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 ();
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: GRUB2: *BSD and more patch
2004-03-20 0:45 ` Sergey Matveychuk
@ 2004-03-20 10:29 ` Jeroen Dekkers
2004-03-20 18:30 ` Sergey Matveychuk
0 siblings, 1 reply; 31+ messages in thread
From: Jeroen Dekkers @ 2004-03-20 10:29 UTC (permalink / raw)
To: The development of GRUB 2
On Sat, Mar 20, 2004 at 03:45:31AM +0300, Sergey Matveychuk wrote:
> +#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.
> @@ -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__.
> @@ -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.
--
Jeroen Dekkers
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: GRUB2: *BSD and more patch
2004-03-20 10:29 ` Jeroen Dekkers
@ 2004-03-20 18:30 ` Sergey Matveychuk
2004-03-20 19:43 ` Marco Gerards
0 siblings, 1 reply; 31+ messages in thread
From: Sergey Matveychuk @ 2004-03-20 18:30 UTC (permalink / raw)
To: The development of GRUB 2
[-- Attachment #1: Type: text/plain, Size: 1098 bytes --]
Jeroen Dekkers wrote:
> 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.
> 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.
> 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 :)
--
Sem.
[-- Attachment #2: grub2-bsd.patch --]
[-- Type: text/plain, Size: 7153 bytes --]
diff -ruNp grub2/ChangeLog grub2.test/ChangeLog
--- grub2/ChangeLog Fri Mar 19 23:55:21 2004
+++ grub2.test/ChangeLog Sat Mar 20 20:57:56 2004
@@ -1,3 +1,21 @@
+2004-03-15 Sergey Matveychuk <sem@ciam.ru>
+
+ * 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 <jeroen@dekkers.cx>
* Makefile.in: Update copyright.
diff -ruNp grub2/configure.ac grub2.test/configure.ac
--- grub2/configure.ac Fri Mar 19 23:55:24 2004
+++ grub2.test/configure.ac Sat Mar 20 01:40:52 2004
@@ -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
diff -ruNp grub2/stamp-h grub2.test/stamp-h
--- grub2/stamp-h Thu Jan 1 03:00:00 1970
+++ grub2.test/stamp-h Sat Mar 20 01:41:16 2004
@@ -0,0 +1 @@
+timestamp
diff -ruNp grub2/util/i386/pc/biosdisk.c grub2.test/util/i386/pc/biosdisk.c
--- grub2/util/i386/pc/biosdisk.c Sun Mar 14 20:48:25 2004
+++ grub2.test/util/i386/pc/biosdisk.c Sat Mar 20 21:05:00 2004
@@ -37,6 +37,17 @@
#include <errno.h>
#include <limits.h>
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+# 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__ */
+
#ifdef __linux__
# include <sys/ioctl.h> /* ioctl */
# if !defined(__GLIBC__) || \
@@ -190,6 +201,48 @@ pupa_util_biosdisk_open (const char *nam
return PUPA_ERR_NONE;
}
+ fail:
+#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+ {
+ int fd;
+
+ fd = open (map[drive], O_RDONLY);
+ if (fd < 0)
+ return pupa_error (PUPA_ERR_BAD_DEVICE, "cannot open `%s'", map[drive]);
+
+ if (fstat (fd, &st) < 0)
+ {
+ close (fd);
+ goto fail;
+ }
+
+#if !defined(__FreeBSD__) || __FreeBSD_version < 500040
+ {
+ struct disklabel hdg;
+ if (ioctl (fd, DIOCGDINFO, &hdg))
+ goto fail;
+
+ disk->total_sectors = hdg.d_secperunit;
+ }
+#else
+ u_int secsize;
+ off_t mediasize;
+
+ if(ioctl(fd, DIOCGSECTORSIZE, &secsize) != 0)
+ secsize = 512;
+
+ if (ioctl(fd, DIOCGMEDIASIZE, &mediasize) != 0)
+ goto fail;
+
+ disk->total_sectors = mediasize / secsize;
+#endif
+
+ close (fd);
+ }
+
+ pupa_util_info ("the size of %s is %lu", name, disk->total_sectors);
+
+ return PUPA_ERR_NONE;
fail:
/* In GNU/Hurd, stat() will return the right size. */
@@ -659,11 +712,15 @@ 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);
+#ifdef __GNU__
if (strncmp ("/dev/sd", path, 7) == 0 || strncmp ("/dev/hd", path, 7) == 0)
+#else
+ if (strncmp ("/dev/ad", path, 7) == 0 || strncmp ("/dev/wd", path, 7) == 0)
+#endif
{
- p = strchr (path, 's');
+ p = strrchr (path, 's');
if (p)
*p = '\0';
}
@@ -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);
-
#if defined(__linux__)
/* Linux counts partitions uniformly, whether a BSD partition or a DOS
partition, so mapping them to PUPA devices is not trivial.
@@ -806,8 +860,9 @@ pupa_util_biosdisk_get_pupa_dev (const c
return make_device_name (drive, dos_part, bsd_part);
}
-#elif defined(__GNU__)
+#elif defined(__GNU__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
/* GNU uses "/dev/[hs]d[0-9]+(s[0-9]+[a-z]?)?". */
+ /* BSD uses "/dev/[aw]d[0-9]+(s[0-9]+[a-z]?)?". */
{
char *p;
int dos_part = -1;
diff -ruNp grub2/util/i386/pc/getroot.c grub2.test/util/i386/pc/getroot.c
--- grub2/util/i386/pc/getroot.c Sat Mar 13 16:59:25 2004
+++ grub2.test/util/i386/pc/getroot.c Sat Mar 20 21:03:29 2004
@@ -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;
diff -ruNp grub2/util/misc.c grub2.test/util/misc.c
--- grub2/util/misc.c Sat Mar 13 16:59:25 2004
+++ grub2.test/util/misc.c Sat Mar 20 02:23:44 2004
@@ -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");
diff -ruNp grub2/util/pupa-emu.c grub2.test/util/pupa-emu.c
--- grub2/util/pupa-emu.c Sat Mar 13 16:59:25 2004
+++ grub2.test/util/pupa-emu.c Sat Mar 20 02:23:52 2004
@@ -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 ();
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: GRUB2: *BSD and more patch
2004-03-20 18:30 ` Sergey Matveychuk
@ 2004-03-20 19:43 ` Marco Gerards
2004-03-21 1:17 ` Sergey Matveychuk
0 siblings, 1 reply; 31+ messages in thread
From: Marco Gerards @ 2004-03-20 19:43 UTC (permalink / raw)
To: The development of GRUB 2
Sergey Matveychuk <sem@ciam.ru> writes:
> 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.
> 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
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: GRUB2: *BSD and more patch
2004-03-20 19:43 ` Marco Gerards
@ 2004-03-21 1:17 ` Sergey Matveychuk
2004-03-21 1:45 ` Marco Gerards
2004-03-21 16:11 ` Yoshinori K. Okuji
0 siblings, 2 replies; 31+ messages in thread
From: Sergey Matveychuk @ 2004-03-21 1:17 UTC (permalink / raw)
To: The development of GRUB 2
[-- Attachment #1: Type: text/plain, Size: 495 bytes --]
Marco Gerards wrote:
> 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.
--
Sem.
[-- Attachment #2: grub2-bsd.patch --]
[-- Type: text/plain, Size: 7153 bytes --]
diff -ruNp grub2/ChangeLog grub2.test/ChangeLog
--- grub2/ChangeLog Fri Mar 19 23:55:21 2004
+++ grub2.test/ChangeLog Sat Mar 20 20:57:56 2004
@@ -1,3 +1,21 @@
+2004-03-15 Sergey Matveychuk <sem@ciam.ru>
+
+ * 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 <jeroen@dekkers.cx>
* Makefile.in: Update copyright.
diff -ruNp grub2/configure.ac grub2.test/configure.ac
--- grub2/configure.ac Fri Mar 19 23:55:24 2004
+++ grub2.test/configure.ac Sat Mar 20 01:40:52 2004
@@ -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
diff -ruNp grub2/stamp-h grub2.test/stamp-h
--- grub2/stamp-h Thu Jan 1 03:00:00 1970
+++ grub2.test/stamp-h Sat Mar 20 01:41:16 2004
@@ -0,0 +1 @@
+timestamp
diff -ruNp grub2/util/i386/pc/biosdisk.c grub2.test/util/i386/pc/biosdisk.c
--- grub2/util/i386/pc/biosdisk.c Sun Mar 14 20:48:25 2004
+++ grub2.test/util/i386/pc/biosdisk.c Sat Mar 20 21:05:00 2004
@@ -37,6 +37,17 @@
#include <errno.h>
#include <limits.h>
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+# 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__ */
+
#ifdef __linux__
# include <sys/ioctl.h> /* ioctl */
# if !defined(__GLIBC__) || \
@@ -190,6 +201,48 @@ pupa_util_biosdisk_open (const char *nam
return PUPA_ERR_NONE;
}
+ fail:
+#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+ {
+ int fd;
+
+ fd = open (map[drive], O_RDONLY);
+ if (fd < 0)
+ return pupa_error (PUPA_ERR_BAD_DEVICE, "cannot open `%s'", map[drive]);
+
+ if (fstat (fd, &st) < 0)
+ {
+ close (fd);
+ goto fail;
+ }
+
+#if !defined(__FreeBSD__) || __FreeBSD_version < 500040
+ {
+ struct disklabel hdg;
+ if (ioctl (fd, DIOCGDINFO, &hdg))
+ goto fail;
+
+ disk->total_sectors = hdg.d_secperunit;
+ }
+#else
+ u_int secsize;
+ off_t mediasize;
+
+ if(ioctl(fd, DIOCGSECTORSIZE, &secsize) != 0)
+ secsize = 512;
+
+ if (ioctl(fd, DIOCGMEDIASIZE, &mediasize) != 0)
+ goto fail;
+
+ disk->total_sectors = mediasize / secsize;
+#endif
+
+ close (fd);
+ }
+
+ pupa_util_info ("the size of %s is %lu", name, disk->total_sectors);
+
+ return PUPA_ERR_NONE;
fail:
/* In GNU/Hurd, stat() will return the right size. */
@@ -659,11 +712,15 @@ 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);
+#ifdef __GNU__
if (strncmp ("/dev/sd", path, 7) == 0 || strncmp ("/dev/hd", path, 7) == 0)
+#else
+ if (strncmp ("/dev/ad", path, 7) == 0 || strncmp ("/dev/wd", path, 7) == 0)
+#endif
{
- p = strchr (path, 's');
+ p = strrchr (path, 's');
if (p)
*p = '\0';
}
@@ -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);
-
#if defined(__linux__)
/* Linux counts partitions uniformly, whether a BSD partition or a DOS
partition, so mapping them to PUPA devices is not trivial.
@@ -806,8 +860,9 @@ pupa_util_biosdisk_get_pupa_dev (const c
return make_device_name (drive, dos_part, bsd_part);
}
-#elif defined(__GNU__)
+#elif defined(__GNU__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
/* GNU uses "/dev/[hs]d[0-9]+(s[0-9]+[a-z]?)?". */
+ /* BSD uses "/dev/[aw]d[0-9]+(s[0-9]+[a-z]?)?". */
{
char *p;
int dos_part = -1;
diff -ruNp grub2/util/i386/pc/getroot.c grub2.test/util/i386/pc/getroot.c
--- grub2/util/i386/pc/getroot.c Sat Mar 13 16:59:25 2004
+++ grub2.test/util/i386/pc/getroot.c Sat Mar 20 21:03:29 2004
@@ -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;
diff -ruNp grub2/util/misc.c grub2.test/util/misc.c
--- grub2/util/misc.c Sat Mar 13 16:59:25 2004
+++ grub2.test/util/misc.c Sat Mar 20 02:23:44 2004
@@ -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");
diff -ruNp grub2/util/pupa-emu.c grub2.test/util/pupa-emu.c
--- grub2/util/pupa-emu.c Sat Mar 13 16:59:25 2004
+++ grub2.test/util/pupa-emu.c Sat Mar 20 02:23:52 2004
@@ -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 ();
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: GRUB2: *BSD and more patch
2004-03-21 1:17 ` Sergey Matveychuk
@ 2004-03-21 1:45 ` Marco Gerards
2004-03-21 2:18 ` Sergey Matveychuk
2004-03-21 16:11 ` Yoshinori K. Okuji
1 sibling, 1 reply; 31+ messages in thread
From: Marco Gerards @ 2004-03-21 1:45 UTC (permalink / raw)
To: The development of GRUB 2
Sergey Matveychuk <sem@ciam.ru> writes:
> Marco Gerards wrote:
>
>> 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? :)
> 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
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: GRUB2: *BSD and more patch
2004-03-21 1:45 ` Marco Gerards
@ 2004-03-21 2:18 ` Sergey Matveychuk
2004-03-21 3:30 ` Marco Gerards
0 siblings, 1 reply; 31+ messages in thread
From: Sergey Matveychuk @ 2004-03-21 2:18 UTC (permalink / raw)
To: The development of GRUB 2
Marco Gerards wrote:
>>>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 :)
--
Sem.
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: GRUB2: *BSD and more patch
2004-03-21 2:18 ` Sergey Matveychuk
@ 2004-03-21 3:30 ` Marco Gerards
0 siblings, 0 replies; 31+ messages in thread
From: Marco Gerards @ 2004-03-21 3:30 UTC (permalink / raw)
To: The development of GRUB 2
Sergey Matveychuk <sem@ciam.ru> writes:
>> 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.
> 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
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: GRUB2: *BSD and more patch
2004-03-21 1:17 ` Sergey Matveychuk
2004-03-21 1:45 ` Marco Gerards
@ 2004-03-21 16:11 ` Yoshinori K. Okuji
2004-03-22 8:20 ` Sergey Matveychuk
1 sibling, 1 reply; 31+ messages in thread
From: Yoshinori K. Okuji @ 2004-03-21 16:11 UTC (permalink / raw)
To: The development of GRUB 2
On Sunday 21 March 2004 02:17, Sergey Matveychuk wrote:
> @@ -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?
> +#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
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: GRUB2: *BSD and more patch
2004-03-21 16:11 ` Yoshinori K. Okuji
@ 2004-03-22 8:20 ` Sergey Matveychuk
2004-03-22 13:49 ` Yoshinori K. Okuji
0 siblings, 1 reply; 31+ messages in thread
From: Sergey Matveychuk @ 2004-03-22 8:20 UTC (permalink / raw)
To: The development of GRUB 2
[-- Attachment #1: Type: text/plain, Size: 1236 bytes --]
Yoshinori K. Okuji wrote:
>>- 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 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.
>
> 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?
--
Sem.
[-- Attachment #2: grub2-bsd.patch --]
[-- Type: text/plain, Size: 7204 bytes --]
diff -ruNp grub2/ChangeLog grub2.devel/ChangeLog
--- grub2/ChangeLog Mon Mar 22 11:02:56 2004
+++ grub2.devel/ChangeLog Mon Mar 22 11:08:56 2004
@@ -1,3 +1,21 @@
+2004-03-15 Sergey Matveychuk <sem@ciam.ru>
+
+ * 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 <jeroen@dekkers.cx>
* Makefile.in: Update copyright.
diff -ruNp grub2/configure.ac grub2.devel/configure.ac
--- grub2/configure.ac Mon Mar 22 11:02:56 2004
+++ grub2.devel/configure.ac Mon Mar 22 11:08:56 2004
@@ -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
diff -ruNp grub2/stamp-h grub2.devel/stamp-h
--- grub2/stamp-h Thu Jan 1 03:00:00 1970
+++ grub2.devel/stamp-h Mon Mar 22 11:08:56 2004
@@ -0,0 +1 @@
+timestamp
diff -ruNp grub2/util/i386/pc/biosdisk.c grub2.devel/util/i386/pc/biosdisk.c
--- grub2/util/i386/pc/biosdisk.c Mon Mar 22 11:02:57 2004
+++ grub2.devel/util/i386/pc/biosdisk.c Mon Mar 22 11:10:43 2004
@@ -37,6 +37,17 @@
#include <errno.h>
#include <limits.h>
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+# 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__ */
+
#ifdef __linux__
# include <sys/ioctl.h> /* ioctl */
# if !defined(__GLIBC__) || \
@@ -190,6 +201,48 @@ pupa_util_biosdisk_open (const char *nam
return PUPA_ERR_NONE;
}
+ fail:
+#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+ {
+ int fd;
+
+ fd = open (map[drive], O_RDONLY);
+ if (fd < 0)
+ return pupa_error (PUPA_ERR_BAD_DEVICE, "cannot open `%s'", map[drive]);
+
+ if (fstat (fd, &st) < 0)
+ {
+ close (fd);
+ goto fail;
+ }
+
+#if !defined(__FreeBSD__) || __FreeBSD_version < 500040
+ {
+ struct disklabel hdg;
+ if (ioctl (fd, DIOCGDINFO, &hdg))
+ goto fail;
+
+ disk->total_sectors = hdg.d_secperunit;
+ }
+#else
+ u_int secsize;
+ off_t mediasize;
+
+ if(ioctl(fd, DIOCGSECTORSIZE, &secsize) != 0)
+ secsize = 512;
+
+ if (ioctl(fd, DIOCGMEDIASIZE, &mediasize) != 0)
+ goto fail;
+
+ disk->total_sectors = mediasize / secsize;
+#endif
+
+ close (fd);
+ }
+
+ pupa_util_info ("the size of %s is %lu", name, disk->total_sectors);
+
+ return PUPA_ERR_NONE;
fail:
/* In GNU/Hurd, stat() will return the right size. */
@@ -659,11 +712,15 @@ 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);
+#ifdef __GNU__
if (strncmp ("/dev/sd", path, 7) == 0 || strncmp ("/dev/hd", path, 7) == 0)
+#else
+ if (strncmp ("/dev/ad", path, 7) == 0 || strncmp ("/dev/wd", path, 7) == 0)
+#endif
{
- p = strchr (path, 's');
+ p = strrchr (path, 's');
if (p)
*p = '\0';
}
@@ -715,9 +772,11 @@ pupa_util_biosdisk_get_pupa_dev (const c
"no mapping exists for `%s'", os_dev);
return 0;
}
-
+
+#ifndef __FreeBSD__
if (! S_ISBLK (st.st_mode))
return make_device_name (drive, -1, -1);
+#endif
#if defined(__linux__)
/* Linux counts partitions uniformly, whether a BSD partition or a DOS
@@ -806,8 +865,9 @@ pupa_util_biosdisk_get_pupa_dev (const c
return make_device_name (drive, dos_part, bsd_part);
}
-#elif defined(__GNU__)
+#elif defined(__GNU__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
/* GNU uses "/dev/[hs]d[0-9]+(s[0-9]+[a-z]?)?". */
+ /* BSD uses "/dev/[aw]d[0-9]+(s[0-9]+[a-z]?)?". */
{
char *p;
int dos_part = -1;
diff -ruNp grub2/util/i386/pc/getroot.c grub2.devel/util/i386/pc/getroot.c
--- grub2/util/i386/pc/getroot.c Mon Mar 22 11:02:57 2004
+++ grub2.devel/util/i386/pc/getroot.c Mon Mar 22 11:08:56 2004
@@ -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;
diff -ruNp grub2/util/misc.c grub2.devel/util/misc.c
--- grub2/util/misc.c Mon Mar 22 11:02:57 2004
+++ grub2.devel/util/misc.c Mon Mar 22 11:11:41 2004
@@ -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");
diff -ruNp grub2/util/pupa-emu.c grub2.devel/util/pupa-emu.c
--- grub2/util/pupa-emu.c Mon Mar 22 11:02:57 2004
+++ grub2.devel/util/pupa-emu.c Mon Mar 22 11:08:56 2004
@@ -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 ();
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: GRUB2: *BSD and more patch
2004-03-22 8:20 ` Sergey Matveychuk
@ 2004-03-22 13:49 ` Yoshinori K. Okuji
2004-03-22 14:26 ` Jeroen Dekkers
` (2 more replies)
0 siblings, 3 replies; 31+ messages in thread
From: Yoshinori K. Okuji @ 2004-03-22 13:49 UTC (permalink / raw)
To: The development of GRUB 2
On Monday 22 March 2004 09:20, Sergey Matveychuk wrote:
> Yoshinori K. Okuji wrote:
> >>- 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.
> > 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.
> @@ -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
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: GRUB2: *BSD and more patch
2004-03-22 13:49 ` Yoshinori K. Okuji
@ 2004-03-22 14:26 ` Jeroen Dekkers
2004-03-22 15:23 ` Yoshinori K. Okuji
2004-03-22 22:03 ` Sergey Matveychuk
2004-03-22 22:10 ` Sergey Matveychuk
2 siblings, 1 reply; 31+ messages in thread
From: Jeroen Dekkers @ 2004-03-22 14:26 UTC (permalink / raw)
To: The development of GRUB 2
On Mon, Mar 22, 2004 at 02:49:41PM +0100, Yoshinori K. Okuji wrote:
> On Monday 22 March 2004 09:20, Sergey Matveychuk wrote:
> > @@ -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.
It doesn't return, pupa_util_error() calls exit().
--
Jeroen Dekkers
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: GRUB2: *BSD and more patch
2004-03-22 14:26 ` Jeroen Dekkers
@ 2004-03-22 15:23 ` Yoshinori K. Okuji
2004-03-22 21:05 ` Sergey Matveychuk
0 siblings, 1 reply; 31+ messages in thread
From: Yoshinori K. Okuji @ 2004-03-22 15:23 UTC (permalink / raw)
To: The development of GRUB 2
On Monday 22 March 2004 15:26, Jeroen Dekkers wrote:
> > 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
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: GRUB2: *BSD and more patch
2004-03-22 15:23 ` Yoshinori K. Okuji
@ 2004-03-22 21:05 ` Sergey Matveychuk
0 siblings, 0 replies; 31+ messages in thread
From: Sergey Matveychuk @ 2004-03-22 21:05 UTC (permalink / raw)
To: The development of GRUB 2
[-- Attachment #1: Type: text/plain, Size: 33 bytes --]
Here is a new version.
--
Sem.
[-- Attachment #2: grub2-bsd.patch --]
[-- Type: text/plain, Size: 7116 bytes --]
diff -ruNp grub2/ChangeLog grub2.devel/ChangeLog
--- grub2/ChangeLog Fri Mar 19 23:55:21 2004
+++ grub2.devel/ChangeLog Mon Mar 22 23:59:56 2004
@@ -1,3 +1,21 @@
+2004-03-15 Sergey Matveychuk <sem@ciam.ru>
+
+ * 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 <jeroen@dekkers.cx>
* Makefile.in: Update copyright.
diff -ruNp grub2/configure.ac grub2.devel/configure.ac
--- grub2/configure.ac Fri Mar 19 23:55:24 2004
+++ grub2.devel/configure.ac Mon Mar 22 23:55:28 2004
@@ -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
diff -ruNp grub2/stamp-h grub2.devel/stamp-h
--- grub2/stamp-h Thu Jan 1 03:00:00 1970
+++ grub2.devel/stamp-h Mon Mar 22 23:55:28 2004
@@ -0,0 +1 @@
+timestamp
diff -ruNp grub2/util/i386/pc/biosdisk.c grub2.devel/util/i386/pc/biosdisk.c
--- grub2/util/i386/pc/biosdisk.c Sun Mar 14 20:48:25 2004
+++ grub2.devel/util/i386/pc/biosdisk.c Tue Mar 23 00:00:48 2004
@@ -37,6 +37,17 @@
#include <errno.h>
#include <limits.h>
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+# 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__ */
+
#ifdef __linux__
# include <sys/ioctl.h> /* ioctl */
# if !defined(__GLIBC__) || \
@@ -190,6 +201,48 @@ pupa_util_biosdisk_open (const char *nam
return PUPA_ERR_NONE;
}
+ fail:
+#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+ {
+ int fd;
+
+ fd = open (map[drive], O_RDONLY);
+ if (fd < 0)
+ return pupa_error (PUPA_ERR_BAD_DEVICE, "cannot open `%s'", map[drive]);
+
+ if (fstat (fd, &st) < 0)
+ {
+ close (fd);
+ goto fail;
+ }
+
+#if !defined(__FreeBSD__) || __FreeBSD_version < 500040
+ {
+ struct disklabel hdg;
+ if (ioctl (fd, DIOCGDINFO, &hdg))
+ goto fail;
+
+ disk->total_sectors = hdg.d_secperunit;
+ }
+#else
+ u_int secsize;
+ off_t mediasize;
+
+ if(ioctl(fd, DIOCGSECTORSIZE, &secsize) != 0)
+ secsize = 512;
+
+ if (ioctl(fd, DIOCGMEDIASIZE, &mediasize) != 0)
+ goto fail;
+
+ disk->total_sectors = mediasize / secsize;
+#endif
+
+ close (fd);
+ }
+
+ pupa_util_info ("the size of %s is %lu", name, disk->total_sectors);
+
+ return PUPA_ERR_NONE;
fail:
/* In GNU/Hurd, stat() will return the right size. */
@@ -659,11 +712,15 @@ 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);
+#ifdef __GNU__
if (strncmp ("/dev/sd", path, 7) == 0 || strncmp ("/dev/hd", path, 7) == 0)
+#else
+ if (strncmp ("/dev/ad", path, 7) == 0 || strncmp ("/dev/wd", path, 7) == 0)
+#endif
{
- p = strchr (path, 's');
+ p = strrchr (path, 's');
if (p)
*p = '\0';
}
@@ -716,7 +773,7 @@ pupa_util_biosdisk_get_pupa_dev (const c
return 0;
}
- if (! S_ISBLK (st.st_mode))
+ if (! S_ISREG (st.st_mode))
return make_device_name (drive, -1, -1);
#if defined(__linux__)
@@ -806,8 +863,9 @@ pupa_util_biosdisk_get_pupa_dev (const c
return make_device_name (drive, dos_part, bsd_part);
}
-#elif defined(__GNU__)
+#elif defined(__GNU__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
/* GNU uses "/dev/[hs]d[0-9]+(s[0-9]+[a-z]?)?". */
+ /* BSD uses "/dev/[aw]d[0-9]+(s[0-9]+[a-z]?)?". */
{
char *p;
int dos_part = -1;
diff -ruNp grub2/util/i386/pc/getroot.c grub2.devel/util/i386/pc/getroot.c
--- grub2/util/i386/pc/getroot.c Sat Mar 13 16:59:25 2004
+++ grub2.devel/util/i386/pc/getroot.c Tue Mar 23 00:01:11 2004
@@ -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;
diff -ruNp grub2/util/misc.c grub2.devel/util/misc.c
--- grub2/util/misc.c Sat Mar 13 16:59:25 2004
+++ grub2.devel/util/misc.c Mon Mar 22 23:55:28 2004
@@ -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");
diff -ruNp grub2/util/pupa-emu.c grub2.devel/util/pupa-emu.c
--- grub2/util/pupa-emu.c Sat Mar 13 16:59:25 2004
+++ grub2.devel/util/pupa-emu.c Mon Mar 22 23:55:28 2004
@@ -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 ();
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: GRUB2: *BSD and more patch
2004-03-22 13:49 ` Yoshinori K. Okuji
2004-03-22 14:26 ` Jeroen Dekkers
@ 2004-03-22 22:03 ` Sergey Matveychuk
2004-03-22 22:10 ` Sergey Matveychuk
2 siblings, 0 replies; 31+ messages in thread
From: Sergey Matveychuk @ 2004-03-22 22:03 UTC (permalink / raw)
To: The development of GRUB 2
Yoshinori K. Okuji wrote:
> 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. :(
--
Sem.
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: GRUB2: *BSD and more patch
2004-03-22 13:49 ` Yoshinori K. Okuji
2004-03-22 14:26 ` Jeroen Dekkers
2004-03-22 22:03 ` Sergey Matveychuk
@ 2004-03-22 22:10 ` Sergey Matveychuk
2004-09-01 22:00 ` Marco Gerards
2 siblings, 1 reply; 31+ messages in thread
From: Sergey Matveychuk @ 2004-03-22 22:10 UTC (permalink / raw)
To: The development of GRUB 2
[-- Attachment #1: Type: text/plain, Size: 328 bytes --]
Yoshinori K. Okuji wrote:
> 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.
--
Sem.
[-- Attachment #2: grub2-bsd.patch --]
[-- Type: text/plain, Size: 7117 bytes --]
diff -ruNp grub2/ChangeLog grub2.devel/ChangeLog
--- grub2/ChangeLog Fri Mar 19 23:55:21 2004
+++ grub2.devel/ChangeLog Tue Mar 23 01:06:06 2004
@@ -1,3 +1,21 @@
+2004-03-15 Sergey Matveychuk <sem@ciam.ru>
+
+ * 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 <jeroen@dekkers.cx>
* Makefile.in: Update copyright.
diff -ruNp grub2/configure.ac grub2.devel/configure.ac
--- grub2/configure.ac Fri Mar 19 23:55:24 2004
+++ grub2.devel/configure.ac Tue Mar 23 01:04:23 2004
@@ -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
diff -ruNp grub2/stamp-h grub2.devel/stamp-h
--- grub2/stamp-h Thu Jan 1 03:00:00 1970
+++ grub2.devel/stamp-h Tue Mar 23 01:04:23 2004
@@ -0,0 +1 @@
+timestamp
diff -ruNp grub2/util/i386/pc/biosdisk.c grub2.devel/util/i386/pc/biosdisk.c
--- grub2/util/i386/pc/biosdisk.c Sun Mar 14 20:48:25 2004
+++ grub2.devel/util/i386/pc/biosdisk.c Tue Mar 23 01:04:56 2004
@@ -37,6 +37,17 @@
#include <errno.h>
#include <limits.h>
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+# 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__ */
+
#ifdef __linux__
# include <sys/ioctl.h> /* ioctl */
# if !defined(__GLIBC__) || \
@@ -190,6 +201,48 @@ pupa_util_biosdisk_open (const char *nam
return PUPA_ERR_NONE;
}
+ fail:
+#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+ {
+ int fd;
+
+ fd = open (map[drive], O_RDONLY);
+ if (fd < 0)
+ return pupa_error (PUPA_ERR_BAD_DEVICE, "cannot open `%s'", map[drive]);
+
+ if (fstat (fd, &st) < 0)
+ {
+ close (fd);
+ goto fail;
+ }
+
+#if !defined(__FreeBSD__) || __FreeBSD_version < 500040
+ {
+ struct disklabel hdg;
+ if (ioctl (fd, DIOCGDINFO, &hdg))
+ goto fail;
+
+ disk->total_sectors = hdg.d_secperunit;
+ }
+#else
+ u_int secsize;
+ off_t mediasize;
+
+ if(ioctl(fd, DIOCGSECTORSIZE, &secsize) != 0)
+ secsize = 512;
+
+ if (ioctl(fd, DIOCGMEDIASIZE, &mediasize) != 0)
+ goto fail;
+
+ disk->total_sectors = mediasize / secsize;
+#endif
+
+ close (fd);
+ }
+
+ pupa_util_info ("the size of %s is %lu", name, disk->total_sectors);
+
+ return PUPA_ERR_NONE;
fail:
/* In GNU/Hurd, stat() will return the right size. */
@@ -659,11 +712,15 @@ 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);
+#ifdef __GNU__
if (strncmp ("/dev/sd", path, 7) == 0 || strncmp ("/dev/hd", path, 7) == 0)
+#else
+ if (strncmp ("/dev/ad", path, 7) == 0 || strncmp ("/dev/wd", path, 7) == 0)
+#endif
{
- p = strchr (path, 's');
+ p = strrchr (path, 's');
if (p)
*p = '\0';
}
@@ -716,7 +773,7 @@ pupa_util_biosdisk_get_pupa_dev (const c
return 0;
}
- if (! S_ISBLK (st.st_mode))
+ if (S_ISREG (st.st_mode))
return make_device_name (drive, -1, -1);
#if defined(__linux__)
@@ -806,8 +863,9 @@ pupa_util_biosdisk_get_pupa_dev (const c
return make_device_name (drive, dos_part, bsd_part);
}
-#elif defined(__GNU__)
+#elif defined(__GNU__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
/* GNU uses "/dev/[hs]d[0-9]+(s[0-9]+[a-z]?)?". */
+ /* BSD uses "/dev/[aw]d[0-9]+(s[0-9]+[a-z]?)?". */
{
char *p;
int dos_part = -1;
diff -ruNp grub2/util/i386/pc/getroot.c grub2.devel/util/i386/pc/getroot.c
--- grub2/util/i386/pc/getroot.c Sat Mar 13 16:59:25 2004
+++ grub2.devel/util/i386/pc/getroot.c Tue Mar 23 01:05:38 2004
@@ -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;
diff -ruNp grub2/util/misc.c grub2.devel/util/misc.c
--- grub2/util/misc.c Sat Mar 13 16:59:25 2004
+++ grub2.devel/util/misc.c Tue Mar 23 01:04:23 2004
@@ -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");
diff -ruNp grub2/util/pupa-emu.c grub2.devel/util/pupa-emu.c
--- grub2/util/pupa-emu.c Sat Mar 13 16:59:25 2004
+++ grub2.devel/util/pupa-emu.c Tue Mar 23 01:04:23 2004
@@ -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 ();
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: GRUB2: *BSD and more patch
2004-03-22 22:10 ` Sergey Matveychuk
@ 2004-09-01 22:00 ` Marco Gerards
2004-09-02 10:50 ` Yoshinori K. Okuji
0 siblings, 1 reply; 31+ messages in thread
From: Marco Gerards @ 2004-09-01 22:00 UTC (permalink / raw)
To: The development of GRUB 2
Sergey Matveychuk <sem@ciam.ru> writes:
> Yoshinori K. Okuji wrote:
>
>> 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
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: GRUB2: *BSD and more patch
2004-09-01 22:00 ` Marco Gerards
@ 2004-09-02 10:50 ` Yoshinori K. Okuji
2004-09-05 9:26 ` Marco Gerards
0 siblings, 1 reply; 31+ messages in thread
From: Yoshinori K. Okuji @ 2004-09-02 10:50 UTC (permalink / raw)
To: The development of GRUB 2
On Thursday 02 September 2004 00:00, Marco Gerards wrote:
> 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
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: GRUB2: *BSD and more patch
2004-09-02 10:50 ` Yoshinori K. Okuji
@ 2004-09-05 9:26 ` Marco Gerards
2004-09-07 10:46 ` Yoshinori K. Okuji
0 siblings, 1 reply; 31+ messages in thread
From: Marco Gerards @ 2004-09-05 9:26 UTC (permalink / raw)
To: The development of GRUB 2
"Yoshinori K. Okuji" <okuji@enbug.org> writes:
> On Thursday 02 September 2004 00:00, Marco Gerards wrote:
>> 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?
In the email in this thread, the same email I replied to.
Here it is in the mailinglist archives:
http://lists.gnu.org/archive/html/grub-devel/2004-03/msg00060.html
--
Marco
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: GRUB2: *BSD and more patch
2004-09-05 9:26 ` Marco Gerards
@ 2004-09-07 10:46 ` Yoshinori K. Okuji
2004-12-29 17:27 ` Marco Gerards
0 siblings, 1 reply; 31+ messages in thread
From: Yoshinori K. Okuji @ 2004-09-07 10:46 UTC (permalink / raw)
To: The development of GRUB 2
On Sunday 05 September 2004 11:26, Marco Gerards wrote:
> 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.
Okuji
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: GRUB2: *BSD and more patch
2004-09-07 10:46 ` Yoshinori K. Okuji
@ 2004-12-29 17:27 ` Marco Gerards
2005-01-11 13:32 ` Yoshinori K. Okuji
0 siblings, 1 reply; 31+ messages in thread
From: Marco Gerards @ 2004-12-29 17:27 UTC (permalink / raw)
To: The development of GRUB 2
"Yoshinori K. Okuji" <okuji@enbug.org> writes:
> On Sunday 05 September 2004 11:26, Marco Gerards wrote:
>> 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
^ permalink raw reply [flat|nested] 31+ messages in thread
* Re: GRUB2: *BSD and more patch
2004-12-29 17:27 ` Marco Gerards
@ 2005-01-11 13:32 ` Yoshinori K. Okuji
0 siblings, 0 replies; 31+ messages in thread
From: Yoshinori K. Okuji @ 2005-01-11 13:32 UTC (permalink / raw)
To: The development of GRUB 2
Hi Marco,
On Wednesday 29 December 2004 18:27, Marco Gerards wrote:
> 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
^ permalink raw reply [flat|nested] 31+ messages in thread
end of thread, other threads:[~2005-01-11 13:45 UTC | newest]
Thread overview: 31+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-03-18 8:15 GRUB2: *BSD and more patch Sergey Matveychuk
2004-03-18 12:31 ` Yoshinori K. Okuji
2004-03-19 21:24 ` Sergey Matveychuk
2004-03-19 21:34 ` Johan Rydberg
2004-03-19 21:42 ` Marco Gerards
2004-03-19 21:56 ` Sergey Matveychuk
2004-03-19 22:22 ` Marco Gerards
2004-03-19 23:24 ` Sergey Matveychuk
2004-03-19 23:55 ` Marco Gerards
2004-03-20 0:45 ` Sergey Matveychuk
2004-03-20 10:29 ` Jeroen Dekkers
2004-03-20 18:30 ` Sergey Matveychuk
2004-03-20 19:43 ` Marco Gerards
2004-03-21 1:17 ` Sergey Matveychuk
2004-03-21 1:45 ` Marco Gerards
2004-03-21 2:18 ` Sergey Matveychuk
2004-03-21 3:30 ` Marco Gerards
2004-03-21 16:11 ` Yoshinori K. Okuji
2004-03-22 8:20 ` Sergey Matveychuk
2004-03-22 13:49 ` Yoshinori K. Okuji
2004-03-22 14:26 ` Jeroen Dekkers
2004-03-22 15:23 ` Yoshinori K. Okuji
2004-03-22 21:05 ` Sergey Matveychuk
2004-03-22 22:03 ` Sergey Matveychuk
2004-03-22 22:10 ` Sergey Matveychuk
2004-09-01 22:00 ` Marco Gerards
2004-09-02 10:50 ` Yoshinori K. Okuji
2004-09-05 9:26 ` Marco Gerards
2004-09-07 10:46 ` Yoshinori K. Okuji
2004-12-29 17:27 ` Marco Gerards
2005-01-11 13:32 ` Yoshinori K. Okuji
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.