home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / Other / Coherent / DemonArchives / sources32 / utils / bsd-df.c.Z / bsd-df.c
Encoding:
C/C++ Source or Header  |  1995-05-23  |  1.8 KB  |  71 lines

  1. /*
  2.  
  3. Author :::::: Predrag S. Bundalo (pred@iitmax.iit.edu)
  4. Date :::::::: October 31st, 1992 (Muahahahaha)
  5. Environment:: COHERENT UNIX-clone v4.0.1
  6. Plea :::::::: I am releasing this program to the public domain.  Do with it
  7.     as you wish.  I only ask that you include these credits.
  8. Description:: This is a Berkeley UNIX df clone.  So far it has been tested
  9.     on COHERENT v4.x only.  It will *not* run under COHERENT 2.x since
  10.     that version of the operating system is missing the statfs() system
  11.     call.
  12. Compiling ::: cc -O bsd-df.c -o df
  13.       ::: strip df
  14. Version   ::: 1.0   (October  31st, 1992 --PSB)
  15. Version   ::: 1.0.1 (November 19th, 1992 --PSB)
  16.  
  17. */
  18. #include <stdio.h>
  19. #include <mtab.h>
  20. #include <sys/statfs.h>
  21. #include <sys/types.h>
  22. #include <errno.h>
  23.  
  24. void fatal(message)
  25. char *message;
  26. {
  27.     perror(message);
  28.     exit(1);
  29. }
  30.  
  31. main(){
  32. struct mtab mtst;
  33. register FILE *ifp;
  34. register unsigned int n;
  35. struct statfs buf;
  36. long int s/*cale*/ = 0L;
  37.  
  38. /*
  39. ** Open the mount table.
  40. */
  41. if ((ifp = fopen("/etc/mtab", "r")) == NULL)
  42.     fatal("mtab ");
  43.  
  44. printf("Filesystem            kbytes    used   avail capacity Mounted on\n");
  45. while ( (n = fread(&mtst, sizeof(struct mtab), 1, ifp)) != 0) {
  46.     /*
  47.     ** Make sure we have a valid entry.  This is the only thing that's
  48.     ** new in version 1.0.1.  There shouldn't be anymore releases of this
  49.     ** program. --PSB
  50.     */
  51.     if( !strlen(mtst.mt_name) )
  52.         continue;
  53.     /*
  54.     ** Stat the filesystem.
  55.     */
  56.     if( statfs(mtst.mt_name, &buf, sizeof(struct statfs), 0) == -1)
  57.         fatal("statfs ");
  58.  
  59.     s = (long)buf.f_bsize;  /* Scale by blocksize to get bytes. */
  60.     printf("/dev/%-16s %6ld %7ld %7ld %5ld%%   %-s\n",
  61.         mtst.mt_special,
  62.         s*buf.f_blocks/1024L,
  63.         s*(buf.f_blocks-buf.f_bfree)/1024L,
  64.         s*buf.f_bfree/1024L,
  65.         (int)(100*((float)(buf.f_blocks-buf.f_bfree)/buf.f_blocks)),
  66.         mtst.mt_name);
  67. }
  68. fclose(ifp);
  69. }
  70.  
  71.