7 static void * tfs_read_inode_bitmap(struct tfs_sb_info
*sbi
)
9 char *buf
= malloc(sbi
->s_block_size
);
11 tfs_bread(sbi
, sbi
->s_inode_bitmap
, buf
);
17 * free an inode, return -1 if failed, or return 9
19 int tfs_free_inode(struct tfs_sb_info
*sbi
, int inr
)
21 char *bitmap
= tfs_read_inode_bitmap(sbi
);
23 /* inode number count from 1 */
24 if (clear_bit(bitmap
, inr
- 1) == 0) {
25 printk("ERROR: trying to free an unallocated inode!\n");
30 tfs_bwrite(sbi
, sbi
->s_inode_bitmap
, bitmap
);
35 int tfs_alloc_inode(struct tfs_sb_info
*sbi
, int inr
)
40 printk("ERROR: trying to alloc a negtive inode!\n");
44 bitmap
= tfs_read_inode_bitmap(sbi
);
45 /* try the target first */
46 if (test_bit(bitmap
, inr
- 1) != 0)
47 inr
= find_first_zero(bitmap
, bitmap
+ sbi
->s_block_size
) + 1;
49 set_bit(bitmap
, inr
- 1);
50 tfs_bwrite(sbi
, sbi
->s_inode_bitmap
, bitmap
);
57 #if 0 /* the deubg part */
59 int main(int argc
, char *argv
[])
63 struct tfs_sb_info
*sbi
;
65 char *command
= argv
[2];
66 char **inodes
= argv
+ 3;
70 printk("Usage: ialloc tfs.img command inodes...\n");
71 printk(" alloc, to alloc inodes\n");
72 printk(" feee, to free inodes\n");
76 sbi
= tfs_mount_by_fsname(fs
);
78 printk("tfs mount failed!\n");
82 if (strcmp(command
, "alloc") == 0) {
83 for (i
= 0; i
< count
; i
++) {
84 inr
= atoi(inodes
[i
]);
85 printk("trying to alloc inode %u\n", inr
);
86 inr
= tfs_alloc_inode(sbi
, inr
);
87 printk("inode number: %u allocated\n", inr
);
89 } else if (strcmp(command
, "free") == 0) {
90 for (i
= 0; i
< count
; i
++) {
91 inr
= atoi(inodes
[i
]);
92 printk("trying to free inode %u\n", inr
);
93 inr
= tfs_free_inode(sbi
, inr
);
94 printk("inode number: %d freed\n", inr
);
97 printk("Unknown command!\n");