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 Public
21 struct expand_dir_struct {
27 static int expand_dir_proc(ext2_filsys fs,
34 struct expand_dir_struct *es = (struct expand_dir_struct *) priv_data;
36 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, (void **) &block);
64 memset(block, 0, fs->blocksize);
65 retval = io_channel_write_blk(fs->io, new_blk, 1, block);
71 ext2fs_free_mem((void **) &block);
73 ext2fs_mark_block_bitmap(fs->block_map, new_blk);
74 ext2fs_mark_bb_dirty(fs);
75 group = ext2fs_group_of_blk(fs, new_blk);
76 fs->group_desc[group].bg_free_blocks_count--;
77 fs->super->s_free_blocks_count--;
78 ext2fs_mark_super_dirty(fs);
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);
109 retval = ext2fs_block_iterate2(fs, dir, BLOCK_FLAG_APPEND,
110 0, expand_dir_proc, &es);
115 return EXT2_ET_EXPAND_DIR_ERR;
118 * Update the size and block count fields in the inode.
120 retval = ext2fs_read_inode(fs, dir, &inode);
124 inode.i_size += fs->blocksize;
125 inode.i_blocks += (fs->blocksize / 512) * es.newblocks;
127 retval = ext2fs_write_inode(fs, dir, &inode);