Code Comments
Programming Forum and web based access to our favorite programming groups.Hi, What would be the best way to check from a C program whether a certain directory is on a NFS mounted filesystem or on a local filesystem? (using Debian GNU/Linux, if it matters) Thanks in advance. Regards, Heiko
Post Follow-up to this messageOn Wed, 27 Apr 2005, it was written: > What would be the best way to check from a C program whether a certain > directory is on a NFS mounted filesystem or on a local filesystem? > (using Debian GNU/Linux, if it matters) Assuming that Linux supports it, the statvfs function is probably what you're after (see the f_basetype member). (I describe this in more detail in my book, Solaris Systems Programming.) HTH, -- Rich Teer, SCNA, SCSA, OpenSolaris CAB member President, Rite Online Inc. Voice: +1 (250) 979-1638 URL: http://www.rite-group.com/rich
Post Follow-up to this messageRich Teer wrote: > On Wed, 27 Apr 2005, it was written: > > > > Assuming that Linux supports it, the statvfs function is probably > what you're after (see the f_basetype member). On Debian struct statvfs does not have a member "f_basetype". However its man page refers to statfs(2). And struct statfs has a member f_type for the filesystem type. So your answer certainly got me on track. Thank you. This raises a next question: How can I get the IP-address of the server? /proc/mounts seems to contain that information. But is parsing /proc the only way (on Linux)? I'm trying to find the fastest and most reliable way, so I'd prefer some syscall? Could anyone help me with this? Thanks. Heiko
Post Follow-up to this messageHeiko <heiko.noordhof_A_xs4all.nl> wrote: >Rich Teer wrote: > > >On Debian struct statvfs does not have a member >"f_basetype". However its man page refers to statfs(2). And >struct statfs has a member f_type for the filesystem type. Linux provides a POSIX compliant statvfs(2), and POSIX does not define a member f_basetype. The f_fsid member (see the statfs(2) man page for values) will tell you if it is an NFS mounted fs or not. (From the man page it appears that this is not portable though.) See /usr/include/bits/statvfs.h for the values of f_flags, which relate to what options it is mounted with but don't indicate the type of the fs. >So your answer certainly got me on track. Thank you. > >This raises a next question: How can I get the IP-address of the server? >/proc/mounts seems to contain that information. But is parsing >/proc the only way (on Linux)? I'm trying to find the fastest >and most reliable way, so I'd prefer some syscall? It appears that it might be the easiest way, and possibly the fastest too. First you need to stat the target directory to determine which mounted filesystem it is part of, but once you have that information everything else is located in /proc/mounts, and it looks fairly easy to parse. If speed is a problem, perhaps you could open(2), read the entire contents with one call to read(2), and then close(2) it, thus making only three slow system calls. -- Floyd L. Davidson <http://web.newsguy.com/floyd_davidson> Ukpeagvik (Barrow, Alaska) floyd@barrow.com
Post Follow-up to this message# This raises a next question: How can I get the IP-address of the server? # /proc/mounts seems to contain that information. But is parsing /proc the # only way (on Linux)? I'm trying to find the fastest and most reliable # way, so I'd prefer some syscall? One the get* functions reads mtab or fstab. getmnt() or something like that. -- SM Ryan http://www.rawbw.com/~wyrmwif/ I hope it feels so good to be right. There's nothing more exhilirating pointing out the shortcomings of others, is there?
Post Follow-up to this messageRich Teer <rich.teer@rite-group.com> wrote: > On Wed, 27 Apr 2005, it was written: > Assuming that Linux supports it, the statvfs function is probably > what you're after (see the f_basetype member). (I describe this > in more detail in my book, Solaris Systems Programming.) a moment's thought should have served to answer the assumption (or google, if thought fails). Linux supports statvfs(), but f_basetype appears to be SVr4-specific, Linux documents its implementation as based on BSD (either conforms to X/Open). Regarding your book - no, there's no more information in that section - pages 439-440 - than is in Sun's manpage. (Providing more words is not the same as providing more detail). -- Thomas E. Dickey http://invisible-island.net ftp://invisible-island.net
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.