Implement user space's printf stuff
[thunix.git] / include / tfs.h
blobfe914ff2fa0df5f6bc76c9bc2a670a7f59dbb7b8
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
15 /* just support I_FILE and I_DIR only currently */
16 enum tfs_inode_mode { I_FILE, I_DIR, I_UNKNOWN };
18 static inline int get_mode(int mode)
20 if (mode & TFS_FILE)
21 return I_FILE;
22 else if (mode & TFS_DIR)
23 return I_DIR;
24 else
25 return I_UNKNOWN;
28 /* It's really enought for a test file system */
29 #define TFS_N_BLOCKS 8
31 struct tfs_inode {
32 uint16_t i_mode; /* File mode */
33 uint16_t i_uid; /* Owner UID */
34 uint32_t i_size; /* File size */
35 uint32_t i_atime; /* Access time */
36 uint32_t i_ctime; /* Create time */
37 uint32_t i_mtime; /* modify time */
38 uint32_t i_dtime; /* delete time */
39 uint32_t i_block[TFS_N_BLOCKS]; /* block address of file's count */
40 uint32_t i_flags; /* flags */
41 uint32_t i_reserved[1];
44 /* The max lenght of each file name */
45 #define TFS_NAME_LEN 28
46 struct tfs_dir_entry {
47 uint32_t d_inode; /* inode number */
48 char d_name[TFS_NAME_LEN]; /* entry name */
51 #define TFS_MAGIC 0x4c534654 /* TFSL */
53 /* TFS super block */
54 struct tfs_super_block {
55 uint32_t s_inodes_count; /* Max file count */
56 uint32_t s_blocks_count;
57 uint32_t s_free_blocks_count;
58 uint32_t s_free_inodes_count;
59 uint32_t s_magic; /* TFS's magic signature */
60 uint32_t s_block_shift; /* Block size */
62 uint32_t s_inode_bitmap;
63 uint32_t s_block_bitmap;
64 uint32_t s_inode_table;
65 uint32_t s_data_area; /* where the data starts */
68 uint32_t s_offset; /* In which sector the fs stored */
69 uint32_t s_reserved[117];
72 /* TFS super block info */
73 struct tfs_sb_info {
74 uint32_t s_inodes_count; /* Max file count */
75 uint32_t s_blocks_count;
76 uint32_t s_free_blocks_count;
77 uint32_t s_free_inodes_count;
78 uint32_t s_block_shift; /* Block size in bits */
79 uint32_t s_block_size; /* Block size in bytes */
81 uint32_t s_inode_bitmap;
82 uint32_t s_inode_bitmap_count;
83 uint32_t s_block_bitmap;
84 uint32_t s_block_bitmap_count;
85 uint32_t s_inode_table;
86 uint32_t s_inode_table_count;
87 uint32_t s_data_area; /* where the data starts */
90 uint32_t s_offset; /* In which sector the fs stored */
92 int s_inodes_per_block;
95 extern struct tfs_sb_info *tfs_sbi;
98 #define TFS_INODES_PER_BLOCK(sbi) (sbi->s_inodes_per_block)
100 #define TFS_DEBUG //printk
102 #define roundup(x, y) ((x) / (y) + (((x) % (y)) ? 1 : 0))
104 struct fs;
106 static inline struct tfs_sb_info * TFS_SBI(struct fs *fs)
108 return fs->sb;
111 /* tfs_diskio.c */
112 extern int tfs_bread(struct tfs_sb_info *, uint32_t , void *);
113 extern int tfs_bwrite(struct tfs_sb_info *, uint32_t, void *);
115 /* super.c */
116 int tfs_get_blk_shift(void *sb);
117 void * tfs_mount(void);
119 /* ialloc.c */
120 int tfs_free_inode(struct tfs_sb_info *, int);
121 int tfs_alloc_inode(struct tfs_sb_info *, int);
123 /* balloc.c */
124 int tfs_alloc_block(struct tfs_sb_info *, uint32_t);
125 int tfs_free_block(struct tfs_sb_info *, uint32_t);
128 /* dir.c */
129 struct cache_struct *tfs_find_entry(struct inode *, const char *, struct tfs_dir_entry **);
130 int tfs_add_entry(struct inode *, const char *, int , int *);
131 int tfs_mkdir(struct inode *, const char *);
132 int tfs_rmdir(struct inode *, const char *);
133 int tfs_unlink(struct inode *, const char *);
135 /* inode.c */
136 struct inode * tfs_new_inode(struct inode *, int, int);
137 int tfs_release_inode(struct tfs_sb_info *, struct inode *);
138 struct inode *tfs_root_init(struct tfs_sb_info *);
139 struct inode *tfs_iget_root(struct fs *);
140 struct inode *tfs_iget_by_inr(struct fs *, int);
141 struct inode *tfs_iget(const char *, struct inode *);
142 uint32_t tfs_bmap(struct inode *, int);
143 int tfs_iwrite(struct inode *);
144 struct inode *tfs_mknod(struct inode *, const char *, int);
147 extern struct inode_operations tfs_inode_ops;
148 extern struct file_operations tfs_file_ops;
150 #endif /* tfs.h */