File: /usr/include/linux/fs.h
1 #ifndef _LINUX_FS_H
2 #define _LINUX_FS_H
3
4 /*
5 * This file has definitions for some important file table
6 * structures etc.
7 */
8
9 #include <linux/config.h>
10 #include <linux/linkage.h>
11 #include <linux/limits.h>
12 #include <linux/wait.h>
13 #include <linux/types.h>
14 #include <linux/vfs.h>
15 #include <linux/net.h>
16 #include <linux/kdev_t.h>
17 #include <linux/ioctl.h>
18 #include <linux/list.h>
19 #include <linux/dcache.h>
20 #include <linux/stat.h>
21 #include <linux/cache.h>
22 #include <linux/stddef.h>
23 #include <linux/string.h>
24
25 #include <asm/atomic.h>
26
27 struct poll_table_struct;
28
29
30 /*
31 * It's silly to have NR_OPEN bigger than NR_FILE, but you can change
32 * the file limit at runtime and only root can increase the per-process
33 * nr_file rlimit, so it's safe to set up a ridiculously high absolute
34 * upper limit on files-per-process.
35 *
36 * Some programs (notably those using select()) may have to be
37 * recompiled to take full advantage of the new limits..
38 */
39
40 /* Fixed constants first: */
41 #undef NR_OPEN
42 #define NR_OPEN (1024*1024) /* Absolute upper limit on fd num */
43 #define INR_OPEN 1024 /* Initial setting for nfile rlimits */
44
45 #define BLOCK_SIZE_BITS 10
46 #define BLOCK_SIZE (1<<BLOCK_SIZE_BITS)
47
48 /* And dynamically-tunable limits and defaults: */
49 struct files_stat_struct {
50 int nr_files; /* read only */
51 int nr_free_files; /* read only */
52 int max_files; /* tunable */
53 };
54 extern struct files_stat_struct files_stat;
55
56 struct inodes_stat_t {
57 int nr_inodes;
58 int nr_unused;
59 int dummy[5];
60 };
61 extern struct inodes_stat_t inodes_stat;
62
63 extern int max_super_blocks, nr_super_blocks;
64 extern int leases_enable, dir_notify_enable, lease_break_time;
65
66 #define NR_FILE 8192 /* this can well be larger on a larger system */
67 #define NR_RESERVED_FILES 10 /* reserved for root */
68 #define NR_SUPER 256
69
70 #define MAY_EXEC 1
71 #define MAY_WRITE 2
72 #define MAY_READ 4
73
74 #define FMODE_READ 1
75 #define FMODE_WRITE 2
76
77 #define READ 0
78 #define WRITE 1
79 #define READA 2 /* read-ahead - don't block if no resources */
80 #define SPECIAL 4 /* For non-blockdevice requests in request queue */
81
82 #define SEL_IN 1
83 #define SEL_OUT 2
84 #define SEL_EX 4
85
86 /* public flags for file_system_type */
87 #define FS_REQUIRES_DEV 1
88 #define FS_NO_DCACHE 2 /* Only dcache the necessary things. */
89 #define FS_NO_PRELIM 4 /* prevent preloading of dentries, even if
90 * FS_NO_DCACHE is not set.
91 */
92 #define FS_SINGLE 8 /*
93 * Filesystem that can have only one superblock;
94 * kernel-wide vfsmnt is placed in ->kern_mnt by
95 * kern_mount() which must be called _after_
96 * register_filesystem().
97 */
98 #define FS_NOMOUNT 16 /* Never mount from userland */
99 #define FS_LITTER 32 /* Keeps the tree in dcache */
100 #define FS_ODD_RENAME 32768 /* Temporary stuff; will go away as soon
101 * as nfs_rename() will be cleaned up
102 */
103 /*
104 * These are the fs-independent mount-flags: up to 32 flags are supported
105 */
106 #define MS_RDONLY 1 /* Mount read-only */
107 #define MS_NOSUID 2 /* Ignore suid and sgid bits */
108 #define MS_NODEV 4 /* Disallow access to device special files */
109 #define MS_NOEXEC 8 /* Disallow program execution */
110 #define MS_SYNCHRONOUS 16 /* Writes are synced at once */
111 #define MS_REMOUNT 32 /* Alter flags of a mounted FS */
112 #define MS_MANDLOCK 64 /* Allow mandatory locks on an FS */
113 #define MS_NOATIME 1024 /* Do not update access times. */
114 #define MS_NODIRATIME 2048 /* Do not update directory access times */
115 #define MS_BIND 4096
116
117 /*
118 * Flags that can be altered by MS_REMOUNT
119 */
120 #define MS_RMT_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|\
121 MS_SYNCHRONOUS|MS_MANDLOCK|MS_NOATIME|MS_NODIRATIME)
122
123 /*
124 * Magic mount flag number. Has to be or-ed to the flag values.
125 */
126 #define MS_MGC_VAL 0xC0ED0000 /* magic flag number to indicate "new" flags */
127 #define MS_MGC_MSK 0xffff0000 /* magic flag number mask */
128
129 /* Inode flags - they have nothing to superblock flags now */
130
131 #define S_SYNC 1 /* Writes are synced at once */
132 #define S_NOATIME 2 /* Do not update access times */
133 #define S_QUOTA 4 /* Quota initialized for file */
134 #define S_APPEND 8 /* Append-only file */
135 #define S_IMMUTABLE 16 /* Immutable file */
136 #define S_DEAD 32 /* removed, but still open directory */
137
138 /*
139 * Note that nosuid etc flags are inode-specific: setting some file-system
140 * flags just means all the inodes inherit those flags by default. It might be
141 * possible to override it selectively if you really wanted to with some
142 * ioctl() that is not currently implemented.
143 *
144 * Exception: MS_RDONLY is always applied to the entire file system.
145 *
146 * Unfortunately, it is possible to change a filesystems flags with it mounted
147 * with files in use. This means that all of the inodes will not have their
148 * i_flags updated. Hence, i_flags no longer inherit the superblock mount
149 * flags, so these have to be checked separately. -- rmk@arm.uk.linux.org
150 */
151 #define __IS_FLG(inode,flg) ((inode)->i_sb->s_flags & (flg))
152
153 #define IS_RDONLY(inode) ((inode)->i_sb->s_flags & MS_RDONLY)
154 #define IS_NOSUID(inode) __IS_FLG(inode, MS_NOSUID)
155 #define IS_NODEV(inode) __IS_FLG(inode, MS_NODEV)
156 #define IS_NOEXEC(inode) __IS_FLG(inode, MS_NOEXEC)
157 #define IS_SYNC(inode) (__IS_FLG(inode, MS_SYNCHRONOUS) || ((inode)->i_flags & S_SYNC))
158 #define IS_MANDLOCK(inode) __IS_FLG(inode, MS_MANDLOCK)
159
160 #define IS_QUOTAINIT(inode) ((inode)->i_flags & S_QUOTA)
161 #define IS_APPEND(inode) ((inode)->i_flags & S_APPEND)
162 #define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE)
163 #define IS_NOATIME(inode) (__IS_FLG(inode, MS_NOATIME) || ((inode)->i_flags & S_NOATIME))
164 #define IS_NODIRATIME(inode) __IS_FLG(inode, MS_NODIRATIME)
165
166 #define IS_DEADDIR(inode) ((inode)->i_flags & S_DEAD)
167
168 /* the read-only stuff doesn't really belong here, but any other place is
169 probably as bad and I don't want to create yet another include file. */
170
171 #define BLKROSET _IO(0x12,93) /* set device read-only (0 = read-write) */
172 #define BLKROGET _IO(0x12,94) /* get read-only status (0 = read_write) */
173 #define BLKRRPART _IO(0x12,95) /* re-read partition table */
174 #define BLKGETSIZE _IO(0x12,96) /* return device size */
175 #define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */
176 #define BLKRASET _IO(0x12,98) /* Set read ahead for block device */
177 #define BLKRAGET _IO(0x12,99) /* get current read ahead setting */
178 #define BLKFRASET _IO(0x12,100)/* set filesystem (mm/filemap.c) read-ahead */
179 #define BLKFRAGET _IO(0x12,101)/* get filesystem (mm/filemap.c) read-ahead */
180 #define BLKSECTSET _IO(0x12,102)/* set max sectors per request (ll_rw_blk.c) */
181 #define BLKSECTGET _IO(0x12,103)/* get max sectors per request (ll_rw_blk.c) */
182 #define BLKSSZGET _IO(0x12,104)/* get block device sector size */
183 #if 0
184 #define BLKPG _IO(0x12,105)/* See blkpg.h */
185 #define BLKELVGET _IOR(0x12,106,sizeof(blkelv_ioctl_arg_t))/* elevator get */
186 #define BLKELVSET _IOW(0x12,107,sizeof(blkelv_ioctl_arg_t))/* elevator set */
187 /* This was here just to show that the number is taken -
188 probably all these _IO(0x12,*) ioctls should be moved to blkpg.h. */
189 #endif
190 #define BLKGETLASTSECT _IO(0x12,108) /* get last sector of block device */
191 #define BLKSETLASTSECT _IO(0x12,109) /* get last sector of block device */
192
193
194 #define BMAP_IOCTL 1 /* obsolete - kept for compatibility */
195 #define FIBMAP _IO(0x00,1) /* bmap access */
196 #define FIGETBSZ _IO(0x00,2) /* get the block size used for bmap */
197
198 #ifdef __KERNEL__
199
200 #include <asm/semaphore.h>
201 #include <asm/byteorder.h>
202 #include <asm/bitops.h>
203
204 extern void update_atime (struct inode *);
205 #define UPDATE_ATIME(inode) update_atime (inode)
206
207 extern void buffer_init(unsigned long);
208 extern void inode_init(unsigned long);
209
210 /* bh state bits */
211 #define BH_Uptodate 0 /* 1 if the buffer contains valid data */
212 #define BH_Dirty 1 /* 1 if the buffer is dirty */
213 #define BH_Lock 2 /* 1 if the buffer is locked */
214 #define BH_Req 3 /* 0 if the buffer has been invalidated */
215 #define BH_Mapped 4 /* 1 if the buffer has a disk mapping */
216 #define BH_New 5 /* 1 if the buffer is new and not yet written out */
217 #define BH_Protected 6 /* 1 if the buffer is protected */
218
219 /*
220 * Try to keep the most commonly used fields in single cache lines (16
221 * bytes) to improve performance. This ordering should be
222 * particularly beneficial on 32-bit processors.
223 *
224 * We use the first 16 bytes for the data which is used in searches
225 * over the block hash lists (ie. getblk() and friends).
226 *
227 * The second 16 bytes we use for lru buffer scans, as used by
228 * sync_buffers() and refill_freelist(). -- sct
229 */
230 struct buffer_head {
231 /* First cache line: */
232 struct buffer_head *b_next; /* Hash queue list */
233 unsigned long b_blocknr; /* block number */
234 unsigned short b_size; /* block size */
235 unsigned short b_list; /* List that this buffer appears */
236 kdev_t b_dev; /* device (B_FREE = free) */
237
238 atomic_t b_count; /* users using this block */
239 kdev_t b_rdev; /* Real device */
240 unsigned long b_state; /* buffer state bitmap (see above) */
241 unsigned long b_flushtime; /* Time when (dirty) buffer should be written */
242
243 struct buffer_head *b_next_free;/* lru/free list linkage */
244 struct buffer_head *b_prev_free;/* doubly linked list of buffers */
245 struct buffer_head *b_this_page;/* circular list of buffers in one page */
246 struct buffer_head *b_reqnext; /* request queue */
247
248 struct buffer_head **b_pprev; /* doubly linked list of hash-queue */
249 char * b_data; /* pointer to data block */
250 struct page *b_page; /* the page this bh is mapped to */
251 void (*b_end_io)(struct buffer_head *bh, int uptodate); /* I/O completion */
252 void *b_private; /* reserved for b_end_io */
253
254 unsigned long b_rsector; /* Real buffer location on disk */
255 wait_queue_head_t b_wait;
256
257 struct inode * b_inode;
258 struct list_head b_inode_buffers; /* doubly linked list of inode dirty buffers */
259 };
260
261 typedef void (bh_end_io_t)(struct buffer_head *bh, int uptodate);
262 void init_buffer(struct buffer_head *, bh_end_io_t *, void *);
263
264 #define __buffer_state(bh, state) (((bh)->b_state & (1UL << BH_##state)) != 0)
265
266 #define buffer_uptodate(bh) __buffer_state(bh,Uptodate)
267 #define buffer_dirty(bh) __buffer_state(bh,Dirty)
268 #define buffer_locked(bh) __buffer_state(bh,Lock)
269 #define buffer_req(bh) __buffer_state(bh,Req)
270 #define buffer_mapped(bh) __buffer_state(bh,Mapped)
271 #define buffer_new(bh) __buffer_state(bh,New)
272 #define buffer_protected(bh) __buffer_state(bh,Protected)
273
274 #define bh_offset(bh) ((unsigned long)(bh)->b_data & ~PAGE_MASK)
275
276 extern void set_bh_page(struct buffer_head *bh, struct page *page, unsigned long offset);
277
278 #define touch_buffer(bh) SetPageReferenced(bh->b_page)
279
280
281 #include <linux/pipe_fs_i.h>
282 #include <linux/minix_fs_i.h>
283 #include <linux/ext2_fs_i.h>
284 #include <linux/hpfs_fs_i.h>
285 #include <linux/ntfs_fs_i.h>
286 #include <linux/msdos_fs_i.h>
287 #include <linux/umsdos_fs_i.h>
288 #include <linux/iso_fs_i.h>
289 #include <linux/nfs_fs_i.h>
290 #include <linux/sysv_fs_i.h>
291 #include <linux/affs_fs_i.h>
292 #include <linux/ufs_fs_i.h>
293 #include <linux/efs_fs_i.h>
294 #include <linux/coda_fs_i.h>
295 #include <linux/romfs_fs_i.h>
296 #include <linux/shmem_fs.h>
297 #include <linux/smb_fs_i.h>
298 #include <linux/hfs_fs_i.h>
299 #include <linux/adfs_fs_i.h>
300 #include <linux/qnx4_fs_i.h>
301 #include <linux/reiserfs_fs_i.h>
302 #include <linux/bfs_fs_i.h>
303 #include <linux/udf_fs_i.h>
304 #include <linux/ncp_fs_i.h>
305 #include <linux/proc_fs_i.h>
306 #include <linux/usbdev_fs_i.h>
307
308 /*
309 * Attribute flags. These should be or-ed together to figure out what
310 * has been changed!
311 */
312 #define ATTR_MODE 1
313 #define ATTR_UID 2
314 #define ATTR_GID 4
315 #define ATTR_SIZE 8
316 #define ATTR_ATIME 16
317 #define ATTR_MTIME 32
318 #define ATTR_CTIME 64
319 #define ATTR_ATIME_SET 128
320 #define ATTR_MTIME_SET 256
321 #define ATTR_FORCE 512 /* Not a change, but a change it */
322 #define ATTR_ATTR_FLAG 1024
323
324 /*
325 * This is the Inode Attributes structure, used for notify_change(). It
326 * uses the above definitions as flags, to know which values have changed.
327 * Also, in this manner, a Filesystem can look at only the values it cares
328 * about. Basically, these are the attributes that the VFS layer can
329 * request to change from the FS layer.
330 *
331 * Derek Atkins <warlord@MIT.EDU> 94-10-20
332 */
333 struct iattr {
334 unsigned int ia_valid;
335 umode_t ia_mode;
336 uid_t ia_uid;
337 gid_t ia_gid;
338 loff_t ia_size;
339 time_t ia_atime;
340 time_t ia_mtime;
341 time_t ia_ctime;
342 unsigned int ia_attr_flags;
343 };
344
345 /*
346 * This is the inode attributes flag definitions
347 */
348 #define ATTR_FLAG_SYNCRONOUS 1 /* Syncronous write */
349 #define ATTR_FLAG_NOATIME 2 /* Don't update atime */
350 #define ATTR_FLAG_APPEND 4 /* Append-only file */
351 #define ATTR_FLAG_IMMUTABLE 8 /* Immutable file */
352 #define ATTR_FLAG_NODIRATIME 16 /* Don't update atime for directory */
353
354 /*
355 * Includes for diskquotas and mount structures.
356 */
357 #include <linux/quota.h>
358 #include <linux/mount.h>
359
360 /*
361 * oh the beauties of C type declarations.
362 */
363 struct page;
364 struct address_space;
365
366 struct address_space_operations {
367 int (*writepage)(struct page *);
368 int (*readpage)(struct file *, struct page *);
369 int (*sync_page)(struct page *);
370 int (*prepare_write)(struct file *, struct page *, unsigned, unsigned);
371 int (*commit_write)(struct file *, struct page *, unsigned, unsigned);
372 void (*truncatepage)(struct page *); /* called from truncate_complete_page */
373 /* Unfortunately this kludge is needed for FIBMAP. Don't use it */
374 int (*bmap)(struct address_space *, long);
375 };
376
377 struct address_space {
378 struct list_head clean_pages; /* list of clean pages */
379 struct list_head dirty_pages; /* list of dirty pages */
380 struct list_head locked_pages; /* list of locked pages */
381 unsigned long nrpages; /* number of total pages */
382 spinlock_t page_lock; /* and spinlock protecting them */
383
384 struct address_space_operations *a_ops; /* methods */
385 struct inode *host; /* owner: inode, block_device */
386 struct vm_area_struct *i_mmap; /* list of private mappings */
387 struct vm_area_struct *i_mmap_shared; /* list of shared mappings */
388 spinlock_t i_shared_lock; /* and spinlock protecting it */
389 int gfp_mask; /* how to allocate the pages */
390 };
391
392 struct block_device {
393 struct list_head bd_hash;
394 atomic_t bd_count;
395 /* struct address_space bd_data; */
396 dev_t bd_dev; /* not a kdev_t - it's a search key */
397 atomic_t bd_openers;
398 const struct block_device_operations *bd_op;
399 struct semaphore bd_sem; /* open/close mutex */
400 };
401
402 struct inode {
403 struct list_head i_hash;
404 struct list_head i_list;
405 struct list_head i_dentry;
406
407 struct list_head i_dirty_buffers;
408
409 unsigned long i_ino;
410 atomic_t i_count;
411 kdev_t i_dev;
412 umode_t i_mode;
413 nlink_t i_nlink;
414 uid_t i_uid;
415 gid_t i_gid;
416 kdev_t i_rdev;
417 loff_t i_size;
418 time_t i_atime;
419 time_t i_mtime;
420 time_t i_ctime;
421 unsigned long i_blksize;
422 unsigned long i_blocks;
423 unsigned long i_version;
424 unsigned short i_bytes;
425 struct semaphore i_sem;
426 struct semaphore i_zombie;
427 struct inode_operations *i_op;
428 struct file_operations *i_fop; /* former ->i_op->default_file_ops */
429 struct super_block *i_sb;
430 wait_queue_head_t i_wait;
431 struct file_lock *i_flock;
432 struct address_space *i_mapping;
433 struct address_space i_data;
434 struct dquot *i_dquot[MAXQUOTAS];
435 struct pipe_inode_info *i_pipe;
436 struct block_device *i_bdev;
437
438 unsigned long i_dnotify_mask; /* Directory notify events */
439 struct dnotify_struct *i_dnotify; /* for directory notifications */
440
441 unsigned long i_state;
442
443 unsigned int i_flags;
444 unsigned char i_sock;
445
446 atomic_t i_writecount;
447 unsigned int i_attr_flags;
448 __u32 i_generation;
449 union {
450 struct minix_inode_info minix_i;
451 struct ext2_inode_info ext2_i;
452 struct hpfs_inode_info hpfs_i;
453 struct ntfs_inode_info ntfs_i;
454 struct msdos_inode_info msdos_i;
455 struct umsdos_inode_info umsdos_i;
456 struct iso_inode_info isofs_i;
457 struct nfs_inode_info nfs_i;
458 struct sysv_inode_info sysv_i;
459 struct affs_inode_info affs_i;
460 struct ufs_inode_info ufs_i;
461 struct efs_inode_info efs_i;
462 struct romfs_inode_info romfs_i;
463 struct shmem_inode_info shmem_i;
464 struct coda_inode_info coda_i;
465 struct smb_inode_info smbfs_i;
466 struct hfs_inode_info hfs_i;
467 struct adfs_inode_info adfs_i;
468 struct qnx4_inode_info qnx4_i;
469 struct reiserfs_inode_info reiserfs_i;
470 struct bfs_inode_info bfs_i;
471 struct udf_inode_info udf_i;
472 struct ncp_inode_info ncpfs_i;
473 struct proc_inode_info proc_i;
474 struct socket socket_i;
475 struct usbdev_inode_info usbdev_i;
476 void *generic_ip;
477 } u;
478 };
479
480 struct fown_struct {
481 int pid; /* pid or -pgrp where SIGIO should be sent */
482 uid_t uid, euid; /* uid/euid of process setting the owner */
483 int signum; /* posix.1b rt signal to be delivered on IO */
484 };
485
486 struct file {
487 struct list_head f_list;
488 struct dentry *f_dentry;
489 struct vfsmount *f_vfsmnt;
490 struct file_operations *f_op;
491 atomic_t f_count;
492 unsigned int f_flags;
493 mode_t f_mode;
494 loff_t f_pos;
495 unsigned long f_reada, f_ramax, f_raend, f_ralen, f_rawin;
496 struct fown_struct f_owner;
497 unsigned int f_uid, f_gid;
498 int f_error;
499
500 unsigned long f_version;
501
502 /* needed for tty driver, and maybe others */
503 void *private_data;
504 };
505 extern spinlock_t files_lock;
506 #define file_list_lock() spin_lock(&files_lock);
507 #define file_list_unlock() spin_unlock(&files_lock);
508
509 #define get_file(x) atomic_inc(&(x)->f_count)
510 #define file_count(x) atomic_read(&(x)->f_count)
511
512 extern int init_private_file(struct file *, struct dentry *, int);
513
514 #define MAX_NON_LFS ((1UL<<31) - 1)
515
516 #define FL_POSIX 1
517 #define FL_FLOCK 2
518 #define FL_BROKEN 4 /* broken flock() emulation */
519 #define FL_ACCESS 8 /* for processes suspended by mandatory locking */
520 #define FL_LOCKD 16 /* lock held by rpc.lockd */
521 #define FL_LEASE 32 /* lease held on this file */
522
523 /*
524 * The POSIX file lock owner is determined by
525 * the "struct files_struct" in the thread group
526 * (or NULL for no owner - BSD locks).
527 *
528 * Lockd stuffs a "host" pointer into this.
529 */
530 typedef struct files_struct *fl_owner_t;
531
532 struct file_lock {
533 struct file_lock *fl_next; /* singly linked list for this inode */
534 struct list_head fl_link; /* doubly linked list of all locks */
535 struct list_head fl_block; /* circular list of blocked processes */
536 fl_owner_t fl_owner;
537 unsigned int fl_pid;
538 wait_queue_head_t fl_wait;
539 struct file *fl_file;
540 unsigned char fl_flags;
541 unsigned char fl_type;
542 loff_t fl_start;
543 loff_t fl_end;
544
545 void (*fl_notify)(struct file_lock *); /* unblock callback */
546 void (*fl_insert)(struct file_lock *); /* lock insertion callback */
547 void (*fl_remove)(struct file_lock *); /* lock removal callback */
548
549 struct fasync_struct * fl_fasync; /* for lease break notifications */
550
551 union {
552 struct nfs_lock_info nfs_fl;
553 } fl_u;
554 };
555
556 /* The following constant reflects the upper bound of the file/locking space */
557 #ifndef OFFSET_MAX
558 #define INT_LIMIT(x) (~((x)1 << (sizeof(x)*8 - 1)))
559 #define OFFSET_MAX INT_LIMIT(loff_t)
560 #define OFFT_OFFSET_MAX INT_LIMIT(off_t)
561 #endif
562
563 extern struct list_head file_lock_list;
564
565 #include <linux/fcntl.h>
566
567 extern int fcntl_getlk(unsigned int, struct flock *);
568 extern int fcntl_setlk(unsigned int, unsigned int, struct flock *);
569 extern asmlinkage long sys_fcntl(unsigned int fd, unsigned int cmd, unsigned long arg);
570 extern asmlinkage long sys_dup(unsigned int fildes);
571 extern asmlinkage long sys_dup2(unsigned int oldfd, unsigned int newfd);
572 extern asmlinkage ssize_t sys_read(unsigned int fd, char * buf, size_t count);
573 extern asmlinkage ssize_t sys_write(unsigned int fd, const char * buf, size_t count);
574 extern asmlinkage long sys_chroot(const char * filename);
575 extern asmlinkage long sys_chdir(const char * filename);
576
577
578 extern int fcntl_getlk64(unsigned int, struct flock64 *);
579 extern int fcntl_setlk64(unsigned int, unsigned int, struct flock64 *);
580
581 /* fs/locks.c */
582 extern void locks_init_lock(struct file_lock *);
583 extern void locks_copy_lock(struct file_lock *, struct file_lock *);
584 extern void locks_remove_posix(struct file *, fl_owner_t);
585 extern void locks_remove_flock(struct file *);
586 extern struct file_lock *posix_test_lock(struct file *, struct file_lock *);
587 extern int posix_lock_file(struct file *, struct file_lock *, unsigned int);
588 extern void posix_block_lock(struct file_lock *, struct file_lock *);
589 extern int posix_locks_deadlock(struct file_lock *, struct file_lock *);
590 extern void posix_unblock_lock(struct file_lock *);
591 extern int __get_lease(struct inode *inode, unsigned int flags);
592 extern time_t lease_get_mtime(struct inode *);
593 extern int lock_may_read(struct inode *, loff_t start, unsigned long count);
594 extern int lock_may_write(struct inode *, loff_t start, unsigned long count);
595
596 struct fasync_struct {
597 int magic;
598 int fa_fd;
599 struct fasync_struct *fa_next; /* singly linked list */
600 struct file *fa_file;
601 };
602
603 #define FASYNC_MAGIC 0x4601
604
605 /* SMP safe fasync helpers: */
606 extern int fasync_helper(int, struct file *, int, struct fasync_struct **);
607 /* can be called from interrupts */
608 extern void kill_fasync(struct fasync_struct **, int, int);
609 /* only for net: no internal synchronization */
610 extern void __kill_fasync(struct fasync_struct *, int, int);
611
612 struct nameidata {
613 struct dentry *dentry;
614 struct vfsmount *mnt;
615 struct qstr last;
616 unsigned int flags;
617 int last_type;
618 };
619
620 #define DQUOT_USR_ENABLED 0x01 /* User diskquotas enabled */
621 #define DQUOT_GRP_ENABLED 0x02 /* Group diskquotas enabled */
622
623 struct quota_info
624 {
625 unsigned int flags; /* Flags for diskquotas on this device */
626 struct semaphore dqio_sem; /* lock device while I/O in progress */
627 struct semaphore dqoff_sem; /* serialize quota_off() and quota_on() on device */
628 struct file *files[MAXQUOTAS]; /* fp's to quotafiles */
629 struct mem_dqinfo info[MAXQUOTAS]; /* Information for each quota type */
630 };
631
632 /*
633 * Umount options
634 */
635
636 #define MNT_FORCE 0x00000001 /* Attempt to forcibily umount */
637
638 #include <linux/minix_fs_sb.h>
639 #include <linux/ext2_fs_sb.h>
640 #include <linux/hpfs_fs_sb.h>
641 #include <linux/ntfs_fs_sb.h>
642 #include <linux/msdos_fs_sb.h>
643 #include <linux/iso_fs_sb.h>
644 #include <linux/nfs_fs_sb.h>
645 #include <linux/sysv_fs_sb.h>
646 #include <linux/affs_fs_sb.h>
647 #include <linux/ufs_fs_sb.h>
648 #include <linux/efs_fs_sb.h>
649 #include <linux/romfs_fs_sb.h>
650 #include <linux/smb_fs_sb.h>
651 #include <linux/hfs_fs_sb.h>
652 #include <linux/adfs_fs_sb.h>
653 #include <linux/qnx4_fs_sb.h>
654 #include <linux/reiserfs_fs_sb.h>
655 #include <linux/bfs_fs_sb.h>
656 #include <linux/udf_fs_sb.h>
657 #include <linux/ncp_fs_sb.h>
658 #include <linux/usbdev_fs_sb.h>
659
660 extern struct list_head super_blocks;
661
662 #define sb_entry(list) list_entry((list), struct super_block, s_list)
663 struct super_block {
664 struct list_head s_list; /* Keep this first */
665 kdev_t s_dev;
666 unsigned long s_blocksize;
667 unsigned char s_blocksize_bits;
668 unsigned char s_lock;
669 unsigned char s_dirt;
670 unsigned long long s_maxbytes; /* Max file size */
671 struct file_system_type *s_type;
672 struct super_operations *s_op;
673 struct dquot_operations *dq_op;
674 unsigned long s_flags;
675 unsigned long s_magic;
676 struct dentry *s_root;
677 wait_queue_head_t s_wait;
678
679 struct list_head s_dirty; /* dirty inodes */
680 struct list_head s_files;
681
682 struct block_device *s_bdev;
683 struct list_head s_mounts; /* vfsmount(s) of this one */
684 struct quota_info s_dquot; /* Diskquota specific options */
685
686 union {
687 struct minix_sb_info minix_sb;
688 struct ext2_sb_info ext2_sb;
689 struct hpfs_sb_info hpfs_sb;
690 struct ntfs_sb_info ntfs_sb;
691 struct msdos_sb_info msdos_sb;
692 struct isofs_sb_info isofs_sb;
693 struct nfs_sb_info nfs_sb;
694 struct sysv_sb_info sysv_sb;
695 struct affs_sb_info affs_sb;
696 struct ufs_sb_info ufs_sb;
697 struct efs_sb_info efs_sb;
698 struct shmem_sb_info shmem_sb;
699 struct romfs_sb_info romfs_sb;
700 struct smb_sb_info smbfs_sb;
701 struct hfs_sb_info hfs_sb;
702 struct adfs_sb_info adfs_sb;
703 struct qnx4_sb_info qnx4_sb;
704 struct reiserfs_sb_info reiserfs_sb;
705 struct bfs_sb_info bfs_sb;
706 struct udf_sb_info udf_sb;
707 struct ncp_sb_info ncpfs_sb;
708 struct usbdev_sb_info usbdevfs_sb;
709 void *generic_sbp;
710 } u;
711 /*
712 * The next field is for VFS *only*. No filesystems have any business
713 * even looking at it. You had been warned.
714 */
715 struct semaphore s_vfs_rename_sem; /* Kludge */
716
717 /* The next field is used by knfsd when converting a (inode number based)
718 * file handle into a dentry. As it builds a path in the dcache tree from
719 * the bottom up, there may for a time be a subpath of dentrys which is not
720 * connected to the main tree. This semaphore ensure that there is only ever
721 * one such free path per filesystem. Note that unconnected files (or other
722 * non-directories) are allowed, but not unconnected diretories.
723 */
724 struct semaphore s_nfsd_free_path_sem;
725 };
726
727 /*
728 * VFS helper functions..
729 */
730 extern int vfs_create(struct inode *, struct dentry *, int);
731 extern int vfs_mkdir(struct inode *, struct dentry *, int);
732 extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t);
733 extern int vfs_symlink(struct inode *, struct dentry *, const char *);
734 extern int vfs_link(struct dentry *, struct inode *, struct dentry *);
735 extern int vfs_rmdir(struct inode *, struct dentry *);
736 extern int vfs_unlink(struct inode *, struct dentry *);
737 extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
738
739 /*
740 * File types
741 */
742 #define DT_UNKNOWN 0
743 #define DT_FIFO 1
744 #define DT_CHR 2
745 #define DT_DIR 4
746 #define DT_BLK 6
747 #define DT_REG 8
748 #define DT_LNK 10
749 #define DT_SOCK 12
750 #define DT_WHT 14
751
752 /*
753 * This is the "filldir" function type, used by readdir() to let
754 * the kernel specify what kind of dirent layout it wants to have.
755 * This allows the kernel to read directories into kernel space or
756 * to have different dirent layouts depending on the binary type.
757 */
758 typedef int (*filldir_t)(void *, const char *, int, off_t, ino_t, unsigned);
759
760 struct block_device_operations {
761 int (*open) (struct inode *, struct file *);
762 int (*release) (struct inode *, struct file *);
763 int (*ioctl) (struct inode *, struct file *, unsigned, unsigned long);
764 int (*check_media_change) (kdev_t);
765 int (*revalidate) (kdev_t);
766 };
767
768 /*
769 * NOTE:
770 * read, write, poll, fsync, readv, writev can be called
771 * without the big kernel lock held in all filesystems.
772 */
773 struct file_operations {
774 struct module *owner;
775 loff_t (*llseek) (struct file *, loff_t, int);
776 ssize_t (*read) (struct file *, char *, size_t, loff_t *);
777 ssize_t (*write) (struct file *, const char *, size_t, loff_t *);
778 int (*readdir) (struct file *, void *, filldir_t);
779 unsigned int (*poll) (struct file *, struct poll_table_struct *);
780 int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);
781 int (*mmap) (struct file *, struct vm_area_struct *);
782 int (*open) (struct inode *, struct file *);
783 int (*flush) (struct file *);
784 int (*release) (struct inode *, struct file *);
785 int (*fsync) (struct file *, struct dentry *, int datasync);
786 int (*fasync) (int, struct file *, int);
787 int (*lock) (struct file *, int, struct file_lock *);
788 ssize_t (*readv) (struct file *, const struct iovec *, unsigned long, loff_t *);
789 ssize_t (*writev) (struct file *, const struct iovec *, unsigned long, loff_t *);
790 ssize_t (*writepage) (struct file *, struct page *, int, size_t, loff_t *, int);
791 };
792
793 struct inode_operations {
794 int (*create) (struct inode *,struct dentry *,int);
795 struct dentry * (*lookup) (struct inode *,struct dentry *);
796 int (*link) (struct dentry *,struct inode *,struct dentry *);
797 int (*unlink) (struct inode *,struct dentry *);
798 int (*symlink) (struct inode *,struct dentry *,const char *);
799 int (*mkdir) (struct inode *,struct dentry *,int);
800 int (*rmdir) (struct inode *,struct dentry *);
801 int (*mknod) (struct inode *,struct dentry *,int,int);
802 int (*rename) (struct inode *, struct dentry *,
803 struct inode *, struct dentry *);
804 int (*readlink) (struct dentry *, char *,int);
805 int (*follow_link) (struct dentry *, struct nameidata *);
806 void (*truncate) (struct inode *);
807 int (*permission) (struct inode *, int);
808 int (*revalidate) (struct dentry *);
809 int (*setattr) (struct dentry *, struct iattr *);
810 int (*getattr) (struct dentry *, struct iattr *);
811 };
812
813 /*
814 * NOTE: write_inode, delete_inode, clear_inode, put_inode can be called
815 * without the big kernel lock held in all filesystems.
816 */
817 struct super_operations {
818 void (*read_inode) (struct inode *);
819
820 /* reiserfs kludge. reiserfs needs 64 bits of information to
821 ** find an inode. We are using the read_inode2 call to get
822 ** that information. We don't like this, and are waiting on some
823 ** VFS changes for the real solution.
824 ** iget4 calls read_inode2, iff it is defined
825 */
826 void (*read_inode2) (struct inode *, void *) ;
827 void (*dirty_inode) (struct inode *);
828 void (*write_inode) (struct inode *, int);
829 void (*put_inode) (struct inode *);
830 void (*delete_inode) (struct inode *);
831 void (*put_super) (struct super_block *);
832 void (*write_super) (struct super_block *);
833 void (*write_super_lockfs) (struct super_block *);
834 void (*unlockfs) (struct super_block *);
835 int (*statfs) (struct super_block *, struct statfs *);
836 int (*remount_fs) (struct super_block *, int *, char *);
837 void (*clear_inode) (struct inode *);
838 void (*umount_begin) (struct super_block *);
839 };
840
841 /* Inode state bits.. */
842 #define I_DIRTY_SYNC 1 /* Not dirty enough for O_DATASYNC */
843 #define I_DIRTY_DATASYNC 2 /* Data-related inode changes pending */
844 #define I_DIRTY_PAGES 4 /* Data-related inode changes pending */
845 #define I_LOCK 8
846 #define I_FREEING 16
847 #define I_CLEAR 32
848
849 #define I_DIRTY (I_DIRTY_SYNC | I_DIRTY_DATASYNC | I_DIRTY_PAGES)
850
851 extern void __mark_inode_dirty(struct inode *, int);
852 static inline void mark_inode_dirty(struct inode *inode)
853 {
854 __mark_inode_dirty(inode, I_DIRTY);
855 }
856
857 static inline void mark_inode_dirty_sync(struct inode *inode)
858 {
859 __mark_inode_dirty(inode, I_DIRTY_SYNC);
860 }
861
862 static inline void inode_add_bytes(struct inode *inode, loff_t bytes)
863 {
864 inode->i_blocks += bytes >> 9;
865 bytes &= 511;
866 inode->i_bytes += bytes;
867 if (inode->i_bytes >= 512) {
868 inode->i_blocks++;
869 inode->i_bytes -= 512;
870 }
871 }
872
873 static inline void inode_sub_bytes(struct inode *inode, loff_t bytes)
874 {
875 inode->i_blocks -= bytes >> 9;
876 bytes &= 511;
877 if (inode->i_bytes < bytes) {
878 inode->i_blocks--;
879 inode->i_bytes += 512;
880 }
881 inode->i_bytes -= bytes;
882 }
883
884 static inline loff_t inode_get_bytes(struct inode *inode)
885 {
886 return (((loff_t)inode->i_blocks) << 9) + inode->i_bytes;
887 }
888
889 static inline void inode_set_bytes(struct inode *inode, loff_t bytes)
890 {
891 inode->i_blocks = bytes >> 9;
892 inode->i_bytes = bytes & 511;
893 }
894
895 static inline void mark_inode_dirty_pages(struct inode *inode)
896 {
897 __mark_inode_dirty(inode, I_DIRTY_PAGES);
898 }
899
900 struct dquot_operations {
901 void (*initialize) (struct inode *, short);
902 void (*drop) (struct inode *);
903 int (*alloc_space) (struct inode *, qsize_t, char);
904 int (*alloc_inode) (const struct inode *, unsigned long);
905 void (*free_space) (struct inode *, qsize_t);
906 void (*free_inode) (const struct inode *, unsigned long);
907 int (*transfer) (struct inode *, struct iattr *);
908 };
909
910 struct file_system_type {
911 const char *name;
912 int fs_flags;
913 struct super_block *(*read_super) (struct super_block *, void *, int);
914 struct module *owner;
915 struct vfsmount *kern_mnt; /* For kernel mount, if it's FS_SINGLE fs */
916 struct file_system_type * next;
917 };
918
919 #define DECLARE_FSTYPE(var,type,read,flags) \
920 struct file_system_type var = { \
921 name: type, \
922 read_super: read, \
923 fs_flags: flags, \
924 owner: THIS_MODULE, \
925 }
926
927 #define DECLARE_FSTYPE_DEV(var,type,read) \
928 DECLARE_FSTYPE(var,type,read,FS_REQUIRES_DEV)
929
930 /* Alas, no aliases. Too much hassle with bringing module.h everywhere */
931 #define fops_get(fops) \
932 (((fops) && (fops)->owner) \
933 ? ( try_inc_mod_count((fops)->owner) ? (fops) : NULL ) \
934 : (fops))
935
936 #define fops_put(fops) \
937 do { \
938 if ((fops) && (fops)->owner) \
939 __MOD_DEC_USE_COUNT((fops)->owner); \
940 } while(0)
941
942 extern int register_filesystem(struct file_system_type *);
943 extern int unregister_filesystem(struct file_system_type *);
944 extern struct vfsmount *kern_mount(struct file_system_type *);
945 extern void kern_umount(struct vfsmount *);
946 extern int may_umount(struct vfsmount *);
947 extern long do_mount(char *, char *, char *, unsigned long, void *);
948
949
950 extern int vfs_statfs(struct super_block *, struct statfs *);
951
952 /* Return value for VFS lock functions - tells locks.c to lock conventionally
953 * REALLY kosha for root NFS and nfs_lock
954 */
955 #define LOCK_USE_CLNT 1
956
957 #define FLOCK_VERIFY_READ 1
958 #define FLOCK_VERIFY_WRITE 2
959
960 extern int locks_mandatory_locked(struct inode *);
961 extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
962
963 /*
964 * Candidates for mandatory locking have the setgid bit set
965 * but no group execute bit - an otherwise meaningless combination.
966 */
967 #define MANDATORY_LOCK(inode) \
968 (IS_MANDLOCK(inode) && ((inode)->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID)
969
970 static inline int locks_verify_locked(struct inode *inode)
971 {
972 if (MANDATORY_LOCK(inode))
973 return locks_mandatory_locked(inode);
974 return 0;
975 }
976
977 static inline int locks_verify_area(int read_write, struct inode *inode,
978 struct file *filp, loff_t offset,
979 size_t count)
980 {
981 if (inode->i_flock && MANDATORY_LOCK(inode))
982 return locks_mandatory_area(read_write, inode, filp, offset, count);
983 return 0;
984 }
985
986 static inline int locks_verify_truncate(struct inode *inode,
987 struct file *filp,
988 loff_t size)
989 {
990 if (inode->i_flock && MANDATORY_LOCK(inode))
991 return locks_mandatory_area(
992 FLOCK_VERIFY_WRITE, inode, filp,
993 size < inode->i_size ? size : inode->i_size,
994 (size < inode->i_size ? inode->i_size - size
995 : size - inode->i_size)
996 );
997 return 0;
998 }
999
1000 extern inline int get_lease(struct inode *inode, unsigned int mode)
1001 {
1002 if (inode->i_flock && (inode->i_flock->fl_flags & FL_LEASE))
1003 return __get_lease(inode, mode);
1004 return 0;
1005 }
1006
1007 /* fs/open.c */
1008
1009 asmlinkage long sys_open(const char *, int, int);
1010 asmlinkage long sys_close(unsigned int); /* yes, it's really unsigned */
1011 extern int do_truncate(struct dentry *, loff_t start);
1012
1013 extern struct file *filp_open(const char *, int, int);
1014 extern struct file * dentry_open(struct dentry *, struct vfsmount *, int);
1015 extern int filp_close(struct file *, fl_owner_t id);
1016 extern char * getname(const char *);
1017
1018 /* fs/dcache.c */
1019 extern void vfs_caches_init(unsigned long);
1020
1021 #define __getname() kmem_cache_alloc(names_cachep, SLAB_KERNEL)
1022 #define putname(name) kmem_cache_free(names_cachep, (void *)(name))
1023
1024 enum {BDEV_FILE, BDEV_SWAP, BDEV_FS, BDEV_RAW};
1025 extern int register_blkdev(unsigned int, const char *, struct block_device_operations *);
1026 extern int unregister_blkdev(unsigned int, const char *);
1027 extern struct block_device *bdget(dev_t);
1028 extern void bdput(struct block_device *);
1029 extern int blkdev_open(struct inode *, struct file *);
1030 extern struct file_operations def_blk_fops;
1031 extern struct file_operations def_fifo_fops;
1032 extern int ioctl_by_bdev(struct block_device *, unsigned, unsigned long);
1033 extern int blkdev_get(struct block_device *, mode_t, unsigned, int);
1034 extern int blkdev_put(struct block_device *, int);
1035
1036 /* fs/devices.c */
1037 extern const struct block_device_operations *get_blkfops(unsigned int);
1038 extern int register_chrdev(unsigned int, const char *, struct file_operations *);
1039 extern int unregister_chrdev(unsigned int, const char *);
1040 extern int chrdev_open(struct inode *, struct file *);
1041 extern const char * bdevname(kdev_t);
1042 extern const char * cdevname(kdev_t);
1043 extern const char * kdevname(kdev_t);
1044 extern void init_special_inode(struct inode *, umode_t, int);
1045
1046 /* Invalid inode operations -- fs/bad_inode.c */
1047 extern void make_bad_inode(struct inode *);
1048 extern int is_bad_inode(struct inode *);
1049
1050 extern struct file_operations read_fifo_fops;
1051 extern struct file_operations write_fifo_fops;
1052 extern struct file_operations rdwr_fifo_fops;
1053 extern struct file_operations read_pipe_fops;
1054 extern struct file_operations write_pipe_fops;
1055 extern struct file_operations rdwr_pipe_fops;
1056
1057 extern int fs_may_remount_ro(struct super_block *);
1058
1059 extern int try_to_free_buffers(struct page *, int);
1060 extern void refile_buffer(struct buffer_head * buf);
1061
1062 /* reiserfs_writepage needs this */
1063 extern void set_buffer_async_io(struct buffer_head *bh) ;
1064
1065 #define BUF_CLEAN 0
1066 #define BUF_LOCKED 1 /* Buffers scheduled for write */
1067 #define BUF_DIRTY 2 /* Dirty buffers, not yet scheduled for write */
1068 #define BUF_PROTECTED 3 /* Ramdisk persistent storage */
1069 #define NR_LIST 4
1070
1071 /*
1072 * This is called by bh->b_end_io() handlers when I/O has completed.
1073 */
1074 static inline void mark_buffer_uptodate(struct buffer_head * bh, int on)
1075 {
1076 if (on)
1077 set_bit(BH_Uptodate, &bh->b_state);
1078 else
1079 clear_bit(BH_Uptodate, &bh->b_state);
1080 }
1081
1082 #define atomic_set_buffer_clean(bh) test_and_clear_bit(BH_Dirty, &(bh)->b_state)
1083
1084 static inline void __mark_buffer_clean(struct buffer_head *bh)
1085 {
1086 refile_buffer(bh);
1087 }
1088
1089 static inline void mark_buffer_clean(struct buffer_head * bh)
1090 {
1091 if (atomic_set_buffer_clean(bh))
1092 __mark_buffer_clean(bh);
1093 }
1094
1095 #define atomic_set_buffer_protected(bh) test_and_set_bit(BH_Protected, &(bh)->b_state)
1096
1097 static inline void __mark_buffer_protected(struct buffer_head *bh)
1098 {
1099 refile_buffer(bh);
1100 }
1101
1102 static inline void mark_buffer_protected(struct buffer_head * bh)
1103 {
1104 if (!atomic_set_buffer_protected(bh))
1105 __mark_buffer_protected(bh);
1106 }
1107
1108 extern void FASTCALL(__mark_buffer_dirty(struct buffer_head *bh));
1109 extern void FASTCALL(mark_buffer_dirty(struct buffer_head *bh));
1110
1111 #define atomic_set_buffer_dirty(bh) test_and_set_bit(BH_Dirty, &(bh)->b_state)
1112
1113 /*
1114 * If an error happens during the make_request, this function
1115 * has to be recalled. It marks the buffer as clean and not
1116 * uptodate, and it notifys the upper layer about the end
1117 * of the I/O.
1118 */
1119 static inline void buffer_IO_error(struct buffer_head * bh)
1120 {
1121 mark_buffer_clean(bh);
1122 /*
1123 * b_end_io has to clear the BH_Uptodate bitflag in the error case!
1124 */
1125 bh->b_end_io(bh, 0);
1126 }
1127
1128 extern void buffer_insert_inode_queue(struct buffer_head *, struct inode *);
1129 static inline void mark_buffer_dirty_inode(struct buffer_head *bh, struct inode *inode)
1130 {
1131 mark_buffer_dirty(bh);
1132 buffer_insert_inode_queue(bh, inode);
1133 }
1134
1135 extern void balance_dirty(kdev_t);
1136 extern int check_disk_change(kdev_t);
1137 extern int invalidate_inodes(struct super_block *);
1138 extern void invalidate_inode_pages(struct inode *);
1139 extern void invalidate_inode_buffers(struct inode *);
1140 #define invalidate_buffers(dev) __invalidate_buffers((dev), 0)
1141 #define destroy_buffers(dev) __invalidate_buffers((dev), 1)
1142 extern void __invalidate_buffers(kdev_t dev, int);
1143 extern void sync_inodes(kdev_t);
1144 extern void write_inode_now(struct inode *, int);
1145 extern void sync_dev(kdev_t);
1146 extern int fsync_dev(kdev_t);
1147 extern int fsync_inode_buffers(struct inode *);
1148 extern int osync_inode_buffers(struct inode *);
1149 extern int inode_has_buffers(struct inode *);
1150 extern void filemap_fdatasync(struct address_space *);
1151 extern void filemap_fdatawait(struct address_space *);
1152 extern void sync_supers(kdev_t);
1153 extern int bmap(struct inode *, int);
1154 extern int notify_change(struct dentry *, struct iattr *);
1155 extern int permission(struct inode *, int);
1156 extern int vfs_permission(struct inode *, int);
1157 extern int get_write_access(struct inode *);
1158 extern int deny_write_access(struct file *);
1159 static inline void put_write_access(struct inode * inode)
1160 {
1161 atomic_dec(&inode->i_writecount);
1162 }
1163 static inline void allow_write_access(struct file *file)
1164 {
1165 if (file)
1166 atomic_inc(&file->f_dentry->d_inode->i_writecount);
1167 }
1168 extern int do_pipe(int *);
1169
1170 extern int open_namei(const char *, int, int, struct nameidata *);
1171
1172 extern int kernel_read(struct file *, unsigned long, char *, unsigned long);
1173 extern struct file * open_exec(const char *);
1174
1175 /* fs/dcache.c -- generic fs support functions */
1176 extern int is_subdir(struct dentry *, struct dentry *);
1177 extern ino_t find_inode_number(struct dentry *, struct qstr *);
1178
1179 /*
1180 * Kernel pointers have redundant information, so we can use a
1181 * scheme where we can return either an error code or a dentry
1182 * pointer with the same return value.
1183 *
1184 * This should be a per-architecture thing, to allow different
1185 * error and pointer decisions.
1186 */
1187 static inline void *ERR_PTR(long error)
1188 {
1189 return (void *) error;
1190 }
1191
1192 static inline long PTR_ERR(const void *ptr)
1193 {
1194 return (long) ptr;
1195 }
1196
1197 static inline long IS_ERR(const void *ptr)
1198 {
1199 return (unsigned long)ptr > (unsigned long)-1000L;
1200 }
1201
1202 /*
1203 * The bitmask for a lookup event:
1204 * - follow links at the end
1205 * - require a directory
1206 * - ending slashes ok even for nonexistent files
1207 * - internal "there are more path compnents" flag
1208 */
1209 #define LOOKUP_FOLLOW (1)
1210 #define LOOKUP_DIRECTORY (2)
1211 #define LOOKUP_CONTINUE (4)
1212 #define LOOKUP_POSITIVE (8)
1213 #define LOOKUP_PARENT (16)
1214 #define LOOKUP_NOALT (32)
1215 #define LOOKUP_ATOMIC (64)
1216 /*
1217 * Type of the last component on LOOKUP_PARENT
1218 */
1219 enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT, LAST_BIND};
1220
1221 /*
1222 * "descriptor" for what we're up to with a read for sendfile().
1223 * This allows us to use the same read code yet
1224 * have multiple different users of the data that
1225 * we read from a file.
1226 *
1227 * The simplest case just copies the data to user
1228 * mode.
1229 */
1230 typedef struct {
1231 size_t written;
1232 size_t count;
1233 char * buf;
1234 int error;
1235 } read_descriptor_t;
1236
1237 typedef int (*read_actor_t)(read_descriptor_t *, struct page *, unsigned long, unsigned long);
1238
1239 /* needed for stackable file system support */
1240 extern loff_t default_llseek(struct file *file, loff_t offset, int origin);
1241
1242 extern int __user_walk(const char *, unsigned, struct nameidata *);
1243 extern int path_init(const char *, unsigned, struct nameidata *);
1244 extern int path_walk(const char *, struct nameidata *);
1245 extern void path_release(struct nameidata *);
1246 extern int follow_down(struct vfsmount **, struct dentry **);
1247 extern int follow_up(struct vfsmount **, struct dentry **);
1248 extern struct dentry * lookup_one(const char *, struct dentry *);
1249 extern struct dentry * lookup_hash(struct qstr *, struct dentry *);
1250 #define user_path_walk(name,nd) __user_walk(name, LOOKUP_FOLLOW|LOOKUP_POSITIVE, nd)
1251 #define user_path_walk_link(name,nd) __user_walk(name, LOOKUP_POSITIVE, nd)
1252
1253 extern void iput (struct inode *);
1254 /*
1255 * This variant of iput() marks the inode as a top
1256 * candidate to be freed. Simple iput preserves the
1257 * LRU list.
1258 */
1259 extern void iput_free (struct inode *);
1260 extern void force_delete(struct inode *);
1261 extern struct inode * igrab(struct inode *);
1262 extern ino_t iunique(struct super_block *, ino_t);
1263
1264 typedef int (*find_inode_t)(struct inode *, unsigned long, void *);
1265 extern struct inode * iget4(struct super_block *, unsigned long, find_inode_t, void *);
1266 static inline struct inode *iget(struct super_block *sb, unsigned long ino)
1267 {
1268 return iget4(sb, ino, NULL, NULL);
1269 }
1270
1271 extern void clear_inode(struct inode *);
1272 extern struct inode * get_empty_inode(void);
1273 static inline struct inode * new_inode(struct super_block *sb)
1274 {
1275 struct inode *inode = get_empty_inode();
1276 if (inode) {
1277 inode->i_sb = sb;
1278 inode->i_dev = sb->s_dev;
1279 }
1280 return inode;
1281 }
1282 extern void remove_suid(struct inode *inode);
1283
1284 extern void insert_inode_hash(struct inode *);
1285 extern void remove_inode_hash(struct inode *);
1286 extern struct file * get_empty_filp(void);
1287 extern void file_move(struct file *f, struct list_head *list);
1288 extern void file_moveto(struct file *new, struct file *old);
1289 extern struct buffer_head * get_hash_table(kdev_t, int, int);
1290 extern struct buffer_head * getblk(kdev_t, int, int);
1291 extern void ll_rw_block(int, int, struct buffer_head * bh[]);
1292 extern void submit_bh(int, struct buffer_head *);
1293 extern int is_read_only(kdev_t);
1294 extern void __brelse(struct buffer_head *);
1295 static inline void brelse(struct buffer_head *buf)
1296 {
1297 if (buf)
1298 __brelse(buf);
1299 }
1300 extern void __bforget(struct buffer_head *);
1301 static inline void bforget(struct buffer_head *buf)
1302 {
1303 if (buf)
1304 __bforget(buf);
1305 }
1306 extern void set_blocksize(kdev_t, int);
1307 extern unsigned int get_hardblocksize(kdev_t);
1308 extern struct buffer_head * bread(kdev_t, int, int);
1309 extern void wakeup_bdflush(int wait);
1310
1311 extern int brw_page(int, struct page *, kdev_t, int [], int);
1312
1313 typedef int (get_block_t)(struct inode*,long,struct buffer_head*,int);
1314
1315 /* Generic buffer handling for block filesystems.. */
1316 extern int block_flushpage(struct page *, unsigned long);
1317 extern int block_symlink(struct inode *, const char *, int);
1318 extern int block_write_full_page(struct page*, get_block_t*);
1319 extern int block_read_full_page(struct page*, get_block_t*);
1320 extern int block_prepare_write(struct page*, unsigned, unsigned, get_block_t*);
1321 extern int cont_prepare_write(struct page*, unsigned, unsigned, get_block_t*,
1322 unsigned long *);
1323 extern int block_sync_page(struct page *);
1324 extern void flush_inode_pages (struct inode * inode);
1325
1326 int generic_block_bmap(struct address_space *, long, get_block_t *);
1327 int generic_commit_write(struct file *, struct page *, unsigned, unsigned);
1328 int block_truncate_page(struct address_space *, loff_t, get_block_t *);
1329
1330 extern int generic_file_mmap(struct file *, struct vm_area_struct *);
1331 extern int file_read_actor(read_descriptor_t * desc, struct page *page, unsigned long offset, unsigned long size);
1332 extern ssize_t generic_file_read(struct file *, char *, size_t, loff_t *);
1333 extern ssize_t generic_file_write(struct file *, const char *, size_t, loff_t *);
1334 extern void do_generic_file_read(struct file *, loff_t *, read_descriptor_t *, read_actor_t, int);
1335
1336 extern ssize_t generic_read_dir(struct file *, char *, size_t, loff_t *);
1337 extern int generic_file_open(struct inode *, struct file *);
1338
1339 extern struct file_operations generic_ro_fops;
1340
1341 extern int vfs_readlink(struct dentry *, char *, int, const char *);
1342 extern int vfs_follow_link(struct nameidata *, const char *);
1343 extern int page_readlink(struct dentry *, char *, int);
1344 extern int page_follow_link(struct dentry *, struct nameidata *);
1345 extern struct inode_operations page_symlink_inode_operations;
1346
1347 extern int vfs_readdir(struct file *, filldir_t, void *);
1348 extern int dcache_readdir(struct file *, void *, filldir_t);
1349
1350 extern struct file_system_type *get_fs_type(const char *name);
1351 extern struct super_block *get_super(kdev_t);
1352 struct super_block *get_empty_super(void);
1353 extern void put_super(kdev_t);
1354 unsigned long generate_cluster(kdev_t, int b[], int);
1355 unsigned long generate_cluster_swab32(kdev_t, int b[], int);
1356 extern kdev_t ROOT_DEV;
1357 extern char root_device_name[];
1358
1359
1360 extern void show_buffers(void);
1361 extern void mount_root(void);
1362
1363 #ifdef CONFIG_BLK_DEV_INITRD
1364 extern kdev_t real_root_dev;
1365 extern int change_root(kdev_t, const char *);
1366 #endif
1367
1368 extern ssize_t char_read(struct file *, char *, size_t, loff_t *);
1369 extern ssize_t block_read(struct file *, char *, size_t, loff_t *);
1370 extern int read_ahead[];
1371
1372 extern ssize_t char_write(struct file *, const char *, size_t, loff_t *);
1373 extern ssize_t block_write(struct file *, const char *, size_t, loff_t *);
1374
1375 extern int file_fsync(struct file *, struct dentry *, int);
1376 extern int generic_buffer_fdatasync(struct inode *inode, unsigned long start_idx, unsigned long end_idx);
1377 extern int generic_osync_inode(struct inode *, int);
1378
1379 extern int inode_change_ok(struct inode *, struct iattr *);
1380 extern int inode_setattr(struct inode *, struct iattr *);
1381
1382 /*
1383 * Common dentry functions for inclusion in the VFS
1384 * or in other stackable file systems. Some of these
1385 * functions were in linux/fs/ C (VFS) files.
1386 *
1387 */
1388
1389 /*
1390 * Locking the parent is needed to:
1391 * - serialize directory operations
1392 * - make sure the parent doesn't change from
1393 * under us in the middle of an operation.
1394 *
1395 * NOTE! Right now we'd rather use a "struct inode"
1396 * for this, but as I expect things to move toward
1397 * using dentries instead for most things it is
1398 * probably better to start with the conceptually
1399 * better interface of relying on a path of dentries.
1400 */
1401 static inline struct dentry *lock_parent(struct dentry *dentry)
1402 {
1403 struct dentry *dir = dget(dentry->d_parent);
1404
1405 down(&dir->d_inode->i_sem);
1406 return dir;
1407 }
1408
1409 static inline struct dentry *get_parent(struct dentry *dentry)
1410 {
1411 return dget(dentry->d_parent);
1412 }
1413
1414 static inline void unlock_dir(struct dentry *dir)
1415 {
1416 up(&dir->d_inode->i_sem);
1417 dput(dir);
1418 }
1419
1420 /*
1421 * Whee.. Deadlock country. Happily there are only two VFS
1422 * operations that does this..
1423 */
1424 static inline void double_down(struct semaphore *s1, struct semaphore *s2)
1425 {
1426 if (s1 != s2) {
1427 if ((unsigned long) s1 < (unsigned long) s2) {
1428 struct semaphore *tmp = s2;
1429 s2 = s1; s1 = tmp;
1430 }
1431 down(s1);
1432 }
1433 down(s2);
1434 }
1435
1436 /*
1437 * Ewwwwwwww... _triple_ lock. We are guaranteed that the 3rd argument is
1438 * not equal to 1st and not equal to 2nd - the first case (target is parent of
1439 * source) would be already caught, the second is plain impossible (target is
1440 * its own parent and that case would be caught even earlier). Very messy.
1441 * I _think_ that it works, but no warranties - please, look it through.
1442 * Pox on bloody lusers who mandated overwriting rename() for directories...
1443 */
1444
1445 static inline void triple_down(struct semaphore *s1,
1446 struct semaphore *s2,
1447 struct semaphore *s3)
1448 {
1449 if (s1 != s2) {
1450 if ((unsigned long) s1 < (unsigned long) s2) {
1451 if ((unsigned long) s1 < (unsigned long) s3) {
1452 struct semaphore *tmp = s3;
1453 s3 = s1; s1 = tmp;
1454 }
1455 if ((unsigned long) s1 < (unsigned long) s2) {
1456 struct semaphore *tmp = s2;
1457 s2 = s1; s1 = tmp;
1458 }
1459 } else {
1460 if ((unsigned long) s1 < (unsigned long) s3) {
1461 struct semaphore *tmp = s3;
1462 s3 = s1; s1 = tmp;
1463 }
1464 if ((unsigned long) s2 < (unsigned long) s3) {
1465 struct semaphore *tmp = s3;
1466 s3 = s2; s2 = tmp;
1467 }
1468 }
1469 down(s1);
1470 } else if ((unsigned long) s2 < (unsigned long) s3) {
1471 struct semaphore *tmp = s3;
1472 s3 = s2; s2 = tmp;
1473 }
1474 down(s2);
1475 down(s3);
1476 }
1477
1478 static inline void double_up(struct semaphore *s1, struct semaphore *s2)
1479 {
1480 up(s1);
1481 if (s1 != s2)
1482 up(s2);
1483 }
1484
1485 static inline void triple_up(struct semaphore *s1,
1486 struct semaphore *s2,
1487 struct semaphore *s3)
1488 {
1489 up(s1);
1490 if (s1 != s2)
1491 up(s2);
1492 up(s3);
1493 }
1494
1495 static inline void double_lock(struct dentry *d1, struct dentry *d2)
1496 {
1497 double_down(&d1->d_inode->i_sem, &d2->d_inode->i_sem);
1498 }
1499
1500 static inline void double_unlock(struct dentry *d1, struct dentry *d2)
1501 {
1502 double_up(&d1->d_inode->i_sem,&d2->d_inode->i_sem);
1503 dput(d1);
1504 dput(d2);
1505 }
1506
1507 #endif /* __KERNEL__ */
1508
1509 #endif /* _LINUX_FS_H */
1510