home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1998 February / PCOnline_02_1998.iso / filesbbs / win95 / ext2tool.exe / EXT2FS / CHK_DESC.C < prev    next >
C/C++ Source or Header  |  1995-05-10  |  2KB  |  65 lines

  1. /*
  2.  * check_desc.c --- Check the group descriptors of an ext2 filesystem
  3.  * 
  4.  * Copyright (C) 1993, 1994 Theodore Ts'o.  This file may be redistributed
  5.  * under the terms of the GNU Public License.
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <unistd.h>
  11. #include <stdlib.h>
  12. #include <fcntl.h>
  13. #include <time.h>
  14. #include <sys/stat.h>
  15. #include <errno.h>
  16. #include <sys/types.h>
  17.  
  18. #include <linux/ext2_fs.h>
  19.  
  20. #include "ext2fs.h"
  21.  
  22. /*
  23.  * This routine sanity checks the group descriptors
  24.  */
  25. errcode_t ext2fs_check_desc(ext2_filsys fs)
  26. {
  27.     int i;
  28.     int block = fs->super->s_first_data_block;
  29.     int next, inode_blocks_per_group;
  30.  
  31.     EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
  32.  
  33.     inode_blocks_per_group = fs->super->s_inodes_per_group /
  34.         EXT2_INODES_PER_BLOCK (fs->super);
  35.  
  36.     for (i = 0; i < fs->group_desc_count; i++) {
  37.         next = block + fs->super->s_blocks_per_group;
  38.         /*
  39.          * Check to make sure block bitmap for group is
  40.          * located within the group.
  41.          */
  42.         if (fs->group_desc[i].bg_block_bitmap < block ||
  43.             fs->group_desc[i].bg_block_bitmap >= next)
  44.             return EXT2_ET_GDESC_BAD_BLOCK_MAP;
  45.         /*
  46.          * Check to make sure inode bitmap for group is
  47.          * located within the group
  48.          */
  49.         if (fs->group_desc[i].bg_inode_bitmap < block ||
  50.             fs->group_desc[i].bg_inode_bitmap >= next)
  51.             return EXT2_ET_GDESC_BAD_INODE_MAP;
  52.         /*
  53.          * Check to make sure inode table for group is located
  54.          * within the group
  55.          */
  56.         if (fs->group_desc[i].bg_inode_table < block ||
  57.             fs->group_desc[i].bg_inode_table+inode_blocks_per_group >=
  58.             next)
  59.             return EXT2_ET_GDESC_BAD_INODE_TABLE;
  60.         
  61.         block = next;
  62.     }
  63.     return 0;
  64. }
  65.