NFS File identity resolution?

Hulk Hogan root at lingua.cltr.uq.OZ.AU
Thu Mar 21 09:49:51 AEST 1991


prakash at fyrpwr.enet.dec.com (Mayank Prakash) writes:
>In article <7169 at idunno.Princeton.EDU>, subbarao at phoenix.Princeton.EDU (Kartik Subbarao) writes:
>|-> You can stat() both files, and compare the inodes and see if they're the
>|-> same. This would only be a problem, I would guess, if the two files had the
>|-> exact same inode number but in fact came from two different disks. Of
>That is the problem I am trying to solve.
>|-> course, you could do a simple popen() to df, chop out the right field, and 
>|-> make sure that they're the same. This would confirm that they were mounted

>This would almost work, except that df truncates the name of the source
>file, and it needs an extra process spawn. Perhaps I should rather ask
>how does df work, instead?

How about using the statfs(2) call?  An extract from the manual follows.

|#include <sys/vfs.h>
|int statfs(path, buf)
|char *path;
|struct statfs *buf;
|
|int fstatfs(fd, buf)
|int fd;
|struct statfs *buf;
|
|statfs() returns information about a  mounted  file  system.
|path  is  the  path  name  of  any  file  within the mounted
|filesystem.  buf  is  a  pointer  to  a  statfs()  structure
|defined as follows:
|
|     typedef struct {
|            long    val[2];
|     } fsid_t;
|     struct statfs {
|            long    f_type;     /* type of info, zero for now */
|            long    f_bsize;    /* fundamental file system block size */
|            long    f_blocks;   /* total blocks in file system */
|            long    f_bfree;    /* free blocks */
|            long    f_bavail;   /* free blocks available to non-super-user
|*/
|            long    f_files;    /* total file nodes in file system */
|            long    f_ffree;    /* free file nodes in fs */
|            fsid_t  f_fsid;     /* file system id */
|            long    f_spare[7]; /* spare for later */
|     };

Disclaimer: I haven't done this. However I guess that each file system
has a unique id, and that this is returned f_fsid field.  If so, then 
this could be used to tell if the two files are on the same filesystem
without the need to parse /etc/fstab. Then it's just a matter for stat().

/\ndy
-- 
Andrew M. Jones,  Systems Programmer, 	Internet: andy at lingua.cltr.uq.oz.au
Centre for Lang. Teaching & Research, 	UUCP: uunet!lingua.cltr.uq.oz.au!andy
University of Queensland,  St. Lucia, 	Phone: +61  7 365 6915 (Use 07 in Oz)
Brisbane,  Qld. AUSTRALIA  4072    	Fax: +61 7 365 7077    IRC: HulkHogan

"No matter what hits the fan, it's never distributed evenly....."



More information about the Comp.unix.shell mailing list