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,
36 struct expand_dir_struct *es = (struct expand_dir_struct *) priv_data;
38 static blk_t last_blk = 0;
47 retval = ext2fs_new_block(fs, last_blk, 0, &new_blk);
53 retval = ext2fs_new_dir_block(fs, 0, 0, &block);
59 retval = ext2fs_write_dir_block(fs, new_blk, block);
61 retval = ext2fs_get_mem(fs->blocksize, (void **) &block);
66 memset(block, 0, fs->blocksize);
67 retval = io_channel_write_blk(fs->io, new_blk, 1, block);
73 ext2fs_free_mem((void **) &block);
75 ext2fs_mark_block_bitmap(fs->block_map, new_blk);
76 ext2fs_mark_bb_dirty(fs);
77 group = ext2fs_group_of_blk(fs, new_blk);
78 fs->group_desc[group].bg_free_blocks_count--;
79 fs->super->s_free_blocks_count--;
80 ext2fs_mark_super_dirty(fs);
82 return (BLOCK_CHANGED | BLOCK_ABORT);
87 errcode_t ext2fs_expand_dir(ext2_filsys fs, 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);
108 retval = ext2fs_block_iterate(fs, dir, BLOCK_FLAG_APPEND,
109 0, expand_dir_proc, &es);
114 return EXT2_ET_EXPAND_DIR_ERR;
117 * Update the size and block count fields in the inode.
119 retval = ext2fs_read_inode(fs, dir, &inode);
123 inode.i_size += fs->blocksize;
124 inode.i_blocks += fs->blocksize / 512;
126 retval = ext2fs_write_inode(fs, dir, &inode);