1997-04-29 20:17:09 +04:00
|
|
|
/*
|
|
|
|
* tst_inode.c --- this function tests the inode scan function
|
2008-08-28 07:07:54 +04:00
|
|
|
*
|
1997-04-29 20:17:09 +04:00
|
|
|
* Copyright (C) 1996 by Theodore Ts'o.
|
2008-08-28 07:07:54 +04:00
|
|
|
*
|
1997-04-29 20:17:09 +04:00
|
|
|
* %Begin-Header%
|
|
|
|
* This file may be redistributed under the terms of the GNU Public
|
|
|
|
* License.
|
|
|
|
* %End-Header%
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
1997-08-11 03:07:40 +04:00
|
|
|
#if HAVE_UNISTD_H
|
1997-04-29 20:17:09 +04:00
|
|
|
#include <unistd.h>
|
1997-08-11 03:07:40 +04:00
|
|
|
#endif
|
1997-04-29 20:17:09 +04:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#if HAVE_ERRNO_H
|
|
|
|
#include <errno.h>
|
|
|
|
#endif
|
|
|
|
|
Many files:
inode.c (ext2fs_open_inode_scan): Initialize the group variables
so that we don't need to call get_next_blockgroup() the first
time around. Saves a bit of time, and prevents us from
needing to assign -1 to current_group (which is an unsigned
value).
icount.c (insert_icount_el): Cast the estimated number of inodes
from a float to an ino_t.
alloc.c, alloc_tables.c, badlbocks.c, bb_compat.c, bb_inode.c,
bitmaps.c, bitops.c, block.c, bmap.c, bmove.c, brel_ma.c,
check_desc.c, closefs.c, cmp_bitmaps.c, dblist.c,
dblist_dir.c, dir_iterate.c, dirblock.c, dupfs.c, expanddir.c,
ext2fs.h, fileio.c, freefs.c, get_pathname.c, getsize.c,
icount.c, initialize.c, inline.c, inode.c, irel_ma.c,
ismounted.c, link.c, lookup.c, mkdir.c, namei.c, native.c,
newdir.c, openfs.c, read_bb.c, read_bb_file.c, rs_bitmap.c,
rw_bitmaps.c, swapfs.c, test_io.c, tst_badblocks.c,
tst_getsize.c, tst_iscan.c, unix_io.c, unlink.c, valid_blk.c,
version.c: If EXT2_FLAT_INCLUDES is defined, then assume all
of the ext2-specific header files are in a flat directory.
block.c, bmove.c, dirblock.c, fileio.c: Explicitly cast
all assignments from void * to be compatible with C++.
closefs.c (ext2fs_flush): Add a call to io_channel_flush() to
make sure the contents of the disk are flushed to disk.
dblist.c (ext2fs_add_dir_block): Change new to be new_entry to
avoid C++ namespace clash.
bitmaps.c (ext2fs_copy_bitmap): Change new to be new_map to
avoid C++ namespace clash.
ext2fs.h, bb_inode.c, block.c, bmove.c, brel.h, brel_ma.c,
irel.h, irel_ma.c, dblist.c, dblist_dir.c, dir_iterate.c,
ext2fsP.h, expanddir.c, get_pathname.c, inode.c, link.c,
unlink.c: Change private to be priv_data (to avoid C++
namespace clash)
1998-01-19 17:47:53 +03:00
|
|
|
#include "ext2_fs.h"
|
1997-04-29 20:17:09 +04:00
|
|
|
#include "ext2fs.h"
|
|
|
|
|
|
|
|
blk_t test_vec[] = { 8, 12, 24, 34, 43, 44, 100, 0 };
|
|
|
|
|
|
|
|
ext2_filsys test_fs;
|
|
|
|
ext2fs_block_bitmap bad_block_map, touched_map;
|
|
|
|
ext2fs_inode_bitmap bad_inode_map;
|
|
|
|
badblocks_list test_badblocks;
|
|
|
|
|
|
|
|
int first_no_comma = 1;
|
|
|
|
int failed = 0;
|
|
|
|
|
|
|
|
static void test_read_blk(unsigned long block, int count, errcode_t err)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (first_no_comma)
|
|
|
|
first_no_comma = 0;
|
|
|
|
else
|
|
|
|
printf(", ");
|
|
|
|
|
|
|
|
if (count > 1)
|
|
|
|
printf("%lu-%lu", block, block+count-1);
|
|
|
|
else
|
|
|
|
printf("%lu", block);
|
|
|
|
|
|
|
|
for (i=0; i < count; i++, block++) {
|
|
|
|
if (ext2fs_test_block_bitmap(touched_map, block)) {
|
|
|
|
printf("\nDuplicate block?!? --- %lu\n", block);
|
|
|
|
failed++;
|
|
|
|
first_no_comma = 1;
|
|
|
|
}
|
|
|
|
ext2fs_mark_block_bitmap(touched_map, block);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup the variables for doing the inode scan test.
|
|
|
|
*/
|
|
|
|
static void setup(void)
|
|
|
|
{
|
|
|
|
errcode_t retval;
|
|
|
|
int i;
|
|
|
|
struct ext2_super_block param;
|
|
|
|
|
|
|
|
initialize_ext2_error_table();
|
|
|
|
|
|
|
|
memset(¶m, 0, sizeof(param));
|
|
|
|
param.s_blocks_count = 12000;
|
|
|
|
|
|
|
|
|
|
|
|
test_io_cb_read_blk = test_read_blk;
|
2008-08-28 07:07:54 +04:00
|
|
|
|
1997-04-29 20:17:09 +04:00
|
|
|
retval = ext2fs_initialize("test fs", 0, ¶m,
|
|
|
|
test_io_manager, &test_fs);
|
|
|
|
if (retval) {
|
|
|
|
com_err("setup", retval,
|
|
|
|
"While initializing filesystem");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
retval = ext2fs_allocate_tables(test_fs);
|
|
|
|
if (retval) {
|
|
|
|
com_err("setup", retval,
|
|
|
|
"While allocating tables for test filesystem");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
retval = ext2fs_allocate_block_bitmap(test_fs, "bad block map",
|
|
|
|
&bad_block_map);
|
|
|
|
if (retval) {
|
|
|
|
com_err("setup", retval,
|
|
|
|
"While allocating bad_block bitmap");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
retval = ext2fs_allocate_block_bitmap(test_fs, "touched map",
|
|
|
|
&touched_map);
|
|
|
|
if (retval) {
|
|
|
|
com_err("setup", retval,
|
|
|
|
"While allocating touched block bitmap");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
retval = ext2fs_allocate_inode_bitmap(test_fs, "bad inode map",
|
|
|
|
&bad_inode_map);
|
|
|
|
if (retval) {
|
|
|
|
com_err("setup", retval,
|
|
|
|
"While allocating bad inode bitmap");
|
|
|
|
exit(1);
|
|
|
|
}
|
2008-08-28 07:07:54 +04:00
|
|
|
|
ChangeLog, dumpe2fs.c, mke2fs.c:
dumpe2fs.c: Use WORDS_BIGENDIAN to determine whether or not we're
(not) using i386 byte order.
dumpe2fs.c, mke2fs.c: Stop using the compatibility badblocks function,
and use the ext2fs_badblocks_* functions instead.
ChangeLog, inode.c, tst_iscan.c:
inode.c, tst_iscan.c: Stop using the compatibility badblocks function,
and use the ext2fs_badblocks_* functions instead.
ChangeLog, badblocks.c:
badblocks.c: Stop using the compatibility badblocks function, and use
the ext2fs_badblocks_* functions instead.
2001-06-13 04:12:04 +04:00
|
|
|
retval = ext2fs_badblocks_list_create(&test_badblocks, 5);
|
1997-04-29 20:17:09 +04:00
|
|
|
if (retval) {
|
|
|
|
com_err("setup", retval, "while creating badblocks list");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
for (i=0; test_vec[i]; i++) {
|
ChangeLog, dumpe2fs.c, mke2fs.c:
dumpe2fs.c: Use WORDS_BIGENDIAN to determine whether or not we're
(not) using i386 byte order.
dumpe2fs.c, mke2fs.c: Stop using the compatibility badblocks function,
and use the ext2fs_badblocks_* functions instead.
ChangeLog, inode.c, tst_iscan.c:
inode.c, tst_iscan.c: Stop using the compatibility badblocks function,
and use the ext2fs_badblocks_* functions instead.
ChangeLog, badblocks.c:
badblocks.c: Stop using the compatibility badblocks function, and use
the ext2fs_badblocks_* functions instead.
2001-06-13 04:12:04 +04:00
|
|
|
retval = ext2fs_badblocks_list_add(test_badblocks, test_vec[i]);
|
1997-04-29 20:17:09 +04:00
|
|
|
if (retval) {
|
|
|
|
com_err("setup", retval,
|
|
|
|
"while adding test vector %d", i);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
ext2fs_mark_block_bitmap(bad_block_map, test_vec[i]);
|
|
|
|
}
|
|
|
|
test_fs->badblocks = test_badblocks;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Iterate using inode_scan
|
|
|
|
*/
|
|
|
|
static void iterate(void)
|
|
|
|
{
|
|
|
|
struct ext2_inode inode;
|
|
|
|
ext2_inode_scan scan;
|
|
|
|
errcode_t retval;
|
Many files:
alloc.c, bb_inode.c, bitmaps.c, bitops.h, block.c, bmap.c, bmove.c,
brel.h, cmp_bitmaps.c, dblist.c, dblist_dir.c, dir_iterate.c,
expanddir.c, ext2fs.h, ext2fsP.h, fileio.c, finddev.c, get_pathname.c,
icount.c, inode.c, irel.h, irel_ma.c, ismounted.c, link.c, lookup.c,
mkdir.c, mkjournal.c, namei.c, newdir.c, read_bb_file.c, test_io.c,
tst_iscan.c, unix_io.c, unlink.c: Change use of ino_t to ext2_ino_t,
to protect applications that attempt to compile
-D_FILE_OFFSET_BITS=64, since this inexplicably changes ino_t(!?). So
we use ext2_ino_t to avoid an unexpected ABI change.
2001-01-11 07:54:39 +03:00
|
|
|
ext2_ino_t ino;
|
1997-04-29 20:17:09 +04:00
|
|
|
|
|
|
|
retval = ext2fs_open_inode_scan(test_fs, 8, &scan);
|
|
|
|
if (retval) {
|
|
|
|
com_err("iterate", retval, "While opening inode scan");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
printf("Reading blocks: ");
|
|
|
|
retval = ext2fs_get_next_inode(scan, &ino, &inode);
|
|
|
|
if (retval) {
|
|
|
|
com_err("iterate", retval, "while reading first inode");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
while (ino) {
|
|
|
|
retval = ext2fs_get_next_inode(scan, &ino, &inode);
|
|
|
|
if (retval == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE) {
|
|
|
|
ext2fs_mark_inode_bitmap(bad_inode_map, ino);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (retval) {
|
|
|
|
com_err("iterate", retval,
|
|
|
|
"while getting next inode");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
ext2fs_close_inode_scan(scan);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify the touched map
|
|
|
|
*/
|
|
|
|
static void check_map(void)
|
|
|
|
{
|
|
|
|
int i, j, first=1;
|
|
|
|
unsigned long blk;
|
|
|
|
|
|
|
|
for (i=0; test_vec[i]; i++) {
|
|
|
|
if (ext2fs_test_block_bitmap(touched_map, test_vec[i])) {
|
2006-09-12 22:56:15 +04:00
|
|
|
printf("Bad block was touched --- %u\n", test_vec[i]);
|
1997-04-29 20:17:09 +04:00
|
|
|
failed++;
|
|
|
|
first_no_comma = 1;
|
|
|
|
}
|
|
|
|
ext2fs_mark_block_bitmap(touched_map, test_vec[i]);
|
|
|
|
}
|
|
|
|
for (i = 0; i < test_fs->group_desc_count; i++) {
|
|
|
|
for (j=0, blk = test_fs->group_desc[i].bg_inode_table;
|
|
|
|
j < test_fs->inode_blocks_per_group;
|
|
|
|
j++, blk++) {
|
|
|
|
if (!ext2fs_test_block_bitmap(touched_map, blk) &&
|
|
|
|
!ext2fs_test_block_bitmap(bad_block_map, blk)) {
|
|
|
|
printf("Missing block --- %lu\n", blk);
|
|
|
|
failed++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("Bad inodes: ");
|
|
|
|
for (i=1; i <= test_fs->super->s_inodes_count; i++) {
|
|
|
|
if (ext2fs_test_inode_bitmap(bad_inode_map, i)) {
|
|
|
|
if (first)
|
|
|
|
first = 0;
|
|
|
|
else
|
|
|
|
printf(", ");
|
2006-09-12 22:56:15 +04:00
|
|
|
printf("%u", i);
|
1997-04-29 20:17:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
setup();
|
|
|
|
iterate();
|
|
|
|
check_map();
|
|
|
|
if (!failed)
|
|
|
|
printf("Inode scan tested OK!\n");
|
|
|
|
return failed;
|
|
|
|
}
|
|
|
|
|