home *** CD-ROM | disk | FTP | other *** search
- /*
-
- Author :::::: Predrag S. Bundalo (pred@iitmax.iit.edu)
- Date :::::::: October 31st, 1992 (Muahahahaha)
- Environment:: COHERENT UNIX-clone v4.0.1
- Plea :::::::: I am releasing this program to the public domain. Do with it
- as you wish. I only ask that you include these credits.
- Description:: This is a Berkeley UNIX df clone. So far it has been tested
- on COHERENT v4.x only. It will *not* run under COHERENT 2.x since
- that version of the operating system is missing the statfs() system
- call.
- Compiling ::: cc -O bsd-df.c -o df
- ::: strip df
- Version ::: 1.0 (October 31st, 1992 --PSB)
- Version ::: 1.0.1 (November 19th, 1992 --PSB)
-
- */
- #include <stdio.h>
- #include <mtab.h>
- #include <sys/statfs.h>
- #include <sys/types.h>
- #include <errno.h>
-
- void fatal(message)
- char *message;
- {
- perror(message);
- exit(1);
- }
-
- main(){
- struct mtab mtst;
- register FILE *ifp;
- register unsigned int n;
- struct statfs buf;
- long int s/*cale*/ = 0L;
-
- /*
- ** Open the mount table.
- */
- if ((ifp = fopen("/etc/mtab", "r")) == NULL)
- fatal("mtab ");
-
- printf("Filesystem kbytes used avail capacity Mounted on\n");
- while ( (n = fread(&mtst, sizeof(struct mtab), 1, ifp)) != 0) {
- /*
- ** Make sure we have a valid entry. This is the only thing that's
- ** new in version 1.0.1. There shouldn't be anymore releases of this
- ** program. --PSB
- */
- if( !strlen(mtst.mt_name) )
- continue;
- /*
- ** Stat the filesystem.
- */
- if( statfs(mtst.mt_name, &buf, sizeof(struct statfs), 0) == -1)
- fatal("statfs ");
-
- s = (long)buf.f_bsize; /* Scale by blocksize to get bytes. */
- printf("/dev/%-16s %6ld %7ld %7ld %5ld%% %-s\n",
- mtst.mt_special,
- s*buf.f_blocks/1024L,
- s*(buf.f_blocks-buf.f_bfree)/1024L,
- s*buf.f_bfree/1024L,
- (int)(100*((float)(buf.f_blocks-buf.f_bfree)/buf.f_blocks)),
- mtst.mt_name);
- }
- fclose(ifp);
- }
-
-