tabs, todo

master
Vitaliy Filippov 2014-01-07 17:06:21 +00:00
parent 553e1273ea
commit 46fc23e2d1
2 changed files with 23 additions and 28 deletions

50
bmove.c
View File

@ -1,6 +1,5 @@
/* /*
* bmove.c --- Move blocks around to make way for a particular * bmove.c --- Move blocks around to make way for a particular filesystem structure.
* filesystem structure.
* *
* Copyright (C) 1997 Theodore Ts'o. * Copyright (C) 1997 Theodore Ts'o.
* *
@ -16,14 +15,14 @@
#include "bmove.h" #include "bmove.h"
struct process_block_struct { struct process_block_struct {
ext2_ino_t ino; ext2_ino_t ino;
struct ext2_inode * inode; struct ext2_inode *inode;
ext2fs_block_bitmap reserve; ext2fs_block_bitmap reserve;
ext2fs_block_bitmap alloc_map; ext2fs_block_bitmap alloc_map;
errcode_t error; errcode_t error;
char *buf; char *buf;
int add_dir; int add_dir;
int flags; int flags;
}; };
static int process_block(ext2_filsys fs, blk64_t *block_nr, static int process_block(ext2_filsys fs, blk64_t *block_nr,
@ -31,9 +30,9 @@ static int process_block(ext2_filsys fs, blk64_t *block_nr,
int ref_offset, void *priv_data) int ref_offset, void *priv_data)
{ {
struct process_block_struct *pb; struct process_block_struct *pb;
errcode_t retval; errcode_t retval;
int ret; int ret;
blk64_t block, orig; blk64_t block, orig;
pb = (struct process_block_struct *) priv_data; pb = (struct process_block_struct *) priv_data;
block = orig = *block_nr; block = orig = *block_nr;
@ -57,7 +56,7 @@ static int process_block(ext2_filsys fs, blk64_t *block_nr,
return BLOCK_ABORT; return BLOCK_ABORT;
} }
} while (ext2fs_test_block_bitmap2(pb->reserve, block) || } while (ext2fs_test_block_bitmap2(pb->reserve, block) ||
ext2fs_test_block_bitmap2(pb->alloc_map, block)); ext2fs_test_block_bitmap2(pb->alloc_map, block));
retval = io_channel_read_blk64(fs->io, orig, 1, pb->buf); retval = io_channel_read_blk64(fs->io, orig, 1, pb->buf);
if (retval) { if (retval) {
@ -75,13 +74,12 @@ static int process_block(ext2_filsys fs, blk64_t *block_nr,
ret = BLOCK_CHANGED; ret = BLOCK_CHANGED;
if (pb->flags & EXT2_BMOVE_DEBUG) if (pb->flags & EXT2_BMOVE_DEBUG)
printf("ino=%u, blockcnt=%lld, %llu->%llu\n", printf("ino=%u, blockcnt=%lld, %llu->%llu\n",
(unsigned) pb->ino, blockcnt, (unsigned) pb->ino, blockcnt,
(unsigned long long) orig, (unsigned long long) orig,
(unsigned long long) block); (unsigned long long) block);
} }
if (pb->add_dir) { if (pb->add_dir) {
retval = ext2fs_add_dir_block2(fs->dblist, pb->ino, retval = ext2fs_add_dir_block2(fs->dblist, pb->ino, block, blockcnt);
block, blockcnt);
if (retval) { if (retval) {
pb->error = retval; pb->error = retval;
ret |= BLOCK_ABORT; ret |= BLOCK_ABORT;
@ -95,12 +93,12 @@ errcode_t ext2fs_move_blocks(ext2_filsys fs,
ext2fs_block_bitmap alloc_map, ext2fs_block_bitmap alloc_map,
int flags) int flags)
{ {
ext2_ino_t ino; ext2_ino_t ino;
struct ext2_inode inode; struct ext2_inode inode;
errcode_t retval; errcode_t retval;
struct process_block_struct pb; struct process_block_struct pb;
ext2_inode_scan scan; ext2_inode_scan scan;
char *block_buf; char *block_buf;
retval = ext2fs_open_inode_scan(fs, 0, &scan); retval = ext2fs_open_inode_scan(fs, 0, &scan);
if (retval) if (retval)
@ -136,18 +134,15 @@ errcode_t ext2fs_move_blocks(ext2_filsys fs,
return retval; return retval;
while (ino) { while (ino) {
if ((inode.i_links_count == 0) || if ((inode.i_links_count == 0) || !ext2fs_inode_has_valid_blocks2(fs, &inode))
!ext2fs_inode_has_valid_blocks2(fs, &inode))
goto next; goto next;
pb.ino = ino; pb.ino = ino;
pb.inode = &inode; pb.inode = &inode;
pb.add_dir = (LINUX_S_ISDIR(inode.i_mode) && pb.add_dir = (LINUX_S_ISDIR(inode.i_mode) && flags & EXT2_BMOVE_GET_DBLIST);
flags & EXT2_BMOVE_GET_DBLIST);
retval = ext2fs_block_iterate3(fs, ino, 0, block_buf, retval = ext2fs_block_iterate3(fs, ino, 0, block_buf, process_block, &pb);
process_block, &pb);
if (retval) if (retval)
return retval; return retval;
if (pb.error) if (pb.error)
@ -160,4 +155,3 @@ errcode_t ext2fs_move_blocks(ext2_filsys fs,
} }
return 0; return 0;
} }

View File

@ -21,6 +21,7 @@
*/ */
/** /**
* TODO fix reallocation for the case when inode tables for flex_bg do not fit into a single block group
* TODO bigalloc compatibility * TODO bigalloc compatibility
* TODO write some tests: for inode moving (image with many files), * TODO write some tests: for inode moving (image with many files),
* for block moving, including extent blocks (one sparse file with many extents), * for block moving, including extent blocks (one sparse file with many extents),