From: Andrey Shuvikov <mr_hyro@yahoo.com>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: Re: stat for FreeBSD
Date: Mon, 6 Apr 2009 08:48:37 -0700 (PDT) [thread overview]
Message-ID: <968853.48080.qm@web42104.mail.mud.yahoo.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 2483 bytes --]
--- On Sat, 2/7/09, Robert Millan <rmh@aybabtu.com> wrote:
> From: Robert Millan <rmh@aybabtu.com>
> Subject: Re: stat for FreeBSD
> To: "The development of GRUB 2" <grub-devel@gnu.org>
> Date: Saturday, February 7, 2009, 2:39 PM
> On Mon, Dec 15, 2008 at 09:24:41AM
> -0800, Andrey Shuvikov wrote:
> > 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?
>
> --
> 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
> Grub-devel@gnu.org
> 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
[-- Attachment #2: grub_probe_freebsd.patch --]
[-- Type: application/octet-stream, Size: 4775 bytes --]
Index: include/grub/util/getroot.h
===================================================================
--- include/grub/util/getroot.h (revision 2068)
+++ include/grub/util/getroot.h (working copy)
@@ -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 */
Index: util/grub-probe.c
===================================================================
--- util/grub-probe.c (revision 2068)
+++ util/grub-probe.c (working copy)
@@ -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);
Index: util/getroot.c
===================================================================
--- util/getroot.c (revision 2068)
+++ util/getroot.c (working copy)
@@ -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;
+}
+
Index: util/hostdisk.c
===================================================================
--- util/hostdisk.c (revision 2068)
+++ util/hostdisk.c (working copy)
@@ -86,6 +86,10 @@
# define FLOPPY_MAJOR 2
#endif
+#ifdef __FreeBSD__
+# include <sys/disk.h> /* DIOCGMEDIASIZE */
+#endif
+
struct
{
char *drive;
@@ -179,7 +183,7 @@
return GRUB_ERR_NONE;
}
-#elif defined(__linux__) || defined(__CYGWIN__)
+#elif defined(__linux__) || defined(__CYGWIN__) || defined(__FreeBSD__)
{
unsigned long long nr;
int fd;
@@ -188,13 +192,21 @@
if (fd == -1)
return grub_error (GRUB_ERR_BAD_DEVICE, "cannot open `%s' while attempting to get disk size", map[drive].device);
+#if defined(__FreeBSD__)
+ if (fstat (fd, &st) < 0 || ! S_ISCHR (st.st_mode))
+#else
if (fstat (fd, &st) < 0 || ! S_ISBLK (st.st_mode))
+#endif
{
close (fd);
goto fail;
}
+#if defined(__FreeBSD__)
+ if (ioctl (fd, DIOCGMEDIASIZE, &nr))
+#else
if (ioctl (fd, BLKGETSIZE64, &nr))
+#endif
{
close (fd);
goto fail;
@@ -746,6 +758,22 @@
path[8] = 0;
return path;
+#elif defined(__FreeBSD__)
+ char *path = xstrdup (os_dev);
+ if (strncmp ("/dev/", path, 5) == 0)
+ {
+ char *p;
+ for (p = path + 5; *p; ++p)
+ if (grub_isdigit(*p))
+ {
+ p = strchr (p, 's');
+ if (p)
+ *p = '\0';
+ break;
+ }
+ }
+ return path;
+
#else
# warning "The function `convert_system_partition_to_system_disk' might not work on your OS correctly."
return xstrdup (os_dev);
@@ -793,7 +821,11 @@
return 0;
}
+#if defined(__FreeBSD__)
+ if (! S_ISCHR (st.st_mode))
+#else
if (! S_ISBLK (st.st_mode))
+#endif
return make_device_name (drive, -1, -1);
#if defined(__linux__) || defined(__CYGWIN__)
@@ -938,6 +970,40 @@
return make_device_name (drive, dos_part, bsd_part);
}
+#elif defined(__FreeBSD__)
+ /* FreeBSD uses "/dev/[a-z]+[0-9]+(s[0-9]+[a-z]?)?". */
+ {
+ int dos_part = -1;
+ int bsd_part = -1;
+
+ if (strncmp ("/dev/", os_dev, 5) == 0)
+ {
+ char *p, *q;
+ long int n;
+
+ for (p = os_dev + 5; *p; ++p)
+ if (grub_isdigit(*p))
+ {
+ p = strchr (p, 's');
+ if (p)
+ {
+ p++;
+ n = strtol (p, &q, 10);
+ if (p != q && n != LONG_MIN && n != LONG_MAX)
+ {
+ dos_part = (int) n - 1;
+
+ if (*q >= 'a' && *q <= 'g')
+ bsd_part = *q - 'a';
+ }
+ }
+ break;
+ }
+ }
+
+ return make_device_name (drive, dos_part, bsd_part);
+ }
+
#else
# warning "The function `grub_util_biosdisk_get_grub_dev' might not work on your OS correctly."
return make_device_name (drive, -1, -1);
next reply other threads:[~2009-04-06 15:49 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-06 15:48 Andrey Shuvikov [this message]
2009-04-07 0:35 ` stat for FreeBSD Yoshinori K. Okuji
-- strict thread matches above, loose matches on Subject: below --
2009-04-10 3:51 Andrey Shuvikov
2009-04-10 7:34 ` Felix Zielcke
2009-04-08 14:32 Andrey Shuvikov
2009-04-09 23:31 ` Yoshinori K. Okuji
2008-12-09 23:26 Andrey Shuvikov
2008-12-14 1:12 ` Robert Millan
2008-12-14 14:26 ` Javier Martín
2008-12-15 17:24 ` Andrey Shuvikov
2009-02-07 19:39 ` Robert Millan
2009-03-12 16:24 ` Andrey Shuvikov
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=968853.48080.qm@web42104.mail.mud.yahoo.com \
--to=mr_hyro@yahoo.com \
--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.