Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

disk information utility

4 views
Skip to first unread message

Brad Lanam

unread,
Feb 27, 1994, 1:34:44 PM2/27/94
to
A friend wanted a 'df' that printed the same information on several
different machines. This code has been compiled and tested on SysV.4,
SysV.3.2 and SunOS 2.x. Enjoy.

-- Brad

--
Until the next disk seek...
-- Brad Lanam b...@gentoo.com ...!netcom!seer!bll

========================================

From the documentation:

Warning: Do not replace your systems 'df' command with this program.
You will in all likelyhood break your installation procedures.

Usage: di -Aafntx
-A : print all fields (used for debugging)
-a : print all mounted devices; normally, those
with 0 total blocks are not printed. e.g.
/dev/proc, /dev/fd.
-f x : use format string <x>
-n : don't print header
-x n : debug level <n>

All values are reported in K (1024 bytes).

Format string values:
m - mount point
b - total blocks
u - used blocks (actual number of blocks used) [ (tot - free) ]
c - calculated number of used blocks [ (tot - avail) ]
f - free blocks
v - available blocks
p - percent blocks used
This gives the percentage not available for use.
(number of blocks not available for use / total disk space)
[ (tot - avail) / tot ]
1 - percent blocks used
This gives the actual percentage used.
(actual number of blocks used / total disk space)
[ (tot - free) / tot ]
2 - percent blocks used (bsd style)
I'm not sure what this number is supposed to mean. Who knows.
It's the percentage of blocks used from the disk space available
to the user, but I really don't see what use it is. Note that it
is possible to get values over 100%. Brain Software Damaged.
(actual number of blocks used / disk space available to user)
[ (tot - free) / (tot - (free - avail)) ]
i - total i-nodes (files)
U - used i-nodes
F - free i-nodes
P - percent i-nodes used [ (tot - avail) / tot ]
s - filesystem name (special)
t - disk partition type (not implemented for sun-os)

System V.4 `/usr/bin/df -v` Has format: msbuf1 (w/512 byte blocks)
System V.4 `/usr/bin/df -k` Has format: sbcvpm
System V.4 `/usr/ucb/df` Has format: sbuv2m

The default format string for this program is: mbuvpiUFP

The environment variable "DIFMT" may be set to the desired format
string.

Note that for filesystems that do not have (S512K fs) or systems (SysV.3)
that do not report available blocks, the number of available blocks is
equal to the number of free blocks.

