Interdata_v6/usr/source/cmds/df.c

Find at most related files.
including files from this version of Unix.

char	*dargv[]
{
	0,
/***
	"/dev/rk2",
	"/dev/rp0",
***/
	"/dev/dfix",
	"/dev/drem",
	0
};
struct
{
	char	*s_isize;
	char	*s_fsize;
	int	s_nfree;
	int	s_free[50];
	int	s_ninode;
	int	s_inode[50];
	char	s_flock;
	char	s_ilock;
	char	s_fmod;
	int	time[2];
	int	pad[21];
} sblock;

int	fi;

main(argc, argv)
char **argv;
{
	register i;

	if(argc <= 1) {
		for(argc = 1; dargv[argc]; argc++);
		argv = dargv;
	}

	for(i=1; i<argc; i++) {
		if(argc > 1)
			printf("%s ", argv[i]);
		dfree(argv[i]);
	}
}

dfree(file)
char *file;
{
	register i;

	fi = open(file, 0);
	if(fi < 0) {
		printf("cannot open %s\n", file);
		return;
	}
	sync();
	bread(1, &sblock);
	i = 0;
	while(alloc())
		i++;
	printf("%l blocks\t%l inodes\n", i, ninodes());
	close(fi);
}

alloc()
{
	register b, i;
	int buf[128];

	i = --sblock.s_nfree;
	if(i<0 || i>=50) {
		printf("bad free count\n");
		return(0);
	}
	b = sblock.s_free[i];
	if(b == 0)
		return(0);
	if(b<sblock.s_isize+2 || b>=sblock.s_fsize) {
		printf("bad free block (%l)\n", b);
		return(0);
	}
	if(sblock.s_nfree <= 0) {
		bread(b, buf);
		sblock.s_nfree = buf[0];
		for(i=0; i<50; i++)
			sblock.s_free[i] = buf[i+1];
	}
	return(b);
}

ninodes()
{
	int buf[128];
	register b, i, n;

	n = 0;
	for (b=2; b<sblock.s_isize+2; b++) {
		bread(b, buf);
		for (i = 0; i < 128; i =+ 16)
			if ((buf[i] & 0100000) == 0)
				n++;
	}
	return(n);
}

bread(bno, buf)
{
	register n;
	extern errno;

	seek(fi, bno, 3);
	if((n=read(fi, buf, 512)) != 512) {
		printf("read error %d\n", bno);
		printf("count = %d; errno = %d\n", n, errno);
		exit();
	}
}