home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1998 February / PCOnline_02_1998.iso / filesbbs / dos / lread10.exe / SUPER.C < prev   
Encoding:
C/C++ Source or Header  |  1995-05-23  |  2.5 KB  |  83 lines

  1. /* super.c
  2.  * David Lutz
  3.  * Error handling by Jason Hunter
  4.  *
  5.  * Routines for reading and manipulating the ext2 superblock
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <time.h>
  10. #define _SUPER_C_
  11. #include "ext2.h"
  12. #include "proto.h"
  13.  
  14. /*
  15.  * Global variables calculated from the super block info
  16.  */
  17. super_block sb;
  18. int BLOCK_SIZE;
  19. int FRAG_SIZE;
  20.  
  21. /* load_super
  22.  *
  23.  * returns 0 for failure
  24.  *        -1 for bad magic
  25.  *         1 for OK
  26.  */
  27. int load_super( void )
  28. {
  29.   if( readdisk( (byte *)&sb, 1024, sizeof(super_block) ) !=
  30.      sizeof(super_block) )
  31.   {
  32.     fprintf( stderr, "Drive unreadable.\n" );
  33.     return( -1 );        /* read failed */
  34.   }
  35.  
  36.   /* Now set a few of our (shhhh!) Global Variables */
  37.   BLOCK_SIZE = EXT2_MIN_BLOCK << sb.s_log_block_size;
  38.   FRAG_SIZE = EXT2_MIN_FRAG << sb.s_log_frag_size;
  39.  
  40.   if( sb.s_magic != EXT2_SUPER_MAGIC )
  41.   {
  42.     fprintf( stderr, "Bad magic number in superblock.  Not Linux.\n" );
  43.     return( -1 );        /* bad magic number */
  44.   }
  45.  
  46.   return( 1 );            /* everything OK */
  47. }
  48.  
  49. /* print_super
  50.  *
  51.  * print out a super block (good for debugging)
  52.  */
  53. void print_super( void )
  54. {
  55.   printf( "Inode Count: %lu\n", sb.s_inodes_count );
  56.   printf( "Block Count: %lu\n", sb.s_blocks_count );
  57.   printf( "Reserved Block Count: %lu\n", sb.s_r_blocks_count );
  58.   printf( "Free Blocks: %lu\n", sb.s_free_blocks_count );
  59.   printf( "Free Inodes: %lu\n", sb.s_free_inodes_count );
  60.   printf( "First Data Block: %lu\n", sb.s_first_data_block );
  61.   printf( "Log Block Size: %lu\n", sb.s_log_block_size );
  62.   printf( "Log Frag Size: %ld\n", sb.s_log_frag_size );
  63.   printf( "Blocks per Group: %lu\n", sb.s_blocks_per_group );
  64.   printf( "Fragments per Group: %lu\n", sb.s_frags_per_group );
  65.   printf( "Inodes per Group: %lu\n", sb.s_inodes_per_group );
  66.   printf( "Mount Time: %s", ctime( &(sb.s_mtime) ) );
  67.   printf( "Write Time: %s", ctime( &(sb.s_wtime) ) );
  68.   printf( "Mount Count: %u\n", sb.s_mnt_count );
  69.   printf( "Max Mount Count: %d\n", sb.s_max_mnt_count );
  70.   printf( "Magic Number: %X  (%s)\n", sb.s_magic,
  71.      sb.s_magic == EXT2_SUPER_MAGIC ? "OK" : "BAD" );
  72.   printf( "File System State: %X\n", sb.s_state );
  73.   printf( "Error Behaviour: %X\n", sb.s_errors );
  74.   printf( "Pad Value: %u\n", sb.s_pad );
  75.   printf( "Last Check: %s", ctime( &(sb.s_lastcheck) ) );
  76.   printf( "Check Interval: %lu\n", sb.s_checkinterval );
  77.   printf( "Creator OS: %lu\n", sb.s_creator_os );
  78.   printf( "Revision Level: %lu\n", sb.s_rev_level );
  79.   printf( "Reserved Block Default UID: %u\n", sb.s_def_resuid );
  80.   printf( "Reserved Block Default GID: %u\n", sb.s_def_resgid );
  81.   printf( "An' a bunch of padding we ain't gonna show ya!\n" );
  82. }
  83.