Whamcloud - gitweb
libext2fs: explicitly ignore a possible unlink failure in ext2fs_free_icount
[tools/e2fsprogs.git] / lib / ext2fs / read_bb.c
index d0f3139..e58b7cb 100644 (file)
@@ -4,11 +4,12 @@
  * Copyright (C) 1994 Theodore Ts'o.
  *
  * %Begin-Header%
- * This file may be redistributed under the terms of the GNU Public
- * License.
+ * This file may be redistributed under the terms of the GNU Library
+ * General Public License, version 2.
  * %End-Header%
  */
 
+#include "config.h"
 #include <stdio.h>
 #include <string.h>
 #if HAVE_UNISTD_H
@@ -38,16 +39,18 @@ struct read_bb_record {
  #pragma argsused
 #endif
 static int mark_bad_block(ext2_filsys fs, blk_t *block_nr,
-                         e2_blkcnt_t blockcnt, blk_t ref_block,
-                         int ref_offset, void *priv_data)
+                         e2_blkcnt_t blockcnt EXT2FS_ATTR((unused)),
+                         blk_t ref_block EXT2FS_ATTR((unused)),
+                         int ref_offset EXT2FS_ATTR((unused)),
+                         void *priv_data)
 {
        struct read_bb_record *rb = (struct read_bb_record *) priv_data;
-       
+
        if (blockcnt < 0)
                return 0;
-       
+
        if ((*block_nr < fs->super->s_first_data_block) ||
-           (*block_nr >= fs->super->s_blocks_count))
+           (*block_nr >= ext2fs_blocks_count(fs->super)))
                return 0;       /* Ignore illegal blocks */
 
        rb->err = ext2fs_badblocks_list_add(rb->bb_list, *block_nr);
@@ -72,10 +75,14 @@ errcode_t ext2fs_read_bb_inode(ext2_filsys fs, ext2_badblocks_list *bb_list)
                retval = ext2fs_read_inode(fs, EXT2_BAD_INO, &inode);
                if (retval)
                        return retval;
-               if (inode.i_blocks < 500)
-                       numblocks = (inode.i_blocks /
-                                    (fs->blocksize / 512)) + 20;
-               else
+               numblocks = inode.i_blocks;
+               if (!(ext2fs_has_feature_huge_file(fs->super) &&
+                     (inode.i_flags & EXT4_HUGE_FILE_FL)))
+                       numblocks = numblocks / (fs->blocksize / 512);
+               numblocks += 20;
+               if (numblocks < 50)
+                       numblocks = 50;
+               if (numblocks > 50000)
                        numblocks = 500;
                retval = ext2fs_badblocks_list_create(bb_list, numblocks);
                if (retval)
@@ -84,8 +91,8 @@ errcode_t ext2fs_read_bb_inode(ext2_filsys fs, ext2_badblocks_list *bb_list)
 
        rb.bb_list = *bb_list;
        rb.err = 0;
-       retval = ext2fs_block_iterate2(fs, EXT2_BAD_INO, 0, 0,
-                                     mark_bad_block, &rb);
+       retval = ext2fs_block_iterate2(fs, EXT2_BAD_INO, BLOCK_FLAG_READ_ONLY,
+                                      0, mark_bad_block, &rb);
        if (retval)
                return retval;