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.
21 struct expand_dir_struct {
27 static int expand_dir_proc(ext2_filsys fs,
30 blk_t ref_block EXT2FS_ATTR((unused)),
31 int ref_offset EXT2FS_ATTR((unused)),
34 struct expand_dir_struct *es = (struct expand_dir_struct *) priv_data;
36 static blk_t last_blk = 0;
44 retval = ext2fs_new_block(fs, last_blk, 0, &new_blk);
50 retval = ext2fs_new_dir_block(fs, 0, 0, &block);
56 retval = ext2fs_write_dir_block(fs, new_blk, block);
58 retval = ext2fs_get_mem(fs->blocksize, &block);
63 memset(block, 0, fs->blocksize);
64 retval = io_channel_write_blk(fs->io, new_blk, 1, block);
70 ext2fs_free_mem(&block);
72 ext2fs_block_alloc_stats(fs, new_blk, +1);
76 return (BLOCK_CHANGED | BLOCK_ABORT);
81 errcode_t ext2fs_expand_dir(ext2_filsys fs, ext2_ino_t dir)
84 struct expand_dir_struct es;
85 struct ext2_inode inode;
87 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
89 if (!(fs->flags & EXT2_FLAG_RW))
90 return EXT2_ET_RO_FILSYS;
93 return EXT2_ET_NO_BLOCK_BITMAP;
95 retval = ext2fs_check_directory(fs, dir);
103 retval = ext2fs_block_iterate2(fs, dir, BLOCK_FLAG_APPEND,
104 0, expand_dir_proc, &es);
109 return EXT2_ET_EXPAND_DIR_ERR;
112 * Update the size and block count fields in the inode.
114 retval = ext2fs_read_inode(fs, dir, &inode);
118 inode.i_size += fs->blocksize;
119 ext2fs_iblk_add_blocks(fs, &inode, es.newblocks);
121 retval = ext2fs_write_inode(fs, dir, &inode);