1
2
3
4
5
6 #ifndef _FS_H
7 #define _FS_H
8
9 #include <sys/types.h>
10 #include <sys/dirent.h>
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 #define IS_SEEKABLE(x) ((x)>=1 && (x)<=3 || (x)==8)
28
29 #define MAY_EXEC 1
30 #define MAY_WRITE 2
31 #define MAY_READ 4
32
33 #define READ 0
34 #define WRITE 1
35 #define READA 2
36 #define WRITEA 3
37
38 void buffer_init(long buffer_end);
39
40 #define MAJOR(a) (((unsigned)(a))>>8)
41 #define MINOR(a) ((a)&0xff)
42
43 #define NR_OPEN 20
44 #define NR_INODE 128
45 #define NR_FILE 64
46 #define NR_SUPER 8
47 #define NR_HASH 307
48 #define NR_BUFFERS nr_buffers
49 #define BLOCK_SIZE 1024
50 #define BLOCK_SIZE_BITS 10
51 #define MAX_CHRDEV 16
52 #define MAX_BLKDEV 16
53
54 #ifndef NULL
55 #define NULL ((void *) 0)
56 #endif
57
58 #define PIPE_READ_WAIT(inode) ((inode).i_wait)
59 #define PIPE_WRITE_WAIT(inode) ((inode).i_wait2)
60 #define PIPE_HEAD(inode) ((inode).i_data[0])
61 #define PIPE_TAIL(inode) ((inode).i_data[1])
62 #define PIPE_SIZE(inode) ((PIPE_HEAD(inode)-PIPE_TAIL(inode))&(PAGE_SIZE-1))
63 #define PIPE_EMPTY(inode) (PIPE_HEAD(inode)==PIPE_TAIL(inode))
64 #define PIPE_FULL(inode) (PIPE_SIZE(inode)==(PAGE_SIZE-1))
65
66 #define NIL_FILP ((struct file *)0)
67 #define SEL_IN 1
68 #define SEL_OUT 2
69 #define SEL_EX 4
70
71 typedef char buffer_block[BLOCK_SIZE];
72
73 struct buffer_head {
74 char * b_data;
75 unsigned long b_blocknr;
76 unsigned short b_dev;
77 unsigned char b_uptodate;
78 unsigned char b_dirt;
79 unsigned char b_count;
80 unsigned char b_lock;
81 struct task_struct * b_wait;
82 struct buffer_head * b_prev;
83 struct buffer_head * b_next;
84 struct buffer_head * b_prev_free;
85 struct buffer_head * b_next_free;
86 struct buffer_head * b_reqnext;
87 };
88
89 struct inode {
90 dev_t i_dev;
91 ino_t i_ino;
92 umode_t i_mode;
93 nlink_t i_nlink;
94 uid_t i_uid;
95 gid_t i_gid;
96 dev_t i_rdev;
97 off_t i_size;
98 time_t i_atime;
99 time_t i_mtime;
100 time_t i_ctime;
101 unsigned long i_data[16];
102 struct inode_operations * i_op;
103 struct super_block * i_sb;
104 struct task_struct * i_wait;
105 struct task_struct * i_wait2;
106 unsigned short i_count;
107 unsigned char i_lock;
108 unsigned char i_dirt;
109 unsigned char i_pipe;
110 unsigned char i_mount;
111 unsigned char i_seek;
112 unsigned char i_update;
113 };
114
115 struct file {
116 unsigned short f_mode;
117 unsigned short f_flags;
118 unsigned short f_count;
119 unsigned short f_reada;
120 struct inode * f_inode;
121 struct file_operations * f_op;
122 off_t f_pos;
123 };
124
125 typedef struct {
126 struct task_struct * old_task;
127 struct task_struct ** wait_address;
128 } wait_entry;
129
130 typedef struct select_table_struct {
131 int nr, woken;
132 struct task_struct * current;
133 struct select_table_struct * next_table;
134 wait_entry entry[NR_OPEN*3];
135 } select_table;
136
137 struct super_block {
138 unsigned short s_ninodes;
139 unsigned short s_nzones;
140 unsigned short s_imap_blocks;
141 unsigned short s_zmap_blocks;
142 unsigned short s_firstdatazone;
143 unsigned short s_log_zone_size;
144 unsigned long s_max_size;
145 unsigned short s_magic;
146
147 struct buffer_head * s_imap[8];
148 struct buffer_head * s_zmap[8];
149 unsigned short s_dev;
150 struct inode * s_covered;
151 struct inode * s_mounted;
152 unsigned long s_time;
153 struct task_struct * s_wait;
154 unsigned char s_lock;
155 unsigned char s_rd_only;
156 unsigned char s_dirt;
157
158 struct super_operations *s_op;
159 };
160
161 struct file_operations {
162 int (*lseek) (struct inode *, struct file *, off_t, int);
163 int (*read) (struct inode *, struct file *, char *, int);
164 int (*write) (struct inode *, struct file *, char *, int);
165 int (*readdir) (struct inode *, struct file *, struct dirent *, int count);
166 int (*select) (struct inode *, struct file *, int, select_table *);
167 int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned int);
168 int (*open) (struct inode *, struct file *);
169 void (*release) (struct inode *, struct file *);
170 };
171
172 struct inode_operations {
173 struct file_operations * default_file_ops;
174 int (*create) (struct inode *,const char *,int,int,struct inode **);
175 int (*lookup) (struct inode *,const char *,int,struct inode **);
176 int (*link) (struct inode *,struct inode *,const char *,int);
177 int (*unlink) (struct inode *,const char *,int);
178 int (*symlink) (struct inode *,const char *,int,const char *);
179 int (*mkdir) (struct inode *,const char *,int,int);
180 int (*rmdir) (struct inode *,const char *,int);
181 int (*mknod) (struct inode *,const char *,int,int,int);
182 int (*rename) (struct inode *,const char *,int,struct inode *,const char *,int);
183 int (*readlink) (struct inode *,char *,int);
184 struct inode * (*follow_link) (struct inode *, struct inode *);
185 int (*bmap) (struct inode *,int);
186 void (*truncate) (struct inode *);
187 };
188
189 struct super_operations {
190 void (*read_inode)(struct inode *inode);
191 void (*write_inode) (struct inode *inode);
192 void (*put_inode) (struct inode *inode);
193 void (*put_super)(struct super_block *sb);
194 };
195
196 struct file_system_type {
197 struct super_block *(*read_super)(struct super_block *sb,void *mode);
198 char *name;
199 };
200
201 extern struct file_operations * chrdev_fops[MAX_CHRDEV];
202 extern struct file_operations * blkdev_fops[MAX_BLKDEV];
203
204 extern struct file_system_type *get_fs_type(char *name);
205
206 extern struct inode inode_table[NR_INODE];
207 extern struct file file_table[NR_FILE];
208 extern struct super_block super_block[NR_SUPER];
209 extern struct buffer_head * start_buffer;
210 extern int nr_buffers;
211
212 extern void check_disk_change(int dev);
213 extern int floppy_change(struct buffer_head * first_block);
214 extern int ticks_to_floppy_on(unsigned int dev);
215 extern void floppy_on(unsigned int dev);
216 extern void floppy_off(unsigned int dev);
217 extern void sync_inodes(void);
218 extern void wait_on(struct inode * inode);
219 extern int bmap(struct inode * inode,int block);
220 extern struct inode * namei(const char * pathname);
221 extern struct inode * lnamei(const char * pathname);
222 extern int permission(struct inode * inode,int mask);
223 extern struct inode * _namei(const char * filename, struct inode * base,
224 int follow_links);
225 extern int open_namei(const char * pathname, int flag, int mode,
226 struct inode ** res_inode);
227 extern void iput(struct inode * inode);
228 extern struct inode * iget(int dev,int nr);
229 extern struct inode * get_empty_inode(void);
230 extern struct inode * get_pipe_inode(void);
231 extern struct buffer_head * get_hash_table(int dev, int block);
232 extern struct buffer_head * getblk(int dev, int block);
233 extern void ll_rw_block(int rw, struct buffer_head * bh);
234 extern void ll_rw_page(int rw, int dev, int nr, char * buffer);
235 extern void ll_rw_swap_file(int rw, int dev, unsigned int *b, int nb, char *buffer);
236 extern void brelse(struct buffer_head * buf);
237 extern struct buffer_head * bread(int dev,int block);
238 extern void bread_page(unsigned long addr,int dev,int b[4]);
239 extern struct buffer_head * breada(int dev,int block,...);
240 extern int sync_dev(int dev);
241 extern struct super_block * get_super(int dev);
242 extern int ROOT_DEV;
243
244 extern void mount_root(void);
245 extern void lock_super(struct super_block * sb);
246 extern void free_super(struct super_block * sb);
247
248 extern int char_read(struct inode *, struct file *, char *, int);
249 extern int block_read(struct inode *, struct file *, char *, int);
250
251 extern int char_write(struct inode *, struct file *, char *, int);
252 extern int block_write(struct inode *, struct file *, char *, int);
253
254 #endif