1 /* vi: set sw=4 ts=4: */
3 * expand.c --- expand an ext2fs directory
5 * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999 Theodore Ts'o.
8 * This file may be redistributed under the terms of the GNU Public
22 struct expand_dir_struct {
28 static int expand_dir_proc(ext2_filsys fs,
31 blk_t ref_block EXT2FS_ATTR((unused)),
32 int ref_offset EXT2FS_ATTR((unused)),
35 struct expand_dir_struct *es = (struct expand_dir_struct *) priv_data;
37 static blk_t last_blk = 0;
45 retval = ext2fs_new_block(fs, last_blk, 0, &new_blk);
51 retval = ext2fs_new_dir_block(fs, 0, 0, &block);
57 retval = ext2fs_write_dir_block(fs, new_blk, block);
59 retval = ext2fs_get_mem(fs->blocksize, &block);
64 memset(block, 0, fs->blocksize);
65 retval = io_channel_write_blk(fs->io, new_blk, 1, block);
71 ext2fs_free_mem(&block);
73 ext2fs_block_alloc_stats(fs, new_blk, +1);
77 return (BLOCK_CHANGED | BLOCK_ABORT);
82 errcode_t ext2fs_expand_dir(ext2_filsys fs, ext2_ino_t dir)
85 struct expand_dir_struct es;
86 struct ext2_inode inode;
88 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
90 if (!(fs->flags & EXT2_FLAG_RW))
91 return EXT2_ET_RO_FILSYS;
94 return EXT2_ET_NO_BLOCK_BITMAP;
96 retval = ext2fs_check_directory(fs, dir);
104 retval = ext2fs_block_iterate2(fs, dir, BLOCK_FLAG_APPEND,
105 0, expand_dir_proc, &es);
110 return EXT2_ET_EXPAND_DIR_ERR;
113 * Update the size and block count fields in the inode.
115 retval = ext2fs_read_inode(fs, dir, &inode);
119 inode.i_size += fs->blocksize;
120 inode.i_blocks += (fs->blocksize / 512) * es.newblocks;
122 retval = ext2fs_write_inode(fs, dir, &inode);