* - The dirinfo directory information cache.
*/
+#include "config.h"
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
void e2fsck_pass3(e2fsck_t ctx)
{
ext2_filsys fs = ctx->fs;
- struct dir_info_iter *iter;
+ struct dir_info_iter *iter = NULL;
#ifdef RESOURCE_TRACK
struct resource_track rtrack;
#endif
/*
* Allocate some bitmaps to do loop detection.
*/
- pctx.errcode = ext2fs_allocate_inode_bitmap(fs, _("inode done bitmap"),
- &inode_done_map);
+ pctx.errcode = e2fsck_allocate_inode_bitmap(fs, _("inode done bitmap"),
+ EXT2FS_BMAP64_AUTODIR,
+ "inode_done_map", &inode_done_map);
if (pctx.errcode) {
pctx.num = 2;
fix_problem(ctx, PR_3_ALLOCATE_IBITMAP_ERROR, &pctx);
if (check_directory(ctx, dir->ino, &pctx))
goto abort_exit;
}
- e2fsck_dir_info_iter_end(ctx, iter);
/*
* Force the creation of /lost+found if not present
*/
- if ((ctx->flags & E2F_OPT_READONLY) == 0)
+ if ((ctx->options & E2F_OPT_READONLY) == 0)
e2fsck_get_lost_and_found(ctx, 1);
/*
e2fsck_rehash_directories(ctx);
abort_exit:
+ if (iter)
+ e2fsck_dir_info_iter_end(ctx, iter);
e2fsck_free_dir_info(ctx);
if (inode_loop_detect) {
ext2fs_free_inode_bitmap(inode_loop_detect);
inode_done_map = 0;
}
+ if (ctx->lnf_repair_block) {
+ ext2fs_unmark_block_bitmap2(ctx->block_found_map,
+ ctx->lnf_repair_block);
+ ctx->lnf_repair_block = 0;
+ }
+ if (ctx->root_repair_block) {
+ ext2fs_unmark_block_bitmap2(ctx->block_found_map,
+ ctx->root_repair_block);
+ ctx->root_repair_block = 0;
+ }
+
print_resource_track(ctx, _("Pass 3"), &rtrack, ctx->fs->io);
}
/*
* First, find a free block
*/
+ if (ctx->root_repair_block) {
+ blk = ctx->root_repair_block;
+ ctx->root_repair_block = 0;
+ goto skip_new_block;
+ }
pctx.errcode = ext2fs_new_block2(fs, 0, ctx->block_found_map, &blk);
if (pctx.errcode) {
pctx.str = "ext2fs_new_block";
return;
}
ext2fs_mark_block_bitmap2(ctx->block_found_map, blk);
+skip_new_block:
ext2fs_mark_block_bitmap2(fs->block_map, blk);
ext2fs_mark_bb_dirty(fs);
return;
}
- pctx.errcode = ext2fs_write_dir_block(fs, blk, block);
+ pctx.errcode = ext2fs_write_dir_block3(fs, blk, block, 0);
if (pctx.errcode) {
- pctx.str = "ext2fs_write_dir_block";
+ pctx.str = "ext2fs_write_dir_block3";
fix_problem(ctx, PR_3_CREATE_ROOT_ERROR, &pctx);
ctx->flags |= E2F_FLAG_ABORT;
return;
if (inode_loop_detect)
ext2fs_clear_inode_bitmap(inode_loop_detect);
else {
- pctx->errcode = ext2fs_allocate_inode_bitmap(fs, _("inode loop detection bitmap"), &inode_loop_detect);
+ pctx->errcode = e2fsck_allocate_inode_bitmap(fs, _("inode loop detection bitmap"), EXT2FS_BMAP64_AUTODIR, "inode_loop_detect", &inode_loop_detect);
if (pctx->errcode) {
pctx->num = 1;
fix_problem(ctx,
/*
* First, find a free block
*/
+ if (ctx->lnf_repair_block) {
+ blk = ctx->lnf_repair_block;
+ ctx->lnf_repair_block = 0;
+ goto skip_new_block;
+ }
retval = ext2fs_new_block2(fs, 0, ctx->block_found_map, &blk);
if (retval) {
pctx.errcode = retval;
return 0;
}
ext2fs_mark_block_bitmap2(ctx->block_found_map, blk);
- ext2fs_block_alloc_stats(fs, blk, +1);
+skip_new_block:
+ ext2fs_block_alloc_stats2(fs, blk, +1);
/*
* Next find a free inode.
return 0;
}
- retval = ext2fs_write_dir_block(fs, blk, block);
+ retval = ext2fs_write_dir_block3(fs, blk, block, 0);
ext2fs_free_mem(&block);
if (retval) {
pctx.errcode = retval;
ext2fs_icount_store(ctx->inode_count, ino, 2);
ext2fs_icount_store(ctx->inode_link_info, ino, 2);
ctx->lost_and_found = ino;
+ quota_data_add(ctx->qctx, &inode, ino, fs->blocksize);
+ quota_data_inodes(ctx->qctx, &inode, ino, +1);
#if 0
printf("/lost+found created; inode #%lu\n", ino);
#endif
*/
struct expand_dir_struct {
- int num;
- int guaranteed_size;
- int newblocks;
- int last_block;
+ blk64_t num;
+ e2_blkcnt_t guaranteed_size;
+ blk64_t newblocks;
+ blk64_t last_block;
errcode_t err;
e2fsck_t ctx;
};
static int expand_dir_proc(ext2_filsys fs,
- blk_t *blocknr,
+ blk64_t *blocknr,
e2_blkcnt_t blockcnt,
- blk_t ref_block EXT2FS_ATTR((unused)),
+ blk64_t ref_block EXT2FS_ATTR((unused)),
int ref_offset EXT2FS_ATTR((unused)),
void *priv_data)
{
struct expand_dir_struct *es = (struct expand_dir_struct *) priv_data;
blk64_t new_blk;
- static blk_t last_blk = 0;
+ static blk64_t last_blk = 0;
char *block;
errcode_t retval;
e2fsck_t ctx;
last_blk = *blocknr;
return 0;
}
- retval = ext2fs_new_block2(fs, last_blk, ctx->block_found_map,
- &new_blk);
- if (retval) {
- es->err = retval;
- return BLOCK_ABORT;
+
+ if (blockcnt &&
+ (EXT2FS_B2C(fs, last_blk) == EXT2FS_B2C(fs, last_blk + 1)))
+ new_blk = last_blk + 1;
+ else {
+ last_blk &= ~EXT2FS_CLUSTER_MASK(fs);
+ retval = ext2fs_new_block2(fs, last_blk, ctx->block_found_map,
+ &new_blk);
+ if (retval) {
+ es->err = retval;
+ return BLOCK_ABORT;
+ }
+ es->newblocks++;
+ ext2fs_block_alloc_stats2(fs, new_blk, +1);
}
+ last_blk = new_blk;
+
if (blockcnt > 0) {
retval = ext2fs_new_dir_block(fs, 0, 0, &block);
if (retval) {
return BLOCK_ABORT;
}
es->num--;
- retval = ext2fs_write_dir_block(fs, new_blk, block);
+ retval = ext2fs_write_dir_block3(fs, new_blk, block, 0);
} else {
retval = ext2fs_get_mem(fs->blocksize, &block);
if (retval) {
return BLOCK_ABORT;
}
memset(block, 0, fs->blocksize);
- retval = io_channel_write_blk(fs->io, new_blk, 1, block);
+ retval = io_channel_write_blk64(fs->io, new_blk, 1, block);
}
if (retval) {
es->err = retval;
ext2fs_free_mem(&block);
*blocknr = new_blk;
ext2fs_mark_block_bitmap2(ctx->block_found_map, new_blk);
- ext2fs_block_alloc_stats(fs, new_blk, +1);
- es->newblocks++;
if (es->num == 0)
return (BLOCK_CHANGED | BLOCK_ABORT);
errcode_t retval;
struct expand_dir_struct es;
struct ext2_inode inode;
+ blk64_t sz;
if (!(fs->flags & EXT2_FLAG_RW))
return EXT2_ET_RO_FILSYS;
es.newblocks = 0;
es.ctx = ctx;
- retval = ext2fs_block_iterate2(fs, dir, BLOCK_FLAG_APPEND,
+ retval = ext2fs_block_iterate3(fs, dir, BLOCK_FLAG_APPEND,
0, expand_dir_proc, &es);
if (es.err)
if (retval)
return retval;
- inode.i_size = (es.last_block + 1) * fs->blocksize;
+ sz = (es.last_block + 1) * fs->blocksize;
+ 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);
e2fsck_write_inode(ctx, dir, &inode, "expand_directory");