# This is a shell archive. Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file". Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
# di.c
# Makefile.di
#
echo x - di.c
sed 's/^X//' >di.c << 'END-of-di.c'
X/*
X * di.c
X *
X * Copyright 1994 Brad Lanam, Walnut Creek, CA
X *
X * Warning: Do not replace your systems 'df' command with this program.
X * You will in all likelyhood break your installation procedures.
X *
X * Usage: di -Aafntx
X * -A : print all fields (used for debugging)
X * -a : print all mounted devices; normally, those
X * with 0 total blocks are not printed. e.g.
X * /dev/proc, /dev/fd.
X * -f x : use format string <x>
X * -n : don't print header
X * -x n : debug level <n>
X *
X * All values are reported in K (1024 bytes).
X *
X * Format string values:
X * m - mount point
X * b - total blocks
X * u - used blocks (actual number of blocks used) [ (tot - free) ]
X * c - calculated number of used blocks [ (tot - avail) ]
X * f - free blocks
X * v - available blocks
X * p - percent blocks used
X * This gives the percentage not available for use.
X * (number of blocks not available for use / total disk space)
X * [ (tot - avail) / tot ]
X * 1 - percent blocks used
X * This gives the actual percentage used.
X * (actual number of blocks used / total disk space)
X * [ (tot - free) / tot ]
X * 2 - percent blocks used (bsd style)
X * I'm not sure what this number is supposed to mean. Who knows.
X * It's the percentage of blocks used from the disk space available
X * to the user, but I really don't see what use it is. Note that it
X * is possible to get values over 100%. Brain Software Damaged.
X * (actual number of blocks used / disk space available to user)
X * [ (tot - free) / (tot - (free - avail)) ]
X * i - total i-nodes (files)
X * U - used i-nodes
X * F - free i-nodes
X * P - percent i-nodes used [ (tot - avail) / tot ]
X * s - filesystem name (special)
X * t - disk partition type (not implemented for sun-os)
X *
X * System V.4 `/usr/bin/df -v` Has format: msbuf1 (w/512 byte blocks)
X * System V.4 `/usr/bin/df -k` Has format: sbcvpm
X * System V.4 `/usr/ucb/df` Has format: sbuv2m
X *
X * The default format string for this program is: mbuvpiUFP
X *
X * The environment variable "DIFMT" may be set to the desired format
X * string.
X *
X * Note that for filesystems that do not have (S512K fs) or systems (SysV.3)
X * that do not report available blocks, the number of available blocks is
X * equal to the number of free blocks.
X *
X */
X
X#include <stdio.h>
X#include <stdlib.h>
X#include <errno.h>
X#include <malloc.h>
X#include <memory.h>
X#include <string.h>
X#include <unistd.h>
X#include <sys/types.h>
X#include <sys/param.h>
X
X#if HAS_MNTTAB
X# include <sys/mnttab.h>
X#endif
X#if HAS_SVR3_MNTTAB
X# include <mnttab.h>
X#endif
X#if HAS_MNTENT
X# include <mntent.h>
X#endif
X
X#if HAS_STATVFS
X# include <sys/statvfs.h>
X#endif
X#if HAS_SYSFS
X# include <sys/fstyp.h>
X# define TYPE_LEN FSTYPSZ
X#endif
X#if HAS_STATFS
X# include <sys/vfs.h>
X#endif
X#if HAS_SYSV_STATFS
X# include <sys/statfs.h>
X#endif
X
X#if HAS_VFSTAB
X# include <sys/vfstab.h>
X# if ! defined (TYPE_LEN)
X# define TYPE_LEN FSTYPSZ
X# endif
X# define VFSTAB_FILE "/etc/vfstab"
X#endif
X
X#if ! defined (TYPE_LEN)
X# define TYPE_LEN 16
X#endif
X
X#if ! defined (UBSIZE)
X# define UBSIZE 512
X#endif
X
X#if defined (MOUNTED)
X# define MOUNT_FILE MOUNTED
X#else
X# if defined (MNTTAB)
X# define MOUNT_FILE MNTTAB
X# else
X# define MOUNT_FILE "/etc/mnttab"
X# endif
X#endif
X
X#if ! defined (TRUE)
X# define TRUE 1
X#endif
X#if ! defined (FALSE)
X# define FALSE 0
X#endif
X
X#define F_ALL 0x0001
X#define F_TOTAL 0x0010
X#define F_NO_HEADER 0x0020
X
X#define FMT_MOUNT 'm'
X#define FMT_BTOT 'b'
X#define FMT_BUSED 'u'
X#define FMT_BCUSED 'c'
X#define FMT_BFREE 'f'
X#define FMT_BAVAIL 'v'
X#define FMT_BPERC_AVAIL 'p'
X#define FMT_BPERC_FREE '1'
X#define FMT_BPERC_BSD '2'
X#define FMT_ITOT 'i'
X#define FMT_IUSED 'U'
X#define FMT_IFREE 'F'
X#define FMT_IPERC 'P'
X#define FMT_SPECIAL 's'
X#define FMT_TYPE 't'
X
X#define DI_BAD 0
X#define DI_OK 1
X#define DI_ZERO 2
X
X#define DEFAULT_FORMAT "mbuvpiUFP"
X#define ALL_FORMAT "mbucfvp12iUFPst"
X
X#define ONE_K 1024.0
X
X /* you may want to change some of these values. Be sure to change all */
X /* related entries. */
X#define BLOCK_FMT "%8lu"
X#define BLOCK_LBL_FMT "%8s"
X#define PERC_FMT "%3.0f%% "
X#define PERC_LBL_FMT "%5s"
X#define INODE_FMT "%7lu"
X#define INODE_LBL_FMT "%7s"
X#define NAME_LEN 15
X#define MOUNT_FMT "%-15.15s"
X#define SPEC_NAME_LEN 18
X#define SPEC_FMT "%-18.18s"
X#define FSTYPE_FMT "%-16.16s"
X
X#if defined (__STDC__)
X# define PROTO(x) x
X#endif
X
X#if ! defined (PROTO)
X# define PROTO(x) ()
X#endif
X
Xtypedef unsigned long _ulong;
X
X#if NEED_GETOPT_DEFS
Xextern char *optarg;
Xextern int optind;
Xextern int getopt PROTO((int, char *[], const char *));
X#endif
X
Xtypedef struct
X{
X _ulong totalBlocks;
X _ulong freeBlocks;
X _ulong availBlocks;
X _ulong totalInodes;
X _ulong freeInodes;
X _ulong availInodes;
X char ok;
X char name [NAME_LEN + 1];
X char special [SPEC_NAME_LEN + 1];
X char fsType [TYPE_LEN + 1];
X} DiskInfo;
X
Xstatic DiskInfo *diskInfo = { (DiskInfo *) NULL };
Xstatic int diCount = { 0 };
Xstatic int debug = { 0 };
Xstatic long flags = { 0 };
Xstatic char *formatString = { DEFAULT_FORMAT };
X
X
Xstatic void cleanup PROTO((void));
Xstatic void printDiskInfo PROTO((void));
Xstatic void printInfo PROTO((DiskInfo *));
Xstatic void addTotals PROTO((DiskInfo *, DiskInfo *));
Xstatic void printTitle PROTO((void));
Xstatic void printPerc PROTO((_ulong, _ulong, char *));
Xstatic char *Realloc PROTO((char *, long));
Xstatic int getDiskEntries PROTO((void));
Xstatic int getDiskInfo PROTO((void));
X
Xmain (argc, argv)
X int argc;
X char *argv [];
X{
X int rc;
X int ch;
X char *ptr;
X
X
X if ((ptr = getenv ("DIFMT")) != (char *) NULL)
X {
X formatString = ptr;
X }
X
X while ((ch = getopt (argc, argv, "Aaf:ntx:")) != -1)
X {
X switch (ch)
X {
X case 'A':
X {
X formatString = ALL_FORMAT;
X break;
X }
X
X case 'a':
X {
X flags |= F_ALL;
X break;
X }
X
X case 'f':
X {
X formatString = optarg;
X break;
X }
X
X case 'n':
X {
X flags |= F_NO_HEADER;
X break;
X }
X
X case 't':
X {
X flags |= F_TOTAL;
X break;
X }
X
X case 'x':
X {
X debug = atoi (optarg);
X break;
X }
X }
X }
X
X if ((rc = getDiskEntries ()) < 0)
X {
X cleanup ();
X exit (1);
X }
X
X if ((rc = getDiskInfo ()) < 0)
X {
X cleanup ();
X exit (1);
X }
X
X printDiskInfo ();
X cleanup ();
X exit (0);
X}
X
X/*
X * cleanup
X *
X * free up allocated memory
X *
X */
X
Xstatic void
Xcleanup ()
X{
X if (diskInfo != (DiskInfo *) NULL)
X {
X free ((char *) diskInfo);
X }
X}
X
X/*
X * printDiskInfo
X *
X * Print out the disk information table.
X * Loops through all mounted disks, prints and calculates totals.
X *
X */
X
Xstatic void
XprintDiskInfo ()
X{
X int i;
X char *label;
X DiskInfo totals;
X
X
X memset ((char *) &totals, '\0', sizeof (DiskInfo));
X strcpy (totals.name, "Total");
X totals.ok = DI_OK;
X
X if ((flags & F_NO_HEADER) != F_NO_HEADER)
X {
X printTitle ();
X }
X
X for (i = 0; i < diCount; ++i)
X {
X if (((flags & F_ALL) == F_ALL && diskInfo [i].ok != DI_BAD) ||
X diskInfo [i].ok == DI_OK)
X {
X printInfo (&diskInfo [i]);
X addTotals (&diskInfo [i], &totals);
X }
X }
X
X if ((flags & F_TOTAL) == F_TOTAL && (flags & F_NO_HEADER) != F_NO_HEADER)
X {
X printInfo (&totals);
X }
X}
X
X/*
X * printInfo
X *
X * Print the information for a single partition. Loop through the
X * format string and print the particular items wanted.
X *
X */
X
Xstatic void
XprintInfo (diskInfo)
X DiskInfo *diskInfo;
X{
X double perc;
X _ulong used;
X _ulong totAvail;
X char *ptr;
X
X
X ptr = formatString;
X while (*ptr)
X {
X switch (*ptr)
X {
X case FMT_MOUNT:
X {
X printf (MOUNT_FMT, diskInfo->name);
X break;
X }
X
X case FMT_BTOT:
X {
X printf (BLOCK_FMT, diskInfo->totalBlocks);
X break;
X }
X
X case FMT_BUSED:
X {
X printf (BLOCK_FMT, diskInfo->totalBlocks - diskInfo->freeBlocks);
X break;
X }
X
X case FMT_BCUSED:
X {
X printf (BLOCK_FMT, diskInfo->totalBlocks - diskInfo->availBlocks);
X break;
X }
X
X case FMT_BFREE:
X {
X printf (BLOCK_FMT, diskInfo->freeBlocks);
X break;
X }
X
X case FMT_BAVAIL:
X {
X printf (BLOCK_FMT, diskInfo->availBlocks);
X break;
X }
X
X case FMT_BPERC_AVAIL:
X {
X used = diskInfo->totalBlocks - diskInfo->availBlocks;
X totAvail = diskInfo->totalBlocks;
X printPerc (used, totAvail, PERC_FMT);
X break;
X }
X
X case FMT_BPERC_FREE:
X {
X used = diskInfo->totalBlocks - diskInfo->freeBlocks;
X totAvail = diskInfo->totalBlocks;
X printPerc (used, totAvail, PERC_FMT);
X break;
X }
X
X case FMT_BPERC_BSD:
X {
X used = diskInfo->totalBlocks - diskInfo->freeBlocks;
X totAvail = diskInfo->totalBlocks -
X (diskInfo->freeBlocks - diskInfo->availBlocks);
X printPerc (used, totAvail, PERC_FMT);
X break;
X }
X
X case FMT_ITOT:
X {
X printf (INODE_FMT, diskInfo->totalInodes);
X break;
X }
X
X case FMT_IUSED:
X {
X printf (INODE_FMT, diskInfo->totalInodes - diskInfo->freeInodes);
X break;
X }
X
X case FMT_IFREE:
X {
X printf (INODE_FMT, diskInfo->freeInodes);
X break;
X }
X
X case FMT_IPERC:
X {
X used = diskInfo->totalInodes - diskInfo->availInodes;
X totAvail = diskInfo->totalInodes;
X printPerc (used, totAvail, PERC_FMT);
X break;
X }
X
X case FMT_SPECIAL:
X {
X printf (SPEC_FMT, diskInfo->special);
X break;
X }
X
X case FMT_TYPE:
X {
X printf (FSTYPE_FMT, diskInfo->fsType);
X break;
X }
X }
X
X ++ptr;
X if (*ptr)
X {
X printf (" ");
X }
X }
X
X printf ("\n");
X}
X
X/*
X * addTotals
X *
X * Add up the totals for the blocks/inodes
X *
X */
X
Xstatic void
XaddTotals (diskInfo, totals)
X DiskInfo *diskInfo;
X DiskInfo *totals;
X{
X totals->totalBlocks += diskInfo->totalBlocks;
X totals->freeBlocks += diskInfo->freeBlocks;
X totals->availBlocks += diskInfo->availBlocks;
X totals->totalInodes += diskInfo->totalInodes;
X totals->freeInodes += diskInfo->freeInodes;
X totals->availInodes += diskInfo->availInodes;
X}
X
X/*
X * printTitle
X *
X * Loop through the format string and print the appropriate headings.
X *
X */
X
Xstatic void
XprintTitle ()
X{
X char *ptr;
X char *label;
X
X ptr = formatString;
X
X while (*ptr)
X {
X switch (*ptr)
X {
X case FMT_MOUNT:
X {
X printf (MOUNT_FMT, "Mount");
X break;
X }
X
X case FMT_BTOT:
X {
X printf (BLOCK_LBL_FMT, "Blocks");
X break;
X }
X
X case FMT_BUSED:
X case FMT_BCUSED:
X {
X printf (BLOCK_LBL_FMT, "Used");
X break;
X }
X
X case FMT_BFREE:
X {
X printf (BLOCK_LBL_FMT, "Free");
X break;
X }
X
X case FMT_BAVAIL:
X {
X printf (BLOCK_LBL_FMT, "Avail");
X break;
X }
X
X case FMT_BPERC_AVAIL:
X case FMT_BPERC_FREE:
X case FMT_BPERC_BSD:
X {
X printf (PERC_LBL_FMT, "%used");
X break;
X }
X
X case FMT_ITOT:
X {
X printf (INODE_LBL_FMT, "Inodes");
X break;
X }
X
X case FMT_IUSED:
X {
X printf (INODE_LBL_FMT, "Used");
X break;
X }
X
X case FMT_IFREE:
X {
X printf (INODE_LBL_FMT, "Free");
X break;
X }
X
X case FMT_IPERC:
X {
X printf (PERC_LBL_FMT, "%used");
X break;
X }
X
X case FMT_SPECIAL:
X {
X printf (SPEC_FMT, "Filesystem");
X break;
X }
X
X case FMT_TYPE:
X {
X printf (FSTYPE_FMT, "fs Type");
X break;
X }
X }
X
X ++ptr;
X if (*ptr)
X {
X printf (" ");
X }
X }
X
X printf ("\n");
X}
X
X/*
X * printPerc
X *
X * Calculate and print a percentage using the values and format passed.
X *
X */
X
Xstatic void
XprintPerc (used, totAvail, format)
X _ulong used;
X _ulong totAvail;
X char *format;
X{
X double perc;
X
X
X if (totAvail > 0L)
X {
X perc = (double) used / (double) totAvail;
X perc *= 100.0;
X }
X else
X {
X perc = 0.0;
X }
X printf (format, perc);
X}
X
X
X/*
X * Realloc
X *
X * portable realloc
X *
X */
X
Xstatic char *
XRealloc (ptr, size)
X char *ptr;
X long size;
X{
X if (ptr == (char *) NULL)
X {
X ptr = (char *) malloc (size);
X }
X else
X {
X ptr = (char *) realloc (ptr, size);
X }
X
X return ptr;
X}
X
X#if HAS_MNTTAB
X
X/*
X * getDiskEntries
X *
X * For SysV.4, we open the file and call getmntent() repeatedly.
X *
X */
X
Xstatic int
XgetDiskEntries ()
X{
X FILE *f;
X int idx;
X struct mnttab mntEntry;
X
X
X if ((f = fopen (MOUNT_FILE, "r")) == (FILE *) NULL)
X {
X fprintf (stderr, "Unable to open: %s errno %d\n", MOUNT_FILE, errno);
X return -1;
X }
X
X while (getmntent (f, &mntEntry) == 0)
X {
X idx = diCount;
X ++diCount;
X diskInfo = (DiskInfo *) Realloc ((char *) diskInfo,
X sizeof (DiskInfo) * diCount);
X memset ((char *) &diskInfo [idx], '\0', sizeof (DiskInfo));
X strncpy (diskInfo [idx].special, mntEntry.mnt_special, SPEC_NAME_LEN);
X strncpy (diskInfo [idx].name, mntEntry.mnt_mountp, NAME_LEN);
X diskInfo [idx].ok = DI_BAD;
X
X if (debug > 0)
X {
X printf ("mnt:%s - %s\n", diskInfo [idx].name,
X diskInfo [idx].special);
X }
X }
X
X fclose (f);
X return 0;
X}
X
X#endif /* HAS_MNTTAB */
X
X#if HAS_SVR3_MNTTAB
X
X/*
X * getDiskEntries
X *
X * For SysV.3 we open the file and read it ourselves.
X *
X */
X
Xstatic int
XgetDiskEntries ()
X{
X FILE *f;
X int idx;
X struct mnttab mntEntry;
X
X
X if ((f = fopen (MOUNT_FILE, "r")) == (FILE *) NULL)
X {
X fprintf (stderr, "Unable to open: %s errno %d\n", MOUNT_FILE, errno);
X return -1;
X }
X
X while (fread ((char *) &mntEntry, sizeof (struct mnttab), 1, f) == 1)
X {
X idx = diCount;
X ++diCount;
X diskInfo = (DiskInfo *) Realloc ((char *) diskInfo,
X sizeof (DiskInfo) * diCount);
X memset ((char *) &diskInfo [idx], '\0', sizeof (DiskInfo));
X strncpy (diskInfo [idx].special, mntEntry.mt_dev, SPEC_NAME_LEN);
X strncpy (diskInfo [idx].name, mntEntry.mt_filsys, NAME_LEN);
X diskInfo [idx].ok = DI_BAD;
X
X if (debug > 0)
X {
X printf ("mnt:%s - %s\n", diskInfo [idx].name,
X diskInfo [idx].special);
X }
X }
X
X fclose (f);
X return 0;
X}
X
X#endif /* HAS_MNTTAB */
X
X#if HAS_MNTENT
X
X/*
X * getDiskEntries
X *
X * SunOS supplies an open and close routine for the mount table.
X *
X */
X
Xstatic int
XgetDiskEntries ()
X{
X FILE *f;
X int idx;
X struct mntent *mntEntry;
X
X
X if ((f = setmntent (MOUNT_FILE, "r")) == (FILE *) NULL)
X {
X fprintf (stderr, "Unable to open: %s errno %d\n", MOUNT_FILE, errno);
X return -1;
X }
X
X while ((mntEntry = getmntent (f)) != (struct mntent *) NULL)
X {
X idx = diCount;
X ++diCount;
X diskInfo = (DiskInfo *) Realloc ((char *) diskInfo,
X sizeof (DiskInfo) * diCount);
X memset ((char *) &diskInfo [idx], '\0', sizeof (DiskInfo));
X strncpy (diskInfo [idx].special, mntEntry->mnt_fsname, SPEC_NAME_LEN);
X strncpy (diskInfo [idx].name, mntEntry->mnt_dir, NAME_LEN);
X diskInfo [idx].ok = DI_BAD;
X
X if (debug > 0)
X {
X printf ("mnt:%s - %s\n", diskInfo [idx].name,
X diskInfo [idx].special);
X }
X }
X
X endmntent (f);
X return 0;
X}
X
X#endif /* HAS_MNTENT */
X
X
X#if HAS_STATVFS
X
X/*
X * getDiskInfo
X *
X * SysV.4. statvfs() returns both the free and available blocks.
X *
X */
X
Xstatic int
XgetDiskInfo ()
X{
X int i;
X int rc;
X double mult;
X struct statvfs statBuf;
X
X for (i = 0; i < diCount; ++i)
X {
X if (statvfs (diskInfo [i].name, &statBuf) == 0)
X {
X mult = (double) statBuf.f_frsize / ONE_K;
X diskInfo [i].totalBlocks =
X (_ulong) ((double) statBuf.f_blocks * mult);
X diskInfo [i].freeBlocks =
X (_ulong) ((double) statBuf.f_bfree * mult);
X diskInfo [i].availBlocks =
X (_ulong) ((double) statBuf.f_bavail * mult);
X diskInfo [i].totalInodes = statBuf.f_files;
X diskInfo [i].freeInodes = statBuf.f_ffree;
X diskInfo [i].availInodes = statBuf.f_favail;
X strcpy (diskInfo [i].fsType, statBuf.f_basetype);
X diskInfo [i].ok = diskInfo [i].totalBlocks > 0L ? DI_OK : DI_ZERO;
X
X if (debug > 0)
X {
X printf ("%s: %s\n", diskInfo [i].name, diskInfo [i].fsType);
X printf ("\tmult:%f\n", mult);
X printf ("\tbsize:%ld frsize:%ld\n", statBuf.f_bsize,
X statBuf.f_frsize);
X printf ("\tblocks: tot:%ld free:%ld avail:%ld\n",
X diskInfo [i].totalBlocks, diskInfo [i].freeBlocks,
X diskInfo [i].availBlocks);
X printf ("\tinodes: tot:%ld free:%ld avail:%ld\n",
X diskInfo [i].totalInodes, diskInfo [i].freeInodes,
X diskInfo [i].availInodes);
X }
X } /* if we got the info */
X } /* for each entry */
X}
X
X#endif /* HAS_STATVFS */
X
X
X#if HAS_STATFS
X
X/*
X * getDiskInfo
X *
X * SunOS/BSD
X *
X */
X
Xstatic int
XgetDiskInfo ()
X{
X int i;
X int rc;
X double mult;
X struct statfs statBuf;
X
X for (i = 0; i < diCount; ++i)
X {
X if (statfs (diskInfo [i].name, &statBuf) == 0)
X {
X mult = (double) statBuf.f_bsize / ONE_K;
X diskInfo [i].totalBlocks =
X (_ulong) ((double) statBuf.f_blocks * mult);
X diskInfo [i].freeBlocks =
X (_ulong) ((double) statBuf.f_bfree * mult);
X diskInfo [i].availBlocks =
X (_ulong) ((double) statBuf.f_bfree * mult);
X diskInfo [i].totalInodes = statBuf.f_files;
X diskInfo [i].freeInodes = statBuf.f_ffree;
X diskInfo [i].availInodes = statBuf.f_ffree;
X#if HAS_SYSFS
X sysfs (GETFSTYP, statBuf.f_fstyp, diskInfo [i].fsType);
X#endif
X diskInfo [i].ok = diskInfo [i].totalBlocks > 0L ? DI_OK : DI_ZERO;
X
X if (debug > 0)
X {
X printf ("%s: %s\n", diskInfo [i].name, diskInfo [i].fsType);
X printf ("\tmult:%f\n", mult);
X printf ("\tbsize:%ld frsize:%ld\n", statBuf.f_bsize,
X statBuf.f_bsize);
X printf ("\tblocks: tot:%ld free:%ld avail:%ld\n",
X diskInfo [i].totalBlocks, diskInfo [i].freeBlocks,
X diskInfo [i].availBlocks);
X printf ("\tinodes: tot:%ld free:%ld avail:%ld\n",
X diskInfo [i].totalInodes, diskInfo [i].freeInodes,
X diskInfo [i].availInodes);
X }
X } /* if we got the info */
X } /* for each entry */
X}
X
X#endif /* HAS_STATFS */
X
X#if HAS_SYSV_STATFS
X
X/*
X * getDiskInfo
X *
X * SysV.3. We don't have available blocks; just set it to free blocks.
X * The sysfs() call is used to get the disk type name.
X *
X */
X
Xstatic int
XgetDiskInfo ()
X{
X int i;
X int rc;
X double mult;
X struct statfs statBuf;
X
X for (i = 0; i < diCount; ++i)
X {
X if (statfs (diskInfo [i].name, &statBuf, sizeof (statBuf), 0) == 0)
X {
X mult = (double) UBSIZE / ONE_K;
X diskInfo [i].totalBlocks =
X (_ulong) ((double) statBuf.f_blocks * mult);
X diskInfo [i].freeBlocks =
X (_ulong) ((double) statBuf.f_bfree * mult);
X diskInfo [i].availBlocks =
X (_ulong) ((double) statBuf.f_bfree * mult);
X diskInfo [i].totalInodes = statBuf.f_files;
X diskInfo [i].freeInodes = statBuf.f_ffree;
X diskInfo [i].availInodes = statBuf.f_ffree;
X#if HAS_SYSFS
X sysfs (GETFSTYP, statBuf.f_fstyp, diskInfo [i].fsType);
X#endif
X diskInfo [i].ok = diskInfo [i].totalBlocks > 0L ? DI_OK : DI_ZERO;
X
X if (debug > 0)
X {
X printf ("%s: %s\n", diskInfo [i].name, diskInfo [i].fsType);
X printf ("\tmult:%f\n", mult);
X printf ("\tbsize:%ld frsize:%ld\n", statBuf.f_bsize,
X statBuf.f_frsize);
X printf ("\tblocks: tot:%ld free:%ld avail:%ld\n",
X diskInfo [i].totalBlocks, diskInfo [i].freeBlocks,
X diskInfo [i].availBlocks);
X printf ("\tinodes: tot:%ld free:%ld avail:%ld\n",
X diskInfo [i].totalInodes, diskInfo [i].freeInodes,
X diskInfo [i].availInodes);
X }
X } /* if we got the info */
X } /* for each entry */
X}
X
X#endif /* HAS_STATFS */
X
END-of-di.c
echo x - Makefile.di
sed 's/^X//' >Makefile.di << 'END-of-Makefile.di'
X#
X# di makefile
X#
X# Copyright 1994 Brad Lanam
X#
X# select:
X# one of
X# HAS_MNTTAB (SysV.4, Solaris)
X# HAS_SVR3_MNTTAB (SysV.3)
X# HAS_MNTENT (SunOS)
X# one of
X# HAS_STATVFS (SysV.4, Solaris)
X# HAS_STATFS (SunOS)
X# HAS_SYSV_STATFS (SysV.3)
X# other
X# NEED_GETOPT_DEFS
X# HAS_SYSFS (SysV.3)
X#
X
XSHELL = /bin/sh
XCC = cc
X
X# sys v.4
XCFLAGS = -Xc -O -DHAS_STATVFS=1 -DHAS_MNTTAB=1
X#CFLAGS = -g -DHAS_SYSV_STATFS=1 -DHAS_MNTTAB=1 -DHAS_SYSFS=1
X
X# sun
X#CFLAGS = -O -DHAS_STATFS=1 -DHAS_MNTENT=1 -DNEED_GETOPT_DEFS=1
X
X# sys v.3
X#CFLAGS = -O -DHAS_SYSV_STATFS=1 -DHAS_SVR3_MNTTAB=1 \
X# -DHAS_SYSFS=1 -DNEED_GETOPT_DEFS=1
X
XLDFLAGS =
X
XSTRIP = strip
XMCS = mcs -d
XINSTALL = /usr/ucb/install
XUSER = root
XGROUP = bin
XINSTDIR = /var/local/bin
X
Xall: di
X
Xclean:
X rm -f di di.o
X
Xinstall:
X $(STRIP) di
X $(MCS) di
X $(INSTALL) -o $(USER) -g $(GROUP) -m 4111 di $(INSTDIR)
X
Xdi: di.o
X $(CC) $(LDFLAGS) -o di di.o
X
Xdi.o: di.c
END-of-Makefile.di
exit

--
Until the next disk seek...
-- Brad Lanam b...@gentoo.com ...!netcom!seer!bll

0 new messages