1997-04-26 17:34:30 +04:00
|
|
|
/*
|
|
|
|
* check_desc.c --- Check the group descriptors of an ext2 filesystem
|
|
|
|
*
|
1997-04-29 20:15:03 +04:00
|
|
|
* Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
|
|
|
|
*
|
|
|
|
* %Begin-Header%
|
|
|
|
* This file may be redistributed under the terms of the GNU Public
|
|
|
|
* License.
|
|
|
|
* %End-Header%
|
1997-04-26 17:34:30 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
1997-08-11 03:07:40 +04:00
|
|
|
#if HAVE_UNISTD_H
|
1997-04-26 17:34:30 +04:00
|
|
|
#include <unistd.h>
|
1997-08-11 03:07:40 +04:00
|
|
|
#endif
|
1997-04-26 17:34:30 +04:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <linux/ext2_fs.h>
|
|
|
|
|
|
|
|
#include "ext2fs.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This routine sanity checks the group descriptors
|
|
|
|
*/
|
|
|
|
errcode_t ext2fs_check_desc(ext2_filsys fs)
|
|
|
|
{
|
|
|
|
int i;
|
Many files:
dosio.c: New file to do DOS/BIOS disk accesses.
namei.c (open_namei): Make pathlen be of type size_t.
llseek.c: Always #include stdlib.h since it's need to define
size_t.
io.h: Use errcode_t for magic numbers.
icount.c (get_icount_el), dupfs.c (ext2fs_dup_handle), dblist.c
(dir_block_cmp): Use size_t where appropriate.
read_bb.c (ext2fs_read_bb_inode), cmp_bitmaps.c
(ext2fs_compare_inode_bitmap): Use blk_t, ino_t and size_t
where appropriate.
closefs.c (ext2fs_flush): Use dgrp_t instead of int where
appropriate.
openfs.c (ext2fs_open), check_desc.c (ext2fs_check_desc): Use blk_t
instead of int where appropriate.
rw_bitmaps.c (read_bitmaps), irel_ma.c, inode.c (ext2fs_write_inode),
initialize.c (ext2fs_initialize): brel_ma.c: Fix to make be
16-bit safe.
link.c (ext2fs_link), unlink.c (ext2fs_unlink), lookup.c (lookup_proc),
ismounted.c (ext2fs_check_if_mounted), block.c (xlate_func):
Add #pragma argsused for Turbo C.
1997-08-12 00:29:22 +04:00
|
|
|
blk_t block = fs->super->s_first_data_block;
|
|
|
|
blk_t next;
|
1997-04-26 17:34:30 +04:00
|
|
|
|
|
|
|
EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
|
|
|
|
|
|
|
|
for (i = 0; i < fs->group_desc_count; i++) {
|
|
|
|
next = block + fs->super->s_blocks_per_group;
|
|
|
|
/*
|
|
|
|
* Check to make sure block bitmap for group is
|
|
|
|
* located within the group.
|
|
|
|
*/
|
|
|
|
if (fs->group_desc[i].bg_block_bitmap < block ||
|
|
|
|
fs->group_desc[i].bg_block_bitmap >= next)
|
|
|
|
return EXT2_ET_GDESC_BAD_BLOCK_MAP;
|
|
|
|
/*
|
|
|
|
* Check to make sure inode bitmap for group is
|
|
|
|
* located within the group
|
|
|
|
*/
|
|
|
|
if (fs->group_desc[i].bg_inode_bitmap < block ||
|
|
|
|
fs->group_desc[i].bg_inode_bitmap >= next)
|
|
|
|
return EXT2_ET_GDESC_BAD_INODE_MAP;
|
|
|
|
/*
|
|
|
|
* Check to make sure inode table for group is located
|
|
|
|
* within the group
|
|
|
|
*/
|
|
|
|
if (fs->group_desc[i].bg_inode_table < block ||
|
1997-04-26 18:48:50 +04:00
|
|
|
((fs->group_desc[i].bg_inode_table +
|
|
|
|
fs->inode_blocks_per_group) >= next))
|
1997-04-26 17:34:30 +04:00
|
|
|
return EXT2_ET_GDESC_BAD_INODE_TABLE;
|
|
|
|
|
|
|
|
block = next;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|