Add tfs remove part
[thunix.git] / include / tfs.h
blob8002950cea95c3256a5914ee7a8b126951b8ff47
1 #ifndef TFS_H
2 #define TFS_H
4 #include <stdint.h>
6 /* in whice sector the tfs stored in the boot image */
7 #define TFS_FS_SECTOR (832)
8 #define TFS_SB_SECTOR (TFS_FS_SECTOR + 1)
10 #define TFS_ROOT_INODE 1
11 #define TFS_FILE 0x1
12 #define TFS_DIR 0x2
14 /* namei: path lookup flags */
15 #define LOOKUP_PARENT 0x1
16 #define LOOKUP_CREATE 0x2
18 /* just support I_FILE and I_DIR only currently */
19 enum tfs_inode_mode { I_FILE, I_DIR, I_UNKNOWN };
21 static inline int get_mode(int mode)
23 if (mode & TFS_FILE)
24 return I_FILE;
25 else if (mode & TFS_DIR)
26 return I_DIR;
27 else
28 return I_UNKNOWN;
31 /* It's really enought for a test file system */
32 #define TFS_N_BLOCKS 8
34 struct tfs_inode {
35 uint16_t i_mode; /* File mode */
36 uint16_t i_uid; /* Owner UID */
37 uint32_t i_size; /* File size */
38 uint32_t i_atime; /* Access time */
39 uint32_t i_ctime; /* Create time */
40 uint32_t i_mtime; /* modify time */
41 uint32_t i_dtime; /* delete time */
42 uint32_t i_block[TFS_N_BLOCKS]; /* block address of file's count */
43 uint32_t i_flags; /* flags */
44 uint32_t i_reserved[1];
47 /*
48 * The inode structure in memory, including the detail file information
50 struct inode {
51 int i_mode; /* FILE or DIR */
52 uint32_t i_size;
53 uint32_t i_ino; /* Inode number */
54 uint32_t i_atime; /* Access time */
55 uint32_t i_mtime; /* Modify time */
56 uint32_t i_ctime; /* Create time */
57 uint32_t i_dtime; /* Delete time */
58 uint32_t * i_data; /* The block address array where the file stores */
59 uint32_t i_flags;
62 /* The max lenght of each file name */
63 #define TFS_NAME_LEN 28
64 struct tfs_dir_entry {
65 uint32_t d_inode; /* inode number */
66 char d_name[TFS_NAME_LEN]; /* entry name */
69 #define TFS_MAGIC 0x4c534654 /* TFSL */
71 /* TFS super block */
72 struct tfs_super_block {
73 uint32_t s_inodes_count; /* Max file count */
74 uint32_t s_blocks_count;
75 uint32_t s_free_blocks_count;
76 uint32_t s_free_inodes_count;
77 uint32_t s_magic; /* TFS's magic signature */
78 uint32_t s_block_shift; /* Block size */
80 uint32_t s_inode_bitmap;
81 uint32_t s_block_bitmap;
82 uint32_t s_inode_table;
83 uint32_t s_data_area; /* where the data starts */
86 uint32_t s_offset; /* In which sector the fs stored */
87 uint32_t s_reserved[117];
90 /* TFS super block info */
91 struct tfs_sb_info {
92 uint32_t s_inodes_count; /* Max file count */
93 uint32_t s_blocks_count;
94 uint32_t s_free_blocks_count;
95 uint32_t s_free_inodes_count;
96 uint32_t s_block_shift; /* Block size in bits */
97 uint32_t s_block_size; /* Block size in bytes */
99 uint32_t s_inode_bitmap;
100 uint32_t s_inode_bitmap_count;
101 uint32_t s_block_bitmap;
102 uint32_t s_block_bitmap_count;
103 uint32_t s_inode_table;
104 uint32_t s_inode_table_count;
105 uint32_t s_data_area; /* where the data starts */
108 uint32_t s_offset; /* In which sector the fs stored */
110 int s_inodes_per_block;
113 extern struct tfs_sb_info *tfs_sbi;
116 #define TFS_INODES_PER_BLOCK(sbi) (sbi->s_inodes_per_block)
118 #define TFS_DEBUG printk
120 #define roundup(x, y) ((x) / (y) + (((x) % (y)) ? 1 : 0))
122 /* tfs_diskio.c */
123 extern void tfs_bread(struct tfs_sb_info *, uint32_t , void *);
124 extern void tfs_bwrite(struct tfs_sb_info *, uint32_t, void *);
126 /* super.c */
127 struct tfs_sb_info * tfs_mount(void);
129 /* ialloc.c */
130 int tfs_free_inode(struct tfs_sb_info *, int);
131 int tfs_alloc_inode(struct tfs_sb_info *, int);
133 /* balloc.c */
134 int tfs_alloc_block(struct tfs_sb_info *, uint32_t);
135 int tfs_free_block(struct tfs_sb_info *, uint32_t);
138 /* dir.c */
139 struct cache_struct *tfs_find_entry(struct tfs_sb_info *, const char *, struct inode *, struct tfs_dir_entry **);
140 int tfs_add_entry(struct tfs_sb_info *, struct inode *, const char *, int , int *);
141 int tfs_mkdir(struct tfs_sb_info *, const char *);
142 int tfs_rmdir(struct tfs_sb_info *, const char *);
144 /* inode.c */
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 uint32_t tfs_bmap(struct inode *, int);
152 int tfs_iwrite(struct tfs_sb_info *, struct inode *);
153 struct inode *__mknod(struct tfs_sb_info *, struct inode *, const char *, int);
154 struct inode *tfs_mknod(struct tfs_sb_info *, const char *, int, struct inode **);
155 const char *get_base_name(const char *);
157 #endif /* tfs.h */