2 # This is a shell archive. Remove anything before this line, then unpack
3 # it by saving it into a file and typing "sh file". To overwrite existing
4 # files, type "sh file -c". You can also feed this as standard input via
5 # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
6 # will see the following message at the end:
7 # "End of archive 2 (of 3)."
9 # Wrapped by root@seer on Thu Feb 24 10:15:51 2000
10 PATH=/bin:/usr/bin:/usr/ucb ; export PATH
11 if test -f 'di.c' -a "${1}" != "-c" ; then
12 echo shar: Will not clobber existing file \"'di.c'\"
14 echo shar: Extracting \"'di.c'\" \(97566 characters\)
15 sed "s/^X//" >'di.c' <<'END_OF_FILE'
17 Xstatic char di_c_sccsid [] =
19 Xstatic char di_c_rcsid [] =
21 Xstatic char di_c_source [] =
23 Xstatic char copyright [] =
24 X"Copyright 1994-1999 Brad Lanam, Walnut Creek, CA";
30 X * Copyright 1994-1999 Brad Lanam, Walnut Creek, CA
32 X * Warning: Do not replace your systems 'df' command with this program.
33 X * You will in all likelihood break your installation procedures.
35 X * Usage: di -AafntwWx [file [...]]
36 X * -A : print all fields (used for debugging)
37 X * -a : print all mounted devices; normally, those
38 X * with 0 total blocks are not printed. e.g.
39 X * /dev/proc, /dev/fd.
40 X * -d x : size to print blocks in (p, k, m, g, <n>)
41 X * -f x : use format string <x>
42 X * -i x : ignore filesystem type(s) x, where x is a comma
44 X * -I x : include only filesystem type(s) x, where x is a
46 X * -l : local filesystems only
47 X * -n : don't print header
50 X * -w n : use <n> for the block print width (default 8).
51 X * -W n : use <n> for the inode print width (default 7).
52 X * -x n : debug level <n>
54 X * All values are reported in K (1024 bytes).
56 X * Sort types (by name is default):
57 X * n - none (mount order)
61 X * Format string values:
63 X * M - mount point, full length
65 X * B - total kbytes available for use by the user.
66 X * [ (tot - (free - avail) ]
67 X * u - kbytes used (actual number of kbytes used) [ (tot - free) ]
68 X * c - calculated number of kbytes used [ (tot - avail) ]
70 X * v - kbytes available
71 X * p - percentage not available for use.
72 X * (number of blocks not available for use / total disk space)
73 X * [ (tot - avail) / tot ]
74 X * 1 - percentage used.
75 X * (actual number of blocks used / total disk space)
76 X * [ (tot - free) / tot ]
77 X * 2 - percentage of user-available space in use (bsd style).
78 X * Note that values over 100% are possible.
79 X * (actual number of blocks used / disk space available to user)
80 X * [ (tot - free) / (tot - (free - avail)) ]
81 X * i - total i-nodes (files)
84 X * P - percent i-nodes used [ (tot - avail) / tot ]
85 X * s - filesystem name (special)
86 X * S - filesystem name (special), full length
87 X * t - disk partition type
88 X * T - disk partition type (full length)
90 X * O - mount options.
92 X * System V.4 `/usr/bin/df -v` Has format: msbuf1 (w/-d512 option: 512 byte blocks)
93 X * System V.4 `/usr/bin/df -k` Has format: sbcvpm
94 X * System V.4 `/usr/ucb/df` Has format: sbuv2m
96 X * The default format string for this program is: smbuvpT
98 X * The environment variable "DIFMT" may be set to the desired format
101 X * Note that for filesystems that do not have (S512K fs) or systems (SysV.3)
102 X * that do not report available blocks, the number of available blocks is
103 X * equal to the number of free blocks.
107 X * Updated for BeOS. This required changes to support c++
108 X * compilation (ansi style functions). Fixes for linux.
110 X * Added sys/fs_types.h (Digital Unix (tru64)).
112 X * Finalize changes for metaconfig.
113 X * Always get stat() for disk device.
114 X * Remove duplicate disks from display.
115 X * Add NetBSD, Unicos, IRIX changes
117 X * Solaris large file version; AIX typo fix
119 X * Ignore will check the file system type beforehand if possible.
120 X * Fixed local mount stuff for osf1.
122 X * Changed totals to use double; the totals can now be displayed with
123 X * any wanted block size; sizes > one k have a single decimal point.
124 X * -d option specifies block size.
125 X * -l option for local file systems only.
129 X * Fixed bsdi variants. The fragment size wasn't being supported.
131 X * fix problem with display widths in conjunction with ignore/include
133 X * added ignore/include file system type lists.
135 X * Added FreeBsd 2.x
137 X * sco nfs 'nothing' fix.
139 X * bsdi [bag@clipper.cs.kiev.ua (Andrey Blochintsev)]
141 X * Added FreeBsd - like OSF/1, but w/o nice mount name table.
143 X * removed ill conceived mount options stuff. Added AIX
144 X * (Erik O'Shaughnessy eriko@risc.austin.ibm.com).
147 X * T format from Bill Davidsen. SunOS file system type.
150 X * cdrom under solaris returning -1 in addition to -2.
151 X * Changed the test to test for any negative value.
153 X * Filesystem type info, and whether its read-write, readonly
154 X * etc is in the mntent structure. Added code to support it.
155 X * [Pat Myrto <pat@rwing.uucp>]
157 X * sun had f_bfree instead of f_bavail!
159 X * -w, -W options, -B option, fixed width for -f M, -f S.
160 X * Usage. Allow other characters in format string.
162 X * -f B, bug fixes. bcopy.
163 X * Solaris cdrom reports total, not free or avail.
164 X * Allow command line specification of file names.
166 X * support for OSF/1 and ULTRIX, -F, -f M, -f S
167 X * [mogul@wrl.dec.com (Jeffrey Mogul)]
169 X * Allow command line specification of filename (s).
170 X * Sort output. Test of nonexistent return code removed.
172 X * # of inodes can be -1L if unreportable.
173 X * [jjb@jagware.bcc.com (J.J.Bailey)]
174 X * [Mark Neale <mark@edscom.demon.co.uk>]
175 X * getDiskInfo () returning garbage
176 X * [costales@ICSI.Berkeley.EDU (Bryan Costales)]
177 X * [Mark Neale <mark@edscom.demon.co.uk>]
179 X * [vogelke@c-17igp.wpafb.af.mil (Contr Karl Vogel)]
180 X * name must be maxpathlen
181 X * [Mark Neale <mark@edscom.demon.co.uk>]
182 X * error prints/compile warnings.
183 X * [Mark Neale <mark@edscom.demon.co.uk>]
192 X#if defined (I_STDLIB)
193 X# include <stdlib.h>
195 X#if defined (I_SYS_TYPES)
196 X# include <sys/types.h>
198 X#if defined (I_LIMITS)
199 X# include <limits.h>
201 X#if defined (I_STRING)
202 X# include <string.h>
204 X# include <strings.h>
206 X#if defined (I_MEMORY)
207 X# include <memory.h>
209 X#if defined (I_MALLOC)
210 X# include <malloc.h>
212 X#if defined (I_UNISTD)
213 X# include <unistd.h>
215 X#if defined (I_TIME)
218 X#if defined (I_SYS_TIME)
219 X# include <sys/time.h>
221 X#if defined (I_SYS_STAT)
222 X# include <sys/stat.h>
224 X#if defined (I_SYS_PARAM)
225 X# include <sys/param.h>
228 X#if defined (I_SYS_MNTTAB)
229 X# include <sys/mnttab.h>
231 X#if defined (I_MNTTAB)
232 X# include <mnttab.h>
234 X#if defined (I_MNTENT)
235 X# include <mntent.h>
237 X#if defined (I_SYS_MNTENT)
238 X# include <sys/mntent.h>
240 X#if defined (I_SYS_MOUNT)
241 X# include <sys/mount.h>
243 X#if defined (I_SYS_FSTYPES)
244 X# include <sys/fstypes.h>
246 X#if defined (I_SYS_FS_TYPES)
247 X# include <sys/fs_types.h>
249 X#if defined (I_SYS_MNTCTL)
250 X# include <sys/mntctl.h>
252 X#if defined (I_SYS_VMOUNT)
253 X# include <sys/vmount.h>
255 X#if defined (I_SYS_STATFS) && ! defined (I_SYS_STATVFS)
256 X# include <sys/statfs.h>
258 X#if defined (I_FSHELP)
259 X# include <fshelp.h>
261 X#if defined (I_SYS_STATVFS)
262 X# include <sys/statvfs.h>
264 X#if defined (I_SYS_FSTYP)
265 X# include <sys/fstyp.h>
266 X# define DI_TYPE_LEN FSTYPSZ
268 X#if defined (I_SYS_VFS)
269 X# include <sys/vfs.h>
271 X#if defined (I_SYS_VFSTAB)
272 X# include <sys/vfstab.h>
273 X# if ! defined (DI_TYPE_LEN)
274 X# define DI_TYPE_LEN FSTYPSZ
277 X#if defined (I_FSHELP)
278 X# include <fshelp.h>
281 X#if defined (I_WINDOWS)
282 X# include <windows.h> /* windows */
284 X#if defined (I_KERNFSINFO)
285 X# include <kernel/fs_info.h>
287 X#if defined (I_STOR_DIRECTORY)
288 X# include <storage/Directory.h>
290 X#if defined (I_STOR_ENTRY)
291 X# include <storage/Entry.h>
293 X/*#if defined (I_STOR_NODE)
294 X# include <storage/Node.h>
296 X#if defined (I_STOR_PATH)
297 X# include <storage/Path.h>
300 X#if ! defined (HAS_MEMCPY) && ! defined (memcpy)
301 X# if ! defined (HAS_BCOPY)
302 X error No memcpy/bcopy available.
304 X# define memcpy(dst, src, cnt) (bcopy((src), (dst), (cnt)), dst)
308 X#if ! defined (MAXPATHLEN)
309 X# if defined (_POSIX_PATH_MAX)
310 X# define MAXPATHLEN _POSIX_PATH_MAX
312 X# if defined (PATH_MAX)
313 X# define MAXPATHLEN PATH_MAX
315 X# if defined (LPNMAX)
316 X# define MAXPATHLEN LPNMAX
321 X#if ! defined (DI_TYPE_LEN)
322 X# define DI_TYPE_LEN 16
325 X#define DI_FSMAGIC 5 /* base AIX configuration has 5 file systems */
327 X#if defined (HAS_STATFS_SYSV3) && ! defined (HAS_STATVFS) && \
328 X ! defined (HAS_GETMNTINFO) && ! defined (HAS_GETMNT) /* SYSV.3 */
329 X# if defined (Ubsize) && Ubsize != ""
330 X# define UBSIZE Ubsize
332 X# if ! defined (UBSIZE)
337 X#if (defined (HAS_GETMNTENT) || defined (HAS_STATFS_BSD) || \
338 X defined (HAS_STATFS_SYSV3)) && ! defined (HAS_GETMNTINFO) && \
339 X ! defined (HAS_GETMNT)
340 X# if defined (MOUNTED)
341 X# define DI_MOUNT_FILE MOUNTED
343 X# if defined (MNTTAB)
344 X# define DI_MOUNT_FILE MNTTAB
346 X# define DI_MOUNT_FILE "/etc/mnttab"
351 X#if ! defined (HAS_MEMSET) && ! defined (memset)
352 X# if ! defined (HAS_BZERO)
353 X error No memset/bzero available.
355 X# define memset(s,c,n) (bzero ((s), (n)), s)
359 X#if defined (NEED_GETENV_DEF)
360 X extern char *getenv _((char *));
363 X#if defined (NEED_STATFS_DEFS)
364 X extern int statfs _((char *, struct statfs *));
367 X#if defined (NEED_ERRNO_DEFS)
371 X#if (defined (_LARGEFILE_SOURCE) || defined (_LARGEFILE64_SOURCE)) && \
372 X _FILE_OFFSET_BITS == 64
373 X# define HAS_64BIT_STATFS_FLDS 1
376 X#if defined (HAS_64BIT_STATFS_FLDS)
377 Xtypedef unsigned long long _fs_size_t;
378 Xtypedef long long _s_fs_size_t;
380 Xtypedef unsigned long _fs_size_t;
381 Xtypedef long _s_fs_size_t;
384 X#if ! defined (HAS_OPTIND)
386 X extern char *optarg;
389 X/* end of system specific includes/configurations */
391 X#if ! defined (TRUE)
394 X#if ! defined (FALSE)
398 X#define DI_F_ALL 0x00000001
399 X#define DI_F_LOCAL_ONLY 0x00000002
400 X#define DI_F_TOTAL 0x00000010
401 X#define DI_F_NO_HEADER 0x00000020
402 X#define DI_F_DEBUG_HDR 0x00000040
404 X /* mount information */
405 X#define DI_FMT_MOUNT 'm'
406 X#define DI_FMT_MOUNT_FULL 'M'
407 X#define DI_FMT_SPECIAL 's'
408 X#define DI_FMT_SPECIAL_FULL 'S'
409 X#define DI_FMT_TYPE 't'
410 X#define DI_FMT_TYPE_FULL 'T'
412 X /* disk information */
413 X#define DI_FMT_BTOT 'b'
414 X#define DI_FMT_BTOT_AVAIL 'B'
415 X#define DI_FMT_BUSED 'u'
416 X#define DI_FMT_BCUSED 'c'
417 X#define DI_FMT_BFREE 'f'
418 X#define DI_FMT_BAVAIL 'v'
419 X#define DI_FMT_BPERC_AVAIL 'p'
420 X#define DI_FMT_BPERC_FREE '1'
421 X#define DI_FMT_BPERC_BSD '2'
422 X#define DI_FMT_ITOT 'i'
423 X#define DI_FMT_IUSED 'U'
424 X#define DI_FMT_IFREE 'F'
425 X#define DI_FMT_IPERC 'P'
426 X#define DI_FMT_MOUNT_TIME 'I'
427 X#define DI_FMT_MOUNT_OPTIONS 'O'
433 X#define DI_SORT_NONE 0
434 X#define DI_SORT_NAME 1
435 X#define DI_SORT_SPECIAL 2
437 X#define DI_SORT_ASCENDING 1
438 X#define DI_SORT_DESCENDING -1
440 X#define DI_UNKNOWN_DEV -1L
441 X#define DI_LIST_SEP ","
443 X#define DI_ALL_FORMAT "MTS\n\tIO\n\tbuf1\n\tbcvp\n\tBuv2\n\tiUFP"
445 X#define DI_HALF_K 512.0
446 X#define DI_ONE_K 1024.0
447 X#define DI_ONE_MEG 1048576.0
448 X#define DI_ONE_GIG 1073241824.0
450 X#if ! defined (MAXPATHLEN)
451 X# define MAXPATHLEN 255
453 X#define DI_SPEC_NAME_LEN MAXPATHLEN
454 X#define DI_OPT_LEN MAXPATHLEN
455 X#define DI_MNT_TIME_LEN 24
457 X#define DI_RETRY_COUNT 5
458 X#define DI_MAX_REMOTE_TYPES 20
460 X /* you may want to change some of these values. Be sure to change all */
461 X /* related entries. */
462 X/* #define DI_DEFAULT_FORMAT "mbuvpiUFP" */
463 X#if ! defined (DI_DEFAULT_FORMAT)
464 X# define DI_DEFAULT_FORMAT "smbuvpT"
466 X#if defined (HAS_MNT_TIME)
467 X# define DI_DEF_MOUNT_FORMAT "MSTIO"
469 X# define DI_DEF_MOUNT_FORMAT "MSTO"
471 X#define DI_PERC_FMT "%3.0f%% "
472 X#define DI_PERC_LBL_FMT "%5s"
473 X#define DI_NAME_LEN MAXPATHLEN
474 X#define DI_FSTYPE_FMT "%-7.7s"
475 X#define DI_MOUNT_FMT "%-15.15s"
476 X#define DI_SPEC_FMT "%-18.18s"
478 X#define DI_UNKNOWN_FSTYPE "Unknown fstyp %.2d"
480 Xtypedef unsigned long _ulong;
481 Xtypedef int (*DI_SORT_FUNC) _((char *, char *));
485 X double totalBlocks;
487 X double availBlocks;
488 X _fs_size_t totalInodes;
489 X _fs_size_t freeInodes;
490 X _fs_size_t availInodes;
491 X _ulong st_dev; /* disk device number */
492 X _ulong sp_dev; /* special device number*/
493 X _ulong sp_rdev; /* special rdev # */
494 X char printFlag; /* do we want to print */
496 X char isLocal; /* is this mount point */
498 X char name [DI_NAME_LEN + 1]; /* mount point */
499 X char special [DI_SPEC_NAME_LEN + 1]; /* special device name */
500 X char fsType [DI_TYPE_LEN + 1]; /* type of file system */
501 X char options [DI_OPT_LEN + 1];
502 X char mountTime [DI_MNT_TIME_LEN + 1];
505 Xstatic DiskInfo *diskInfo = { (DiskInfo *) NULL };
506 Xstatic int diCount = { 0 };
507 Xstatic int debug = { 0 };
508 Xstatic _ulong flags = { 0 };
509 Xstatic int sortType = { DI_SORT_NAME };
510 Xstatic int sortOrder = { DI_SORT_ASCENDING };
511 Xstatic char *formatString = { DI_DEFAULT_FORMAT };
512 Xstatic char mountFormat [20];
513 X static char specialFormat [20];
514 Xstatic char typeFormat [20];
515 Xstatic char optFormat [20];
516 Xstatic char mTimeFormat [20];
517 Xstatic int width = { 8 };
518 Xstatic int inodeWidth = { 7 };
519 Xstatic char blockFormat [20];
520 Xstatic char blockLabelFormat [20];
521 Xstatic char inodeFormat [20];
522 Xstatic char inodeLabelFormat [20];
523 Xstatic char **ignoreList = { (char **) NULL };
524 Xstatic char **includeList = { (char **) NULL };
525 Xstatic double dispBlockSize = { DI_ONE_MEG };
526 Xstatic int remoteFileSystemCount = { 0 };
527 Xstatic char remoteFileSystemTypes [DI_MAX_REMOTE_TYPES][DI_TYPE_LEN];
530 Xstatic void cleanup _((void));
531 Xstatic void printDiskInfo _((void));
532 Xstatic void printInfo _((DiskInfo *));
533 Xstatic void addTotals _((DiskInfo *, DiskInfo *));
534 Xstatic void printTitle _((void));
535 Xstatic void printPerc _((double, double, char *));
536 Xstatic char *Realloc _((char *, long));
537 Xstatic void sortArray _((char *, int, int, DI_SORT_FUNC));
538 Xstatic int diCompare _((char *, char *));
539 Xstatic void getDiskStatInfo _((void));
540 Xstatic void getDiskSpecialInfo _((void));
541 Xstatic void printFileInfo _((int, int, char *[]));
542 Xstatic void checkDiskInfo _((void));
543 Xstatic void usage _((void));
544 Xstatic void processArgs _((int, char *[]));
545 Xstatic void parseList _((char ***, char *));
546 Xstatic void checkIgnoreList _((DiskInfo *));
547 Xstatic void checkIncludeList _((DiskInfo *));
549 Xstatic int getDiskEntries _((void));
550 Xstatic void getDiskInfo _((void));
553 X#if defined (CAN_PROTOTYPE)
554 Xmain (int argc, char *argv [])
564 X ptr = argv [0] + strlen (argv [0]) - 2;
565 X if (memcmp (ptr, MPROG, 2) == 0)
567 X formatString = DI_DEF_MOUNT_FORMAT;
569 X else /* don't use DIFMT env var if running mi. */
571 X if ((ptr = getenv ("DIFMT")) != (char *) NULL)
573 X formatString = ptr;
577 X processArgs (argc, argv);
580 X printf ("di ver $Revision$\n");
583 X if (getDiskEntries () < 0)
590 X getDiskSpecialInfo ();
594 X getDiskStatInfo ();
595 X printFileInfo (optind, argc, argv);
609 X * free up allocated memory
614 X#if defined (CAN_PROTOTYPE)
623 X if (diskInfo != (DiskInfo *) NULL)
625 X free ((char *) diskInfo);
628 X if (ignoreList != (char **) NULL)
631 X while (*lptr != (char *) NULL)
633 X free ((char *) *lptr);
636 X free ((char *) ignoreList);
639 X if (includeList != (char **) NULL)
641 X lptr = includeList;
642 X while (*lptr != (char *) NULL)
644 X free ((char *) *lptr);
647 X free ((char *) includeList);
654 X * Print out the disk information table.
655 X * Loops through all mounted disks, prints and calculates totals.
660 X#if defined (CAN_PROTOTYPE)
661 XprintDiskInfo (void)
670 X memset ((char *) &totals, '\0', sizeof (DiskInfo));
671 X strcpy (totals.name, "Total");
672 X totals.printFlag = DI_OK;
674 X if ((flags & DI_F_NO_HEADER) != DI_F_NO_HEADER)
679 X if (sortType != DI_SORT_NONE)
681 X sortArray ((char *) diskInfo, sizeof (DiskInfo), diCount, diCompare);
684 X for (i = 0; i < diCount; ++i)
686 X if (( (flags & DI_F_ALL) == DI_F_ALL &&
687 X diskInfo [i].printFlag != DI_BAD) ||
688 X diskInfo [i].printFlag == DI_OK)
690 X printInfo (&diskInfo [i]);
691 X addTotals (&diskInfo [i], &totals);
695 X if ((flags & DI_F_TOTAL) == DI_F_TOTAL &&
696 X (flags & DI_F_NO_HEADER) != DI_F_NO_HEADER)
698 X printInfo (&totals);
705 X * Print the information for a single partition. Loop through the
706 X * format string and print the particular items wanted.
711 X#if defined (CAN_PROTOTYPE)
712 XprintInfo (DiskInfo *diskInfo)
714 XprintInfo (diskInfo)
715 X DiskInfo *diskInfo;
724 X ptr = formatString;
733 X printf (DI_MOUNT_FMT, diskInfo->name);
737 X case DI_FMT_MOUNT_FULL:
739 X printf (mountFormat, diskInfo->name);
745 X printf (blockFormat, diskInfo->totalBlocks);
749 X case DI_FMT_BTOT_AVAIL:
751 X printf (blockFormat, diskInfo->totalBlocks -
752 X (diskInfo->freeBlocks - diskInfo->availBlocks));
758 X printf (blockFormat, diskInfo->totalBlocks -
759 X diskInfo->freeBlocks);
763 X case DI_FMT_BCUSED:
765 X printf (blockFormat, diskInfo->totalBlocks - diskInfo->availBlocks);
771 X printf (blockFormat, diskInfo->freeBlocks);
775 X case DI_FMT_BAVAIL:
777 X printf (blockFormat, diskInfo->availBlocks);
781 X case DI_FMT_BPERC_AVAIL:
783 X used = diskInfo->totalBlocks - diskInfo->availBlocks;
784 X totAvail = diskInfo->totalBlocks;
785 X printPerc (used, totAvail, DI_PERC_FMT);
789 X case DI_FMT_BPERC_FREE:
791 X used = diskInfo->totalBlocks - diskInfo->freeBlocks;
792 X totAvail = diskInfo->totalBlocks;
793 X printPerc (used, totAvail, DI_PERC_FMT);
797 X case DI_FMT_BPERC_BSD:
799 X used = diskInfo->totalBlocks - diskInfo->freeBlocks;
800 X totAvail = diskInfo->totalBlocks -
801 X (diskInfo->freeBlocks - diskInfo->availBlocks);
802 X printPerc (used, totAvail, DI_PERC_FMT);
808 X printf (inodeFormat, diskInfo->totalInodes);
814 X printf (inodeFormat, diskInfo->totalInodes - diskInfo->freeInodes);
820 X printf (inodeFormat, diskInfo->freeInodes);
826 X used = diskInfo->totalInodes - diskInfo->availInodes;
827 X totAvail = diskInfo->totalInodes;
828 X printPerc (used, totAvail, DI_PERC_FMT);
832 X case DI_FMT_SPECIAL:
834 X printf (DI_SPEC_FMT, diskInfo->special);
838 X case DI_FMT_SPECIAL_FULL:
840 X printf (specialFormat, diskInfo->special);
846 X printf (DI_FSTYPE_FMT, diskInfo->fsType);
850 X case DI_FMT_TYPE_FULL:
852 X printf (typeFormat, diskInfo->fsType);
856 X case DI_FMT_MOUNT_OPTIONS:
858 X printf (optFormat, diskInfo->options);
862 X case DI_FMT_MOUNT_TIME:
864 X#if defined (HAS_MNT_TIME)
865 X printf (mTimeFormat, diskInfo->mountTime);
872 X printf ("%c", *ptr);
891 X * Add up the totals for the blocks/inodes
896 X#if defined (CAN_PROTOTYPE)
897 XaddTotals (DiskInfo *diskInfo, DiskInfo *totals)
899 XaddTotals (diskInfo, totals)
900 X DiskInfo *diskInfo;
904 X totals->totalBlocks += diskInfo->totalBlocks;
905 X totals->freeBlocks += diskInfo->freeBlocks;
906 X totals->availBlocks += diskInfo->availBlocks;
907 X totals->totalInodes += diskInfo->totalInodes;
908 X totals->freeInodes += diskInfo->freeInodes;
909 X totals->availInodes += diskInfo->availInodes;
915 X * Loop through the format string and print the appropriate headings.
920 X#if defined (CAN_PROTOTYPE)
930 X if ((flags & DI_F_DEBUG_HDR) == DI_F_DEBUG_HDR)
932 X printf ("di ver $Revision$ Default Format: %s\n",
933 X DI_DEFAULT_FORMAT);
936 X ptr = formatString;
946 X printf (DI_MOUNT_FMT, "Mount");
950 X case DI_FMT_MOUNT_FULL:
952 X printf (mountFormat, "Mount");
957 X case DI_FMT_BTOT_AVAIL:
959 X if (dispBlockSize == DI_ONE_K)
961 X printf (blockLabelFormat, "Kbytes");
963 X else if (dispBlockSize == DI_ONE_MEG)
965 X printf (blockLabelFormat, " Megs");
967 X else if (dispBlockSize == DI_ONE_GIG)
969 X printf (blockLabelFormat, " Gigs");
971 X else if (dispBlockSize == DI_HALF_K)
973 X printf (blockLabelFormat, " 512b");
977 X sprintf (tbuff, "%6.0f", dispBlockSize);
978 X printf (blockLabelFormat, tbuff);
984 X case DI_FMT_BCUSED:
986 X printf (blockLabelFormat, "Used");
992 X printf (blockLabelFormat, "Free");
996 X case DI_FMT_BAVAIL:
998 X printf (blockLabelFormat, "Avail");
1002 X case DI_FMT_BPERC_AVAIL:
1003 X case DI_FMT_BPERC_FREE:
1004 X case DI_FMT_BPERC_BSD:
1006 X printf (DI_PERC_LBL_FMT, "%used");
1012 X printf (inodeLabelFormat, "Inodes");
1016 X case DI_FMT_IUSED:
1018 X printf (inodeLabelFormat, "Used");
1022 X case DI_FMT_IFREE:
1024 X printf (inodeLabelFormat, "Free");
1028 X case DI_FMT_IPERC:
1030 X printf (DI_PERC_LBL_FMT, "%used");
1034 X case DI_FMT_SPECIAL:
1036 X printf (DI_SPEC_FMT, "Filesystem");
1040 X case DI_FMT_SPECIAL_FULL:
1042 X printf (specialFormat, "Filesystem");
1048 X printf (DI_FSTYPE_FMT, "fsType");
1052 X case DI_FMT_TYPE_FULL:
1054 X printf (typeFormat, "fs Type");
1058 X case DI_FMT_MOUNT_OPTIONS:
1060 X printf (optFormat, "Options");
1064 X case DI_FMT_MOUNT_TIME:
1066 X#if defined (HAS_MNT_TIME)
1067 X printf (mTimeFormat, "Mount Time");
1074 X printf ("%c", *ptr);
1081 X if (*ptr && valid)
1093 X * Calculate and print a percentage using the values and format passed.
1098 X#if defined (CAN_PROTOTYPE)
1099 XprintPerc (double used, double totAvail, char *format)
1101 XprintPerc (used, totAvail, format)
1110 X if (totAvail > 0.0)
1112 X perc = used / totAvail;
1119 X printf (format, perc);
1126 X * portable realloc
1131 X#if defined (CAN_PROTOTYPE)
1132 XRealloc (char *ptr, long size)
1134 XRealloc (ptr, size)
1139 X if (ptr == (char *) NULL)
1141 X ptr = (char *) malloc (size);
1145 X ptr = (char *) realloc (ptr, size);
1153 X#if defined (CAN_PROTOTYPE)
1154 XprintFileInfo (int optind, int argc, char *argv [])
1156 XprintFileInfo (optind, argc, argv)
1164 X struct stat statBuf;
1168 X memset ((char *) &totals, '\0', sizeof (DiskInfo));
1169 X strcpy (totals.name, "Total");
1170 X totals.printFlag = DI_OK;
1172 X if ((flags & DI_F_NO_HEADER) != DI_F_NO_HEADER)
1177 X for (i = optind; i < argc; ++i)
1179 X if (stat (argv [i], &statBuf) == 0)
1181 X for (j = 0; j < diCount; ++j)
1183 X if (diskInfo [j].printFlag != DI_BAD &&
1184 X diskInfo [j].st_dev != DI_UNKNOWN_DEV &&
1185 X (_ulong) statBuf.st_dev == diskInfo [j].st_dev)
1187 X printInfo (&diskInfo [j]);
1188 X addTotals (&diskInfo [j], &totals);
1189 X break; /* out of inner for */
1192 X } /* if stat ok */
1195 X fprintf (stderr, "stat: %s ", argv[i]);
1198 X } /* for each file specified on command line */
1200 X if ((flags & DI_F_TOTAL) == DI_F_TOTAL && (flags & DI_F_NO_HEADER) != DI_F_NO_HEADER)
1202 X printInfo (&totals);
1214 X#if defined (CAN_PROTOTYPE)
1215 XsortArray (char *data, int dataSize, int count, DI_SORT_FUNC compareFunc)
1217 XsortArray (data, dataSize, count, compareFunc)
1221 X DI_SORT_FUNC compareFunc;
1235 X tempData = (char *) malloc ((unsigned) dataSize);
1236 X if (tempData == (char *) NULL)
1238 X fprintf (stderr, "malloc failed in sortArray(). errno %d\n", errno);
1244 X while (gap < count)
1246 X gap = 3 * gap + 1;
1249 X for (gap /= 3; gap > 0; gap /= 3)
1251 X for (i = gap; i < count; ++i)
1253 X memcpy ((char *) tempData, (char *) &(data [i * dataSize]),
1258 X compareFunc (&(data [j * dataSize]), tempData) > 0)
1260 X memcpy ((char *) &(data [(j + gap) * dataSize]),
1261 X (char *) &(data [j * dataSize]), dataSize);
1268 X memcpy ((char *) &(data [j * dataSize]),
1269 X (char *) tempData, dataSize);
1274 X free ((char *) tempData);
1279 X#if defined (CAN_PROTOTYPE)
1280 XdiCompare (char *a, char *b)
1291 X di1 = (DiskInfo *) a;
1292 X di2 = (DiskInfo *) b;
1297 X case DI_SORT_NONE:
1302 X case DI_SORT_NAME:
1304 X return (strcmp (di1->name, di2->name) * sortOrder);
1307 X case DI_SORT_SPECIAL:
1309 X return (strcmp (di1->special, di2->special) * sortOrder);
1311 X } /* switch on sort type */
1320 X * gets the disk device number for each entry.
1325 X#if defined (CAN_PROTOTYPE)
1326 XgetDiskStatInfo (void)
1332 X struct stat statBuf;
1334 X for (i = 0; i < diCount; ++i)
1336 X diskInfo [i].st_dev = (_ulong) DI_UNKNOWN_DEV;
1338 X if (stat (diskInfo [i].name, &statBuf) == 0)
1340 X diskInfo [i].st_dev = (_ulong) statBuf.st_dev;
1343 X printf ("dev: %s: %ld\n", diskInfo [i].name,
1344 X diskInfo [i].st_dev);
1349 X fprintf (stderr, "stat: %s ", diskInfo [i].name);
1356 X * getDiskSpecialInfo
1358 X * gets the disk device number for each entry.
1363 X#if defined (CAN_PROTOTYPE)
1364 XgetDiskSpecialInfo (void)
1366 XgetDiskSpecialInfo ()
1370 X struct stat statBuf;
1372 X for (i = 0; i < diCount; ++i)
1374 X if (stat (diskInfo [i].special, &statBuf) == 0)
1376 X diskInfo [i].sp_dev = (_ulong) statBuf.st_dev;
1377 X diskInfo [i].sp_rdev = (_ulong) statBuf.st_rdev;
1380 X printf ("special dev: %s: %ld rdev: %ld\n", diskInfo [i].special,
1381 X diskInfo [i].sp_dev, diskInfo [i].sp_rdev);
1386 X diskInfo [i].sp_dev = 0;
1387 X diskInfo [i].sp_rdev = 0;
1395 X * checks the disk information returned for various return values.
1400 X#if defined (CAN_PROTOTYPE)
1401 XcheckDiskInfo (void)
1410 X int maxMountString;
1411 X int maxSpecialString;
1412 X int maxTypeString;
1414 X int maxMntTimeString;
1420 X maxMountString = (flags & DI_F_NO_HEADER) == DI_F_NO_HEADER ? 0 : 5;
1421 X maxSpecialString = (flags & DI_F_NO_HEADER) == DI_F_NO_HEADER ? 0 : 10;
1422 X maxTypeString = (flags & DI_F_NO_HEADER) == DI_F_NO_HEADER ? 0 : 7;
1423 X maxOptString = (flags & DI_F_NO_HEADER) == DI_F_NO_HEADER ? 0 : 7;
1424 X maxMntTimeString = (flags & DI_F_NO_HEADER) == DI_F_NO_HEADER ? 0 : 26;
1426 X for (i = 0; i < diCount; ++i)
1428 X /* Solaris reports a cdrom as having no free blocks, */
1429 X /* no available. Their df doesn't always work right! */
1430 X /* -1 is returned. */
1433 X printf ("chk: %s free: %f\n", diskInfo [i].name,
1434 X diskInfo [i].freeBlocks);
1436 X if (diskInfo [i].freeBlocks < 0.0)
1438 X diskInfo [i].freeBlocks = 0.0;
1440 X if (diskInfo [i].availBlocks < 0.0)
1442 X diskInfo [i].availBlocks = 0.0;
1446 X if (diskInfo [i].totalInodes == temp)
1448 X diskInfo [i].totalInodes = 0;
1449 X diskInfo [i].freeInodes = 0;
1450 X diskInfo [i].availInodes = 0;
1455 X printf ("chk: %s total: %f\n", diskInfo [i].name,
1456 X diskInfo [i].totalBlocks);
1458 X if (diskInfo [i].totalBlocks <= 0.0 &&
1459 X diskInfo [i].printFlag != DI_BAD)
1461 X diskInfo [i].printFlag = DI_IGNORE;
1464 X printf ("chk: ignore: totalBlocks <= 0: %s\n",
1465 X diskInfo [i].name);
1469 X checkIgnoreList (&diskInfo [i]);
1470 X checkIncludeList (&diskInfo [i]);
1471 X } /* for all disks */
1473 X /* this loop sets duplicate entries to be ignored. */
1474 X for (i = 0; i < diCount; ++i)
1476 X /* don't need to bother checking real partitions */
1477 X /* don't bother if already ignored */
1478 X if (diskInfo [i].sp_rdev != 0 &&
1479 X (diskInfo [i].printFlag == DI_OK ||
1480 X ((flags & DI_F_ALL) == DI_F_ALL &&
1481 X diskInfo [i].printFlag != DI_BAD)))
1483 X sp_dev = diskInfo [i].sp_dev;
1484 X sp_rdev = diskInfo [i].sp_rdev;
1487 X for (j = 0; j < diCount; ++j)
1489 X if (diskInfo [j].sp_dev == sp_rdev)
1497 X printf ("dup: chk: %s %ld %ld dup: %d\n", diskInfo [i].name,
1498 X sp_dev, sp_rdev, dupCount);
1501 X for (j = 0; dupCount > 0 && j < diCount; ++j)
1503 X if (diskInfo [j].sp_rdev == 0 &&
1504 X diskInfo [j].sp_dev == sp_rdev)
1506 X diskInfo [j].printFlag = DI_IGNORE;
1509 X printf ("chk: ignore: duplicate: %s\n",
1510 X diskInfo [j].name);
1513 X } /* duplicate check for each disk */
1514 X } /* if this is a printable disk */
1519 X printf ("chk: dup: not checked: %s prnt: %d dev: %ld rdev: %ld\n",
1520 X diskInfo [i].name, diskInfo [i].printFlag,
1521 X diskInfo [i].sp_dev, diskInfo [i].sp_rdev);
1524 X } /* for each disk */
1526 X /* this loop gets the max string lengths */
1527 X for (i = 0; i < diCount; ++i)
1529 X if (diskInfo [i].printFlag == DI_OK || (flags & DI_F_ALL) == DI_F_ALL)
1531 X len = strlen (diskInfo [i].name);
1532 X if (len > maxMountString)
1534 X maxMountString = len;
1537 X len = strlen (diskInfo [i].special);
1538 X if (len > maxSpecialString)
1540 X maxSpecialString = len;
1543 X len = strlen (diskInfo [i].fsType);
1544 X if (len > maxTypeString)
1546 X maxTypeString = len;
1549 X len = strlen (diskInfo [i].options);
1550 X if (len > maxOptString)
1552 X maxOptString = len;
1555 X len = strlen (diskInfo [i].mountTime);
1556 X if (len > maxMntTimeString)
1558 X maxMntTimeString = len;
1560 X } /* if we are printing this item */
1561 X } /* for all disks */
1563 X sprintf (mountFormat, "%%-%d.%ds", maxMountString, maxMountString);
1564 X sprintf (specialFormat, "%%-%d.%ds", maxSpecialString,
1565 X maxSpecialString);
1566 X sprintf (typeFormat, "%%-%d.%ds", maxTypeString, maxTypeString);
1567 X sprintf (optFormat, "%%-%d.%ds", maxOptString, maxOptString);
1568 X sprintf (mTimeFormat, "%%-%d.%ds", maxMntTimeString, maxMntTimeString);
1570 X if (dispBlockSize <= DI_ONE_K)
1572 X sprintf (blockFormat, "%%%d.0f", width);
1576 X sprintf (blockFormat, "%%%d.1f", width);
1578 X sprintf (blockLabelFormat, "%%%ds", width);
1579 X#if defined (HAS_64BIT_STATFS_FLDS)
1580 X sprintf (inodeFormat, "%%%dllu", inodeWidth);
1582 X sprintf (inodeFormat, "%%%dlu", inodeWidth);
1584 X sprintf (inodeLabelFormat, "%%%ds", inodeWidth);
1593 X#if defined (CAN_PROTOTYPE)
1599 X printf ("di ver $Revision$ Default Format: %s\n", DI_DEFAULT_FORMAT);
1600 X /* 12345678901234567890123456789012345678901234567890123456789012345678901234567890 */
1601 X printf ("Usage: di [-ant] [-f format] [-s sort-type] [-i ignore-fstyp-list]\n");
1602 X printf (" [-I include-fstyp-list] [-w kbyte-width] [-W inode-width] [file [...]]\n");
1603 X printf (" -a : print all mounted devices; normally, those with 0 total blocks are\n");
1604 X printf (" not printed. e.g. /dev/proc, /dev/fd.\n");
1605 X printf (" -d x : size to print blocks in (p - posix (512), k - kbytes,\n");
1606 X printf (" m - megabytes, g - gigabytes, <x> - numeric size).\n");
1607 X printf (" -f x : use format string <x>\n");
1608 X printf (" -i x : ignore file system types in <x>\n");
1609 X printf (" -I x : include only file system types in <x>\n");
1610 X printf (" -l : display local filesystems only\n");
1611 X printf (" -n : don't print header\n");
1612 X printf (" -s t : sort type; n - no sort, s - by special device, r - reverse\n");
1613 X printf (" -t : print totals\n");
1614 X printf (" -w n : use width <n> for kbytes\n");
1615 X printf (" -W n : use width <n> for i-nodes\n");
1616 X printf (" Format string values:\n");
1617 X printf (" m - mount point M - mount point, full length\n");
1618 X printf (" b - total kbytes B - kbytes available for use\n");
1619 X printf (" u - used kbytes c - calculated kbytes in use\n");
1620 X printf (" f - kbytes free v - kbytes available\n");
1621 X printf (" p - percentage not avail. for use 1 - percentage used\n");
1622 X printf (" 2 - percentage of user-available space in use.\n");
1623 X printf (" i - total file slots (i-nodes) U - used file slots\n");
1624 X printf (" F - free file slots P - percentage file slots used\n");
1625 X printf (" s - filesystem name S - filesystem name, full length\n");
1626 X printf (" t - disk partition type T - partition type, full length\n");
1631 X#if defined (CAN_PROTOTYPE)
1632 XprocessArgs (int argc, char *argv [])
1634 XprocessArgs (argc, argv)
1642 X while ((ch = getopt (argc, argv, "Aad:f:hi:I:Flns:tw:W:x:")) != -1)
1648 X formatString = DI_ALL_FORMAT;
1649 X flags |= DI_F_ALL | DI_F_DEBUG_HDR | DI_F_TOTAL;
1650 X flags &= ~ DI_F_NO_HEADER;
1658 X flags |= DI_F_ALL;
1664 X switch (tolower (*optarg))
1668 X dispBlockSize = DI_HALF_K;
1674 X dispBlockSize = DI_ONE_K;
1680 X dispBlockSize = DI_ONE_MEG;
1686 X dispBlockSize = DI_ONE_GIG;
1692 X if (isdigit ((int) (*optarg)))
1694 X dispBlockSize = atof (optarg);
1704 X formatString = optarg;
1717 X parseList (&ignoreList, optarg);
1723 X parseList (&includeList, optarg);
1729 X flags |= DI_F_LOCAL_ONLY;
1735 X flags |= DI_F_NO_HEADER;
1745 X sortType = DI_SORT_SPECIAL;
1751 X sortType = DI_SORT_NONE;
1757 X sortOrder = DI_SORT_DESCENDING;
1766 X flags |= DI_F_TOTAL;
1772 X width = atoi (optarg);
1778 X inodeWidth = atoi (optarg);
1784 X debug = atoi (optarg);
1798 X /* list is assumed to be global */
1800 X#if defined (CAN_PROTOTYPE)
1801 XparseList (char ***list, char *str)
1803 XparseList (list, str)
1816 X dstr = (char *) malloc (i + 1);
1817 X if (dstr == (char *) NULL)
1819 X fprintf (stderr, "malloc failed in parseList() (1). errno %d\n", errno);
1824 X memcpy (dstr, str, i + 1);
1826 X ptr = strtok (dstr, DI_LIST_SEP);
1828 X while (ptr != (char *) NULL)
1831 X ptr = strtok ((char *) NULL, DI_LIST_SEP);
1834 X *list = (char **) malloc ((count + 1) * sizeof (char *));
1835 X if (*list == (char **) NULL)
1837 X fprintf (stderr, "malloc failed in parseList() (2). errno %d\n", errno);
1844 X for (i = 0; i < count; ++i)
1846 X len = strlen (ptr);
1847 X *lptr = (char *) malloc (len + 1);
1848 X if (*lptr == (char *) NULL)
1850 X fprintf (stderr, "malloc failed in parseList() (3). errno %d\n",
1855 X strcpy (*lptr, ptr);
1860 X *lptr = (char *) NULL;
1861 X free ((char *) dstr);
1866 X#if defined (CAN_PROTOTYPE)
1867 XcheckIgnoreList (DiskInfo *diskInfo)
1869 XcheckIgnoreList (diskInfo)
1870 X DiskInfo *diskInfo;
1875 X /* if the file system type is in the ignore list, skip it */
1876 X if (ignoreList != (char **) NULL)
1879 X while (*ptr != (char *) NULL)
1881 X if (strcmp (*ptr, diskInfo->fsType) == 0)
1883 X diskInfo->printFlag = DI_IGNORE;
1886 X printf ("chkign: ignore: fstype %s match: %s\n", *ptr,
1893 X } /* if an ignore list was specified */
1897 X#if defined (CAN_PROTOTYPE)
1898 XcheckIncludeList (DiskInfo *diskInfo)
1900 XcheckIncludeList (diskInfo)
1901 X DiskInfo *diskInfo;
1906 X /* if the file system type is not in the include list, skip it */
1907 X if (includeList != (char **) NULL)
1909 X ptr = includeList;
1910 X while (*ptr != (char *) NULL)
1912 X if (strcmp (*ptr, diskInfo->fsType) == 0)
1914 X diskInfo->printFlag = DI_OK;
1919 X diskInfo->printFlag = DI_IGNORE;
1922 X printf ("chkinc: ! include: fstype %s match: %s\n", *ptr,
1928 X } /* if an include list was specified */
1932 X#if defined (HAS_FS_INFO)
1942 XgetDiskEntries (void)
1948 X char buff [B_FILE_NAME_LENGTH];
1957 X while ((dev = next_dev (&count)) != B_BAD_VALUE)
1959 X if ((stat = fs_stat_dev (dev, &fsinfo)) == B_BAD_VALUE)
1966 X diskInfo = (DiskInfo *) Realloc ((char *) diskInfo,
1967 X sizeof (DiskInfo) * diCount);
1968 X memset ((char *) &diskInfo [idx], '\0', sizeof (DiskInfo));
1969 X diskInfo [idx].printFlag = DI_OK;
1971 X nref.device = dev;
1972 X nref.node = fsinfo.root;
1973 X dir = new BDirectory (&nref);
1974 X stat = dir->GetEntry (&entry);
1975 X stat = entry.GetPath (&path);
1976 X strncpy (diskInfo [idx].name, path.Path (), DI_NAME_LEN);
1977 X strncpy (diskInfo [idx].special, fsinfo.device_name, DI_SPEC_NAME_LEN);
1978 X strncpy (diskInfo [idx].fsType, fsinfo.fsh_name, DI_TYPE_LEN);
1979 X diskInfo [idx].isLocal = TRUE;
1980 X mult = (double) (long) fsinfo.block_size / dispBlockSize;
1981 X diskInfo [idx].totalBlocks =
1982 X ((double) (_s_fs_size_t) fsinfo.total_blocks * mult);
1983 X diskInfo [idx].freeBlocks =
1984 X ((double) (_s_fs_size_t) fsinfo.free_blocks * mult);
1985 X diskInfo [idx].availBlocks =
1986 X ((double) (_s_fs_size_t) fsinfo.free_blocks * mult);
1987 X diskInfo [idx].totalInodes = fsinfo.total_nodes;
1988 X diskInfo [idx].freeInodes = fsinfo.free_nodes;
1989 X diskInfo [idx].availInodes = fsinfo.free_nodes;
1991 X checkIgnoreList (&diskInfo [idx]);
1992 X checkIncludeList (&diskInfo [idx]);
1996 X printf ("mnt:%s - %s\n", diskInfo [idx].name,
1997 X diskInfo [idx].special);
1998 X printf ("dev:%d fs:%s\n", dev, diskInfo [idx].fsType);
2002 X printf ("%s: %s\n", diskInfo [idx].name, diskInfo [idx].fsType);
2003 X printf ("\tmult:%f\n", mult);
2004 X printf ("\tblocks: tot:%ld free:%ld\n",
2005 X fsinfo.total_blocks, fsinfo.free_blocks);
2006 X printf ("\tinodes: tot:%ld free:%ld\n",
2007 X fsinfo.total_nodes, fsinfo.free_nodes);
2021 X#if defined (HAS_GETMNTENT) && ! defined (HAS_SETMNTENT)
2023 X# define DFS_FS_TABLE "/etc/dfs/fstypes"
2028 X * For SysV.4, we open the file and call getmntent () repeatedly.
2038 X struct mnttab mntEntry;
2041 X char *devp; /* local ptr to dev entry */
2044 X if ((flags & DI_F_LOCAL_ONLY) == DI_F_LOCAL_ONLY)
2046 X i = remoteFileSystemCount;
2048 X if ((f = fopen (DFS_FS_TABLE, "r")) != (FILE *) NULL)
2050 X fgets (buff, 80, f);
2053 X printf ("remote file system type: %s\n", buff);
2055 X sscanf (buff, "%s", remoteFileSystemTypes [i++]);
2059 X remoteFileSystemCount = i;
2062 X if ((f = fopen (DI_MOUNT_FILE, "r")) == (FILE *) NULL)
2064 X fprintf (stderr, "Unable to open: %s errno %d\n", DI_MOUNT_FILE, errno);
2068 X while (getmntent (f, &mntEntry) == 0)
2072 X diskInfo = (DiskInfo *) Realloc ((char *) diskInfo,
2073 X sizeof (DiskInfo) * diCount);
2074 X memset ((char *) &diskInfo [idx], '\0', sizeof (DiskInfo));
2075 X diskInfo [idx].printFlag = DI_OK;
2077 X strncpy (diskInfo [idx].special, mntEntry.mnt_special,
2078 X DI_SPEC_NAME_LEN);
2079 X strncpy (diskInfo [idx].name, mntEntry.mnt_mountp, DI_NAME_LEN);
2080 X# if defined (MNTOPT_IGNORE)
2081 X if (strstr (mntEntry.mnt_mntopts, MNTOPT_IGNORE) != (char *) NULL)
2083 X if (strstr (mntEntry.mnt_mntopts, "ignore") != (char *) NULL)
2086 X diskInfo [idx].printFlag = DI_IGNORE;
2089 X printf ("mnt: ignore: mntopt 'ignore': %s\n",
2090 X diskInfo [idx].name);
2093 X# if defined (MNTOPT_DEV)
2094 X sprintf (buff, "%s=", MNTOPT_DEV);
2095 X if ((devp = strstr (mntEntry.mnt_mntopts, buff)) != (char *) NULL)
2097 X if ((devp = strstr (mntEntry.mnt_mntopts, "dev=")) != (char *) NULL)
2100 X if (devp != mntEntry.mnt_mntopts)
2104 X *devp = 0; /* point to preceeding comma and cut off */
2106 X strncpy (diskInfo [idx].options, mntEntry.mnt_mntopts, DI_OPT_LEN);
2107 X mtime = atol (mntEntry.mnt_time);
2108 X strncpy (diskInfo [idx].mountTime, ctime (&mtime), DI_MNT_TIME_LEN);
2110 X /* get the file system type now... */
2111 X strncpy (diskInfo [idx].fsType, mntEntry.mnt_fstype, DI_TYPE_LEN);
2113 X diskInfo [idx].isLocal = TRUE;
2114 X for (i = 0; i < remoteFileSystemCount; ++i)
2116 X if (strcmp (diskInfo [idx].fsType, remoteFileSystemTypes [i]) == 0)
2118 X diskInfo [idx].isLocal = FALSE;
2122 X checkIgnoreList (&diskInfo [idx]);
2123 X checkIncludeList (&diskInfo [idx]);
2127 X printf ("mnt:%s - %s\n", diskInfo [idx].name,
2128 X diskInfo [idx].special);
2136 X#endif /* HAS_GETMNTENT */
2138 X#if ! defined (HAS_GETMNTENT) && ! defined (HAS_MNTCTL) && \
2139 X ! defined (HAS_GETMNTINFO) && ! defined (HAS_GETMNT) && \
2140 X ! defined (HAS_GETDISKFREESPACE) && ! defined (HAS_FS_INFO)
2145 X * For SysV.3 we open the file and read it ourselves.
2154 X struct mnttab mntEntry;
2157 X if ((f = fopen (DI_MOUNT_FILE, "r")) == (FILE *) NULL)
2159 X fprintf (stderr, "Unable to open: %s errno %d\n", DI_MOUNT_FILE, errno);
2163 X while (fread ((char *) &mntEntry, sizeof (struct mnttab), 1, f) == 1)
2165 X /* xenix allows null mount table entries */
2166 X /* sco nfs background mounts are marked as "nothing" */
2167 X if (mntEntry.mt_filsys [0] &&
2168 X strcmp (mntEntry.mt_filsys, "nothing") != 0)
2172 X diskInfo = (DiskInfo *) Realloc ((char *) diskInfo,
2173 X sizeof (DiskInfo) * diCount);
2174 X memset ((char *) &diskInfo [idx], '\0', sizeof (DiskInfo));
2175 X diskInfo [idx].printFlag = DI_OK;
2176 X diskInfo [idx].isLocal = TRUE;
2178 X# if defined (COHERENT)
2179 X /* Coherent seems to have these fields reversed. oh well. */
2180 X strncpy (diskInfo [idx].name, mntEntry.mt_dev, DI_NAME_LEN);
2181 X strncpy (diskInfo [idx].special, mntEntry.mt_filsys, DI_SPEC_NAME_LEN);
2183 X strncpy (diskInfo [idx].special, mntEntry.mt_dev, DI_SPEC_NAME_LEN);
2184 X strncpy (diskInfo [idx].name, mntEntry.mt_filsys, DI_NAME_LEN);
2186 X strncpy (diskInfo [idx].options, mntEntry.mnt_mntopts, DI_OPT_LEN);
2187 X strncpy (diskInfo [idx].mountTime, mntEntry.mnt_time,
2193 X printf ("mnt:%s - %s\n", diskInfo [idx].name,
2194 X diskInfo [idx].special);
2202 X#endif /* Sys V.3 */
2204 X#if defined (HAS_GETMNTENT) && defined (HAS_SETMNTENT) && \
2205 X defined (HAS_ENDMNTENT)
2210 X * SunOS supplies an open and close routine for the mount table.
2219 X struct mntent *mntEntry;
2220 X char *devp; /* local ptr to dev entry */
2223 X#if defined (HAS_SETMNTENT_ONE_ARG)
2224 X if ((f = setmntent (DI_MOUNT_FILE)) == (FILE *) NULL)
2226 X if ((f = setmntent (DI_MOUNT_FILE, "r")) == (FILE *) NULL)
2229 X fprintf (stderr, "Unable to open: %s errno %d\n", DI_MOUNT_FILE, errno);
2233 X while ((mntEntry = getmntent (f)) != (struct mntent *) NULL)
2237 X diskInfo = (DiskInfo *) Realloc ((char *) diskInfo,
2238 X sizeof (DiskInfo) * diCount);
2239 X memset ((char *) &diskInfo [idx], '\0', sizeof (DiskInfo));
2240 X diskInfo [idx].printFlag = DI_OK;
2241 X diskInfo [idx].isLocal = TRUE;
2243 X strncpy (diskInfo [idx].special, mntEntry->mnt_fsname, DI_SPEC_NAME_LEN);
2244 X strncpy (diskInfo [idx].name, mntEntry->mnt_dir, DI_NAME_LEN);
2245 X strncpy (diskInfo [idx].fsType, mntEntry->mnt_type, DI_TYPE_LEN);
2247 X if (strcmp (mntEntry->mnt_type, MNTTYPE_IGNORE) == 0)
2249 X diskInfo [idx].printFlag = DI_IGNORE;
2252 X printf ("mnt: ignore: mntopt 'ignore': %s\n",
2253 X diskInfo [idx].name);
2257 X if ((devp = strstr (mntEntry->mnt_opts, "dev=")) != (char *) NULL)
2259 X if (devp != mntEntry->mnt_opts)
2263 X *devp = 0; /* point to preceeding comma and cut off */
2265 X strncpy (diskInfo [idx].options, mntEntry->mnt_opts, DI_OPT_LEN);
2267 X checkIgnoreList (&diskInfo [idx]);
2268 X checkIncludeList (&diskInfo [idx]);
2272 X printf ("mnt:%s - %s : %s\n", diskInfo [idx].name,
2273 X diskInfo [idx].special, diskInfo [idx].fsType);
2281 X#endif /* HAS_GETMNTENT && HAS_SETMNTENT && HAS_ENDMNTENT */
2283 X#if defined (HAS_GETMNTINFO)
2288 X * OSF/1 does this with a system call and library routine
2290 X * [mogul@wrl.dec.com (Jeffrey Mogul)]
2293 X#if defined (INITMOUNTNAMES)
2294 Xstatic char *mnt_names [] = INITMOUNTNAMES;
2295 X# define MNT_NUMTYPES (MOUNT_MAXTYPE + 1)
2298 X /* osf/1 mount flags start w/M_ vs. MNT_ */
2299 X /* this saves us from lots of duplicate code */
2300 X#if defined (M_RDONLY)
2301 X# define MNT_RDONLY M_RDONLY
2303 X#if defined (M_SYNCHRONOUS)
2304 X# define MNT_SYNCHRONOUS M_SYNCHRONOUS
2306 X#if defined (M_NOEXEC)
2307 X# define MNT_NOEXEC M_NOEXEC
2309 X#if defined (M_NOSUID)
2310 X# define MNT_NOSUID M_NOSUID
2312 X#if defined (M_NODEV)
2313 X# define MNT_NODEV M_NODEV
2315 X#if defined (M_GRPID)
2316 X# define MNT_GRPID M_GRPID
2318 X#if defined (M_EXPORTED)
2319 X# define MNT_EXPORTED M_EXPORTED
2321 X#if defined (M_EXRDONLY)
2322 X# define MNT_EXRDONLY M_EXRDONLY
2324 X#if defined (M_EXRDMOSTLY)
2325 X# define MNT_EXRDMOSTLY M_EXRDMOSTLY
2327 X#if defined (M_SECURE)
2328 X# define MNT_SECURE M_SECURE
2330 X#if defined (M_LOCAL)
2331 X# define MNT_LOCAL M_LOCAL
2333 X#if defined (M_QUOTA)
2334 X# define MNT_QUOTA M_QUOTA
2344 X struct statfs *mntbufp;
2347 X count = getmntinfo (&mntbufp, MNT_WAIT);
2350 X fprintf (stderr, "Unable to do getmntinfo () errno %d\n", errno);
2355 X diskInfo = (DiskInfo *) malloc (sizeof (DiskInfo) * count);
2356 X if (diskInfo == (DiskInfo *) NULL)
2358 X fprintf (stderr, "malloc failed for diskInfo. errno %d\n", errno);
2361 X memset ((char *) diskInfo, '\0', sizeof (DiskInfo) * count);
2365 X printf ("type_len %d name_len %d spec_name_len %d\n", DI_TYPE_LEN,
2366 X DI_NAME_LEN, DI_SPEC_NAME_LEN);
2369 X for (idx = 0; idx < count; idx++)
2371 X diskInfo [idx].printFlag = DI_OK;
2372 X diskInfo [idx].isLocal = FALSE;
2373 X#if defined (MNT_LOCAL)
2374 X if ((mntbufp [idx].f_flags & MNT_LOCAL) == MNT_LOCAL)
2376 X diskInfo [idx].isLocal = TRUE;
2380 X if (diskInfo [idx].isLocal == FALSE &&
2381 X (flags & DI_F_LOCAL_ONLY) == DI_F_LOCAL_ONLY)
2383 X diskInfo [idx].printFlag = DI_IGNORE;
2386 X printf ("mnt: ignore: remote: %s\n",
2387 X diskInfo [idx].name);
2391 X strncpy (diskInfo [idx].special, mntbufp [idx].f_mntfromname,
2392 X DI_SPEC_NAME_LEN);
2393 X strncpy (diskInfo [idx].name, mntbufp [idx].f_mntonname, DI_NAME_LEN);
2397 X# if defined (HAS_GETMNTINFO_FSIZE) /* 1.x */
2398 X mult = (double) mntbufp [idx].f_fsize / dispBlockSize;
2400 X# if defined (HAS_GETMNTINFO_BSIZE) /* 2.x */
2401 X mult = (double) mntbufp [idx].f_bsize / dispBlockSize;
2403 X diskInfo [idx].totalBlocks = ((double) (_s_fs_size_t) mntbufp [idx].f_blocks * mult);
2404 X diskInfo [idx].freeBlocks = ((double) (_s_fs_size_t) mntbufp [idx].f_bfree * mult);
2405 X diskInfo [idx].availBlocks = ((double) (_s_fs_size_t) mntbufp [idx].f_bavail * mult);
2407 X diskInfo [idx].totalInodes = mntbufp [idx].f_files;
2408 X diskInfo [idx].freeInodes = mntbufp [idx].f_ffree;
2409 X diskInfo [idx].availInodes = mntbufp [idx].f_ffree;
2411 X fstype = mntbufp [idx].f_type;
2412 X# if ! defined (I_SYS_FSTYP) && ! defined (INITMOUNTNAMES) && \
2413 X ! defined (HAS_GETMNTINFO_FSTYPENAME)
2414 X if ((fstype >= 0) && (fstype <= MOUNT_MAXTYPE))
2418 X# if defined (MOUNT_NONE)
2419 X case MOUNT_NONE: /* No Filesystem */
2421 X strncpy (diskInfo [idx].fsType, "none", DI_TYPE_LEN);
2426 X# if defined (MOUNT_UFS)
2427 X case MOUNT_UFS: /* UNIX "Fast" Filesystem */
2429 X strncpy (diskInfo [idx].fsType, "ufs", DI_TYPE_LEN);
2434 X# if defined (MOUNT_NFS)
2435 X case MOUNT_NFS: /* Network Filesystem */
2437 X strncpy (diskInfo [idx].fsType, "nfs", DI_TYPE_LEN);
2442 X# if defined (MOUNT_MFS)
2443 X case MOUNT_MFS: /* Memory Filesystem */
2445 X strncpy (diskInfo [idx].fsType, "mfs", DI_TYPE_LEN);
2450 X# if defined (MOUNT_MSDOS)
2451 X case MOUNT_MSDOS: /* MSDOS Filesystem */
2453 X strncpy (diskInfo [idx].fsType, "msdos", DI_TYPE_LEN);
2458 X# if defined (MOUNT_LFS)
2461 X strncpy (diskInfo [idx].fsType, "lfs", DI_TYPE_LEN);
2466 X# if defined (MOUNT_LOFS)
2469 X strncpy (diskInfo [idx].fsType, "lofs", DI_TYPE_LEN);
2474 X# if defined (MOUNT_FDESC)
2477 X strncpy (diskInfo [idx].fsType, "fdesc", DI_TYPE_LEN);
2482 X# if defined (MOUNT_PORTAL)
2483 X case MOUNT_PORTAL:
2485 X strncpy (diskInfo [idx].fsType, "portal", DI_TYPE_LEN);
2490 X# if defined (MOUNT_NULL)
2493 X strncpy (diskInfo [idx].fsType, "null", DI_TYPE_LEN);
2498 X# if defined (MOUNT_UMAP)
2501 X strncpy (diskInfo [idx].fsType, "umap", DI_TYPE_LEN);
2506 X# if defined (MOUNT_KERNFS)
2507 X case MOUNT_KERNFS:
2509 X strncpy (diskInfo [idx].fsType, "kernfs", DI_TYPE_LEN);
2514 X# if defined (MOUNT_PROCFS)
2515 X case MOUNT_PROCFS: /* proc filesystem */
2517 X strncpy (diskInfo [idx].fsType, "pfs", DI_TYPE_LEN);
2522 X# if defined (MOUNT_AFS)
2525 X strncpy (diskInfo [idx].fsType, "afs", DI_TYPE_LEN);
2530 X# if defined (MOUNT_ISOFS)
2531 X case MOUNT_ISOFS: /* iso9660 cdrom */
2533 X strncpy (diskInfo [idx].fsType, "iso9660fs", DI_TYPE_LEN);
2538 X# if defined (MOUNT_ISO9660) && ! defined (MOUNT_CD9660)
2539 X case MOUNT_ISO9660: /* iso9660 cdrom */
2541 X strncpy (diskInfo [idx].fsType, "iso9660", DI_TYPE_LEN);
2546 X# if defined (MOUNT_CD9660)
2547 X case MOUNT_CD9660: /* iso9660 cdrom */
2549 X strncpy (diskInfo [idx].fsType, "cd9660", DI_TYPE_LEN);
2554 X# if defined (MOUNT_UNION)
2557 X strncpy (diskInfo [idx].fsType, "union", DI_TYPE_LEN);
2561 X } /* switch on mount type */
2564 X# if defined (HAS_GETMNTINFO_FSTYPENAME)
2565 X strncpy (diskInfo [idx].fsType, mntbufp [idx].f_fstypename, DI_TYPE_LEN);
2567 X /* could use getvfsbytype here... */
2568 X if ((fstype >= 0) && (fstype < MNT_NUMTYPES))
2570 X strncpy (diskInfo [idx].fsType, mnt_names [fstype], DI_TYPE_LEN);
2574 X sprintf (diskInfo [idx].fsType, DI_UNKNOWN_FSTYPE, fstype);
2577 X# endif /* has fs_types.h */
2579 X#if defined (MNT_RDONLY)
2580 X if ((mntbufp [idx].f_flags & MNT_RDONLY) == MNT_RDONLY)
2582 X strcat (diskInfo [idx].options, "ro,");
2586 X strcat (diskInfo [idx].options, "rw,");
2589 X#if defined (MNT_SYNCHRONOUS)
2590 X if ((mntbufp [idx].f_flags & MNT_SYNCHRONOUS) == MNT_SYNCHRONOUS)
2592 X strcat (diskInfo [idx].options, "sync,");
2595 X#if defined (MNT_NOEXEC)
2596 X if ((mntbufp [idx].f_flags & MNT_NOEXEC) == MNT_NOEXEC)
2598 X strcat (diskInfo [idx].options, "noexec,");
2601 X#if defined (MNT_NOSUID)
2602 X if ((mntbufp [idx].f_flags & MNT_NOSUID) != MNT_NOSUID)
2604 X strcat (diskInfo [idx].options, "suid,");
2607 X#if defined (MNT_NODEV)
2608 X if ((mntbufp [idx].f_flags & MNT_NODEV) == MNT_NODEV)
2610 X strcat (diskInfo [idx].options, "nodev,");
2613 X#if defined (MNT_GRPID)
2614 X if ((mntbufp [idx].f_flags & MNT_GRPID) == MNT_GRPID)
2616 X strcat (diskInfo [idx].options, "grpid,");
2619 X#if defined (MNT_UNION)
2620 X if ((mntbufp [idx].f_flags & MNT_UNION) == MNT_UNION)
2622 X strcat (diskInfo [idx].options, "union,");
2625 X#if defined (MNT_ASYNC)
2626 X if ((mntbufp [idx].f_flags & MNT_ASYNC) == MNT_ASYNC)
2628 X strcat (diskInfo [idx].options, "async,");
2631 X#if defined (MNT_EXRDONLY)
2632 X if ((mntbufp [idx].f_flags & MNT_EXRDONLY) == MNT_EXRDONLY)
2634 X strcat (diskInfo [idx].options, "exported ro,");
2637 X#if defined (MNT_EXPORTED)
2638 X if ((mntbufp [idx].f_flags & MNT_EXPORTED) == MNT_EXPORTED)
2640 X strcat (diskInfo [idx].options, "exported,");
2643 X#if defined (MNT_EXRDMOSTLY)
2644 X if ((mntbufp [idx].f_flags & MNT_EXRDMOSTLY) == MNT_EXRDMOSTLY)
2646 X /* what's read-mostly ? */
2647 X strcat (diskInfo [idx].options, "exported read-mostly,");
2650 X#if defined (MNT_DEFEXPORTED)
2651 X if ((mntbufp [idx].f_flags & MNT_DEFEXPORTED) == MNT_DEFEXPORTED)
2653 X /* what's this ? */
2654 X strcat (diskInfo [idx].options, "exported world,");
2657 X#if defined (MNT_EXPORTANON)
2658 X if ((mntbufp [idx].f_flags & MNT_EXPORTANON) == MNT_EXPORTANON)
2660 X strcat (diskInfo [idx].options, "exported anon,");
2663 X#if defined (MNT_EXKERB)
2664 X if ((mntbufp [idx].f_flags & MNT_EXKERB) == MNT_EXKERB)
2666 X strcat (diskInfo [idx].options, "exported kerberos,");
2669 X#if defined (MNT_LOCAL)
2670 X if ((mntbufp [idx].f_flags & MNT_LOCAL) == MNT_LOCAL)
2672 X strcat (diskInfo [idx].options, "local,");
2675 X#if defined (MNT_QUOTA)
2676 X if ((mntbufp [idx].f_flags & MNT_QUOTA) == MNT_QUOTA)
2678 X strcat (diskInfo [idx].options, "quota,");
2681 X#if defined (MNT_ROOTFS)
2682 X if ((mntbufp [idx].f_flags & MNT_ROOTFS) == MNT_ROOTFS)
2684 X strcat (diskInfo [idx].options, "root,");
2687 X#if defined (MNT_USER)
2688 X if ((mntbufp [idx].f_flags & MNT_USER) == MNT_USER)
2690 X strcat (diskInfo [idx].options, "user,");
2693 X#if defined (MNT_SECURE)
2694 X if ((mntbufp [idx].f_flags & MNT_SECURE) == MNT_SECURE)
2696 X strcat (diskInfo [idx].options, "secure,");
2700 X len = strlen (diskInfo [idx].options);
2705 X if (diskInfo [idx].options [len]==',')
2707 X diskInfo [idx].options [len] = '\0';
2712 X printf ("%s: %s\n", diskInfo [idx].name, diskInfo [idx].fsType);
2713 X printf ("\tblocks: tot:%ld free:%ld avail:%ld\n",
2714 X mntbufp [idx].f_blocks, mntbufp [idx].f_bfree,
2715 X mntbufp [idx].f_bavail);
2716 X printf ("\tmult: %f\n", mult);
2717 X# if defined (HAS_GETMNTINFO_FSIZE)
2718 X printf ("\tfsize:%ld \n", mntbufp [idx].f_fsize);
2719 X printf ("\tbsize:%ld \n", mntbufp [idx].f_bsize);
2721 X# if defined (HAS_GETMNTINFO_BSIZE)
2722 X printf ("\tbsize:%ld \n", mntbufp [idx].f_bsize);
2723 X printf ("\tiosize:%ld \n", mntbufp [idx].f_iosize);
2725 X printf ("\tinodes: tot:%ld free:%ld\n",
2726 X mntbufp [idx].f_files, mntbufp [idx].f_ffree);
2730 X free ((char *) mntbufp); /* man page says this can't be freed. */
2731 X /* is it ok to try? */
2735 X/* this is a no-op; we have already done all the work */
2741 X#endif /* HAS_GETMNTINFO */
2743 X#if defined (HAS_GETMNT)
2748 X * ULTRIX does this with a system call. The system call allows one
2749 X * to retrieve the information in a series of calls, but coding that
2750 X * looks a little tricky; I just allocate a huge buffer and do it in
2753 X * [mogul@wrl.dec.com (Jeffrey Mogul)]
2763 X struct fs_data *fsdbuf;
2768 X bufsize = NMOUNT * sizeof (struct fs_data); /* enough for max # mounts */
2769 X fsdbuf = (struct fs_data *) malloc (bufsize);
2770 X if (fsdbuf == (struct fs_data *) NULL)
2772 X fprintf (stderr, "malloc (%d) for getmnt () failed errno %d\n",
2778 X count = getmnt (&start, fsdbuf, bufsize, STAT_MANY, 0);
2781 X fprintf (stderr, "Unable to do getmnt () [= %d] errno %d\n",
2783 X free ((char *) fsdbuf);
2788 X diskInfo = (DiskInfo *) malloc (sizeof (DiskInfo) * count);
2789 X if (diskInfo == (DiskInfo *) NULL)
2791 X fprintf (stderr, "malloc failed for diskInfo. errno %d\n", errno);
2792 X free ((char *) fsdbuf);
2795 X memset ((char *) diskInfo, '\0', sizeof (DiskInfo) * count);
2797 X for (idx = 0; idx < count; idx++)
2799 X diskInfo [idx].printFlag = DI_OK;
2800 X diskInfo [idx].isLocal = TRUE;
2802 X if ((fsdbuf [idx].fd_req.flags & M_LOCAL) != M_LOCAL)
2804 X diskInfo [idx].isLocal = FALSE;
2807 X if (diskInfo [idx].isLocal == FALSE &&
2808 X (flags & DI_F_LOCAL_ONLY) == DI_F_LOCAL_ONLY)
2810 X diskInfo [idx].printFlag = DI_IGNORE;
2813 X printf ("mnt: ignore: remote: %s\n",
2814 X diskInfo [idx].name);
2818 X strncpy (diskInfo [idx].special, fsdbuf [idx].fd_devname, DI_SPEC_NAME_LEN);
2819 X strncpy (diskInfo [idx].name, fsdbuf [idx].fd_path, DI_NAME_LEN);
2821 X /* ULTRIX keeps these fields in units of 1K byte */
2822 X diskInfo [idx].totalBlocks = fsdbuf [idx].fd_btot;
2823 X diskInfo [idx].freeBlocks = fsdbuf [idx].fd_bfree;
2824 X diskInfo [idx].availBlocks = (int) fsdbuf [idx].fd_bfreen;
2826 X diskInfo [idx].totalInodes = fsdbuf [idx].fd_gtot;
2827 X diskInfo [idx].freeInodes = fsdbuf [idx].fd_gfree;
2828 X diskInfo [idx].availInodes = fsdbuf [idx].fd_gfree;
2830 X fstype = fsdbuf [idx].fd_fstype;
2831 X if (fstype == GT_UNKWN)
2833 X diskInfo [idx].printFlag = DI_IGNORE;
2836 X printf ("mnt: ignore: disk type unknown: %s\n",
2837 X diskInfo [idx].name);
2840 X else if ((fstype > 0) && (fstype < GT_NUMTYPES))
2842 X strncpy (diskInfo [idx].fsType, gt_names [fstype], DI_TYPE_LEN);
2846 X sprintf (diskInfo [idx].fsType, "Unknown fstyp %.2d", fstype);
2849 X if ((fsdbuf [idx].fd_req.flags & M_RONLY) == M_RONLY)
2851 X strcat (diskInfo [idx].options, "ro,");
2855 X strcat (diskInfo [idx].options, "rw,");
2857 X if ((fsdbuf [idx].fd_req.flags & M_NOSUID) != M_NOSUID)
2859 X strcat (diskInfo [idx].options, "suid,");
2861 X if ((fsdbuf [idx].fd_req.flags & M_QUOTA) == M_QUOTA)
2863 X strcat (diskInfo [idx].options, "quota,");
2865 X if ((fsdbuf [idx].fd_req.flags & M_LOCAL) != M_LOCAL)
2867 X strcat (diskInfo [idx].options, "remote,");
2869 X if ((fsdbuf [idx].fd_req.flags & M_NODEV) == M_NODEV)
2871 X strcat (diskInfo [idx].options, "nodev,");
2873 X if ((fsdbuf [idx].fd_req.flags & M_FORCE) == M_FORCE)
2875 X strcat (diskInfo [idx].options, "force,");
2877 X if ((fsdbuf [idx].fd_req.flags & M_SYNC) == M_SYNC)
2879 X strcat (diskInfo [idx].options, "sync,");
2881 X if ((fsdbuf [idx].fd_req.flags & M_NOCACHE) == M_NOCACHE)
2883 X strcat (diskInfo [idx].options, "nocache,");
2885 X if ((fsdbuf [idx].fd_req.flags & M_EXPORTED) == M_EXPORTED)
2887 X strcat (diskInfo [idx].options, "exported," );
2889 X if ((fsdbuf [idx].fd_req.flags & M_EXRONLY) == M_EXRONLY)
2891 X strcat (diskInfo [idx].options, "exported ro,");
2893 X if ((fsdbuf [idx].fd_req.flags & M_NOEXEC) == M_NOEXEC)
2895 X strcat (diskInfo [idx].options, "noexec,");
2898 X len = strlen (diskInfo [idx].options);
2903 X if (diskInfo [idx].options [len]==',')
2905 X diskInfo [idx].options [len] = '\0';
2910 X printf ("%s: %s\n", diskInfo [idx].name, diskInfo [idx].fsType);
2911 X printf ("\tblocks: tot:%ld free:%ld avail:%ld\n",
2912 X fsdbuf [idx].fd_btot, fsdbuf [idx].fd_bfree,
2913 X (int) fsdbuf [idx].fd_bfreen);
2914 X printf ("\tinodes: tot:%ld free:%ld\n",
2915 X fsdbuf [idx].fd_gtot, fsdbuf [idx].fd_gfree);
2919 X free ((char *) fsdbuf);
2923 X/* this is a no-op; we have already done all the work */
2929 X#endif /* HAS_GETMNT */
2932 X#if defined (HAS_MNTCTL)
2937 X * AIX V3.2 uses mntctl to find out about mounted file systems
2941 X# define NUM_AIX_FSTYPES 6
2942 Xstatic char *AIX_fsType [NUM_AIX_FSTYPES] =
2943 X { "oaix", "", "nfs", "jfs", "", "cdrom" };
2951 X * MNT_CDROM - "cdrom"
2952 X * other - "user defined"
2959 X int num; /* number of vmount structs returned */
2960 X char *vmbuf; /* buffer for vmount structs returned */
2961 X int vmbufsz; /* size in bytes of vmbuf */
2962 X int i; /* index for looping and stuff */
2963 X char *bufp; /* pointer into vmbuf */
2964 X struct vmount *vmtp; /* pointer into vmbuf */
2965 X struct vfs_ent *ve; /* pointer for file system type entry */
2970 X vmbufsz = sizeof (struct vmount) * DI_FSMAGIC; /* initial vmount buffer */
2974 X if ((vmbuf = (char *) malloc (vmbufsz)) == (char *) NULL)
2976 X fprintf (stderr, "malloc (%d) for mntctl() failed errno %d\n",
2981 X num = mntctl (MCTL_QUERY, vmbufsz, vmbuf);
2983 X * vmbuf is too small, could happen for
2984 X * following reasons:
2985 X * - inital buffer is too small
2986 X * - newly mounted file system
2990 X memcpy (&vmbufsz, vmbuf, sizeof (vmbufsz)); /* see mntctl(2) */
2993 X printf ("vmbufsz too small, new size: %d\n", vmbufsz);
2995 X free ((char *) vmbuf); /* free this last, it's still being used! */
2998 X } while (num == 0 && i < DI_RETRY_COUNT);
3000 X if (i >= DI_RETRY_COUNT)
3002 X free ((char *) vmbuf);
3003 X fprintf (stderr, "unable to allocate adequate buffer for mntctl\n");
3009 X /* error happened, probably null vmbuf */
3012 X free ((char *) vmbuf);
3013 X fprintf (stderr,"%s errno %d\n", strerror (errno), errno);
3017 X /* 'num' vmount structs returned in vmbuf */
3021 X diskInfo = (DiskInfo *) calloc (sizeof (DiskInfo), diCount);
3022 X if (diskInfo == (DiskInfo *) NULL)
3024 X fprintf (stderr, "malloc failed for diskInfo. errno %d\n", errno);
3029 X for (i = 0; i < num; i++)
3031 X vmtp = (struct vmount *) bufp;
3032 X diskInfo [i].printFlag = DI_OK;
3033 X diskInfo [i].isLocal = TRUE;
3035 X strncpy (diskInfo [i].special,
3036 X (char *) vmt2dataptr (vmtp, VMT_OBJECT),
3037 X DI_SPEC_NAME_LEN);
3038 X strncpy (diskInfo [i].name,
3039 X (char *) vmt2dataptr (vmtp, VMT_STUB), DI_NAME_LEN);
3041 X ve = getvfsbytype (vmtp->vmt_gfstype);
3042 X if (ve == (struct vfs_ent *) NULL || *ve->vfsent_name == '\0')
3044 X if (vmtp->vmt_gfstype >= 0 &&
3045 X (vmtp->vmt_gfstype < NUM_AIX_FSTYPES))
3047 X strncpy (diskInfo [i].fsType,
3048 X AIX_fsType [vmtp->vmt_gfstype], DI_TYPE_LEN);
3053 X strncpy (diskInfo [i].fsType, ve->vfsent_name, DI_TYPE_LEN);
3056 X if ((vmtp->vmt_flags & MNT_READONLY) == MNT_READONLY)
3058 X strcat (diskInfo [i].options, "ro,");
3062 X strcat (diskInfo [i].options, "rw,");
3064 X if ((vmtp->vmt_flags & MNT_NOSUID) != MNT_NOSUID)
3066 X strcat (diskInfo [i].options, "suid,");
3068 X if ((vmtp->vmt_flags & MNT_REMOVABLE) == MNT_REMOVABLE)
3070 X strcat (diskInfo [i].options, "removable,");
3072 X if ((vmtp->vmt_flags & MNT_DEVICE) == MNT_DEVICE)
3074 X strcat (diskInfo [i].options, "device,");
3076 X if ((vmtp->vmt_flags & MNT_REMOTE) == MNT_REMOTE)
3078 X strcat (diskInfo [i].options, "remote,");
3079 X diskInfo [i].isLocal = FALSE;
3081 X if ((vmtp->vmt_flags & MNT_UNMOUNTING) == MNT_UNMOUNTING)
3083 X strcat (diskInfo [i].options, "unmounting,");
3085 X if ((vmtp->vmt_flags & MNT_SYSV_MOUNT) == MNT_SYSV_MOUNT)
3087 X strcat (diskInfo [i].options, "sysv mount,");
3089 X if ((vmtp->vmt_flags & MNT_NODEV) == MNT_NODEV)
3091 X strcat (diskInfo [i].options, "nodev,");
3094 X /* remove trailing comma */
3095 X len = strlen (diskInfo [i].options);
3100 X if (diskInfo [i].options [len] == ',')
3102 X diskInfo [i].options [len] = '\0';
3105 X strncpy (diskInfo [i].mountTime, ctime (&vmtp->vmt_time),
3108 X if (diskInfo [i].isLocal == FALSE &&
3109 X (flags & DI_F_LOCAL_ONLY) == DI_F_LOCAL_ONLY)
3111 X diskInfo [i].printFlag = DI_IGNORE;
3114 X printf ("mnt: ignore: remote: %s\n",
3115 X diskInfo [i].name);
3119 X bufp += vmtp->vmt_length;
3124 X printf ("mnt:%s - %s : %s\n", diskInfo [i].name,
3125 X diskInfo [i].special, diskInfo [i].fsType);
3126 X printf ("\t%s\n", (char *) vmt2dataptr (vmtp, VMT_ARGS));
3130 X } /* valid value returned */
3131 X } /* switch on num */
3134 X#endif /* HAS_MNTCTL */
3137 X#if defined (HAS_STATVFS)
3142 X * SysV.4. statvfs () returns both the free and available blocks.
3151 X struct statvfs statBuf;
3153 X for (i = 0; i < diCount; ++i)
3155 X if (diskInfo [i].isLocal == FALSE &&
3156 X (flags & DI_F_LOCAL_ONLY) == DI_F_LOCAL_ONLY)
3158 X diskInfo [i].printFlag = DI_IGNORE;
3161 X printf ("mnt: ignore: remote: %s\n",
3162 X diskInfo [i].name);
3166 X if (diskInfo [i].printFlag == DI_OK || (flags & DI_F_ALL) == DI_F_ALL)
3168 X if (statvfs (diskInfo [i].name, &statBuf) == 0)
3170 X /* data general DG/UX 5.4R3.00 sometime returns 0 */
3171 X /* in the fragment size field. */
3172 X if (statBuf.f_frsize == 0 && statBuf.f_bsize != 0)
3174 X mult = (double) (long) statBuf.f_bsize / dispBlockSize;
3178 X mult = (double) (long) statBuf.f_frsize / dispBlockSize;
3181 X diskInfo [i].totalBlocks = ((double) (_s_fs_size_t) statBuf.f_blocks * mult);
3182 X diskInfo [i].freeBlocks = ((double) (_s_fs_size_t) statBuf.f_bfree * mult);
3183 X diskInfo [i].availBlocks = ((double) (_s_fs_size_t) statBuf.f_bavail * mult);
3185 X diskInfo [i].totalInodes = statBuf.f_files;
3186 X diskInfo [i].freeInodes = statBuf.f_ffree;
3187 X diskInfo [i].availInodes = statBuf.f_favail;
3189 X#if defined (HAS_STATVFS_BASETYPE)
3190 X strncpy (diskInfo [i].fsType, statBuf.f_basetype, DI_TYPE_LEN);
3195 X printf ("%s: %s\n", diskInfo [i].name, diskInfo [i].fsType);
3196 X printf ("\tmult:%f\n", mult);
3197 X printf ("\tbsize:%ld frsize:%ld\n", statBuf.f_bsize,
3198 X statBuf.f_frsize);
3199 X#if defined (HAS_64BIT_STATFS_FLDS)
3200 X printf ("\tblocks: tot:%llu free:%lld avail:%llu\n",
3201 X statBuf.f_blocks, statBuf.f_bfree, statBuf.f_bavail);
3202 X printf ("\tinodes: tot:%llu free:%lld avail:%llu\n",
3203 X statBuf.f_files, statBuf.f_ffree, statBuf.f_favail);
3205 X printf ("\tblocks: tot:%lu free:%ld avail:%lu\n",
3206 X statBuf.f_blocks, statBuf.f_bfree, statBuf.f_bavail);
3207 X printf ("\tinodes: tot:%lu free:%ld avail:%lu\n",
3208 X statBuf.f_files, statBuf.f_ffree, statBuf.f_favail);
3214 X fprintf (stderr, "statvfs: %s ", diskInfo [i].name);
3218 X } /* for each entry */
3221 X#endif /* HAS_STATVFS */
3224 X#if defined (HAS_STATFS_BSD) && ! defined (HAS_STATVFS) && \
3225 X ! defined (HAS_GETMNTINFO) && ! defined (HAS_GETMNT)
3230 X * SunOS/BSD/Pyramid
3239 X struct statfs statBuf;
3241 X for (i = 0; i < diCount; ++i)
3243 X if (diskInfo [i].printFlag == DI_OK || (flags & DI_F_ALL) == DI_F_ALL)
3245 X if (statfs (diskInfo [i].name, &statBuf) == 0)
3247 X mult = (double) statBuf.f_bsize / dispBlockSize;
3248 X diskInfo [i].totalBlocks = ((double) (_s_fs_size_t) statBuf.f_blocks * mult);
3249 X diskInfo [i].freeBlocks = ((double) (_s_fs_size_t) statBuf.f_bfree * mult);
3250 X diskInfo [i].availBlocks = ((double) (_s_fs_size_t) statBuf.f_bavail * mult);
3252 X diskInfo [i].totalInodes = statBuf.f_files;
3253 X diskInfo [i].freeInodes = statBuf.f_ffree;
3254 X diskInfo [i].availInodes = statBuf.f_ffree;
3255 X# if defined (HAS_SYSFS)
3256 X sysfs (GETFSTYP, statBuf.f_fstyp, diskInfo [i].fsType);
3261 X printf ("%s: %s\n", diskInfo [i].name, diskInfo [i].fsType);
3262 X printf ("\tmult:%f\n", mult);
3263 X printf ("\tbsize:%ld\n", statBuf.f_bsize);
3264 X printf ("\tblocks: tot:%ld free:%ld avail:%ld\n",
3265 X statBuf.f_blocks, statBuf.f_bfree, statBuf.f_bavail);
3266 X printf ("\tinodes: tot:%ld free:%ld\n",
3267 X statBuf.f_files, statBuf.f_ffree);
3269 X } /* if we got the info */
3272 X fprintf (stderr, "statfs: %s ", diskInfo [i].name);
3276 X } /* for each entry */
3279 X#endif /* HAS_STATFS_BSD */
3281 X#if defined (HAS_STATFS_SYSV3) && ! defined (HAS_STATVFS) && \
3282 X ! defined (HAS_GETMNTINFO) && ! defined (HAS_GETMNT)
3287 X * SysV.3. We don't have available blocks; just set it to free blocks.
3288 X * The sysfs () call is used to get the disk type name.
3297 X struct statfs statBuf;
3299 X for (i = 0; i < diCount; ++i)
3301 X if (diskInfo [i].printFlag == DI_OK || (flags & DI_F_ALL) == DI_F_ALL)
3303 X if (statfs (diskInfo [i].name, &statBuf, sizeof (statBuf), 0) == 0)
3305 X# if defined (HAS_STATFS_FRSIZE)
3306 X if (statBuf.f_frsize == 0 && statBuf.f_bsize != 0)
3308 X mult = (double) (long) statBuf.f_bsize / dispBlockSize;
3312 X mult = (double) (long) statBuf.f_frsize / dispBlockSize;
3315 X mult = (double) UBSIZE / dispBlockSize;
3317 X diskInfo [i].totalBlocks = ((double) (_s_fs_size_t) statBuf.f_blocks * mult);
3318 X diskInfo [i].freeBlocks = ((double) (_s_fs_size_t) statBuf.f_bfree * mult);
3319 X diskInfo [i].availBlocks = ((double) (_s_fs_size_t) statBuf.f_bfree * mult);
3321 X diskInfo [i].totalInodes = statBuf.f_files;
3322 X diskInfo [i].freeInodes = statBuf.f_ffree;
3323 X diskInfo [i].availInodes = statBuf.f_ffree;
3324 X# if defined (HAS_SYSFS)
3325 X sysfs (GETFSTYP, statBuf.f_fstyp, diskInfo [i].fsType);
3330 X printf ("%s: %s\n", diskInfo [i].name, diskInfo [i].fsType);
3331 X printf ("\tmult:%f\n", mult);
3332 X# if defined (HAS_STATFS_FRSIZE)
3333 X printf ("\tbsize:%ld\n", statBuf.f_bsize);
3334 X printf ("\tfrsize:%ld\n", statBuf.f_frsize);
3336 X printf ("\tUBSIZE:%ld\n", UBSIZE);
3338 X printf ("\tblocks: tot:%ld free:%ld\n",
3339 X statBuf.f_blocks, statBuf.f_bfree);
3340 X printf ("\tinodes: tot:%ld free:%ld\n",
3341 X statBuf.f_files, statBuf.f_ffree);
3343 X } /* if we got the info */
3346 X fprintf (stderr, "statfs: %s ", diskInfo [i].name);
3350 X } /* for each entry */
3353 X#endif /* HAS_STATFS_SYSV3 */
3356 X#if defined (HAS_GETDISKFREESPACE)
3365 X# define NUM_MSDOS_FSTYPES 7
3366 Xstatic char *MSDOS_diskType [NUM_MSDOS_FSTYPES] =
3367 X { "unknown", "", "removable", "fixed", "remote", "cdrom", "ramdisk" };
3368 X# define MSDOS_BUFFER_SIZE 128
3369 X# define BYTES_PER_LOGICAL_DRIVE 4
3378 X char buff [MSDOS_BUFFER_SIZE];
3381 X diskflag = DI_IGNORE;
3382 X rc = GetLogicalDriveStrings (MSDOS_BUFFER_SIZE, buff);
3383 X diCount = rc / BYTES_PER_LOGICAL_DRIVE;
3385 X diskInfo = (DiskInfo *) calloc (sizeof (DiskInfo), diCount);
3386 X if (diskInfo == (DiskInfo *) NULL)
3388 X fprintf (stderr, "malloc failed for diskInfo. errno %d\n", errno);
3392 X for (i = 0; i < diCount; ++i)
3394 X p = buff + (BYTES_PER_LOGICAL_DRIVE * i);
3395 X strncpy (diskInfo [i].name, p, DI_NAME_LEN);
3396 X rc = GetDriveType (p);
3397 X diskInfo [i].printFlag = DI_OK;
3399 X if (rc == DRIVE_NO_ROOT_DIR)
3401 X diskInfo [i].printFlag = DI_BAD;
3404 X /* assume that any removable drives before the */
3405 X /* first non-removable disk are floppies... */
3406 X else if (rc == DRIVE_REMOVABLE)
3408 X diskInfo [i].printFlag = diskflag;
3415 X if (rc != DRIVE_REMOTE)
3417 X diskInfo [i].isLocal = TRUE;
3419 X /* strncpy (diskInfo [i].fsType, MSDOS_diskType [rc], DI_TYPE_LEN); */
3420 X } /* for each mounted drive */
3438 X unsigned long sectorspercluster;
3439 X unsigned long bytespersector;
3440 X unsigned long totalclusters;
3441 X unsigned long freeclusters;
3442 X char tbuff [MSDOS_BUFFER_SIZE];
3443 X char volName [MSDOS_BUFFER_SIZE];
3444 X char fsName [MSDOS_BUFFER_SIZE];
3450 X for (i = 0; i < diCount; ++i)
3452 X if (diskInfo [i].isLocal == FALSE &&
3453 X (flags & DI_F_LOCAL_ONLY) == DI_F_LOCAL_ONLY)
3455 X diskInfo [i].printFlag = DI_IGNORE;
3458 X printf ("mnt: ignore: remote: %s\n",
3459 X diskInfo [i].name);
3463 X if (diskInfo [i].printFlag == DI_OK || (flags & DI_F_ALL) == DI_F_ALL)
3465 X rc = GetVolumeInformation (diskInfo [i].name,
3466 X volName, MSDOS_BUFFER_SIZE, &serialNo, &maxCompLen,
3467 X &fsFlags, fsName, MSDOS_BUFFER_SIZE);
3468 X /* strcpy (tbuff, diskInfo [i].fsType); */
3469 X /* strcat (tbuff, " "); */
3470 X strncpy (diskInfo [i].fsType, fsName, DI_TYPE_LEN);
3471 X strncpy (diskInfo [i].special, volName, DI_SPEC_NAME_LEN);
3473 X rc = GetDiskFreeSpace (diskInfo [i].name,
3474 X (LPDWORD) §orspercluster, (LPDWORD) &bytespersector,
3475 X (LPDWORD) &freeclusters, (LPDWORD) &totalclusters);
3479 X mult = (double) (sectorspercluster *
3480 X bytespersector) / dispBlockSize;
3481 X diskInfo [i].totalBlocks = ((double) (_s_fs_size_t) totalclusters * mult);
3482 X diskInfo [i].freeBlocks = ((double) (_s_fs_size_t) freeclusters * mult);
3483 X diskInfo [i].availBlocks = ((double) (_s_fs_size_t) freeclusters * mult);
3485 X diskInfo [i].totalInodes = 0;
3486 X diskInfo [i].freeInodes = 0;
3487 X diskInfo [i].availInodes = 0;
3491 X printf ("%s: %s\n", diskInfo [i].name, diskInfo [i].fsType);
3492 X printf ("\ts/c:%ld b/s:%ld\n", sectorspercluster,
3494 X printf ("\tmult:%f\n", mult);
3495 X printf ("\tclusters: tot:%ld free:%ld\n",
3496 X totalclusters, freeclusters);
3501 X diskInfo [i].printFlag = DI_BAD;
3504 X printf ("disk %s; could not get disk space\n",
3505 X diskInfo [i].name);
3508 X } /* if printable drive */
3509 X } /* for each mounted drive */
3512 X#endif /* HAS_GETDISKFREESPACE */
3514 if test 97566 -ne `wc -c <'di.c'`; then
3515 echo shar: \"'di.c'\" unpacked with wrong size!
3519 echo shar: End of archive 2 \(of 3\).
3520 cp /dev/null ark2isdone
3523 if test ! -f ark${I}isdone ; then
3524 MISSING="${MISSING} ${I}"
3527 if test "${MISSING}" = "" ; then
3528 echo You have unpacked all 3 archives.
3529 rm -f ark[1-9]isdone
3531 echo You still need to unpack the following archives:
3534 ## End of shell archive.