Whamcloud - gitweb
ChangeLog, tune2fs.8.in:
[tools/e2fsprogs.git] / debugfs / icheck.c
index 848c76a..33daa3b 100644 (file)
 #include <ctype.h>
 #include <string.h>
 #include <time.h>
-#include <getopt.h>
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
 #include <sys/types.h>
-#include <sys/stat.h>
 
 #include "debugfs.h"
 
 struct block_info {
-       blk_t   blk;
-       ino_t   ino;
+       blk_t           blk;
+       ext2_ino_t      ino;
 };
 
 struct block_walk_struct {
        struct block_info       *barray;
        int                     blocks_left;
        int                     num_blocks;
-       ino_t                   inode;
+       ext2_ino_t              inode;
 };
 
-int icheck_proc(ext2_filsys fs,
-               blk_t   *block_nr,
-               int blockcnt,
-               void *private)
+static int icheck_proc(ext2_filsys fs,
+                      blk_t    *block_nr,
+                      int blockcnt,
+                      void *private)
 {
        struct block_walk_struct *bw = (struct block_walk_struct *) private;
        int     i;
@@ -55,7 +56,7 @@ void do_icheck(int argc, char **argv)
        struct block_info       *binfo;
        int                     i;
        ext2_inode_scan         scan = 0;
-       ino_t                   ino;
+       ext2_ino_t              ino;
        struct ext2_inode       inode;
        errcode_t               retval;
        char                    *tmp;
@@ -76,7 +77,7 @@ void do_icheck(int argc, char **argv)
        }
        memset(bw.barray, 0, sizeof(struct block_info) * argc);
 
-       block_buf = malloc(fs->blocksize * 3);
+       block_buf = malloc(current_fs->blocksize * 3);
        if (!block_buf) {
                com_err("icheck", ENOMEM, "while allocating block buffer");
                goto error_out;
@@ -92,13 +93,15 @@ void do_icheck(int argc, char **argv)
 
        bw.num_blocks = bw.blocks_left = argc-1;
 
-       retval = ext2fs_open_inode_scan(fs, 0, &scan);
+       retval = ext2fs_open_inode_scan(current_fs, 0, &scan);
        if (retval) {
                com_err("icheck", retval, "while opening inode scan");
                goto error_out;
        }
 
-       retval = ext2fs_get_next_inode(scan, &ino, &inode);
+       do {
+               retval = ext2fs_get_next_inode(scan, &ino, &inode);
+       } while (retval == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE);
        if (retval) {
                com_err("icheck", retval, "while starting inode scan");
                goto error_out;
@@ -107,6 +110,8 @@ void do_icheck(int argc, char **argv)
        while (ino) {
                if (!inode.i_links_count)
                        goto next;
+               if (!ext2fs_inode_has_valid_blocks(&inode))
+                       goto next;
                /*
                 * To handle filesystems touched by 0.3c extfs; can be
                 * removed later.
@@ -116,7 +121,7 @@ void do_icheck(int argc, char **argv)
 
                bw.inode = ino;
                
-               retval = ext2fs_block_iterate(fs, ino, 0, block_buf,
+               retval = ext2fs_block_iterate(current_fs, ino, 0, block_buf,
                                              icheck_proc, &bw);
                if (retval) {
                        com_err("icheck", retval,
@@ -128,7 +133,9 @@ void do_icheck(int argc, char **argv)
                        break;
 
        next:
-               retval = ext2fs_get_next_inode(scan, &ino, &inode);
+               do {
+                       retval = ext2fs_get_next_inode(scan, &ino, &inode);
+               } while (retval == EXT2_ET_BAD_BLOCK_IN_INODE_TABLE);
                if (retval) {
                        com_err("icheck", retval,
                                "while doing inode scan");
@@ -139,10 +146,10 @@ void do_icheck(int argc, char **argv)
        printf("Block\tInode number\n");
        for (i=0, binfo = bw.barray; i < bw.num_blocks; i++, binfo++) {
                if (binfo->ino == 0) {
-                       printf("%ld\t<block not found>\n", binfo->blk);
+                       printf("%u\t<block not found>\n", binfo->blk);
                        continue;
                }
-               printf("%ld\t%ld\n", binfo->blk, binfo->ino);
+               printf("%u\t%u\n", binfo->blk, binfo->ino);
        }
 
 error_out:
@@ -152,6 +159,3 @@ error_out:
                ext2fs_close_inode_scan(scan);
        return;
 }
-
-
-