Whamcloud - gitweb
libext2fs: don't hang in ext2fs_new_block2() on a full bigalloc file system
[tools/e2fsprogs.git] / lib / ext2fs / bmove.c
index 49839c6..deabf38 100644 (file)
@@ -2,8 +2,12 @@
  * bmove.c --- Move blocks around to make way for a particular
  *     filesystem structure.
  *
- * Copyright (C) 1997 Theodore Ts'o.  This file may be redistributed
- * under the terms of the GNU Public License.
+ * Copyright (C) 1997 Theodore Ts'o.
+ *
+ * %Begin-Header%
+ * This file may be redistributed under the terms of the GNU Library
+ * General Public License, version 2.
+ * %End-Header%
  */
 
 #include <stdio.h>
@@ -32,14 +36,14 @@ struct process_block_struct {
        int                     flags;
 };
 
-static int process_block(ext2_filsys fs, blk_t *block_nr,
-                        e2_blkcnt_t blockcnt, blk_t ref_block,
+static int process_block(ext2_filsys fs, blk64_t *block_nr,
+                        e2_blkcnt_t blockcnt, blk64_t ref_block,
                         int ref_offset, void *priv_data)
 {
        struct process_block_struct *pb;
        errcode_t       retval;
        int             ret;
-       blk_t           block, orig;
+       blk64_t         block, orig;
 
        pb = (struct process_block_struct *) priv_data;
        block = orig = *block_nr;
@@ -50,7 +54,7 @@ static int process_block(ext2_filsys fs, blk_t        *block_nr,
         */
        if (ext2fs_test_block_bitmap2(pb->reserve, block)) {
                do {
-                       if (++block >= fs->super->s_blocks_count)
+                       if (++block >= ext2fs_blocks_count(fs->super))
                                block = fs->super->s_first_data_block;
                        if (block == orig) {
                                pb->error = EXT2_ET_BLOCK_ALLOC_FAIL;
@@ -73,12 +77,14 @@ static int process_block(ext2_filsys fs, blk_t      *block_nr,
                ext2fs_mark_block_bitmap2(pb->alloc_map, block);
                ret = BLOCK_CHANGED;
                if (pb->flags & EXT2_BMOVE_DEBUG)
-                       printf("ino=%ld, blockcnt=%lld, %u->%u\n", pb->ino,
-                              blockcnt, orig, block);
+                       printf("ino=%u, blockcnt=%lld, %llu->%llu\n",
+                              (unsigned) pb->ino, blockcnt, 
+                              (unsigned long long) orig,
+                              (unsigned long long) block);
        }
        if (pb->add_dir) {
-               retval = ext2fs_add_dir_block(fs->dblist, pb->ino,
-                                             block, (int) blockcnt);
+               retval = ext2fs_add_dir_block2(fs->dblist, pb->ino,
+                                              block, blockcnt);
                if (retval) {
                        pb->error = retval;
                        ret |= BLOCK_ABORT;
@@ -143,8 +149,8 @@ errcode_t ext2fs_move_blocks(ext2_filsys fs,
                pb.add_dir = (LINUX_S_ISDIR(inode.i_mode) &&
                              flags & EXT2_BMOVE_GET_DBLIST);
 
-               retval = ext2fs_block_iterate2(fs, ino, 0, block_buf,
-                                             process_block, &pb);
+               retval = ext2fs_block_iterate3(fs, ino, 0, block_buf,
+                                              process_block, &pb);
                if (retval)
                        return retval;
                if (pb.error)