[comp.sources.bugs] patch to run fsanalyze under SCO XENIX

chip@killer.UUCP (Chip Rosenthal) (01/17/88)

The following patch allows fsanalyze (the filesystem fragmentation report
generator just posted to comp.sources.misc) to run under SCO XENIX.  I
have tested the patched version under SCO V2.2 and Microport.

Index: fsanalyze.c
*** fsanalyze.c.ORIG	Sat Jan 16 01:05:12 1988
--- fsanalyze.c	Sat Jan 16 16:16:14 1988
***************
*** 66,69
   * 12 Nov 1987    MJY       Volume size statistics now long instead of int
   *  7 Jan 1988    MJY       Modified blk_no() to use l3tol()
   */
  

--- 66,74 -----
   * 12 Nov 1987    MJY       Volume size statistics now long instead of int
   *  7 Jan 1988    MJY       Modified blk_no() to use l3tol()
+  *
+  * Sat Jan 16 16:05:34 CST 1988 - C. Rosenthal (chip@vector.UUCP)
+  *	Ported to SCO XENIX.  Added HAVE_FSSTAT def for those who don't.
+  *	Replaced IBLK and I_BLOCK_FACTOR with ROOTINO and INOPB.  Added
+  *	use of SUPERBOFF.
   */
  
***************
*** 68,71
   */
  
  
  # include <stdio.h>

--- 73,77 -----
   */
  
+ /*#define HAVE_FSSTAT 		/* define this if you have /etc/fsstat	*/
  
  
***************
*** 69,72
  
  
  # include <stdio.h>
  # include <sys/types.h>

--- 75,79 -----
  /*#define HAVE_FSSTAT 		/* define this if you have /etc/fsstat	*/
  
+ 
  # include <stdio.h>
  # include <sys/types.h>
***************
*** 76,81
  # include <sys/stat.h>
  
! # define BLK_SIZE	512		/* block size */
! # define IBLK 		2		/* block number of first i-node */
  
  # define I_BLOCK_FACTOR	32		/* number of i-nodes per block */

--- 83,100 -----
  # include <sys/stat.h>
  
! /*
!  * The following <sys/param.h> constants are used:
!  *   ROOTINO	Block number of the first inode.
!  *   SUPERBOFF	The seek offset for the superblock (see note below).
!  *   INOPB	Number of inodes per block.
!  *
!  * The following are used only if SUPERBOFF is not defined:
!  *   SUPERB	The block number of the superblock.
!  *   BSIZE	The physical block size in bytes.
!  *
!  * SCO XENIX doesn't have SUPERBOFF, so we will compute it using SUPERB
!  * and BSIZE.  Note that this calculation won't work for all systems,
!  * e.g.  Microport where BSIZE*SUPERB is 1024*1 but SUPERBOFF is 512.
!  */
  
  #ifndef SUPERBOFF
***************
*** 79,83
  # define IBLK 		2		/* block number of first i-node */
  
! # define I_BLOCK_FACTOR	32		/* number of i-nodes per block */
  
  /*

--- 98,104 -----
   */
  
! #ifndef SUPERBOFF
! # define SUPERBOFF	(BSIZE*SUPERB)
! #endif
  
  /*
***************
*** 82,85
  
  /*
   * file mode definitions
   */

--- 103,111 -----
  
  /*
+  * The "s_type" entry in the superblock is defined as BSIZE/BLK_SIZE
+  */
+ #define BLK_SIZE	512L
+ 
+ /*
   * file mode definitions
   */
***************
*** 182,185
  	}
  
  /*
   * check_fs : checks the file system to be sure it is not in need of

--- 208,212 -----
  	}
  
+ #ifdef HAVE_FSSTAT /* { */
  /*
   * check_fs : checks the file system to be sure it is not in need of
***************
*** 212,215
  	return (TRUE);
  	}
  
  /*

--- 239,243 -----
  	return (TRUE);
  	}
+ #endif /* } HAVE_FSSTAT */
  
  /*
***************
*** 299,302
  	if (special == NULL)usage();		/* no fs parameter */
  
  	/*
  	 * check for good file system (let fsstat do the dirty work!)

--- 327,331 -----
  	if (special == NULL)usage();		/* no fs parameter */
  
+ #ifdef HAVE_FSSTAT
  	/*
  	 * check for good file system (let fsstat do the dirty work!)
***************
*** 302,306
  	 * check for good file system (let fsstat do the dirty work!)
  	 */
