Subject: Re: Determining if a file is on a local or r
To: None <>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-kern
Date: 07/16/1997 09:53:58
> We want to be able to determine whether a file is on a local or
> remote (NFS) system.

On NetBSD this is not really possible.  Imagine a union mount with ffs
front layer and nfs back layer - whether any particular file is remote
depends on which layer it resides in, which is not information exported
to users of the filesystem, and indeed can change dynamically.

That said, you could use statfs()/fstatfs() and check for the MNT_LOCAL
bit in f_flags.  (Reading manpages and header files makes it look as
though this will work, though admittedly I have not actually tried it.)

> But there does seem to be an easier way using stat(2)'s st_dev field.

> According to the Solaris documentation, st_dev should be NODEV (=
> (dev_t)(-1)) on a remote filesystem.  AIX seems to agree.  The only
> problem is that this isn't true.

So, I guess the documentation lies.  Is anyone surprised?

> But what does seem to be consistent is that if st_dev is treated as a
> signed number, then it will be a negative number for remote
> filesystems (the highest bit is set).  This holds on Solaris, AIX,
> HPUX... But I don't have any other systems here to test it on.

This is not true on an SGI machine I just checked it on; there, my home
directory (which is NFS-mounted) stats as major 34 minor 6.  I'm not
sure about NetBSD; based on a quick look at the code, I think the
st_dev field will ultimately come from getnewfsid(), in
kern/vfs_subr.c, which appears to assign major numbers based on a hash
of the filesystem name (makefstype(), as pased as the second arg to
getnewfsid() in mountnfs(), nfs/nfs_vfsops.c.  This means that it
depends on the hash makefstype() happens to produce for "nfs", which I
don't feel like working out.

					der Mouse

		     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B