Sorry about statbug!; try this: ustatbug.c: Spot BUG with NFS ustat()

Greyham Stoney greyham at hades.OZ
Wed Mar 14 00:46:53 AEST 1990


My previous posting pointing out what I thought was a bug in stat() over NFS
was *WRONG*. It's quite legal for stat() to return a negative number. What's
NOT legal is for ustat() to give incorrect info about the filesystem specified
by that number. The program below tests this. This time for sure. :-)

Sorry about that. Please try this one instead.

SYSTEM:	ISC 386/ix 2.0.2 NFS

PROBLEM: ustat() library function doesn't fill the ustat structure in for
	NFS mounted filesystems.

SYMPTOM: I noticed it because /bin/ed fails every second attempt to write an
	NFS mounted file.

TEST:	The program below (ustatbug.c), when run with a single filename argument
 	will see if the f_tfree member of the ustat info returned by ustat() is
	changed by ustat().

	The file specified must exist (for stat() to work) and be on an NFS
	mounted filesystem (for the bug to be exercised). The file is not
	affected in any way, and it can be a directory name too.

	On my system the output looks like this:

		% ustatbug /usr3/ugh
		file /usr3/ugh is on device -767, which reports:
			-1 blocks free
			65535 inodes free
			filesys name 'FAIL!'
			filesys pack name 'FAIL!'
		*** Looks Like you've got the ustat bug!!! ***

	But for a non-NFS mounted filesytem, it looks like this:

		% ustatbug /usr4/blub
		file /usr4/blub is on device 4, which reports:
			21804 blocks free
			21606 inodes free
			filesys name 'usr4'
			filesys pack name '1'
		No problem with your ustat()!

Please tell me if your system fails this test.

								Greyham.
------------------------------cut-here----------------------------------------
/* ustatbug - see if there is a ustat bug in your NFS.
 *
 * usage: ustatbug path-to-any-nfs-mounted-file
 *
 * Problem: ustat seems to not fill in the ustat return structure for NFS
 * mounted filesystems on ISC 386/ix. Run this program with the argument being
 * any NFS mounted file (The file will not be affected in any way) and see if
 * ustat doesn't change the -1 for blocks free (f_tfree).
 */
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ustat.h>

main(argc,argv)
int argc;
char *argv[];
{
	struct stat stat_buf;
	struct ustat ustat_buf;

	/* check arg */
	if (argc != 2)
	{
		printf("usage: ustatbug path-to-any-nfs-mounted-file\n");
		return 2;
	}

	/* find what fs the file is on */
	if (stat(argv[1],&stat_buf))
	{
		printf("can't stat %s - probably doesn't exist!\n",argv[1]);
		return 2;
	}

	/* set rediculous values to see if they get clobbered */
	ustat_buf.f_tinode = -1;
	ustat_buf.f_tfree = -1;
	strcpy(ustat_buf.f_fname,"FAIL!");
	strcpy(ustat_buf.f_fpack,"FAIL!");

	/* get info about the filesystem */
	if (ustat(stat_buf.st_dev,&ustat_buf))
	{
		printf("can't ustat device %d - something wrong!\n",
							stat_buf.st_dev);
		return 2;
	}

	/* now check what's free on the filesystem */
	printf("file %s is on device %d, which reports:\n",
						argv[1],stat_buf.st_dev);

	printf("\t%d blocks free\n\t%d inodes free\n\tfilesys name '%.6s'\n",
		ustat_buf.f_tfree,ustat_buf.f_tinode,ustat_buf.f_fname);

	printf("\tfilesys pack name '%.6s'\n",ustat_buf.f_fpack);

	/* see if ustat actually filled in the structure */
	if (ustat_buf.f_tfree == -1)
	{
		printf("*** Looks Like you've got the ustat bug!!! ***\n");
		return 1;
	}

	printf("No problem with your ustat()!\n");

	return 0;
}
-- 
/*  Greyham Stoney:                            Australia: (02) 428 6476  *
 *     greyham at hades.oz  - Ausonics Pty Ltd, Lane Cove, Sydney, Oz.      *
 * "Beware! Grid Bugs!"  \ Quotes from the Ultimate Video Experience...  *
 * "Nice Try, Timelord!" / Can you identify it? Win absolutely nothing!  */



More information about the Comp.unix.i386 mailing list