Whamcloud - gitweb
Merge branch 'maint' into next
[tools/e2fsprogs.git] / debugfs / filefrag.c
index 30933b6..961b696 100644 (file)
@@ -145,8 +145,7 @@ static void filefrag(ext2_ino_t ino, struct ext2_inode *inode,
        if (fs->options & VERBOSE_OPT) {
                blk64_t num_blocks = ext2fs_inode_i_blocks(current_fs, inode);
 
-               if (!(current_fs->super->s_feature_ro_compat &
-                    EXT4_FEATURE_RO_COMPAT_HUGE_FILE) ||
+               if (!ext2fs_has_feature_huge_file(current_fs->super) ||
                    !(inode->i_flags & EXT4_HUGE_FILE_FL))
                        num_blocks /= current_fs->blocksize / 512;
 
@@ -154,11 +153,13 @@ static void filefrag(ext2_ino_t ino, struct ext2_inode *inode,
                        fs->name, num_blocks, EXT2_I_SIZE(inode));
        }
        print_header(fs);
-       retval = ext2fs_block_iterate3(current_fs, ino,
-                                      BLOCK_FLAG_READ_ONLY, NULL,
-                                      filefrag_blocks_proc, fs);
-       if (retval)
-               com_err("ext2fs_block_iterate3", retval, 0);
+       if (ext2fs_inode_has_valid_blocks2(current_fs, inode)) {
+               retval = ext2fs_block_iterate3(current_fs, ino,
+                                              BLOCK_FLAG_READ_ONLY, NULL,
+                                              filefrag_blocks_proc, fs);
+               if (retval)
+                       com_err("ext2fs_block_iterate3", retval, 0);
+       }
 
        report_filefrag(fs);
        fprintf(fs->f, "%s: %d contiguous extents%s\n", fs->name, fs->ext,
@@ -183,7 +184,7 @@ static int filefrag_dir_proc(ext2_ino_t dir EXT2FS_ATTR((unused)),
        if (entry == DIRENT_DELETED_FILE)
                return 0;
 
-       thislen = dirent->name_len & 0xFF;
+       thislen = ext2fs_dirent_name_len(dirent);
        strncpy(name, dirent->name, thislen);
        name[thislen] = '\0';
        ino = dirent->inode;
@@ -259,7 +260,8 @@ static void dir_iterate(ext2_ino_t ino, struct filefrag_struct *fs)
        }
 }
 
-void do_filefrag(int argc, char *argv[])
+void do_filefrag(int argc, char *argv[], int sci_idx EXT2FS_ATTR((unused)),
+                void *infop EXT2FS_ATTR((unused)))
 {
        struct filefrag_struct fs;
        struct ext2_inode inode;
@@ -271,7 +273,7 @@ void do_filefrag(int argc, char *argv[])
                return;
 
        reset_getopt();
-       while ((c = getopt (argc, argv, "dvr")) != EOF) {
+       while ((c = getopt(argc, argv, "dvr")) != EOF) {
                switch (c) {
                case 'd':
                        fs.options |= DIR_OPT;
@@ -289,7 +291,7 @@ void do_filefrag(int argc, char *argv[])
 
        if (argc > optind+1) {
        print_usage:
-               com_err(0, 0, "Usage: filefrag [-dv] file");
+               com_err(0, 0, "Usage: filefrag [-dvr] file");
                return;
        }