This source file includes following definitions.
- buffer_uptodate
- buffer_dirty
- buffer_locked
- buffer_req
- buffer_touched
- buffer_has_aged
- mark_buffer_uptodate
- mark_buffer_clean
- mark_buffer_dirty
- brelse
- bforget
- iget
1 #ifndef _LINUX_FS_H
2 #define _LINUX_FS_H
3
4
5
6
7
8
9 #include <linux/linkage.h>
10 #include <linux/limits.h>
11 #include <linux/wait.h>
12 #include <linux/types.h>
13 #include <linux/vfs.h>
14 #include <linux/net.h>
15 #include <linux/kdev_t.h>
16 #include <linux/ioctl.h>
17
18 #include <asm/bitops.h>
19
20
21
22
23
24
25
26
27
28 #undef NR_OPEN
29 #define NR_OPEN 256
30
31 #define NR_INODE 2048
32 #define NR_FILE 1024
33 #define NR_SUPER 32
34 #define NR_IHASH 131
35 #define BLOCK_SIZE 1024
36 #define BLOCK_SIZE_BITS 10
37
38 #define MAY_EXEC 1
39 #define MAY_WRITE 2
40 #define MAY_READ 4
41
42 #define READ 0
43 #define WRITE 1
44 #define READA 2
45 #define WRITEA 3
46
47 #ifndef NULL
48 #define NULL ((void *) 0)
49 #endif
50
51 #define NIL_FILP ((struct file *)0)
52 #define SEL_IN 1
53 #define SEL_OUT 2
54 #define SEL_EX 4
55
56
57
58
59 #define MS_RDONLY 1
60 #define MS_NOSUID 2
61 #define MS_NODEV 4
62 #define MS_NOEXEC 8
63 #define MS_SYNCHRONOUS 16
64 #define MS_REMOUNT 32
65
66 #define S_APPEND 256
67 #define S_IMMUTABLE 512
68
69
70
71
72 #define MS_RMT_MASK (MS_RDONLY)
73
74
75
76
77 #define MS_MGC_VAL 0xC0ED0000
78 #define MS_MGC_MSK 0xffff0000
79
80
81
82
83
84
85
86
87
88 #define IS_RDONLY(inode) (((inode)->i_sb) && ((inode)->i_sb->s_flags & MS_RDONLY))
89 #define IS_NOSUID(inode) ((inode)->i_flags & MS_NOSUID)
90 #define IS_NODEV(inode) ((inode)->i_flags & MS_NODEV)
91 #define IS_NOEXEC(inode) ((inode)->i_flags & MS_NOEXEC)
92 #define IS_SYNC(inode) ((inode)->i_flags & MS_SYNCHRONOUS)
93
94 #define IS_APPEND(inode) ((inode)->i_flags & S_APPEND)
95 #define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE)
96
97
98
99
100 #define BLKROSET _IO(0x12,93)
101 #define BLKROGET _IO(0x12,94)
102 #define BLKRRPART _IO(0x12,95)
103 #define BLKGETSIZE _IO(0x12,96)
104 #define BLKFLSBUF _IO(0x12,97)
105 #define BLKRASET _IO(0x12,98)
106 #define BLKRAGET _IO(0x12,99)
107
108 #define BMAP_IOCTL 1
109 #define FIBMAP _IO(0x00,1)
110 #define FIGETBSZ _IO(0x00,2)
111
112 #ifdef __KERNEL__
113 extern void buffer_init(void);
114 extern unsigned long inode_init(unsigned long start, unsigned long end);
115 extern unsigned long file_table_init(unsigned long start, unsigned long end);
116 extern unsigned long name_cache_init(unsigned long start, unsigned long end);
117
118 typedef char buffer_block[BLOCK_SIZE];
119
120
121 #define BH_Uptodate 0
122 #define BH_Dirty 1
123 #define BH_Lock 2
124 #define BH_Req 3
125 #define BH_Touched 4
126 #define BH_Has_aged 5
127
128 struct buffer_head {
129 char * b_data;
130 unsigned long b_size;
131 unsigned long b_blocknr;
132 kdev_t b_dev;
133 unsigned long b_state;
134 unsigned int b_count;
135 unsigned int b_list;
136 unsigned long b_flushtime;
137
138 unsigned long b_lru_time;
139
140 struct wait_queue * b_wait;
141 struct buffer_head * b_prev;
142 struct buffer_head * b_next;
143 struct buffer_head * b_prev_free;
144 struct buffer_head * b_next_free;
145 struct buffer_head * b_this_page;
146 struct buffer_head * b_reqnext;
147 };
148
149 static inline int buffer_uptodate(struct buffer_head * bh)
150 {
151 return test_bit(BH_Uptodate, &bh->b_state);
152 }
153
154 static inline int buffer_dirty(struct buffer_head * bh)
155 {
156 return test_bit(BH_Dirty, &bh->b_state);
157 }
158
159 static inline int buffer_locked(struct buffer_head * bh)
160 {
161 return test_bit(BH_Lock, &bh->b_state);
162 }
163
164 static inline int buffer_req(struct buffer_head * bh)
165 {
166 return test_bit(BH_Req, &bh->b_state);
167 }
168
169 static inline int buffer_touched(struct buffer_head * bh)
170 {
171 return test_bit(BH_Touched, &bh->b_state);
172 }
173
174 static inline int buffer_has_aged(struct buffer_head * bh)
175 {
176 return test_bit(BH_Has_aged, &bh->b_state);
177 }
178
179 #include <linux/pipe_fs_i.h>
180 #include <linux/minix_fs_i.h>
181 #include <linux/ext_fs_i.h>
182 #include <linux/ext2_fs_i.h>
183 #include <linux/hpfs_fs_i.h>
184 #include <linux/msdos_fs_i.h>
185 #include <linux/umsdos_fs_i.h>
186 #include <linux/iso_fs_i.h>
187 #include <linux/nfs_fs_i.h>
188 #include <linux/xia_fs_i.h>
189 #include <linux/sysv_fs_i.h>
190
191
192
193
194
195 #define ATTR_MODE 1
196 #define ATTR_UID 2
197 #define ATTR_GID 4
198 #define ATTR_SIZE 8
199 #define ATTR_ATIME 16
200 #define ATTR_MTIME 32
201 #define ATTR_CTIME 64
202 #define ATTR_ATIME_SET 128
203 #define ATTR_MTIME_SET 256
204
205
206
207
208
209
210
211
212
213
214 struct iattr {
215 unsigned int ia_valid;
216 umode_t ia_mode;
217 uid_t ia_uid;
218 gid_t ia_gid;
219 off_t ia_size;
220 time_t ia_atime;
221 time_t ia_mtime;
222 time_t ia_ctime;
223 };
224
225 struct inode {
226 kdev_t i_dev;
227 unsigned long i_ino;
228 umode_t i_mode;
229 nlink_t i_nlink;
230 uid_t i_uid;
231 gid_t i_gid;
232 kdev_t i_rdev;
233 off_t i_size;
234 time_t i_atime;
235 time_t i_mtime;
236 time_t i_ctime;
237 unsigned long i_blksize;
238 unsigned long i_blocks;
239 unsigned long i_version;
240 struct semaphore i_sem;
241 struct inode_operations * i_op;
242 struct super_block * i_sb;
243 struct wait_queue * i_wait;
244 struct file_lock * i_flock;
245 struct vm_area_struct * i_mmap;
246 struct inode * i_next, * i_prev;
247 struct inode * i_hash_next, * i_hash_prev;
248 struct inode * i_bound_to, * i_bound_by;
249 struct inode * i_mount;
250 unsigned short i_count;
251 unsigned short i_wcount;
252 unsigned short i_flags;
253 unsigned char i_lock;
254 unsigned char i_dirt;
255 unsigned char i_pipe;
256 unsigned char i_sock;
257 unsigned char i_seek;
258 unsigned char i_update;
259 union {
260 struct pipe_inode_info pipe_i;
261 struct minix_inode_info minix_i;
262 struct ext_inode_info ext_i;
263 struct ext2_inode_info ext2_i;
264 struct hpfs_inode_info hpfs_i;
265 struct msdos_inode_info msdos_i;
266 struct umsdos_inode_info umsdos_i;
267 struct iso_inode_info isofs_i;
268 struct nfs_inode_info nfs_i;
269 struct xiafs_inode_info xiafs_i;
270 struct sysv_inode_info sysv_i;
271 struct socket socket_i;
272 void * generic_ip;
273 } u;
274 };
275
276 struct file {
277 mode_t f_mode;
278 loff_t f_pos;
279 unsigned short f_flags;
280 unsigned short f_count;
281 off_t f_reada;
282 struct file *f_next, *f_prev;
283 int f_owner;
284 struct inode * f_inode;
285 struct file_operations * f_op;
286 unsigned long f_version;
287 void *private_data;
288 };
289
290 struct file_lock {
291 struct file_lock *fl_next;
292 struct file_lock *fl_nextlink;
293 struct file_lock *fl_prevlink;
294 struct file_lock *fl_block;
295 struct task_struct *fl_owner;
296 struct wait_queue *fl_wait;
297 struct file *fl_file;
298 char fl_flags;
299 char fl_type;
300 off_t fl_start;
301 off_t fl_end;
302 };
303
304 struct fasync_struct {
305 int magic;
306 struct fasync_struct *fa_next;
307 struct file *fa_file;
308 };
309
310 #define FASYNC_MAGIC 0x4601
311
312 extern int fasync_helper(struct inode *, struct file *, int, struct fasync_struct **);
313
314 #include <linux/minix_fs_sb.h>
315 #include <linux/ext_fs_sb.h>
316 #include <linux/ext2_fs_sb.h>
317 #include <linux/hpfs_fs_sb.h>
318 #include <linux/msdos_fs_sb.h>
319 #include <linux/iso_fs_sb.h>
320 #include <linux/nfs_fs_sb.h>
321 #include <linux/xia_fs_sb.h>
322 #include <linux/sysv_fs_sb.h>
323
324 struct super_block {
325 kdev_t s_dev;
326 unsigned long s_blocksize;
327 unsigned char s_blocksize_bits;
328 unsigned char s_lock;
329 unsigned char s_rd_only;
330 unsigned char s_dirt;
331 struct file_system_type *s_type;
332 struct super_operations *s_op;
333 unsigned long s_flags;
334 unsigned long s_magic;
335 unsigned long s_time;
336 struct inode * s_covered;
337 struct inode * s_mounted;
338 struct wait_queue * s_wait;
339 union {
340 struct minix_sb_info minix_sb;
341 struct ext_sb_info ext_sb;
342 struct ext2_sb_info ext2_sb;
343 struct hpfs_sb_info hpfs_sb;
344 struct msdos_sb_info msdos_sb;
345 struct isofs_sb_info isofs_sb;
346 struct nfs_sb_info nfs_sb;
347 struct xiafs_sb_info xiafs_sb;
348 struct sysv_sb_info sysv_sb;
349 void *generic_sbp;
350 } u;
351 };
352
353
354
355
356
357
358
359 typedef int (*filldir_t)(void *, const char *, int, off_t, ino_t);
360
361 struct file_operations {
362 int (*lseek) (struct inode *, struct file *, off_t, int);
363 int (*read) (struct inode *, struct file *, char *, int);
364 int (*write) (struct inode *, struct file *, const char *, int);
365 int (*readdir) (struct inode *, struct file *, void *, filldir_t);
366 int (*select) (struct inode *, struct file *, int, select_table *);
367 int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);
368 int (*mmap) (struct inode *, struct file *, struct vm_area_struct *);
369 int (*open) (struct inode *, struct file *);
370 void (*release) (struct inode *, struct file *);
371 int (*fsync) (struct inode *, struct file *);
372 int (*fasync) (struct inode *, struct file *, int);
373 int (*check_media_change) (kdev_t dev);
374 int (*revalidate) (kdev_t dev);
375 };
376
377 struct inode_operations {
378 struct file_operations * default_file_ops;
379 int (*create) (struct inode *,const char *,int,int,struct inode **);
380 int (*lookup) (struct inode *,const char *,int,struct inode **);
381 int (*link) (struct inode *,struct inode *,const char *,int);
382 int (*unlink) (struct inode *,const char *,int);
383 int (*symlink) (struct inode *,const char *,int,const char *);
384 int (*mkdir) (struct inode *,const char *,int,int);
385 int (*rmdir) (struct inode *,const char *,int);
386 int (*mknod) (struct inode *,const char *,int,int,int);
387 int (*rename) (struct inode *,const char *,int,struct inode *,const char *,int);
388 int (*readlink) (struct inode *,char *,int);
389 int (*follow_link) (struct inode *,struct inode *,int,int,struct inode **);
390 int (*bmap) (struct inode *,int);
391 void (*truncate) (struct inode *);
392 int (*permission) (struct inode *, int);
393 int (*smap) (struct inode *,int);
394 };
395
396 struct super_operations {
397 void (*read_inode) (struct inode *);
398 int (*notify_change) (struct inode *, struct iattr *);
399 void (*write_inode) (struct inode *);
400 void (*put_inode) (struct inode *);
401 void (*put_super) (struct super_block *);
402 void (*write_super) (struct super_block *);
403 void (*statfs) (struct super_block *, struct statfs *, int);
404 int (*remount_fs) (struct super_block *, int *, char *);
405 };
406
407 struct file_system_type {
408 struct super_block *(*read_super) (struct super_block *, void *, int);
409 const char *name;
410 int requires_dev;
411 struct file_system_type * next;
412 };
413
414 extern int register_filesystem(struct file_system_type *);
415 extern int unregister_filesystem(struct file_system_type *);
416
417 asmlinkage int sys_open(const char *, int, int);
418 asmlinkage int sys_close(unsigned int);
419
420 extern void kill_fasync(struct fasync_struct *fa, int sig);
421
422 extern int getname(const char * filename, char **result);
423 extern void putname(char * name);
424
425 extern int register_blkdev(unsigned int, const char *, struct file_operations *);
426 extern int unregister_blkdev(unsigned int major, const char * name);
427 extern int blkdev_open(struct inode * inode, struct file * filp);
428 extern struct file_operations def_blk_fops;
429 extern struct inode_operations blkdev_inode_operations;
430
431 extern int register_chrdev(unsigned int, const char *, struct file_operations *);
432 extern int unregister_chrdev(unsigned int major, const char * name);
433 extern int chrdev_open(struct inode * inode, struct file * filp);
434 extern struct file_operations def_chr_fops;
435 extern struct inode_operations chrdev_inode_operations;
436
437 extern void init_fifo(struct inode * inode);
438
439 extern struct file_operations connecting_fifo_fops;
440 extern struct file_operations read_fifo_fops;
441 extern struct file_operations write_fifo_fops;
442 extern struct file_operations rdwr_fifo_fops;
443 extern struct file_operations read_pipe_fops;
444 extern struct file_operations write_pipe_fops;
445 extern struct file_operations rdwr_pipe_fops;
446
447 extern struct file_system_type *get_fs_type(const char *name);
448
449 extern int fs_may_mount(kdev_t dev);
450 extern int fs_may_umount(kdev_t dev, struct inode * mount_root);
451 extern int fs_may_remount_ro(kdev_t dev);
452
453 extern struct file *first_file;
454 extern int nr_files;
455 extern struct super_block super_blocks[NR_SUPER];
456
457 extern int shrink_buffers(unsigned int priority, unsigned long limit);
458 extern void refile_buffer(struct buffer_head * buf);
459 extern void set_writetime(struct buffer_head * buf, int flag);
460 extern void refill_freelist(int size);
461
462 extern struct buffer_head ** buffer_pages;
463 extern int nr_buffers;
464 extern int buffermem;
465 extern int nr_buffer_heads;
466
467 #define BUF_CLEAN 0
468 #define BUF_UNSHARED 1
469 #define BUF_LOCKED 2
470 #define BUF_LOCKED1 3
471 #define BUF_DIRTY 4
472 #define BUF_SHARED 5
473 #define NR_LIST 6
474
475 extern inline void mark_buffer_uptodate(struct buffer_head * bh, int on)
476 {
477 if (on)
478 set_bit(BH_Uptodate, &bh->b_state);
479 else
480 clear_bit(BH_Uptodate, &bh->b_state);
481 }
482
483 extern inline void mark_buffer_clean(struct buffer_head * bh)
484 {
485 if (clear_bit(BH_Dirty, &bh->b_state)) {
486 if (bh->b_list == BUF_DIRTY)
487 refile_buffer(bh);
488 }
489 }
490
491 extern inline void mark_buffer_dirty(struct buffer_head * bh, int flag)
492 {
493 if (!set_bit(BH_Dirty, &bh->b_state)) {
494 set_writetime(bh, flag);
495 if (bh->b_list != BUF_DIRTY)
496 refile_buffer(bh);
497 }
498 }
499
500 extern int check_disk_change(kdev_t dev);
501 extern void invalidate_inodes(kdev_t dev);
502 extern void invalidate_buffers(kdev_t dev);
503 extern int floppy_is_wp(int minor);
504 extern void sync_inodes(kdev_t dev);
505 extern void sync_dev(kdev_t dev);
506 extern int fsync_dev(kdev_t dev);
507 extern void sync_supers(kdev_t dev);
508 extern int bmap(struct inode * inode,int block);
509 extern int notify_change(struct inode *, struct iattr *);
510 extern int namei(const char * pathname, struct inode ** res_inode);
511 extern int lnamei(const char * pathname, struct inode ** res_inode);
512 extern int permission(struct inode * inode,int mask);
513 extern int get_write_access(struct inode * inode);
514 extern void put_write_access(struct inode * inode);
515 extern int open_namei(const char * pathname, int flag, int mode,
516 struct inode ** res_inode, struct inode * base);
517 extern int do_mknod(const char * filename, int mode, dev_t dev);
518 extern int do_pipe(int *);
519 extern void iput(struct inode * inode);
520 extern struct inode * __iget(struct super_block * sb,int nr,int crsmnt);
521 extern struct inode * get_empty_inode(void);
522 extern void insert_inode_hash(struct inode *);
523 extern void clear_inode(struct inode *);
524 extern struct inode * get_pipe_inode(void);
525 extern struct file * get_empty_filp(void);
526 extern int close_fp(struct file *filp);
527 extern struct buffer_head * get_hash_table(kdev_t dev, int block, int size);
528 extern struct buffer_head * getblk(kdev_t dev, int block, int size);
529 extern void ll_rw_block(int rw, int nr, struct buffer_head * bh[]);
530 extern void ll_rw_page(int rw, kdev_t dev, unsigned long nr, char * buffer);
531 extern void ll_rw_swap_file(int rw, kdev_t dev, unsigned int *b, int nb, char *buffer);
532 extern int is_read_only(kdev_t dev);
533 extern void __brelse(struct buffer_head *buf);
534 extern inline void brelse(struct buffer_head *buf)
535 {
536 if (buf)
537 __brelse(buf);
538 }
539 extern void __bforget(struct buffer_head *buf);
540 extern inline void bforget(struct buffer_head *buf)
541 {
542 if (buf)
543 __bforget(buf);
544 }
545 extern void set_blocksize(kdev_t dev, int size);
546 extern struct buffer_head * bread(kdev_t dev, int block, int size);
547 extern unsigned long bread_page(unsigned long addr,kdev_t dev,int b[],int size,int no_share);
548 extern void bwrite_page(unsigned long addr,kdev_t dev,int b[],int size);
549 extern struct buffer_head * breada(kdev_t dev,int block, int size,
550 unsigned int pos, unsigned int filesize);
551 extern void put_super(kdev_t dev);
552 unsigned long generate_cluster(kdev_t dev, int b[], int size);
553 extern kdev_t ROOT_DEV;
554
555 extern void show_buffers(void);
556 extern void mount_root(void);
557
558 extern int char_read(struct inode *, struct file *, char *, int);
559 extern int block_read(struct inode *, struct file *, char *, int);
560 extern int read_ahead[];
561
562 extern int char_write(struct inode *, struct file *, const char *, int);
563 extern int block_write(struct inode *, struct file *, const char *, int);
564
565 extern int generic_mmap(struct inode *, struct file *, struct vm_area_struct *);
566
567 extern int block_fsync(struct inode *, struct file *);
568 extern int file_fsync(struct inode *, struct file *);
569
570 extern void dcache_add(struct inode *, const char *, int, unsigned long);
571 extern int dcache_lookup(struct inode *, const char *, int, unsigned long *);
572
573 extern int inode_change_ok(struct inode *, struct iattr *);
574 extern void inode_setattr(struct inode *, struct iattr *);
575
576 extern inline struct inode * iget(struct super_block * sb,int nr)
577 {
578 return __iget(sb,nr,1);
579 }
580
581 #endif
582
583 #endif