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.
22 struct expand_dir_struct {
29 static int expand_dir_proc(ext2_filsys fs,
32 blk64_t ref_block EXT2FS_ATTR((unused)),
33 int ref_offset EXT2FS_ATTR((unused)),
36 struct expand_dir_struct *es = (struct expand_dir_struct *) priv_data;
47 (EXT2FS_B2C(fs, es->goal) == EXT2FS_B2C(fs, es->goal+1)))
50 es->goal &= ~EXT2FS_CLUSTER_MASK(fs);
51 retval = ext2fs_new_block2(fs, es->goal, 0, &new_blk);
59 retval = ext2fs_new_dir_block(fs, 0, 0, &block);
65 retval = ext2fs_write_dir_block(fs, new_blk, block);
67 retval = ext2fs_get_mem(fs->blocksize, &block);
72 memset(block, 0, fs->blocksize);
73 retval = io_channel_write_blk64(fs->io, new_blk, 1, block);
81 ext2fs_free_mem(&block);
83 ext2fs_block_alloc_stats2(fs, new_blk, +1);
86 return (BLOCK_CHANGED | BLOCK_ABORT);
91 errcode_t ext2fs_expand_dir(ext2_filsys fs, ext2_ino_t dir)
94 struct expand_dir_struct es;
95 struct ext2_inode inode;
97 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
99 if (!(fs->flags & EXT2_FLAG_RW))
100 return EXT2_ET_RO_FILSYS;
103 return EXT2_ET_NO_BLOCK_BITMAP;
105 retval = ext2fs_check_directory(fs, dir);
114 retval = ext2fs_block_iterate3(fs, dir, BLOCK_FLAG_APPEND,
115 0, expand_dir_proc, &es);
120 return EXT2_ET_EXPAND_DIR_ERR;
123 * Update the size and block count fields in the inode.
125 retval = ext2fs_read_inode(fs, dir, &inode);
129 inode.i_size += fs->blocksize;
130 ext2fs_iblk_add_blocks(fs, &inode, es.newblocks);
132 retval = ext2fs_write_inode(fs, dir, &inode);