Skip to contentSkip to conversation

stat for FreeBSD

DISCUSSION Andrey Shuvikov 3 participants 6 messages Dec 9, 2008 – Mar 12, 2009

lore
Share & tools
lore
#0 lore raw

Hello,

I tried to compile Grub2 under FreeBSD, it compiles but doesn't work (grub-setup). The problem seems to be in the stat() call, which is used to determine disk size. The call returns 0 for st_size, and grub-setup complains for "Read out of range". Is it a known issue? Is there a way to use Grub2 under FreeBSD?

Thank you,
Andrey

#1 lore raw
Quoted 3 lines · Andrey Shuvikov

Hello,

I tried to compile Grub2 under FreeBSD, it compiles but doesn't work (grub-setup). The problem seems to be in the stat() call, which is used to determine disk size. The call returns 0 for st_size, and grub-setup complains for "Read out of range". Is it a known issue? Is there a way to use Grub2 under FreeBSD?

Do you know how to obtain the disk size on FreeBSD ?

Signature · 5 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."
#2 lore raw
Quoted 7 lines · Robert Millan
Quoted 3 lines · Andrey Shuvikov

Hello,

I tried to compile Grub2 under FreeBSD, it compiles but doesn't work (grub-setup). The problem seems to be in the stat() call, which is used to determine disk size. The call returns 0 for st_size, and grub-setup complains for "Read out of range". Is it a known issue? Is there a way to use Grub2 under FreeBSD?

Do you know how to obtain the disk size on FreeBSD ?

IF parted works on FreeBSD, we could look at what it does, since it's a GNU project, copyrights assigned to the FSF and all that (isn't it?)

#3 lore raw
In reply to Robert Millan

I don't have much experience developing under FreeBSD but this call taken from the fdisk source code seems to work (see attachment also):

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

Thanks,
Andrey

Quoted 32 lines · Robert Millan

From: Robert Millan <[email protected]>
Subject: Re: stat for FreeBSD
To: "The development of GRUB 2" <[email protected]>
Date: Saturday, December 13, 2008, 8:12 PM

Quoted 3 lines · Andrey Shuvikov

Hello,

I tried to compile Grub2 under FreeBSD, it compiles

but doesn't work (grub-setup). The problem seems to be in the stat() call, which is used to determine disk size. The call returns 0 for st_size, and grub-setup complains for "Read out of range". Is it a known issue? Is there a way to use Grub2 under FreeBSD?

Do you know how to obtain the disk size on FreeBSD ?

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
#4 lore raw
Quoted 3 lines · Andrey Shuvikov

I don't have much experience developing under FreeBSD but this call taken from the fdisk source code seems to work (see attachment also):

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

This seems fine. Could you provide a tested patch?

Signature · 5 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."
#5 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 23 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 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.

Regards,
Andrey Shuvikov

grub/util/getroot.h (working copy) renamed from grub/util/getroot.h (revision 2028) +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 (working copy) renamed from grub-probe.c (revision 2028) +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 (working copy) renamed from getroot.c (revision 2028) +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 (working copy) renamed from hostdisk.c (revision 2028) +67 -1

112 lines not on this page · raw message