Add the implementation of tfs
[thunix.git] / fs / tfs / super.c
blob80e08dd3943ec1b78fee8b99fa0dd4d238f2c036
1 #include <stdio.h>
2 #include <malloc.h>
3 #include <tfs.h>
4 #include <fd.h>
7 struct tfs_sb_info * tfs_mount(void)
9 struct tfs_sb_info *sbi;
10 struct tfs_super_block sb;
12 /* Read the sector */
13 floppy_read(TFS_SB_SECTOR, &sb);
14 if (sb.s_magic != TFS_MAGIC) {
15 printk("Trying to mount not tfs file system!\n");
16 return NULL;
19 sbi = malloc(sizeof(*sbi));
20 if (!sbi) {
21 printk("Malloc from tfs sbi object failed!\n");
22 return NULL;
25 sbi->s_block_shift = sb.s_block_shift;
26 sbi->s_block_size = 1 << sbi->s_block_shift;
27 sbi->s_blocks_count = sb.s_blocks_count;
28 sbi->s_inodes_count = sb.s_inodes_count;
29 sbi->s_free_blocks_count = sb.s_free_blocks_count;
30 sbi->s_free_inodes_count = sb.s_free_inodes_count;
33 sbi->s_inode_bitmap = sb.s_inode_bitmap;
34 sbi->s_block_bitmap = sb.s_block_bitmap;
35 sbi->s_inode_table = sb.s_inode_table;
36 sbi->s_data_area = sb.s_data_area;
38 sbi->s_inode_bitmap_count = sb.s_block_bitmap - sb.s_inode_bitmap;
39 sbi->s_block_bitmap_count = sb.s_inode_table - sb.s_block_bitmap;
40 sbi->s_inode_table_count = sb.s_data_area - sb.s_inode_table;
43 sbi->s_offset = sb.s_offset;
45 sbi->s_inodes_per_block = sbi->s_block_size / sizeof(struct tfs_inode);
47 return sbi;