Two fixes
[tfsprogs.git] / tfs.h
blobbb226fa6ea46c67657c40bd60131140b0ac772d0
1 #ifndef TFS_H
2 #define TFS_H
4 #include <stdint.h>
6 #define TFS_ROOT_INODE 1
7 #define TFS_FILE 0x1
8 #define TFS_DIR 0x2
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)
19 if (mode & TFS_FILE)
20 return I_FILE;
21 else if (mode & TFS_DIR)
22 return I_DIR;
23 else
24 return I_UNKNOWN;
27 /* It's really enought for a test file system */
28 #define TFS_N_BLOCKS 8
30 struct tfs_inode {
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];
43 /*
44 * The inode structure in memory, including the detail file information
46 struct inode {
47 int i_mode; /* FILE or DIR */
48 uint32_t i_size;
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 */
55 uint32_t i_flags;
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 */
67 /* TFS super block */
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 */
87 struct tfs_sb_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))
116 /* utils.c */
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 *);
127 extern uint32_t open_fs(char *);
129 /* super.c */
130 struct tfs_sb_info * tfs_mount(void);
131 struct tfs_sb_info * tfs_mount_by_fsname(const char *);
133 /* ialloc.c */
134 int tfs_free_inode(struct tfs_sb_info *, int);
135 int tfs_alloc_inode(struct tfs_sb_info *, int);
137 /* balloc.c */
138 int tfs_alloc_block(struct tfs_sb_info *, uint32_t);
139 int tfs_free_block(struct tfs_sb_info *, uint32_t);
142 /* dir.c */
143 struct cache_struct *tfs_find_entry(struct tfs_sb_info *, const char *, struct inode *, struct tfs_dir_entry **);
144 int tfs_add_entry(struct tfs_sb_info *, struct inode *, const char *, int , int *);
145 int tfs_mkdir(struct tfs_sb_info *, const char *);
146 int tfs_rmdir(struct tfs_sb_info *, const char *);
148 /* inode.c */
149 struct inode *new_inode(int);
150 void free_inode(struct inode *);
151 struct inode *tfs_root_init(struct tfs_sb_info *);
152 struct inode *tfs_iget_root(struct tfs_sb_info *);
153 struct inode *tfs_iget(struct tfs_sb_info *, char *, struct inode *);
154 struct inode *tfs_namei(struct tfs_sb_info *, const char *, uint32_t);
155 uint32_t tfs_bmap(struct inode *, int);
156 int tfs_iwrite(struct tfs_sb_info *, struct inode *);
157 struct inode *__mknod(struct tfs_sb_info *, struct inode *, const char *, int);
158 struct inode *tfs_mknod(struct tfs_sb_info *, const char *, int, struct inode **);
159 const char *get_base_name(const char *);
161 #endif /* tfs.h */