finding NFS dirs in csh?

Barry Shein bzs at bu-cs.BU.EDU
Fri Dec 5 12:31:37 AEST 1986


I realize that the original question was how to find out if a file is
across an NFS system from the csh. Find does it if that's applicable.
Now there's wondering out loud how it is done from a C program. I
suppose both questions are answered by a simple C command that can
be used in a csh script to test nfsness.

	-Barry Shein, Boston University

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>

/*
 * given a file name on the command line this program:
 *
 *	Prints NFS or LOCAL if the file is on an NFS or LOCAL file
 *	system respectively.
 *	Silently exits with a non-zero exit status if the file could
 *	not be accessed.
 */

/*
 * This magic cookie is gleaned from nfs_vnodeops.c
 * (is it likely to change? I dunno.)
 */
#define NFS_DEV 0xff

main(argc,argv) int argc; char **argv;
{
	struct stat sbuf;

	if(argc != 2) exit(1);
	if(stat(*++argv,&sbuf) < 0)
	  exit(1);

	/* Here's what you're looking for */
	if(major(sbuf.st_dev) == NFS_DEV)
	  printf("NFS\n",*argv);
	else printf("LOCAL\n");
	exit(0);
}



More information about the Comp.unix.questions mailing list