home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume19 / df2_r4 / part01 next >
Encoding:
Internet Message Format  |  1991-04-29  |  12.0 KB

  1. From: wht@n4hgf.Mt-Park.GA.US (Warren Tucker)
  2. Newsgroups: comp.sources.misc
  3. Subject: v19i004:  df2_r4 - R3/R4 son of df2, Part01/01
  4. Message-ID: <1991Apr30.040632.3319@sparky.IMD.Sterling.COM>
  5. Date: 30 Apr 91 04:06:32 GMT
  6. Approved: kent@sparky.imd.sterling.com
  7. X-Checksum-Snefru: f20e6753 70735bde d86e3594 cdebd22e
  8.  
  9. Submitted-by: Warren Tucker <wht@n4hgf.Mt-Park.GA.US>
  10. Posting-number: Volume 19, Issue 4
  11. Archive-name: df2_r4/part01
  12.  
  13. DF2 has proven popular.  Here is a child of it which supports
  14. System V Release 3 or 4.  I am also submitting a patch to the
  15. first df2 from Chip Salzenburg for the original to do NFS
  16. support.
  17.  
  18. My goal was to customize a df for my needs and to make the code
  19. available for others to do likewise.  Note my original had just
  20. enough room for my longest mount directory :-).  80 characters is
  21. not a lot of room for the wide range of stuff you want to print.
  22. We all are likely to customize.
  23.  
  24. So, with this version and Chip's NFS patches to the original, we
  25. have a better collection of code and fragments to each build our
  26. idea of a "df -me" dream hack.
  27.  
  28. #!/bin/sh
  29. # This is df2_r4, a shell archive (shar 3.46)
  30. # made 04/29/1991 16:33 UTC by wht@n4hgf
  31. # Source directory /u1/src/df2
  32. #
  33. # existing files will NOT be overwritten unless -c is specified
  34. #
  35. # This shar contains:
  36. # length  mode       name
  37. # ------ ---------- ------------------------------------------
  38. #   3200 -rw-r--r-- README
  39. #   1140 -rw-r--r-- Makefile
  40. #   4421 -rw-r--r-- df2.c
  41. #
  42. # ============= README ==============
  43. if test -f 'README' -a X"$1" != X"-c"; then
  44.     echo 'x - skipping README (File already exists)'
  45. else
  46. echo 'x - extracting README (Text)'
  47. sed 's/^X//' << 'SHAR_EOF' > 'README' &&
  48. XThis is an updated version of df2, originally posted to comp.sources.misc as 
  49. X
  50. X> Posting-number: Volume 18, Issue 81
  51. X> Archive-name: df2/part01
  52. X
  53. XPaul Slootman has ported it to System 5 Release 4 (does he REALLY
  54. Xhave all that disk ?? :->).
  55. X
  56. Xit is still easy to make, though the needed library and the compile
  57. Xoptions have prompted a Makefile.  Read and edit the Makefile as
  58. Xnecessary and just make it.
  59. X
  60. XX-Organization: DataCount Register Informatici
  61. X                Postbus 888
  62. X                7640 AW  Wierden
  63. X                The Netherlands
  64. X>Date: Thu, 25 Apr 91 15:43 MDT
  65. X>From: emory!dri.nl!slootman (Paul Slootman)
  66. X>To: wht@n4hgf.mt-park.ga.us
  67. X>Subject: df2 ported to SysV.4
  68. X
  69. XHi,
  70. X
  71. XI snarfed your df2 from the net, and have ported it to System V.4
  72. X(on an ICL DRS6000 Sparc). It needed a few adjustments to allow
  73. Xfor the virtual filesystems, but seems to be running ok for now.
  74. XI'm going to extend it to take into account that some filesystems
  75. Xhave a requirement that some percentage of the disk MUST be free
  76. X(i.e. a normal user may only use up to 90%; beyond that he gets a
  77. X"filesystem full" error). This is something the standard df doesn't
  78. Xhandle. (When it's 89% full, that's what it says. When it's 90%
  79. Xfull, df states 100% full -- which can be confusing "Hey just a
  80. Xmoment ago it said 89%!!!").
  81. XThe percentage is rounded now. That's the usual way.
  82. XA small cosmetic adjustment has also been made - the filesystem
  83. Xnames are longer. Eg.:
  84. X                                   Size (kb)                  Inodes        
  85. XFilesystem      |Direct.| Total   Free    Used   Used| Total  Free  Used   Used
  86. X----------------+-------+----------------------------+-------------------------
  87. X/dev/dsk/c0d0s7 |/      |  28623   10731   17892  63%| 10240   8968   1272  12%
  88. X/proc           |/proc  |      0       0       0   0%|  1002    885    117  12%
  89. X/dev/fd         |/dev/fd|      0       0       0   0%|    50      0     50 100%
  90. X/dev/dsk/c0d0s2 |/stand |  10240    3566    6674  65%|   200    112     88  44%
  91. X/dev/dsk/c0d0s8 |/var   |  24964   13621   11343  45%| 13376  12468    908   7%
  92. X/dev/dsk/c0d0s9 |/dsk00 | 101102   20340   80762  80%| 10240   4470   5770  56%
  93. X/dev/dsk/c0d0s10|/dsk01 |  33679   28435    5244  16%|  3456   2602    854  25%
  94. X/dev/dsk/c0d0s11|/dsk02 |  84490   22899   61591  73%| 35840  28262   7578  21%
  95. X/dev/dsk/c0d0s12|/dsk03 |  63297   26060   37237  59%| 27136  24587   2549   9%
  96. X/dev/dsk/c0d0s14|/dsk04 |  73916   28332   45584  62%| 31232  28899   2333   7%
  97. X/dev/dsk/c0d0s15|/dsk09 |  84490   14107   70383  83%| 35840  33104   2736   8%
  98. X/dev/dsk/c0d0s16|/tmp   |  28223   23147    5076  18%| 12288  12094    194   2%
  99. X/dev/dsk/c1d0s0 |/usr   | 108809   21860   86949  80%| 58048  49097   8951  15%
  100. X/dev/dsk/c1d0s2 |/dsk10 |  52758    6804   45954  87%| 22528  19389   3139  14%
  101. X/dev/dsk/c1d0s3 |/dsk11 | 169005   25563  143442  85%| 71168  60238  10930  15%
  102. X/dev/dsk/c1d0s4 |/dsk12 |  84490   14421   70069  83%| 35840  32931   2909   8%
  103. X/dev/dsk/c1d0s5 |/dsk19 | 182634   25472  157162  86%| 77312  70749   6563   8%
  104. X----------------+-------+----------------------------+-------------------------
  105. X                |total  |1130720  285358  845362  74%|445796 388855  56941  12%
  106. X
  107. SHAR_EOF
  108. chmod 0644 README ||
  109. echo 'restore of README failed'
  110. Wc_c="`wc -c < 'README'`"
  111. test 3200 -eq "$Wc_c" ||
  112.     echo 'README: original size 3200, current size' "$Wc_c"
  113. fi
  114. # ============= Makefile ==============
  115. if test -f 'Makefile' -a X"$1" != X"-c"; then
  116.     echo 'x - skipping Makefile (File already exists)'
  117. else
  118. echo 'x - extracting Makefile (Text)'
  119. sed 's/^X//' << 'SHAR_EOF' > 'Makefile' &&
  120. X#+------------------------------------------------------------
  121. X#  Makefile for df2
  122. X#  Set PROGRAM to the executable name
  123. X#-------------------------------------------------------------
  124. X#+:EDITS:
  125. X#:04-26-1991-03:15-wht@n4hgf-since we have two versions and -lm, use a Makefile
  126. X
  127. X#-->   comment if you have System 5 Release 3
  128. X#    uncomment if you have System 5 Release 4
  129. X#SYSVR4 = -DSYSVR4
  130. X
  131. X#--> your compiler may vary
  132. XCC = cc
  133. X#CC = gcc -fwritable-strings -fpcc-struct-return 
  134. X
  135. X#--> where do you want to install it?
  136. XLBIN = /usr/local/bin
  137. X
  138. X# probably don't need to change below here
  139. XCFLAGS = -O $(SYSVR4)
  140. XLDFLAGS =
  141. XLIBS = -lm
  142. XSHELL = /bin/sh
  143. XPROGRAM = df2
  144. XINSTALLED = $(LBIN)/$(PROGRAM)
  145. XSRC = $(PROGRAM).c
  146. XOBJ = $(PROGRAM).o
  147. X.SUFFIXES:
  148. X.SUFFIXES: .c .o .h
  149. X.c.o:; $(CC) -c $(CFLAGS) $*.c
  150. X
  151. X$(PROGRAM): $(OBJ)
  152. X    rm -rf $@
  153. X    $(CC) -o $@ $(LDFLAGS) $(OBJ) $(LIBS)
  154. X
  155. Xinstall: $(PROGRAM)
  156. X    rm -f $(INSTALLED) $(INSTALLED)~
  157. X    if [ -f $(INSTALLED) ]; then mv $(INSTALLED) $(INSTALLED)~; fi
  158. X    cp $(PROGRAM) $(INSTALLED)
  159. X    strip $(INSTALLED)
  160. X    [ -x /usr/bin/mcs ] && /usr/bin/mcs -d $(INSTALLED)
  161. X    chmod o+x $(INSTALLED)
  162. X
  163. Xlint:
  164. X    lint -u -x $(SRC) > $(PROGRAM).lint
  165. SHAR_EOF
  166. chmod 0644 Makefile ||
  167. echo 'restore of Makefile failed'
  168. Wc_c="`wc -c < 'Makefile'`"
  169. test 1140 -eq "$Wc_c" ||
  170.     echo 'Makefile: original size 1140, current size' "$Wc_c"
  171. fi
  172. # ============= df2.c ==============
  173. if test -f 'df2.c' -a X"$1" != X"-c"; then
  174.     echo 'x - skipping df2.c (File already exists)'
  175. else
  176. echo 'x - extracting df2.c (Text)'
  177. sed 's/^X//' << 'SHAR_EOF' > 'df2.c' &&
  178. X/* CHK=0x90B3 */
  179. Xchar *rev = "1.10";
  180. X/*+-------------------------------------------------------------------------
  181. X    df2.c - another df-like utility
  182. X    wht@n4hgf.Mt-Park.GA.US
  183. X--------------------------------------------------------------------------*/
  184. X/*+:EDITS:*/
  185. X/*:04-26-1991-04:26-wht@n4hgf-merge R3 code with R4 */
  186. X/*:04-25-1991-15:45-slootman@dri.nl-port to SysV.4 */
  187. X/*:04-07-1991-02:58-wht@n4hgf-creation */
  188. X
  189. X#include <stdio.h>
  190. X#include <ctype.h>
  191. X#include <math.h>
  192. X#include <sys/errno.h>
  193. X#include <sys/types.h>
  194. X#include <sys/stat.h>
  195. X#ifdef SYSVR4
  196. X#include <sys/statvfs.h>
  197. X#include <sys/mnttab.h>
  198. X#define statfs statvfs
  199. X#else
  200. X#include <sys/statfs.h>
  201. X#include <mnttab.h>
  202. X#endif /* SYSVR4 */
  203. X
  204. Xextern int errno;
  205. Xextern char *sys_errlist[];
  206. X
  207. Xchar *heading[] =
  208. X{
  209. X"                                   Size (kb)                  Inodes        ",
  210. X#ifdef SYSVR4
  211. X"Filesystem      |Direct.| Total   Free    Used   Used| Total  Free  Used   Used",
  212. X#else
  213. X"Filesystem|Mount Dir    | Total   Free    Used   Used| Total  Free  Used   Used",
  214. X#endif /* SYSVR4 */
  215. X(char *)0
  216. X};
  217. X
  218. X#ifdef SYSVR4
  219. Xchar *sep =
  220. X"----------------+-------+----------------------------+-------------------------";
  221. X#else
  222. Xchar *sep =
  223. X"----------+-------------+----------------------------+-------------------------";
  224. X#endif /* SYSVR4 */
  225. X
  226. X/*+-------------------------------------------------------------------------
  227. X    main(argc,argv)
  228. X--------------------------------------------------------------------------*/
  229. X/*ARGSUSED*/
  230. Xmain(argc,argv)
  231. Xint argc;
  232. Xchar **argv;
  233. X{
  234. Xchar **cpptr = heading;
  235. Xchar *etc_mnttab = "/etc/mnttab";
  236. XFILE *fpmt;
  237. Xstruct mnttab mnttab_buf;
  238. Xstruct mnttab *mt = &mnttab_buf;
  239. Xstruct statfs statf_buf;
  240. Xstruct statfs *fs = &statf_buf;
  241. X
  242. Xlong kb_size;
  243. Xlong kb_free;
  244. Xlong kb_used;
  245. Xint kb_used_pct;
  246. Xlong kb_size_total = 0;
  247. Xlong kb_free_total = 0;
  248. Xlong kb_used_total = 0;
  249. X
  250. Xlong ino_size;
  251. Xlong ino_free;
  252. Xlong ino_used;
  253. Xint ino_used_pct;
  254. Xlong ino_size_total = 0;
  255. Xlong ino_free_total = 0;
  256. Xlong ino_used_total = 0;
  257. X
  258. X#ifdef SYSVR4
  259. Xchar *fmt_line ="%-16.16s|%-7.7s|%7ld %7ld %7ld %3d%%|%6ld %6ld %6ld %3d%%\n";
  260. X#else
  261. Xchar *fmt_line ="%-10.10s|%-13.13s|%7ld %7ld %7ld %3d%%|%6ld %6ld %6ld %3d%%\n";
  262. X#endif /* SYSVR4 */
  263. X
  264. X    if(argc != 1)
  265. X    {
  266. X        (void)fprintf(stderr,"df2 %s: no arguments required or accepted\n",rev);
  267. X        exit(1);
  268. X    }
  269. X
  270. X    if(!(fpmt = fopen(etc_mnttab,"r")))
  271. X    {
  272. X        perror(etc_mnttab);
  273. X        exit(1);
  274. X    }
  275. X
  276. X    while(*cpptr)
  277. X        (void)printf("%s\n",*cpptr++);
  278. X    (void)printf("%s\n",sep);
  279. X
  280. X    while    (
  281. X#ifdef SYSVR4
  282. X        !getmntent(fpmt,mt)
  283. X#else
  284. X        fread((char *)mt,1,sizeof(*mt),fpmt) == sizeof(*mt)
  285. X#endif /* SYSVR4 */
  286. X            )
  287. X    {
  288. X        if(
  289. X#ifdef SYSVR4
  290. X            statvfs(mt->mnt_mountp,fs)
  291. X#else
  292. X            statfs(mt->mt_filsys,fs,sizeof(*fs),0)
  293. X#endif
  294. X                )
  295. X        {
  296. X#ifdef SYSVR4
  297. X            (void)printf("%-16.16s statvfs: %s\n",
  298. X                mt->mnt_special,sys_errlist[errno]);
  299. X#else
  300. X            (void)printf("%-10.10s statfs: %s\n",
  301. X                mt->mt_dev,sys_errlist[errno]);
  302. X#endif /* SYSVR4 */
  303. X            continue;
  304. X        }
  305. X
  306. X#ifdef SYSVR4
  307. X        kb_size = fs->f_blocks * fs->f_frsize / 1024L;
  308. X        kb_free = fs->f_bfree * fs->f_frsize / 1024L;
  309. X#else
  310. X        kb_size = fs->f_blocks  / 2L;
  311. X        kb_free = fs->f_bfree / 2L;
  312. X#endif /* SYSVR4 */
  313. X        kb_used = kb_size - kb_free;
  314. X
  315. X        if(kb_size>0) 
  316. X        {
  317. X            kb_used_pct = (int)floor(
  318. X                ((double)kb_used * 100) / (double)kb_size + 0.5);
  319. X        }
  320. X        else
  321. X            kb_used_pct = 0;
  322. X
  323. X        ino_size = fs->f_files;
  324. X        ino_free = fs->f_ffree;
  325. X        ino_used = ino_size - ino_free;
  326. X        if(ino_size>0)
  327. X        {
  328. X            ino_used_pct = (int)floor(
  329. X                ((double)ino_used * 100) / (double)ino_size + 0.5);
  330. X        }
  331. X        else
  332. X            ino_used_pct=0;
  333. X
  334. X#ifdef SYSVR4
  335. X        (void)printf(fmt_line,
  336. X            mt->mnt_special,mt->mnt_mountp,
  337. X            kb_size,kb_free,kb_used,kb_used_pct,
  338. X            ino_size,ino_free,ino_used,ino_used_pct);
  339. X#else
  340. X        (void)printf(fmt_line,
  341. X            mt->mt_dev,mt->mt_filsys,
  342. X            kb_size,kb_free,kb_used,kb_used_pct,
  343. X            ino_size,ino_free,ino_used,ino_used_pct);
  344. X#endif /* SYSVR4 */
  345. X
  346. X        kb_size_total  += kb_size;
  347. X        kb_free_total  += kb_free;
  348. X        kb_used_total  += kb_used;
  349. X
  350. X        ino_size_total  += ino_size;
  351. X        ino_free_total  += ino_free;
  352. X        ino_used_total  += ino_used;
  353. X    }
  354. X
  355. X    kb_used_pct = (int)(kb_used_total * 100 / kb_size_total);
  356. X    ino_used_pct = (int)(ino_used_total * 100L / (long)ino_size_total);
  357. X
  358. X    (void)printf("%s\n",sep);
  359. X    (void)printf(fmt_line, "","total",
  360. X        kb_size_total,kb_free_total,kb_used_total,kb_used_pct,
  361. X        ino_size_total,ino_free_total,ino_used_total,ino_used_pct);
  362. X
  363. X    exit(0);
  364. X    /*NOTREACHED*/
  365. X}    /* end of main */
  366. X
  367. X/* vi: set tabstop=4 shiftwidth=4: */
  368. X/* end of df2.c */
  369. SHAR_EOF
  370. chmod 0644 df2.c ||
  371. echo 'restore of df2.c failed'
  372. Wc_c="`wc -c < 'df2.c'`"
  373. test 4421 -eq "$Wc_c" ||
  374.     echo 'df2.c: original size 4421, current size' "$Wc_c"
  375. fi
  376. exit 0
  377.  
  378. ---------------------------------------------------------------------
  379. Warren Tucker, TuckerWare  emory!n4hgf!wht or wht@n4hgf.Mt-Park.GA.US
  380. Ker-au'-lo-phon.   An  8-foot  partial  flue-stop, having metal pipes
  381. surmounted by adjustable rings, and with a hole bored near the top of
  382. each pipe.  Tone soft and "reedy".
  383.  
  384. exit 0 # Just in case...
  385. -- 
  386. Kent Landfield                   INTERNET: kent@sparky.IMD.Sterling.COM
  387. Sterling Software, IMD           UUCP:     uunet!sparky!kent
  388. Phone:    (402) 291-8300         FAX:      (402) 291-4362
  389. Please send comp.sources.misc-related mail to kent@uunet.uu.net.
  390.