2 * alloc.c --- allocate new inodes, blocks for ext2fs
4 * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
7 * This file may be redistributed under the terms of the GNU Public
18 #include <sys/types.h>
23 #include <linux/ext2_fs.h>
28 * Right now, just search forward from the parent directory's block
29 * group to find the next free inode.
31 * Should have a special policy for directories.
33 errcode_t ext2fs_new_inode(ext2_filsys fs, ino_t dir, int mode,
34 ext2fs_inode_bitmap map, ino_t *ret)
40 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
45 return EXT2_ET_NO_INODE_BITMAP;
48 dir_group = (dir - 1) / EXT2_INODES_PER_GROUP(fs->super);
50 start_inode = (dir_group * EXT2_INODES_PER_GROUP(fs->super)) + 1;
51 if (start_inode < EXT2_FIRST_INODE(fs->super))
52 start_inode = EXT2_FIRST_INODE(fs->super);
56 if (!ext2fs_test_inode_bitmap(map, i))
59 if (i > fs->super->s_inodes_count)
60 i = EXT2_FIRST_INODE(fs->super);
61 } while (i != start_inode);
63 if (ext2fs_test_inode_bitmap(map, i))
70 * Stupid algorithm --- we now just search forward starting from the
71 * goal. Should put in a smarter one someday....
73 errcode_t ext2fs_new_block(ext2_filsys fs, blk_t goal,
74 ext2fs_block_bitmap map, blk_t *ret)
78 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
83 return EXT2_ET_NO_BLOCK_BITMAP;
84 if (!goal || (goal >= fs->super->s_blocks_count))
85 goal = fs->super->s_first_data_block;
88 if (!ext2fs_test_block_bitmap(map, i)) {
93 if (i >= fs->super->s_blocks_count)
94 i = fs->super->s_first_data_block;
99 errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start, blk_t finish,
100 int num, ext2fs_block_bitmap map, blk_t *ret)
104 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
109 return EXT2_ET_NO_BLOCK_BITMAP;
111 b = fs->super->s_first_data_block;
117 if (b+num-1 > fs->super->s_blocks_count)
118 b = fs->super->s_first_data_block;
119 if (ext2fs_fast_test_block_bitmap_range(map, b, num)) {
124 } while (b != finish);