2 * expand.c --- expand an ext2fs directory
4 * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999 Theodore Ts'o.
7 * This file may be redistributed under the terms of the GNU Library
8 * General Public License, version 2.
23 struct expand_dir_struct {
31 static int expand_dir_proc(ext2_filsys fs,
34 blk64_t ref_block EXT2FS_ATTR((unused)),
35 int ref_offset EXT2FS_ATTR((unused)),
38 struct expand_dir_struct *es = (struct expand_dir_struct *) priv_data;
49 (EXT2FS_B2C(fs, es->goal) == EXT2FS_B2C(fs, es->goal+1)))
52 es->goal &= ~EXT2FS_CLUSTER_MASK(fs);
53 retval = ext2fs_new_block2(fs, es->goal, 0, &new_blk);
59 ext2fs_block_alloc_stats2(fs, new_blk, +1);
62 retval = ext2fs_new_dir_block(fs, 0, 0, &block);
68 retval = ext2fs_write_dir_block4(fs, new_blk, block, 0,
70 ext2fs_free_mem(&block);
72 retval = ext2fs_zero_blocks2(fs, new_blk, 1, NULL, NULL);
82 return (BLOCK_CHANGED | BLOCK_ABORT);
87 errcode_t ext2fs_expand_dir(ext2_filsys fs, ext2_ino_t dir)
90 struct expand_dir_struct es;
91 struct ext2_inode inode;
93 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
95 if (!(fs->flags & EXT2_FLAG_RW))
96 return EXT2_ET_RO_FILSYS;
99 return EXT2_ET_NO_BLOCK_BITMAP;
101 retval = ext2fs_check_directory(fs, dir);
105 retval = ext2fs_read_inode(fs, dir, &inode);
111 es.goal = ext2fs_find_inode_goal(fs, dir, &inode, 0);
115 retval = ext2fs_block_iterate3(fs, dir, BLOCK_FLAG_APPEND,
116 0, expand_dir_proc, &es);
117 if (retval == EXT2_ET_INLINE_DATA_CANT_ITERATE)
118 return ext2fs_inline_data_expand(fs, dir);
123 return EXT2_ET_EXPAND_DIR_ERR;
126 * Update the size and block count fields in the inode.
128 retval = ext2fs_read_inode(fs, dir, &inode);
132 inode.i_size += fs->blocksize;
133 ext2fs_iblk_add_blocks(fs, &inode, es.newblocks);
135 retval = ext2fs_write_inode(fs, dir, &inode);