Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!batcomputer!munnari.oz.au!brolga!lingua.cltr.uq.OZ.AU!root From: root@lingua.cltr.uq.OZ.AU (Hulk Hogan) Newsgroups: comp.unix.shell Subject: Re: NFS File identity resolution? Message-ID: <1991Mar20.234951.29055@lingua.cltr.uq.OZ.AU> Date: 20 Mar 91 23:49:51 GMT References: <21078@shlump.nac.dec.com> <7169@idunno.Princeton.EDU> <21155@shlump.nac.dec.com> Organization: Centre for Language Teaching and Research, Uni of Queensland, AUSTRALIA. Lines: 58 prakash@fyrpwr.enet.dec.com (Mayank Prakash) writes: >In article <7169@idunno.Princeton.EDU>, subbarao@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 |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@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....."