All of lore.kernel.org
 help / color / mirror / Atom feed
* 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

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.