]> git.ipfire.org Git - thirdparty/e2fsprogs.git/blobdiff - debugfs/icheck.c
ext2fs: convert unicode normalization from NFKD -> NFD
[thirdparty/e2fsprogs.git] / debugfs / icheck.c
index 136c52ee2435135ed7e129d2e4a8ed6806a5e350..71164cf740a0a4e178927455e1db91ff3a04606c 100644 (file)
@@ -1,10 +1,11 @@
 /*
  * icheck.c --- given a list of blocks, generate a list of inodes
- * 
+ *
  * Copyright (C) 1994 Theodore Ts'o.  This file may be redistributed
  * under the terms of the GNU Public License.
  */
 
+#include "config.h"
 #include <stdio.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include "debugfs.h"
 
 struct block_info {
-       blk_t   blk;
-       ino_t   ino;
+       blk64_t         blk;
+       ext2_ino_t      ino;
 };
 
 struct block_walk_struct {
        struct block_info       *barray;
-       int                     blocks_left;
-       int                     num_blocks;
-       ino_t                   inode;
+       e2_blkcnt_t             blocks_left;
+       e2_blkcnt_t             num_blocks;
+       ext2_ino_t              inode;
 };
 
-static int icheck_proc(ext2_filsys fs,
-                      blk_t    *block_nr,
-                      int blockcnt,
+static int icheck_proc(ext2_filsys fs EXT2FS_ATTR((unused)),
+                      blk64_t  *block_nr,
+                      e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)),
+                      blk64_t ref_block EXT2FS_ATTR((unused)),
+                      int ref_offset EXT2FS_ATTR((unused)),
                       void *private)
 {
        struct block_walk_struct *bw = (struct block_walk_struct *) private;
-       int     i;
+       e2_blkcnt_t     i;
 
        for (i=0; i < bw->num_blocks; i++) {
-               if (bw->barray[i].blk == *block_nr) {
+               if (!bw->barray[i].ino && bw->barray[i].blk == *block_nr) {
                        bw->barray[i].ino = bw->inode;
                        bw->blocks_left--;
                }
        }
        if (!bw->blocks_left)
                return BLOCK_ABORT;
-       
+
        return 0;
 }
 
-void do_icheck(int argc, char **argv)
+void do_icheck(int argc, char **argv, int sci_idx EXT2FS_ATTR((unused)),
+              void *infop EXT2FS_ATTR((unused)))
 {
        struct block_walk_struct bw;
        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;
        char                    *block_buf;
-       
+
        if (argc < 2) {
                com_err(argv[0], 0, "Usage: icheck <block number> ...");
                return;
@@ -84,11 +87,8 @@ void do_icheck(int argc, char **argv)
        }
 
        for (i=1; i < argc; i++) {
-               bw.barray[i-1].blk = strtol(argv[i], &tmp, 0);
-               if (*tmp) {
-                       com_err(argv[0], 0, "Bad block - %s", argv[i]);
-                       return;
-               }
+               if (strtoblk(argv[0], argv[i], NULL, &bw.barray[i-1].blk))
+                       goto error_out;
        }
 
        bw.num_blocks = bw.blocks_left = argc-1;
@@ -106,11 +106,25 @@ void do_icheck(int argc, char **argv)
                com_err("icheck", retval, "while starting inode scan");
                goto error_out;
        }
-       
+
        while (ino) {
+               blk64_t blk;
+
                if (!inode.i_links_count)
                        goto next;
-               if (!ext2fs_inode_has_valid_blocks(&inode))
+
+               bw.inode = ino;
+
+               blk = ext2fs_file_acl_block(current_fs, &inode);
+               if (blk) {
+                       icheck_proc(current_fs, &blk, 0,
+                                   0, 0, &bw);
+                       if (bw.blocks_left == 0)
+                               break;
+                       ext2fs_file_acl_block_set(current_fs, &inode, blk);
+               }
+
+               if (!ext2fs_inode_has_valid_blocks2(current_fs, &inode))
                        goto next;
                /*
                 * To handle filesystems touched by 0.3c extfs; can be
@@ -119,13 +133,12 @@ void do_icheck(int argc, char **argv)
                if (inode.i_dtime)
                        goto next;
 
-               bw.inode = ino;
-               
-               retval = ext2fs_block_iterate(current_fs, ino, 0, block_buf,
-                                             icheck_proc, &bw);
+               retval = ext2fs_block_iterate3(current_fs, ino,
+                                              BLOCK_FLAG_READ_ONLY, block_buf,
+                                              icheck_proc, &bw);
                if (retval) {
                        com_err("icheck", retval,
-                               "while calling ext2_block_iterate");
+                               "while calling ext2fs_block_iterate");
                        goto next;
                }
 
@@ -146,10 +159,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("%u\t<block not found>\n", binfo->blk);
+                       printf("%llu\t<block not found>\n", binfo->blk);
                        continue;
                }
-               printf("%u\t%ld\n", binfo->blk, binfo->ino);
+               printf("%llu\t%u\n", binfo->blk, binfo->ino);
        }
 
 error_out: