home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
misc
/
volume18
/
df2
/
part01
next >
Wrap
Internet Message Format
|
1991-04-23
|
6KB
From: wht@n4hgf.Mt-Park.GA.US (Warren Tucker)
Newsgroups: comp.sources.misc
Subject: v18i081: df2 - an alternate S5R3 df utility, Part01/01
Message-ID: <1991Apr23.015218.8166@sparky.IMD.Sterling.COM>
Date: 23 Apr 91 01:52:18 GMT
Approved: kent@sparky.imd.sterling.com
X-Checksum-Snefru: 3c942a34 1683df75 c1a73fb7 f627f006
Submitted-by: Warren Tucker <wht@n4hgf.Mt-Park.GA.US>
Posting-number: Volume 18, Issue 81
Archive-name: df2/part01
This is df2, an alternate df-like utility for System V.
It needs mnttab.h and sys/statfs.h, so it probably will only
work for S5R3. I've never used ustat() but it may be an
alternate way to getting it going under earlier OSes.
Simple to compile: cc -O -o df2 df2.c
make df2 (if you are in a directory with no [Mm]akefile)
Simple to use: no options, just say
df2
Sample output:
Size (kb) Inodes
Filesystem|Mount Dir | Total Free Used Used| Total Free Used Used
----------+-------------+----------------------------+-------------------------
/dev/root |/ | 279559 122432 157127 56%| 65488 52903 12585 19%
/dev/u |/u/spool/news| 19642 18272 1370 6%| 4992 4672 320 6%
/dev/v0 |/c | 63137 41227 21910 34%| 15776 15190 586 3%
/dev/v1 |/u4 | 63137 43170 19967 31%| 15776 14502 1274 8%
/dev/v2 |/u5 | 63137 29194 33943 53%| 15776 12723 3053 19%
/dev/v3 |/v3 | 63137 62138 999 1%| 15776 15773 3 0%
/dev/v4 |/u7 | 63137 1783 61354 97%| 15776 15362 414 2%
----------+-------------+----------------------------+-------------------------
|total | 614886 318216 296670 48%|149360 131125 18235 12%
Warren
----
#!/bin/sh
# This is df2, a shell archive (shar 3.46)
# made 04/16/1991 21:13 UTC by wht@n4hgf
# Source directory /t
#
# existing files will NOT be overwritten unless -c is specified
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 2872 -rw-r--r-- df2.c
#
# ============= df2.c ==============
if test -f 'df2.c' -a X"$1" != X"-c"; then
echo 'x - skipping df2.c (File already exists)'
else
echo 'x - extracting df2.c (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'df2.c' &&
X/* CHK=0x254C */
X/*+-------------------------------------------------------------------------
X df2.c - another df-like utility
X wht@n4hgf.Mt-Park.GA.US
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:04-07-1991-02:58-wht@n4hgf-creation */
X
X#include <stdio.h>
X#include <ctype.h>
X#include <sys/errno.h>
X#include <sys/types.h>
X#include <sys/stat.h>
X#include <sys/statfs.h>
X#include <mnttab.h>
X
Xextern int errno;
Xextern char *sys_errlist[];
X
Xchar *heading[] =
X{
X" Size (kb) Inodes ",
X"Filesystem|Mount Dir | Total Free Used Used| Total Free Used Used",
X(char *)0
X};
X
Xchar *sep =
X"----------+-------------+----------------------------+-------------------------";
X
X/*+-------------------------------------------------------------------------
X main(argc,argv)
X--------------------------------------------------------------------------*/
Xmain(argc,argv)
Xint argc;
Xchar **argv;
X{
Xchar **cpptr = heading;
Xchar *etc_mnttab = "/etc/mnttab";
XFILE *fpmt;
Xstruct mnttab mnttab_buf;
Xstruct mnttab *mt = &mnttab_buf;
Xstruct statfs statf_buf;
Xstruct statfs *fs = &statf_buf;
X
Xlong kb_size;
Xlong kb_free;
Xlong kb_used;
Xint kb_used_pct;
Xlong kb_size_total = 0;
Xlong kb_free_total = 0;
Xlong kb_used_total = 0;
X
Xlong ino_size;
Xlong ino_free;
Xlong ino_used;
Xint ino_used_pct;
Xlong ino_size_total = 0;
Xlong ino_free_total = 0;
Xlong ino_used_total = 0;
X
X if(!(fpmt = fopen(etc_mnttab,"r")))
X {
X perror(etc_mnttab);
X exit(1);
X }
X
X while(*cpptr)
X printf("%s\n",*cpptr++);
X printf("%s\n",sep);
X
X while(fread((char *)mt,1,sizeof(*mt),fpmt) == sizeof(*mt))
X {
X if(statfs(mt->mt_filsys,fs,sizeof(*fs),0))
X {
X printf("%-10.10s statfs: %s\n",mt->mt_dev,sys_errlist[errno]);
X continue;
X }
X
X kb_size = fs->f_blocks / 2L;
X kb_free = fs->f_bfree / 2L;
X kb_used = kb_size - kb_free;
X kb_used_pct = (kb_used * 100) / kb_size;
X
X ino_size = fs->f_files;
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 kb_free_total += kb_free;
X kb_used_total += kb_used;
X
X ino_size_total += ino_size;
X ino_free_total += ino_free;
X ino_used_total += ino_used;
X }
X
X kb_used_pct = (int)(kb_used_total * 100 / kb_size_total);
X ino_used_pct = (int)(ino_used_total * 100L / (long)ino_size_total);
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 ino_size_total,ino_free_total,ino_used_total,ino_used_pct);
X
X exit(0);
X} /* end of main */
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of df2.c */
SHAR_EOF
chmod 0644 df2.c ||
echo 'restore of df2.c failed'
Wc_c="`wc -c < 'df2.c'`"
test 2872 -eq "$Wc_c" ||
echo 'df2.c: original size 2872, current size' "$Wc_c"
fi
exit 0
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.