From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by monty-python.gnu.org with archive (Exim 4.30) id 1B4RU6-0006Ou-1x for mharc-grub-devel@gnu.org; Fri, 19 Mar 2004 16:24:54 -0500 Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.30) id 1B4RU2-0006Np-PH for grub-devel@gnu.org; Fri, 19 Mar 2004 16:24:50 -0500 Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.30) id 1B4RTW-0006HY-AX for grub-devel@gnu.org; Fri, 19 Mar 2004 16:24:49 -0500 Received: from [213.147.57.66] (helo=mail.ciam.ru) by monty-python.gnu.org with esmtp (TLSv1:DES-CBC3-SHA:168) (Exim 4.30) id 1B4RTV-0006F9-DK for grub-devel@gnu.org; Fri, 19 Mar 2004 16:24:17 -0500 Received: from ppp8-107.pppoe.mtu-net.ru ([81.195.8.107] helo=ciam.ru) by mail.ciam.ru with esmtp (Exim 4.x) id 1B4RTI-000D59-Ud for grub-devel@gnu.org; Sat, 20 Mar 2004 00:24:05 +0300 Message-ID: <405B64FB.4020109@ciam.ru> Date: Sat, 20 Mar 2004 00:24:11 +0300 From: Sergey Matveychuk User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6) Gecko/20040113 X-Accept-Language: en-us, en MIME-Version: 1.0 To: The development of GRUB 2 References: <40595AA3.6000800@ciam.ru> <200403181331.51694.okuji@enbug.org> In-Reply-To: <200403181331.51694.okuji@enbug.org> Content-Type: multipart/mixed; boundary="------------040008060505070703090107" X-Spam-Score: 2.6 (++) Subject: Re: GRUB2: *BSD and more patch X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.4 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 19 Mar 2004 21:24:51 -0000 This is a multi-part message in MIME format. --------------040008060505070703090107 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit 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. --------------040008060505070703090107 Content-Type: text/plain; name="grub2-bsd.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="grub2-bsd.patch" 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 + + * 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 * 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 header file. */ #undef HAVE_MEMORY_H +/* Define to 1 if you have the header file. */ +#undef HAVE_MALLOC_H + /* Define to 1 if you have the 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 #include +#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) +# include /* ioctl */ +# include +# if defined(__FreeBSD__) +# include +# if __FreeBSD_version >= 500040 +# include +# endif +# endif +#endif /* __FreeBSD__ || __NetBSD__ || __OpenBSD__ */ + #ifdef __linux__ # include /* 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 #include #include #include @@ -24,7 +25,9 @@ #include #include #include +#if HAVE_MALLOC_H #include +#endif #include #include @@ -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 +#if !defined(__FreeBSD__) #include +#endif #include #include #include @@ -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 (); --------------040008060505070703090107--