wht@n4hgf.Mt-Park.GA.US (Warren Tucker) (04/30/91)
Submitted-by: Warren Tucker <wht@n4hgf.Mt-Park.GA.US> Posting-number: Volume 19, Issue 3 Archive-name: df2/patch01 Patch-To: df2: Volume 18, Issue 81 This patch was sent to me by Chip Salzenburg after Paul Slootman had sent me a port for System 5 Release 4. It has some advantages for use in an NFS environment. My goal was to customize a df for my needs and to make the code available for others to do likewise. Note my original had just enough room for MY longest mount directory :-). In addition, I have just one more digit in the numeric columns than I need for blocks and inodes. 80 characters is not a lot of room for the wide range of stuff you want to print. We all are likely to customize. So, with this version and Paul Slootman's R4 port (df2_r4) of the original, we have a better collection of code and fragments to each build our idea of a "df -me" dream hack. Chip Salzenberg <chip@tct.com>, <uunet!pdn!tct!chip> says: >... [O]ur environment (SCO UNIX w/NFS) required a couple of changes to df2. > >First, our NFS server (an RS/6000) doesn't report inode stats. >Second, the pathnames of the NFS directories didn't fit in the column >constraints. > >So I rearranged the columns a bit to leave more space for the mount >pathname. (I gained from omitting "/dev/" in the first column.) Then >I special-cased NFS filesystems to show the source directory in the >inode column (since that isn't used for NFS directories anyway). Patches below. Unshar, patch < df2.p01 and enjoy. #!/bin/sh # This is a shell archive (shar 3.46) # made 04/29/1991 17:05 UTC by wht@n4hgf # Source directory /u1/src/df2 # # existing files will NOT be overwritten unless -c is specified # # This shar contains: # length mode name # ------ ---------- ------------------------------------------ # 2797 -rw-r--r-- df2.p01 # # ============= df2.p01 ============== if test -f 'df2.p01' -a X"$1" != X"-c"; then echo 'x - skipping df2.p01 (File already exists)' else echo 'x - extracting df2.p01 (Text)' sed 's/^X//' << 'SHAR_EOF' > 'df2.p01' && XIndex: df2.c X*************** X*** 13,16 **** X--- 13,17 ---- X #include <sys/stat.h> X #include <sys/statfs.h> X+ #include <sys/fstyp.h> X #include <mnttab.h> X X*************** X*** 21,25 **** X { X " Size (kb) Inodes ", X! "Filesystem|Mount Dir | Total Free Used Used| Total Free Used Used", X (char *)0 X }; X--- 22,26 ---- X { X " Size (kb) Inodes ", X! "Filsys|Mount Dir | Total Free Used Used | Total Free Used Used", X (char *)0 X }; X*************** X*** 26,30 **** X X char *sep = X! "----------+-------------+----------------------------+-------------------------"; X X /*+------------------------------------------------------------------------- X--- 27,31 ---- X X char *sep = X! "------+---------------+-----------------------------+-------------------------"; X X /*+------------------------------------------------------------------------- X*************** X*** 42,45 **** X--- 43,47 ---- X struct statfs statf_buf; X struct statfs *fs = &statf_buf; X+ int fstyp_nfs = sysfs(GETFSIND, "NFS"); X X long kb_size; X*************** X*** 71,74 **** X--- 73,78 ---- X while(fread((char *)mt,1,sizeof(*mt),fpmt) == sizeof(*mt)) X { X+ char *dev; X+ X if(statfs(mt->mt_filsys,fs,sizeof(*fs),0)) X { X*************** X*** 85,94 **** X ino_free = fs->f_ffree; X ino_used = ino_size - ino_free; X! ino_used_pct = (ino_used * 100) / ino_size; X X! printf("%-10.10s|%-13.13s|%7ld %7ld %7ld %3d%%|%6ld %6ld %6ld %3d%%\n", X! mt->mt_dev,mt->mt_filsys, X! kb_size,kb_free,kb_used,kb_used_pct, X! ino_size,ino_free,ino_used,ino_used_pct); X X kb_size_total += kb_size; X--- 89,111 ---- X ino_free = fs->f_ffree; X ino_used = ino_size - ino_free; X! ino_used_pct = ino_size ? ((ino_used * 100) / ino_size) : 0; X X! dev = (fs->f_fstyp == fstyp_nfs) ? "NFS" X! : (strncmp(mt->mt_dev, "/dev/", 5) == 0) ? mt->mt_dev + 5 X! : mt->mt_dev; X! X! printf("%-6.6s|%-15.15s|%7ld %7ld %7ld %3d%% |", X! dev, mt->mt_filsys, X! kb_size,kb_free,kb_used,kb_used_pct); X! if (fs->f_fstyp == fstyp_nfs) X! { X! printf(" [%s]", mt->mt_dev); X! } X! else if (ino_size) X! { X! printf("%6ld %6ld %6ld %3d%%", X! ino_size,ino_free,ino_used,ino_used_pct); X! } X! printf("\n"); X X kb_size_total += kb_size; X*************** X*** 105,109 **** X X printf("%s\n",sep); X! printf("%-10.10s|%-13.13s|%7ld %7ld %7ld %3d%%|%6ld %6ld %6ld %3d%%\n", X "","total", X kb_size_total,kb_free_total,kb_used_total,kb_used_pct, X--- 122,126 ---- X X printf("%s\n",sep); X! printf("%-6.6s|%-15.15s|%7ld %7ld %7ld %3d%% |%6ld %6ld %6ld %3d%%\n", X "","total", X kb_size_total,kb_free_total,kb_used_total,kb_used_pct, X SHAR_EOF chmod 0644 df2.p01 || echo 'restore of df2.p01 failed' Wc_c="`wc -c < 'df2.p01'`" test 2797 -eq "$Wc_c" || echo 'df2.p01: original size 2797, current size' "$Wc_c" fi exit 0 ---------------------------------------------------------------------------- Warren Tucker emory!n4hgf!wht or wht@n4hgf.Mt-Park.GA.US "I was 35 years old before I knew a pie was meant to be eaten." - Moe Howard exit 0 # Just in case... -- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM Sterling Software, IMD UUCP: uunet!sparky!kent Phone: (402) 291-8300 FAX: (402) 291-4362 Please send comp.sources.misc-related mail to kent@uunet.uu.net.