2 * expand.c --- expand an ext2fs directory
4 * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
7 * This file may be redistributed under the terms of the GNU Public
18 #if EXT2_FLAT_INCLUDES
21 #include <linux/ext2_fs.h>
26 struct expand_dir_struct {
31 static int expand_dir_proc(ext2_filsys fs,
38 struct expand_dir_struct *es = (struct expand_dir_struct *) priv_data;
40 static blk_t last_blk = 0;
49 retval = ext2fs_new_block(fs, last_blk, 0, &new_blk);
55 retval = ext2fs_new_dir_block(fs, 0, 0, &block);
61 retval = ext2fs_write_dir_block(fs, new_blk, block);
63 retval = ext2fs_get_mem(fs->blocksize, (void **) &block);
68 memset(block, 0, fs->blocksize);
69 retval = io_channel_write_blk(fs->io, new_blk, 1, block);
75 ext2fs_free_mem((void **) &block);
77 ext2fs_mark_block_bitmap(fs->block_map, new_blk);
78 ext2fs_mark_bb_dirty(fs);
79 group = ext2fs_group_of_blk(fs, new_blk);
80 fs->group_desc[group].bg_free_blocks_count--;
81 fs->super->s_free_blocks_count--;
82 ext2fs_mark_super_dirty(fs);
84 return (BLOCK_CHANGED | BLOCK_ABORT);
89 errcode_t ext2fs_expand_dir(ext2_filsys fs, ino_t dir)
92 struct expand_dir_struct es;
93 struct ext2_inode inode;
95 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
97 if (!(fs->flags & EXT2_FLAG_RW))
98 return EXT2_ET_RO_FILSYS;
101 return EXT2_ET_NO_BLOCK_BITMAP;
103 retval = ext2fs_check_directory(fs, dir);
110 retval = ext2fs_block_iterate2(fs, dir, BLOCK_FLAG_APPEND,
111 0, expand_dir_proc, &es);
116 return EXT2_ET_EXPAND_DIR_ERR;
119 * Update the size and block count fields in the inode.
121 retval = ext2fs_read_inode(fs, dir, &inode);
125 inode.i_size += fs->blocksize;
126 inode.i_blocks += fs->blocksize / 512;
128 retval = ext2fs_write_inode(fs, dir, &inode);