]>
git.ipfire.org Git - thirdparty/e2fsprogs.git/blob - lib/ext2fs/expanddir.c
2 * expand.c --- expand an ext2fs directory
4 * Copyright (C) 1993 Theodore Ts'o. This file may be redistributed
5 * under the terms of the GNU Public License.
13 #include <linux/ext2_fs.h>
17 struct expand_dir_struct
{
22 static int expand_dir_proc(ext2_filsys fs
,
27 struct expand_dir_struct
*es
= (struct expand_dir_struct
*) private;
29 static blk_t last_blk
= 0;
38 retval
= ext2fs_new_block(fs
, last_blk
, 0, &new_blk
);
44 retval
= ext2fs_new_dir_block(fs
, 0, 0, &block
);
51 block
= malloc(fs
->blocksize
);
56 memset(block
, 0, fs
->blocksize
);
58 retval
= io_channel_write_blk(fs
->io
, new_blk
, 1, block
);
65 ext2fs_mark_block_bitmap(fs
, fs
->block_map
, new_blk
);
66 ext2fs_mark_bb_dirty(fs
);
67 group
= ext2fs_group_of_blk(fs
, new_blk
);
68 fs
->group_desc
[group
].bg_free_blocks_count
--;
69 fs
->super
->s_free_blocks_count
--;
70 ext2fs_mark_super_dirty(fs
);
72 return (BLOCK_CHANGED
| BLOCK_ABORT
);
77 errcode_t
ext2fs_expand_dir(ext2_filsys fs
, ino_t dir
)
80 struct expand_dir_struct es
;
81 struct ext2_inode inode
;
83 if (!(fs
->flags
& EXT2_FLAG_RW
))
84 return EXT2_ET_RO_FILSYS
;
86 retval
= ext2fs_check_directory(fs
, dir
);
93 retval
= ext2fs_block_iterate(fs
, dir
, BLOCK_FLAG_APPEND
,
94 0, expand_dir_proc
, &es
);
99 return EXT2_ET_EXPAND_DIR_ERR
;
102 * Update the size and block count fields in the inode.
104 retval
= ext2fs_read_inode(fs
, dir
, &inode
);
108 inode
.i_size
+= fs
->blocksize
;
109 inode
.i_blocks
+= fs
->blocksize
/ 512;
111 retval
= ext2fs_write_inode(fs
, dir
, &inode
);