From: Sergey Matveychuk <sem@ciam.ru>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: Re: GRUB2: *BSD and more patch
Date: Tue, 23 Mar 2004 01:10:10 +0300 [thread overview]
Message-ID: <405F6442.2070402@ciam.ru> (raw)
In-Reply-To: <200403221449.41600.okuji@enbug.org>
[-- 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 ();
next prev parent reply other threads:[~2004-03-22 22:24 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=405F6442.2070402@ciam.ru \
--to=sem@ciam.ru \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.