6 #define TFS_ROOT_INODE 1
10 /* namei: path lookup flags */
11 #define LOOKUP_PARENT 0x1
12 #define LOOKUP_CREATE 0x2
14 /* just support I_FILE and I_DIR only currently */
15 enum tfs_inode_mode
{ I_FILE
, I_DIR
, I_UNKNOWN
};
17 static inline int get_mode(int mode
)
21 else if (mode
& TFS_DIR
)
27 /* It's really enought for a test file system */
28 #define TFS_N_BLOCKS 8
31 uint16_t i_mode
; /* File mode */
32 uint16_t i_uid
; /* Owner UID */
33 uint32_t i_size
; /* File size */
34 uint32_t i_atime
; /* Access time */
35 uint32_t i_ctime
; /* Create time */
36 uint32_t i_mtime
; /* modify time */
37 uint32_t i_dtime
; /* delete time */
38 uint32_t i_block
[TFS_N_BLOCKS
]; /* block address of file's count */
39 uint32_t i_flags
; /* flags */
40 uint32_t i_reserved
[1];
44 * The inode structure in memory, including the detail file information
47 int i_mode
; /* FILE or DIR */
49 uint32_t i_ino
; /* Inode number */
50 uint32_t i_atime
; /* Access time */
51 uint32_t i_mtime
; /* Modify time */
52 uint32_t i_ctime
; /* Create time */
53 uint32_t i_dtime
; /* Delete time */
54 uint32_t * i_data
; /* The block address array where the file stores */
58 /* The max lenght of each file name */
59 #define TFS_NAME_LEN 28
60 struct tfs_dir_entry
{
61 uint32_t d_inode
; /* inode number */
62 char d_name
[TFS_NAME_LEN
]; /* entry name */
65 #define TFS_MAGIC 0x4c534654 /* TFSL */
68 struct tfs_super_block
{
69 uint32_t s_inodes_count
; /* Max file count */
70 uint32_t s_blocks_count
;
71 uint32_t s_free_blocks_count
;
72 uint32_t s_free_inodes_count
;
73 uint32_t s_magic
; /* TFS's magic signature */
74 uint32_t s_block_shift
; /* Block size */
76 uint32_t s_inode_bitmap
;
77 uint32_t s_block_bitmap
;
78 uint32_t s_inode_table
;
79 uint32_t s_data_area
; /* where the data starts */
82 uint32_t s_offset
; /* In which sector the fs stored */
83 uint32_t s_reserved
[117];
86 /* TFS super block info */
88 uint32_t s_inodes_count
; /* Max file count */
89 uint32_t s_blocks_count
;
90 uint32_t s_free_blocks_count
;
91 uint32_t s_free_inodes_count
;
92 uint32_t s_block_shift
; /* Block size in bits */
93 uint32_t s_block_size
; /* Block size in bytes */
95 uint32_t s_inode_bitmap
;
96 uint32_t s_inode_bitmap_count
;
97 uint32_t s_block_bitmap
;
98 uint32_t s_block_bitmap_count
;
99 uint32_t s_inode_table
;
100 uint32_t s_inode_table_count
;
101 uint32_t s_data_area
; /* where the data starts */
104 uint32_t s_offset
; /* In which sector the fs stored */
106 int s_inodes_per_block
;
110 #define TFS_INODES_PER_BLOCK(sbi) (sbi->s_inodes_per_block)
112 #define TFS_DEBUG printf
114 #define roundup(x, y) ((x) / (y) + (((x) % (y)) ? 1 : 0))
117 extern int set_bit(void *, unsigned int);
118 extern int clear_bit(void *, unsigned int);
119 extern int test_bit(const void *, unsigned int);
120 extern uint32_t find_first_zero(void *, void *);
122 extern int write_sector(uint32_t, void *, int);
123 extern int read_sector(uint32_t, void *, int);
124 extern int tfs_bread(struct tfs_sb_info
*, uint32_t , void *);
125 extern int tfs_bwrite(struct tfs_sb_info
*, uint32_t, void *);
128 struct tfs_sb_info
* tfs_mount(void);
129 struct tfs_sb_info
* tfs_mount_by_fsname(const char *);
132 int tfs_free_inode(struct tfs_sb_info
*, int);
133 int tfs_alloc_inode(struct tfs_sb_info
*, int);
136 int tfs_alloc_block(struct tfs_sb_info
*, uint32_t);
137 int tfs_free_block(struct tfs_sb_info
*, uint32_t);
141 struct tfs_dir_entry
*tfs_find_entry(struct tfs_sb_info
*, const char *, struct inode
*);
142 int tfs_add_entry(struct tfs_sb_info
*, struct inode
*, const char *, int , int *);
143 int tfs_mkdir(struct tfs_sb_info
*, const char *);
146 struct inode
*new_inode(int);
147 void free_inode(struct inode
*);
148 struct inode
*tfs_root_init(struct tfs_sb_info
*);
149 struct inode
*tfs_iget_root(struct tfs_sb_info
*);
150 struct inode
*tfs_iget(struct tfs_sb_info
*, char *, struct inode
*);
151 struct inode
*tfs_namei(struct tfs_sb_info
*, const char *, uint32_t);
152 uint32_t tfs_bmap(struct inode
*, int);
153 int tfs_iwrite(struct tfs_sb_info
*, struct inode
*);
154 struct inode
*__mknod(struct tfs_sb_info
*, struct inode
*, const char *, int);
155 struct inode
*tfs_mknod(struct tfs_sb_info
*, const char *, int, struct inode
**);