home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume39 / enh-du2 / part02 / du.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-08-21  |  6.2 KB  |  226 lines

  1. /* @(#) du.h 1.15 93/08/18 00:09:02 
  2.  *
  3.  * "du" enhanced disk usage summary - version 2.
  4.  *
  5.  * Copyright 1990-1993, Unicom Systems Development.  All rights reserved.
  6.  * See accompanying README file for terms of distribution and use.
  7.  *
  8.  * Edit at tabstops=4.
  9.  */
  10.  
  11.  
  12. #define TRUE        1
  13. #define FALSE        0
  14.  
  15. /*
  16.  * Severity levels for errmssg() routine.
  17.  */
  18. #define ERR_WARN    0
  19. #define ERR_ABORT    1
  20.  
  21. #ifdef DEBUG
  22. # define Dprintf    if (!Debug) ; else fprintf
  23. #endif
  24.  
  25. #ifdef S_IFMT
  26. # ifndef S_ISREG
  27. #  define S_ISREG(m)    (((m) & S_IFMT) == S_IFREG)
  28. # endif
  29. # ifndef S_ISDIR
  30. #  define S_ISDIR(m)    (((m) & S_IFMT) == S_IFDIR)
  31. # endif
  32. #endif
  33.  
  34. #if defined(lint) && defined(NULL)
  35. # undef NULL
  36. # define NULL 0
  37. #endif
  38.  
  39. /*
  40.  * A boolean true/false value.
  41.  */
  42. typedef int BOOL;
  43.  
  44. /*
  45.  * Structure used to store information on mounted filesystems.
  46.  */
  47. struct fsinfo {
  48.     int dev;                /* the device number                        */
  49.     int nino;                /* number of available inodes on filesys    */
  50.     int bsize;                /* num bytes in a disk block for this dev    */
  51.     int nindir;                /* num direct disk addr can fit in a block    */
  52.     BOOL remote;            /* is this filesys a remote mount?            */
  53. #ifdef BROKE_STBLOCKS
  54.     int stbsize;            /* quanta for st_blocks reported by stat(2)    */
  55. #endif
  56.     int path_max;            /* max pathlen for an entry on this filesys    */
  57.     unsigned char *idone;    /* bit vector to mark inodes of links done    */
  58. };
  59.  
  60.  
  61. /*
  62.  * Structure to accumulate usage statistics.
  63.  *
  64.  * The statistics are accumulated in a chronological breakdown, as
  65.  * specified by "Num_break" and the "Breakdown[]" array.  "Num_break"
  66.  * indicates the number of columns in the breakdown, and "Breakdown[]"
  67.  * specifies the age for each of those columns.
  68.  *
  69.  * The "Num_break" value will range from 1 to MAX_BREAK.  The "blocks[n]"
  70.  * value accumulates the disk usage of all filesystem entries "Breakdown[n]"
  71.  * days or older.  The "files[n]" value counts the number of filesystem
  72.  * entries that contributed to that total.
  73.  *
  74.  * By default, "Num_break" will be 1 and "Breakdown[0]" will be 0.  That
  75.  * says accumulate a single set of statistics for all filesystem entries
  76.  * zero days old or older (i.e. everything).
  77.  *
  78.  */
  79. struct dusage {
  80.     long blocks[MAX_BREAK];    /* accumulated disk usage                    */
  81.     int files[MAX_BREAK];    /* number of disk entries                    */
  82. };
  83.  
  84.  
  85. #ifdef INTERN
  86. #    define EXTERN
  87. #    define INIT(X) = X
  88. #else
  89. #    define EXTERN extern
  90. #    define INIT(X)
  91. #endif
  92.  
  93. EXTERN char *Progname;
  94. #ifdef DEBUG
  95. EXTERN BOOL Debug INIT(FALSE);
  96. #endif
  97.  
  98. /*
  99.  * What to do at filesystem mount points.
  100.  */
  101. EXTERN enum {
  102.     FS_ALWAYS_CROSS,    /* always cross mount points (default)    */
  103.     FS_NEVER_CROSS,        /* never cross mount points (-f)        */
  104.     FS_LOCAL_ONLY        /* cross only local mount points (-F)    */
  105. } Handle_filesys INIT(FS_ALWAYS_CROSS);
  106.  
  107. /*
  108.  * What to do with hard links.
  109.  */
  110. EXTERN enum {
  111.     LK_COUNT_FIRST,        /* count just first link encountered (default)    */
  112.     LK_COUNT_ALL,        /* handle all hard links (-l)                    */
  113.     LK_COUNT_NONE,        /* ignore all hard links (-u)                    */
  114.     LK_COUNT_AVERAGE    /* average disk usage across hard links (-L)    */
  115. } Handle_links INIT(LK_COUNT_FIRST);
  116.  
  117. /*
  118.  * What to report.
  119.  */
  120. EXTERN enum {
  121.     PR_DIRS_ONLY,        /* report usage at all directories (default)    */
  122.     PR_TOTALS_ONLY,        /* report usage just for cmd line items (-s)    */
  123.     PR_EVERYTHING        /* report usage for everything encountered (-a)    */
  124. } Handle_output INIT(PR_DIRS_ONLY);
  125.  
  126. /*
  127.  * If true, accumulate the disk usage of a subdirectory into the usage
  128.  * of its parent directory.  If false, the disk usage of a directory will
  129.  * include just the contents of that directory.
  130.  */
  131. EXTERN BOOL Do_accum_subdirs INIT(TRUE);
  132.  
  133. /*
  134.  * If true, display file counts as well as disk block usage.
  135.  */
  136. EXTERN BOOL Do_file_counts INIT(FALSE);
  137.  
  138. #ifdef OBSOLETEOPT
  139. /*
  140.  * If true, descend into directories and accumulate usage (subject to
  141.  * filesystem handling at mount points).  If false, do not descend into
  142.  * directories and simply report the usage of the directory filesystem
  143.  * entry (i.e. sans contents) as its usage.
  144.  *
  145.  * This is a pretty useless option, but was present in the original
  146.  * "enh-du".  Unless somebody tells me they really use it, it is
  147.  * subject to removal in a future version.
  148.  */
  149. EXTERN BOOL Do_descend_dirs INIT(TRUE);
  150. #endif
  151.  
  152. /*
  153.  * If true, the sum of the usages of all items specified on the command
  154.  * line is displayed.  If false, this grand total is omitted.
  155.  */
  156. EXTERN BOOL Do_print_grand_total INIT(FALSE);
  157.  
  158. /*
  159.  * If true, error messages are displayed (rational behavior).
  160.  * If false, error messages are suppressed (traditional behavior).
  161.  */
  162. #ifdef PRINT_ERRORS
  163. EXTERN BOOL Do_print_errors INIT(TRUE);
  164. #else
  165. EXTERN BOOL Do_print_errors INIT(FALSE);
  166. #endif
  167.  
  168. /*
  169.  * Block size used in reporting disk usage.  The actual disk usage is
  170.  * calculated, and then scaled to blocks of the size indicated here.  If
  171.  * the value is zero, then the native filesystem block size is used.
  172.  */
  173. EXTERN int Report_blksize INIT(REPORT_BLKSIZE);
  174.  
  175. /*
  176.  * Only count usage for the user whose UID is this value, or
  177.  * negative to count usage for all users.
  178.  */
  179. EXTERN int Selected_user INIT(-1);
  180.  
  181. /*
  182.  * Specifies ages for the chronological breakdown in a (struct dusage).
  183.  * See comments in the (struct dusage) declaration for more info.
  184.  */
  185. EXTERN int Breakdown[MAX_BREAK] INIT({0});
  186.  
  187. /*
  188.  * Number of columns in the chronological breakdown.
  189.  * Specifies number of elements in "Breakdown[]" that are actually used.
  190.  */
  191. EXTERN int Num_break INIT(1);
  192.  
  193. /*
  194.  * Current time, used for calculation of the chronological breakdown.
  195.  */
  196. EXTERN long Curr_time;
  197.  
  198.  
  199. #if defined(__STDC__) && !defined(NO_PROTOTYPE)
  200. #    define __ARGS(X) X
  201. #else
  202. #    define __ARGS(X) ()
  203. #endif
  204.  
  205. /*
  206.  * Procedures.
  207.  */
  208. PTRTYPE *xmalloc __ARGS((unsigned));
  209. PTRTYPE *xrealloc __ARGS((PTRTYPE *, unsigned));
  210. void errmssg __ARGS((int, int, char *, ...));
  211. void zero_usage __ARGS((struct dusage *));
  212. void set_usage __ARGS((struct dusage *, time_t, long));
  213. void add_usage __ARGS((struct dusage *, struct dusage *));
  214. void print_usage __ARGS((char *, struct dusage *));
  215. int max_path_len __ARGS((char *));
  216. void du_entry __ARGS((char *, struct dusage *));
  217. int du_dir __ARGS((char *, struct stat    *, struct fsinfo *, struct dusage *));
  218. void fs_initinfo __ARGS((void));
  219. struct fsinfo *fs_getinfo __ARGS((struct stat *));
  220. int fs_linkdone __ARGS((struct fsinfo *, struct stat *));
  221. long fs_numblocks __ARGS((struct fsinfo *, struct stat *));
  222.  
  223.  
  224. extern int errno;
  225.  
  226.