Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

How to check if dir is NFS mounted?
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

Report this thread to moderator Post Follow-up to this message
Old Post
Heiko
04-27-05 08:59 PM


Re: How to check if dir is NFS mounted?
On 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

Report this thread to moderator Post Follow-up to this message
Old Post
Rich Teer
04-27-05 08:59 PM


Re: How to check if dir is NFS mounted?
Rich 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

Report this thread to moderator Post Follow-up to this message
Old Post
Heiko
04-27-05 08:59 PM


Re: How to check if dir is NFS mounted?
Heiko <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

Report this thread to moderator Post Follow-up to this message
Old Post
Floyd L. Davidson
04-27-05 08:59 PM


Re: How to check if dir is NFS mounted?
# 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?

Report this thread to moderator Post Follow-up to this message
Old Post
SM Ryan
04-27-05 08:59 PM


Re: How to check if dir is NFS mounted?
Rich 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

Report this thread to moderator Post Follow-up to this message
Old Post
Thomas Dickey
04-27-05 08:59 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Unix Programming archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:34 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.