suspicious behavior of lseek() on NFS files

Ed Vielmetti emv at ox.com
Thu Feb 21 09:29:04 AEST 1991


There's a way to determinine the current position and size of a
file that goes like this:

	curpos = lseek(fd, 0, SEEK_CUR);
	filesize = lseek(fd, 0, SEEK_END);
	if (lseek(fd,curpos,SEEK_SET) != 0) {
	    /* complain bitterly about this and all errors */
	} ;

and you're back to where you came from.  This shouldn't have any side
effects, or should it?

What I'm seeing (Ultrix 4.1, Dec 3100) is that NFS mounted files
sometimes read back nulls at the end of a growing file when the size
is determined this way.  Almost as the the lseek(fd,0,SEEK_END) was
zero-filling some cache somewhere with the wrong thing.  Note that on
"real" unix filesystems this works just fine (45 mb/day read this way).

A possible solution is to run it something like this (not tested)
	
	curpos = lseek(fd, 0, SEEK_CUR);
	if (fstat(fd, stbuf) == 0) {
	    filesize = stbuf.st_size;
	} else {
	    /* complain bitterly about this and all errors */
	} ;

I'd be interested in knowing what exactly goes over the wire for an
NFS fstat() call as opposed to the lseek() call; questions of
efficiency show up since this is going to be happening quite a few
times a minute.

--Ed

Edward Vielmetti
emv at ox.com

(this has been called into Ultrix support, #A 910 220-2454)



More information about the Comp.unix.ultrix mailing list