! 	if (check_fs (special)){
  
  		/*

--- 331,337 -----
  	 * check for good file system (let fsstat do the dirty work!)
  	 */
! 	if ( !check_fs (special))
! 		exit(1);		/* bad file system, error status */
! #endif
  
  	/*
***************
*** 304,329
  	if (check_fs (special)){
  
! 		/*
! 		 * open file system and read the super block
! 		 */
! 		if ((fsys=fopen (special, "r")) == NULL){
! 			error (errno, "error opening \"%s\"\n", special);
! 			/* NOTREACHED */
! 			}
! 		if (fseek (fsys, 512L, 0)){
! 			error (errno, "error seeking superblock");
! 			/* NOTREACHED */
! 			}
! 		if (fread (&super, sizeof (struct filsys), 1, fsys) != 1){
! 			error (errno, "error reading superblock");
! 			/* NOTREACHED */
! 			}
! 
! 		num_inodes = (super.s_isize-2) * 16;
! 		if (super.s_magic != FsMAGIC)
! 			fs_type = Fs1b;
! 		else fs_type = super.s_type;
! 
! 		return i;		/* return # of next argument to be processed */
  		}
  	else {

--- 335,344 -----
  #endif
  
! 	/*
! 	 * open file system and read the super block
! 	 */
! 	if ((fsys=fopen (special, "r")) == NULL){
! 		error (errno, "error opening \"%s\"\n", special);
! 		/* NOTREACHED */
  		}
  	if (fseek (fsys, (long)SUPERBOFF, 0)){
***************
*** 327,332
  		return i;		/* return # of next argument to be processed */
  		}
! 	else {
! 		exit(1);		/* bad file system, error status */
  		}
  	}

--- 342,348 -----
  		/* NOTREACHED */
  		}
! 	if (fseek (fsys, (long)SUPERBOFF, 0)){
! 		error (errno, "error seeking superblock");
! 		/* NOTREACHED */
  		}
  	if (fread (&super, sizeof (struct filsys), 1, fsys) != 1){
***************
*** 330,333
  		exit(1);		/* bad file system, error status */
  		}
  	}
  

--- 346,366 -----
  		/* NOTREACHED */
  		}
+ 	if (fread (&super, sizeof (struct filsys), 1, fsys) != 1){
+ 		error (errno, "error reading superblock");
+ 		/* NOTREACHED */
+ 		}
+ 
+ #if defined(FsMAGIC) && defined(Fs1B)
+ 	/* I have absolutely no idea what this is for */
+ 	if (super.s_magic != FsMAGIC)
+ 		fs_type = Fs1b;
+ 	else fs_type = super.s_type;
+ #else
+ 	fs_type = super.s_type;
+ #endif
+ 
+ 	num_inodes = (super.s_isize-2) * 16;
+ 
+ 	return i;		/* return # of next argument to be processed */
  	}
  
***************
*** 360,364
  						 * first requested i-node */
  
! 	position = (IBLK * BLK_SIZE * fs_type) + 
  		   (sizeof (struct dinode) * ((long)in-1));
  

--- 393,397 -----
  						 * first requested i-node */
  
! 	position = (ROOTINO * BLK_SIZE * fs_type) + 
  		   (sizeof (struct dinode) * ((long)in-1));
  
***************
*** 397,401
  	 * get the indirect block
  	 */
