home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume5 / fsanalyze4.1 / part01 / fsanalyze.c < prev    next >
C/C++ Source or Header  |  1989-02-03  |  6KB  |  179 lines

  1. static char sccsid[] = "@(#)$Id: fsanalyze.c, V4.1 88/11/16 17:30:08 $";
  2.  
  3. /*
  4.  * fsanalyze.c - file system analyzer
  5.  * Version  : 4.1 - 88/11/16 17:30:08
  6.  *
  7.  * Author   : Michael J. Young
  8.  * USmail   : Software Development Technologies, Inc.
  9.  *            375 Dutton Rd
  10.  *            Sudbury MA 01776
  11.  * UUCP     : harvard!sdti!mjy
  12.  * Internet : mjy@sdti.SDTI.COM
  13.  *
  14.  * =========================================================================
  15.  * Note : This program has been placed in the public domain to permit
  16.  * unrestricted distribution and use.  I have placed no copyright on it, but
  17.  * I request that you keep me informed about any enhancements and bug fixes
  18.  * you make so I can keep an up-to-date copy for further distribution.
  19.  *
  20.  * This program is being provided "as is", with no warrantee as to safety or
  21.  * accuracy of results.  Use at your own risk.
  22.  * =========================================================================
  23.  */
  24.  
  25. /*
  26.  * Modification History:
  27.  *
  28.  *    Date       Author                   Description
  29.  * -----------  --------  -----------------------------------------------
  30.  * 28 Jul 1987    MJY       Originated
  31.  *  5 Oct 1987    MJY       Capability to analyze individual files,
  32.  *                          Added error checking to file system argument,
  33.  *                          Added -o flag
  34.  *                          Prints out volume and file system name in summary
  35.  * 12 Oct 1987    MJY       Use /etc/fsstat to do file system validity
  36.  *                          checking
  37.  *  9 Nov 1987    MJY       print out warning if file system is mounted
  38.  * 12 Nov 1987    MJY       Volume size statistics now long instead of int
  39.  *  7 Jan 1988    MJY       Modified blk_no() to use l3tol()
  40.  *
  41.  * Wed Mar  9 17:51:38 EST 1988 - M. Young (mjy@sdti.SDTI.COM),
  42.  *    Rewrite for portability between various versions of System V, esp.
  43.  *    SCO XENIX and 5.3 systems.  First (incomplete) attempt at porting
  44.  *    to BSD 4.3.  See README for details.
  45.  *
  46.  * Thu Apr  7 10:03:21 EDT 1988 - M. Young (mjy@sdti.SDTI.COM),
  47.  *    Seeks for files that span cylinders due to their sheer size are
  48.  *    ignored.  Average seek distance is now reported.
  49.  *
  50.  * Wed Apr 13 17:33:03 EDT 1988 - M. Young (mjy@sdti.SDTI.COM),
  51.  *    Completed port to BSD.  Fixed bug in inode numbering for BSD.
  52.  *    Symbolic links now handled correctly for individual files.
  53.  *
  54.  * Wed Jun 15 14:08:30 EDT 1988 - M. Young (mjy@sdti.SDTI.COM),
  55.  *    Number of top offenders is now a configurable parameter via the
  56.  *    NUMOFFEND macro in fsconfig.h.
  57.  *
  58.  * Fri Jun 24 16:22:10 EDT 1988 - M. Young (mjy@sdti.SDTI.COM),
  59.  *    Make top offender size report consistent with anal_file reports.
  60.  *
  61.  * Tue Jul 26 15:24:30 EDT 1988 - M. Young (mjy@sdti.SDTI.COM),
  62.  *    Added wasted space metric
  63.  *    Modified BSD rotation delay algorithm
  64.  *
  65.  * Thu Jul 28 16:15:22 EDT 1988 - M. Young (mjy@sdti.SDTI.COM),
  66.  *    Opt_interleave() formula now makes sense
  67.  *    Re-organized code and general cleanup in preparation for posting.
  68.  *
  69.  * Mon Aug 08 11:27:39 EDT 1988 - M. Young (mjy@sdti.SDTI.COM),
  70.  *    Revised OS_TYPE and FS_TYPE macros to avoid name-space conflicts
  71.  *
  72.  * Wed Nov 16 11:31:32 EST 1988 - M. Young (mjy@sdti.SDTI.COM),
  73.  *    Placed under SCCS
  74.  */
  75.  
  76. /*
  77.  * Include files
  78.  */
  79. #include "fsconfig.h"
  80. #include "fsanalyze.h"
  81.  
  82. /***************************************************************************
  83.  *                           Global Variables                              *
  84.  ***************************************************************************/
  85.  
  86. /*
  87.  * interface to system error messages
  88.  */
  89. extern char *sys_errlist[];
  90. extern int sys_nerr;
  91.  
  92. /*
  93.  * error : performs a function similar to perror(3), but supports variable
  94.  * argument lists.  Prints out a formatted error string to stderr, followed if
  95.  * possible by an appropriate system error message.  Control is then
  96.  * returned to the system with an error status.  This function does not
  97.  * return.
  98.  */
  99. /* VARARGS0 */
  100. void error (va_alist)
  101. va_dcl                            /* varargs */
  102. {
  103.     int err;                      /* 1st arg - error number */
  104.     char *str;                    /* 2nd arg - error format string */
  105.     va_list args;
  106.     va_start(args);
  107.     err = va_arg (args, int);
  108.     str = va_arg (args, char *);
  109.     vfprintf (stderr, str, args);
  110.     if (err <= sys_nerr && err > 0)
  111.         fprintf (stderr, "%s\n", sys_errlist[err]);
  112.     else
  113.         fprintf (stderr, "unknown error : %d\n", err);
  114.     va_end(args);
  115.  
  116.     /*
  117.      * print out partial report, if possible
  118.      */
  119.     if (fil_sys != NULL)print_report ();
  120.     exit(1);                      /* exit with error status */
  121.     }
  122.  
  123. main (argc, argv)
  124. int argc;
  125. char *argv[];
  126. {
  127.     int next_param;
  128.     extern int stat ();
  129.     struct stat f_stat;
  130.  
  131.     /*
  132.      * perform various initialization functions
  133.      */
  134.     next_param = init (argc, argv);
  135.  
  136.     if (next_param == argc){
  137.         /*
  138.          * no individual files to check, scan entire file system
  139.          */
  140.         printf ("Analyzing file system %s...\n", special);
  141.  
  142.         /*
  143.          * scan through all i-nodes in the file system
  144.          */
  145.         scan();
  146.  
  147.         /*
  148.          * print out statistics summary
  149.          */
  150.         print_report();
  151.         }
  152.     else {
  153.         /*
  154.          * scan individual files instead of entire file system
  155.          */
  156.         printf ("                  \t                                       Seek  Wasted\n");
  157.         printf ("        Name      \ti-node    Fragments  Size      %%       Dist  Space\n");
  158.         for (; next_param < argc; next_param++){
  159.             if (stat (argv[next_param], &f_stat) != 0){
  160.                 error (errno, "error opening \"%s\"\n",
  161.                        argv[next_param]);
  162.                 /* NOTREACHED */
  163.                 }
  164.             else {
  165.  
  166.                 /*
  167.                  * make sure the inode belongs to the correct device
  168.                  * (for BSD systems with symbolic links)
  169.                  */
  170.                 if ((f_stat.st_dev == fs_device) &&
  171.                     !IS_SPECIAL (f_stat.st_mode)){
  172.                     anal_file (f_stat.st_ino, argv[next_param]);
  173.                     }
  174.                 }
  175.             }
  176.         }
  177.     return (0);
  178.     }
  179.