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