meissner@osf.org (Michael Meissner) (06/27/90)
In article <103399@convex.convex.com> thurlow@convex.com (Robert Thurlow) writes: | pjb@tcom.stc.co.uk (Peter J. Bishop) writes: | | >The program is running on an Ultrix machine and performs a stat on a file, and | >returns relevant information about that file. Unfortunately I cannot find a way | >to return the NFS mount information if the file resides on an NFS mounted | >partition. | | I'm assuming you want to know the hostname and the path on the remote | machine. It's a little ugly, half because you're asking the system to | tell you things that are 'transparent' and part because NFS isn't fully | designed into BSD, but is more of an add-on. We had an internal program | here that was to print out the host, filesystem and directory info on | each file it used. My advice at the time was this: | | --- | I think I'd want to do something like this: | | 1) Call statfs(filename) to get info about the filesystem the file | is on, and see if it's an NFS-mounted file. If not, you might | need to strip symlinks out of it for best results (see below). | 2) Find out the best path without '.', '..' or symbolic links. | A new routine called realpath(3) is in SunOS 4.0's libc; you | could also chdir(2) to the immediate parent and do a getwd(2). | 3) Scan through /etc/mtab with the getmntent(3) routines looking for | the mount point that has the most characters in common with the | real filename. You'll have the hostname and remote pathname. | 4) Append the non-matching characters in the filename to the remote | pathname. If all you need is the hostname and mount point, statfs tells you that information. Points 2-4 seem to be overkill. On Ultrix at least, statfs returns the following: fd_flags /* how mounted */ fd_mtsize /* max transfer size */ fd_otsize /* optimal transfer size */ fd_bsize /* fs block size for vm code */ fd_fstype /* see ../h/fs_types.h */ fd_gtot /* total number of gnodes */ fd_gfree /* # of free gnodes */ fd_btot /* total number of blocks */ fd_bfree /* # of free blocks */ fd_bfreen /* user consumable blocks */ fd_pgthresh /* min file size before paging*/ fd_uid /* uid that mounted me */ fd_dev /* major/minor of fs */ fd_exroot /* root mapping from exports */ fd_devname /* name of dev */ fd_path /* name of mount point */ The flags tell you whether the file is local or remote, and if remote fd_devname is the normal hostname:remote-disk. -- Michael Meissner email: meissner@osf.org phone: 617-621-8861 Open Software Foundation, 11 Cambridge Center, Cambridge, MA Do apple growers tell their kids money doesn't grow on bushes?