* grub-probe && statfs(2)
@ 2007-12-29 12:36 Francis Gendreau
2007-12-30 12:38 ` Yoshinori K. Okuji
0 siblings, 1 reply; 3+ messages in thread
From: Francis Gendreau @ 2007-12-29 12:36 UTC (permalink / raw)
To: grub-devel
[-- Attachment #1: Type: text/plain, Size: 3236 bytes --]
Hello everyone,
I'd like to know if someone here conceived using the statfs() system
call in find_root_device() (or grub_guess_root_device()) instead of
doing a linear look-up into the /dev directory.
My concern here is, that on FreeBSD system using devfs or not, the
approach employed by find_root_device() of getting the dev_t from struct
stat st_dev is not functional. The reason is simple, the function assume
that the st_dev value would be identical for an inode of a particular
device and for the device entry of /dev.
I wrote a short program (in attachment), that provided me the proof of
what I am reporting below.
FreeBSD-4.11 > ./test $HOME /dev/ad0s1f /tmp /dev/ad0s1h / /dev/ad0s1a
$HOME : dev_t=160773, mntfrom="/dev/ad0s1f", mnton="/home"
/dev/ad0s1f : dev_t=160768, mntfrom="/dev/ad0s1a", mnton="/"
/tmp : dev_t=160775, mntfrom="/dev/ad0s1h", mnton="/tmp"
/dev/ad0s1h : dev_t=160768, mntfrom="/dev/ad0s1a", mnton="/"
/ : dev_t=160768, mntfrom="/dev/ad0s1a", mnton="/"
/dev/ad0s1a : dev_t=160768, mntfrom="/dev/ad0s1a", mnton="/"
Freebsd-6.2_devfs> ./test . /dev/ad4s1h /tmp /dev/ad4s1e / /dev/ad4s1a /dev /mnt
. : dev_t=117, mntfrom="/dev/ad4s1h", mnton="/home"
/dev/ad4s1h : dev_t=16842496, mntfrom="devfs", mnton="/dev"
/tmp : dev_t=114, mntfrom="/dev/ad4s1e", mnton="/tmp"
/dev/ad4s1e : dev_t=16842496, mntfrom="devfs", mnton="/dev"
/ : dev_t=110, mntfrom="/dev/ad4s1a", mnton="/"
/dev/ad4s1a : dev_t=16842496, mntfrom="devfs", mnton="/dev"
/dev : dev_t=16842496, mntfrom="devfs", mnton="/dev"
/mnt : dev_t=138, mntfrom="/dev/ad0s1a", mnton="/mnt"
OpenBSD-3.2 > ./test . /dev/wd0a /mnt/cdrom/I386 /dev/cd0a
. : dev_t=0, mntfrom="/dev/wd0a", mnton="/"
/dev/wd0a : dev_t=0, mntfrom="/dev/wd0a", mnton="/"
/mnt/cdrom/I386 : dev_t=768, mntfrom="/dev/cd0a", mnton="/mnt/cdrom"
/dev/cd0a : dev_t=0, mntfrom="/dev/wd0a", mnton="/"
Speculating, it seems there is a difference between 44BSD (?) and Linux
in the assigned value of st_dev. While Linux seems to set the same value
for the inodes on the device and the device entry in /dev, BSDs tends to
treat entries in /dev as inodes of the device there are stored on.
My recommendation would be relatively simple. grub_guess_root_device()
could simply call statfs() and extract the device name from struct
statfs f_mntfromname, maybe as simply as the following, but I may lack
of knowledge about some technologies on which this might not work (like
RAID ...).
size_t strnlen (const char *s, size_t max)
{
size_t l = 0;
if ( s )
for (; l < max && *s ; ++l );
return l;
}
char *
grub_guess_root_device (const char *path)
{
char *ret = NULL;
struct statfs sfsb;
if ( statfs (path, &sfsb) )
{
ret = xmalloc (strnlen (sfsb.f_mntfromname, MNAMELEN));
if ( ret )
strncpy (ret, sfsb.f_mntfromname, MNAMELEN);
else
{
perror ("Root device string allocation failed!");
exit (ENOMEM);
}
}
else
{
grub_util_error ("unable to stat `%s'", path);
}
return ret;
}
I would like to know what you guys think about this.
Francis Gendreau
[-- Attachment #2: stat_vs_statfs.c --]
[-- Type: text/x-csrc, Size: 775 bytes --]
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <sys/mount.h>
void do_stat( const char *path);
int main( int argc, char **argv)
{
int i;
if ( argc > 1 )
for ( i = 1; i < argc; ++i)
do_stat( argv[i]);
else
printf( "usage: %s <path> [<path> ...]\n", argv[0]);
return 0;
}
void do_stat( const char *path)
{
struct stat sb;
struct statfs sfsb;
if ( !stat( path, &sb) )
{
if ( !statfs( path, &sfsb) )
{
printf(
"%s: dev_t=%d, mntfrom=\"%s\", mnton=\"%s\"\n",
path,
sb.st_dev,
sfsb.f_mntfromname,
sfsb.f_mntonname
);
return;
}
printf( "cannot statfs() %s\n", path); // should never print
}
printf( "cannot stat() %s\n", path);
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: grub-probe && statfs(2)
2007-12-29 12:36 grub-probe && statfs(2) Francis Gendreau
@ 2007-12-30 12:38 ` Yoshinori K. Okuji
2008-01-01 10:12 ` Francis Gendreau
0 siblings, 1 reply; 3+ messages in thread
From: Yoshinori K. Okuji @ 2007-12-30 12:38 UTC (permalink / raw)
To: The development of GRUB 2
Hello,
On Saturday 29 December 2007 13:36, Francis Gendreau wrote:
> My recommendation would be relatively simple. grub_guess_root_device()
> could simply call statfs() and extract the device name from struct
> statfs f_mntfromname, maybe as simply as the following, but I may lack
> of knowledge about some technologies on which this might not work (like
> RAID ...).
Unfortunately, statfs in Linux does not return a filename. From statfs(2):
The Linux statfs was inspired by the 4.4BSD one (but they do not use
the same structure).
In fact, struct statfs does not contain f_mntfromname or anything equivallent
on Linux.
So I think it would be necessary to use statfs, only on *BSD (or if struct
statfs contains f_mntfromname).
Thanks,
Okuji
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: grub-probe && statfs(2)
2007-12-30 12:38 ` Yoshinori K. Okuji
@ 2008-01-01 10:12 ` Francis Gendreau
0 siblings, 0 replies; 3+ messages in thread
From: Francis Gendreau @ 2008-01-01 10:12 UTC (permalink / raw)
To: The development of GRUB 2
On Sun, 2007-12-30 at 13:38 +0100, Yoshinori K. Okuji wrote:
> Hello,
>
> On Saturday 29 December 2007 13:36, Francis Gendreau wrote:
> > My recommendation would be relatively simple. grub_guess_root_device()
> > could simply call statfs() and extract the device name from struct
> > statfs f_mntfromname, maybe as simply as the following, but I may lack
> > of knowledge about some technologies on which this might not work (like
> > RAID ...).
>
> Unfortunately, statfs in Linux does not return a filename. From statfs(2):
>
> The Linux statfs was inspired by the 4.4BSD one (but they do not use
> the same structure).
>
> In fact, struct statfs does not contain f_mntfromname or anything equivallent
> on Linux.
>
> So I think it would be necessary to use statfs, only on *BSD (or if struct
> statfs contains f_mntfromname).
>
> Thanks,
> Okuji
>
Well, after some googling, which I should have done before submitting, I
saw that Linux does not contain any informations required for the
operation. OpenBSD and FreeBSD does, but NetBSD do not offer this system
call.
I already wrote a patch for FreeBSD but lots of other errors makes it
almost useless. I'm currently tring to elaborate the necessary
alterations to the source so grub2 can be installed from a FreeBSD
system.
Francis Gendreau
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-01-01 10:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-29 12:36 grub-probe && statfs(2) Francis Gendreau
2007-12-30 12:38 ` Yoshinori K. Okuji
2008-01-01 10:12 ` Francis Gendreau
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.