diff options
author | Darrick J. Wong <darrick.wong@oracle.com> | 2014-07-26 14:34:56 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2014-07-26 14:34:56 -0400 |
commit | 97c607b1a25e1f4e83bf246c76b679d91470f5dc (patch) | |
tree | b542ac7ef606e7e60e2d2133755956808db9c774 /e2fsck | |
parent | a30a4e93f3fd51d81687de82ab96e57a3694d71c (diff) | |
download | e2fsprogs-97c607b1a25e1f4e83bf246c76b679d91470f5dc.tar.gz |
libext2fs: provide a function to set inode size
Provide an API to set i_size in an inode and take care of all required
feature flag modifications. Refactor the code to use this new
function.
[ Moved the function to lib/ext2fs/blk_num.c, which is the rest of
these sorts of functions live, and renamed it to be
ext2fs_inode_size_set() instead of ext2fs_inode_set_size() to be
consistent with the other functions in in blk_num.c -- tytso ]
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'e2fsck')
-rw-r--r-- | e2fsck/pass1.c | 9 | ||||
-rw-r--r-- | e2fsck/pass2.c | 11 | ||||
-rw-r--r-- | e2fsck/pass3.c | 5 | ||||
-rw-r--r-- | e2fsck/rehash.c | 5 |
4 files changed, 20 insertions, 10 deletions
diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c index dc15db29..0f2b9be9 100644 --- a/e2fsck/pass1.c +++ b/e2fsck/pass1.c @@ -265,8 +265,7 @@ static void check_size(e2fsck_t ctx, struct problem_context *pctx) if (!fix_problem(ctx, PR_1_SET_NONZSIZE, pctx)) return; - inode->i_size = 0; - inode->i_size_high = 0; + ext2fs_inode_size_set(ctx->fs, inode, 0); e2fsck_write_inode(ctx, pctx->ino, pctx->inode, "pass1"); } @@ -2263,9 +2262,9 @@ static void check_blocks(e2fsck_t ctx, struct problem_context *pctx, pctx->num = (pb.last_block+1) * fs->blocksize; pctx->group = bad_size; if (fix_problem(ctx, PR_1_BAD_I_SIZE, pctx)) { - inode->i_size = pctx->num; - if (!LINUX_S_ISDIR(inode->i_mode)) - inode->i_size_high = pctx->num >> 32; + if (LINUX_S_ISDIR(inode->i_mode)) + pctx->num &= 0xFFFFFFFFULL; + ext2fs_inode_size_set(fs, inode, pctx->num); dirty_inode++; } pctx->num = 0; diff --git a/e2fsck/pass2.c b/e2fsck/pass2.c index 517adaa9..2f57af61 100644 --- a/e2fsck/pass2.c +++ b/e2fsck/pass2.c @@ -1466,8 +1466,15 @@ static int allocate_dir_block(e2fsck_t ctx, */ e2fsck_read_inode(ctx, db->ino, &inode, "allocate_dir_block"); ext2fs_iblk_add_blocks(fs, &inode, 1); - if (inode.i_size < (db->blockcnt+1) * fs->blocksize) - inode.i_size = (db->blockcnt+1) * fs->blocksize; + if (EXT2_I_SIZE(&inode) < (db->blockcnt+1) * fs->blocksize) { + pctx->errcode = ext2fs_inode_size_set(fs, &inode, + (db->blockcnt+1) * fs->blocksize); + if (pctx->errcode) { + pctx->str = "ext2fs_inode_size_set"; + fix_problem(ctx, PR_2_ALLOC_DIRBOCK, pctx); + return 1; + } + } e2fsck_write_inode(ctx, db->ino, &inode, "allocate_dir_block"); /* diff --git a/e2fsck/pass3.c b/e2fsck/pass3.c index f9d4aae3..fb217273 100644 --- a/e2fsck/pass3.c +++ b/e2fsck/pass3.c @@ -804,8 +804,9 @@ errcode_t e2fsck_expand_directory(e2fsck_t ctx, ext2_ino_t dir, return retval; sz = (es.last_block + 1) * fs->blocksize; - inode.i_size = sz; - inode.i_size_high = sz >> 32; + retval = ext2fs_inode_size_set(fs, &inode, sz); + if (retval) + return retval; ext2fs_iblk_add_blocks(fs, &inode, es.newblocks); quota_data_add(ctx->qctx, &inode, dir, es.newblocks * fs->blocksize); diff --git a/e2fsck/rehash.c b/e2fsck/rehash.c index e80ed3ad..8ff48838 100644 --- a/e2fsck/rehash.c +++ b/e2fsck/rehash.c @@ -699,7 +699,10 @@ static errcode_t write_directory(e2fsck_t ctx, ext2_filsys fs, inode.i_flags &= ~EXT2_INDEX_FL; else inode.i_flags |= EXT2_INDEX_FL; - inode.i_size = outdir->num * fs->blocksize; + retval = ext2fs_inode_size_set(fs, &inode, + outdir->num * fs->blocksize); + if (retval) + return retval; ext2fs_iblk_sub_blocks(fs, &inode, wd.cleared); e2fsck_write_inode(ctx, ino, &inode, "rehash_dir"); |