Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1J8avt-00067s-RI for mharc-grub-devel@gnu.org; Sat, 29 Dec 2007 07:36:53 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1J8avr-00067J-NN for grub-devel@gnu.org; Sat, 29 Dec 2007 07:36:51 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1J8avp-00066T-61 for grub-devel@gnu.org; Sat, 29 Dec 2007 07:36:51 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1J8avo-00066Q-Ti for grub-devel@gnu.org; Sat, 29 Dec 2007 07:36:48 -0500 Received: from relais.videotron.ca ([24.201.245.36]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1J8avo-0002U2-NS for grub-devel@gnu.org; Sat, 29 Dec 2007 07:36:48 -0500 MIME-version: 1.0 Content-type: multipart/mixed; boundary="Boundary_(ID_taeoXj0u1oTBicHDws427A)" Received: from [192.168.0.2] ([66.130.161.69]) by VL-MH-MR002.ip.videotron.ca (Sun Java(tm) System Messaging Server 6.3-4.01 (built Aug 3 2007; 32bit)) with ESMTP id <0JTT005VJ9PBPN10@VL-MH-MR002.ip.videotron.ca> for grub-devel@gnu.org; Sat, 29 Dec 2007 07:36:47 -0500 (EST) From: Francis Gendreau To: grub-devel@gnu.org Date: Sat, 29 Dec 2007 07:36:46 -0500 Message-id: <1198931806.11143.65.camel@latsun.main.fg> X-Mailer: Evolution 2.8.1.1 FreeBSD GNOME Team Port X-detected-kernel: by monty-python.gnu.org: Solaris 10 (beta) Subject: grub-probe && statfs(2) X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 29 Dec 2007 12:36:52 -0000 --Boundary_(ID_taeoXj0u1oTBicHDws427A) Content-type: text/plain; CHARSET=US-ASCII Content-transfer-encoding: 7BIT 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 --Boundary_(ID_taeoXj0u1oTBicHDws427A) Content-type: text/x-csrc; name=stat_vs_statfs.c; charset=us-ascii Content-transfer-encoding: 7BIT Content-disposition: attachment; filename=stat_vs_statfs.c #include #include #include #include #include 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 [ ...]\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); } --Boundary_(ID_taeoXj0u1oTBicHDws427A)--