! 	if (fseek (fsys, block * 512L * fs_type, 0)){
  		error (errno, "\nerror seeking indirect block %ld\n", block);
  		/* NOTREACHED */

--- 430,434 -----
  	 * get the indirect block
  	 */
! 	if (fseek (fsys, block * BLK_SIZE * fs_type, 0)){
  		error (errno, "\nerror seeking indirect block %ld\n", block);
  		/* NOTREACHED */
***************
*** 456,460
  	 * get the d-i block
  	 */
! 	if (fseek (fsys, block * 512L * fs_type, 0)){
  		error (errno, "\nerror seeking double indirect block %ld\n",
  			 block);

--- 489,493 -----
  	 * get the d-i block
  	 */
! 	if (fseek (fsys, block * BLK_SIZE * fs_type, 0)){
  		error (errno, "\nerror seeking double indirect block %ld\n",
  			 block);
***************
*** 512,516
  	 * get the t-i block
  	 */
! 	if (fseek (fsys, block * 512L * fs_type, 0)){
  		error (errno, "\nerror seeking triple indirect block %ld\n",
  			 block);

--- 545,549 -----
  	 * get the t-i block
  	 */
! 	if (fseek (fsys, block * BLK_SIZE * fs_type, 0)){
  		error (errno, "\nerror seeking triple indirect block %ld\n",
  			 block);
***************
*** 647,651
  	 * fsck phase 1)
  	 */
! 	file_size = (inode->di_size + (512 * fs_type - 1)) / (512 * fs_type);
  	if (file_size != data->data_blocks){
  		size_errors++;

--- 680,684 -----
  	 * fsck phase 1)
  	 */
! 	file_size = (inode->di_size + (BLK_SIZE * fs_type - 1)) / (BLK_SIZE * fs_type);
  	if (file_size != data->data_blocks){
  		size_errors++;
***************
*** 702,706
  void scan (){
  	int	i, j;				/* loop counters */
! 	struct dinode i_node[I_BLOCK_FACTOR];	/* holds a block of inodes */
  	struct file_data data;			/* per-inode statistics */
  

--- 735,739 -----
  void scan (){
  	int	i, j;				/* loop counters */
! 	struct dinode i_node[INOPB];		/* holds a block of inodes */
  	struct file_data data;			/* per-inode statistics */
  
***************
*** 705,709
  	struct file_data data;			/* per-inode statistics */
  
! 	for (i = 1; i < num_inodes; i+=I_BLOCK_FACTOR){
  
  		/*

--- 738,742 -----
  	struct file_data data;			/* per-inode statistics */
  
! 	for (i = 1; i < num_inodes; i+=INOPB){
  
  		/*
***************
*** 710,714
  		 * for efficiency, read a block of i-nodes at a time
  		 */
! 		get_inodes (i, i_node, I_BLOCK_FACTOR);
  
  		/*

--- 743,747 -----
  		 * for efficiency, read a block of i-nodes at a time
  		 */
! 		get_inodes (i, i_node, INOPB);
  
  		/*
***************
*** 715,719
  		 * scan through each i-node that was read in
  		 */
! 		for (j = 0; i+j < num_inodes && j < I_BLOCK_FACTOR; j++){
  			if (debug){
  				printf ("inode %d\r", i+j);

--- 748,752 -----
  		 * scan through each i-node that was read in
  		 */
! 		for (j = 0; i+j < num_inodes && j < INOPB; j++){
  			if (debug){
  				printf ("inode %d\r", i+j);
***************
*** 768,772
  	printf ("\n\nFile system name = \"%.6s\", Volume name = \"%.6s\"\n",
  		super.s_fname, super.s_fpack);
! 	printf ("File system logical block size = %d bytes\n", 512 * fs_type);
  	printf ("Volume Size = %ld blocks (%ld bytes)\n",
  		super.s_fsize, super.s_fsize * 512L * fs_type);

--- 801,805 -----
  	printf ("\n\nFile system name = \"%.6s\", Volume name = \"%.6s\"\n",
  		super.s_fname, super.s_fpack);
! 	printf ("File system logical block size = %d bytes\n", BLK_SIZE * fs_type);
  	printf ("Volume Size = %ld blocks (%ld bytes)\n",
  		super.s_fsize, super.s_fsize * BLK_SIZE * fs_type);
***************
*** 770,774
  	printf ("File system logical block size = %d bytes\n", 512 * fs_type);
  	printf ("Volume Size = %ld blocks (%ld bytes)\n",
! 		super.s_fsize, super.s_fsize * 512L * fs_type);
  	printf ("\t%u blocks reserved for super block and inodes\n", super.s_isize);
  	printf ("\t%lu blocks reserved for data\n", 

--- 803,807 -----
  	printf ("File system logical block size = %d bytes\n", BLK_SIZE * fs_type);
  	printf ("Volume Size = %ld blocks (%ld bytes)\n",
! 		super.s_fsize, super.s_fsize * BLK_SIZE * fs_type);
  	printf ("\t%u blocks reserved for super block and inodes\n", super.s_isize);
  	printf ("\t%lu blocks reserved for data\n", 
-- 
Chip Rosenthal         chip@vector.UUCP		| But if you want to sing the
Dallas Semiconductor     (214) 450-0400		|  blues, then boy you better
{texsun,codas,ihnp4}!killer!vector!chip		|  learn how to lose.