Skip to contentSkip to conversation

stat for FreeBSD

DISCUSSION Andrey Shuvikov 2 participants 2 messages Apr 6, 2009 – Apr 7, 2009

lore
Share & tools
lore
#0 lore raw
Quoted 6 lines · Robert Millan

From: Robert Millan <[email protected]>
Subject: Re: stat for FreeBSD
To: "The development of GRUB 2" <[email protected]>
Date: Saturday, February 7, 2009, 2:39 PM
On Mon, Dec 15, 2008 at 09:24:41AM
-0800, Andrey Shuvikov wrote:

Quoted 24 lines
Quoted 1 line

I don't have much experience developing under FreeBSD

but this call taken from the fdisk source code seems to work (see attachment also):

Quoted 2 lines

error = ioctl(fd, DIOCGMEDIASIZE, &size);

This seems fine.  Could you provide a tested patch?

Signature · 14 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We
will decide when (and
  how) you may access your data; but nobody's
threatening your freedom: we
  still allow you to remove your data and not access
it at all."


_______________________________________________
Grub-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/grub-devel

Here is the patch against the latest revision to make grub-probe working on FreeBSD. It includes this ioctl call, FreeBSD device names parsing, and accounts for the fact that disk drives are character devices under FreeBSD. Below is the reply from FSF:

======================================================================
Hello Andrey,

Your GRUB2 assignment/disclaimer process with the FSF is currently complete; your fully executed PDF will be sent to you in a separate email immediately following this one.

Please remember to let us know when your employment status changes, as this may effect your assignment status.

Thank you for your contribution!

All the best,

Donald R. Robertson, III, J.D.
Assignment Administrator
Free Software Foundation
51 Franklin Street, Fifth Floor
Boston, MA 02110
Phone +1-617-542-5942
Fax +1-617-542-2652

cc - maintainer
_______________________________________________________________________
INFORMATION FOR THE MAINTAINER(S)

Here's how the contributor answered the question, “ Did you copy any files or text written by someone else in these changes?”

Copied some lines from the same project, then modified.

[Which files have you changed so far, and which new files have you written so far?]

include/grub/util/getroot.h
util/grub-probe.c
util/getroot.c
util/hostdisk.c
======================================================================

Regards,
Andrey Shuvikov

grub/util/getroot.h +1 -0
Index: include/grub/util/getroot.h
===================================================================
@@ -30,5 +30,6 @@
 int grub_util_get_dev_abstraction (const char *os_dev);
 char *grub_util_get_grub_dev (const char *os_dev);
 const char *grub_util_check_block_device (const char *blk_dev);
+const char *grub_util_check_char_device (const char *blk_dev);
 
 #endif /* ! GRUB_UTIL_GETROOT_HEADER */
grub-probe.c +5 -0
Index: util/grub-probe.c
===================================================================
@@ -112,8 +112,13 @@
   
   if (path == NULL)
     {
+#if defined(__FreeBSD__)
+      if (! grub_util_check_char_device (device_name))
+        grub_util_error ("%s is not a character device.\n", device_name);
+#else
       if (! grub_util_check_block_device (device_name))
         grub_util_error ("%s is not a block device.\n", device_name);
+#endif
     }
   else
     device_name = grub_guess_root_device (path);
getroot.c +19 -0
Index: util/getroot.c
===================================================================
@@ -238,7 +238,11 @@
 	    }
 	}
 
+#ifdef __FreeBSD__ 
+      if (S_ISCHR (st.st_mode) && st.st_rdev == dev)
+#else
       if (S_ISBLK (st.st_mode) && st.st_rdev == dev)
+#endif
 	{
 #ifdef __linux__
 	  /* Skip device names like /dev/dm-0, which are short-hand aliases
@@ -519,3 +523,18 @@
   else
     return 0;
 }
+
+const char *
+grub_util_check_char_device (const char *blk_dev)
+{
+  struct stat st;
+
+  if (stat (blk_dev, &st) < 0)
+    grub_util_error ("Cannot stat `%s'", blk_dev);
+
+  if (S_ISCHR (st.st_mode))
+    return (blk_dev);
+  else
+    return 0;
+}
+
hostdisk.c +67 -1

112 lines not on this page · raw message

#1 lore raw
Quoted 3 lines · On Tuesday 07 April 2009 00:48:37 Andrey Shuvikov wrote:

Here is the patch against the latest revision to make grub-probe working on FreeBSD. It includes this ioctl call, FreeBSD device names parsing, and accounts for the fact that disk drives are character devices under FreeBSD.

Do you have an account on Savannah? I can have you to check it in yourself. ;)

Regards,
Okuji