5 * This file has definitions for some important file table
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>
25 #include <asm/atomic.h>
26 #include <asm/bitops.h>
28 struct poll_table_struct;
32 * It's silly to have NR_OPEN bigger than NR_FILE, but you can change
33 * the file limit at runtime and only root can increase the per-process
34 * nr_file rlimit, so it's safe to set up a ridiculously high absolute
35 * upper limit on files-per-process.
37 * Some programs (notably those using select()) may have to be
38 * recompiled to take full advantage of the new limits..
41 /* Fixed constants first: */
43 #define NR_OPEN (1024*1024) /* Absolute upper limit on fd num */
44 #define INR_OPEN 1024 /* Initial setting for nfile rlimits */
46 #define BLOCK_SIZE_BITS 10
47 #define BLOCK_SIZE (1<<BLOCK_SIZE_BITS)
49 /* And dynamically-tunable limits and defaults: */
50 struct files_stat_struct {
51 int nr_files; /* read only */
52 int nr_free_files; /* read only */
53 int max_files; /* tunable */
55 extern struct files_stat_struct files_stat;
57 struct inodes_stat_t {
62 extern struct inodes_stat_t inodes_stat;
64 extern int leases_enable, dir_notify_enable, lease_break_time;
66 #define NR_FILE 8192 /* this can well be larger on a larger system */
67 #define NR_RESERVED_FILES 10 /* reserved for root */
79 #define READA 2 /* read-ahead - don't block if no resources */
80 #define SPECIAL 4 /* For non-blockdevice requests in request queue */
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.
92 #define FS_SINGLE 8 /* Filesystem that can have only one superblock */
93 #define FS_NOMOUNT 16 /* Never mount from userland */
94 #define FS_LITTER 32 /* Keeps the tree in dcache */
95 #define FS_ODD_RENAME 32768 /* Temporary stuff; will go away as soon
96 * as nfs_rename() will be cleaned up
99 * These are the fs-independent mount-flags: up to 32 flags are supported
101 #define MS_RDONLY 1 /* Mount read-only */
102 #define MS_NOSUID 2 /* Ignore suid and sgid bits */
103 #define MS_NODEV 4 /* Disallow access to device special files */
104 #define MS_NOEXEC 8 /* Disallow program execution */
105 #define MS_SYNCHRONOUS 16 /* Writes are synced at once */
106 #define MS_REMOUNT 32 /* Alter flags of a mounted FS */
107 #define MS_MANDLOCK 64 /* Allow mandatory locks on an FS */
108 #define MS_NOATIME 1024 /* Do not update access times. */
109 #define MS_NODIRATIME 2048 /* Do not update directory access times */
113 #define MS_VERBOSE 32768
114 #define MS_ACTIVE (1<<30)
115 #define MS_NOUSER (1<<31)
118 * Superblock flags that can be altered by MS_REMOUNT
120 #define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_NOATIME|\
124 * Old magic mount flag and mask
126 #define MS_MGC_VAL 0xC0ED0000
127 #define MS_MGC_MSK 0xffff0000
129 /* Inode flags - they have nothing to superblock flags now */
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 #define S_NOQUOTA 64 /* Inode is not counted to quota */
140 * Note that nosuid etc flags are inode-specific: setting some file-system
141 * flags just means all the inodes inherit those flags by default. It might be
142 * possible to override it selectively if you really wanted to with some
143 * ioctl() that is not currently implemented.
145 * Exception: MS_RDONLY is always applied to the entire file system.
147 * Unfortunately, it is possible to change a filesystems flags with it mounted
148 * with files in use. This means that all of the inodes will not have their
149 * i_flags updated. Hence, i_flags no longer inherit the superblock mount
150 * flags, so these have to be checked separately. -- rmk@arm.uk.linux.org
152 #define __IS_FLG(inode,flg) ((inode)->i_sb->s_flags & (flg))
154 #define IS_RDONLY(inode) ((inode)->i_sb->s_flags & MS_RDONLY)
155 #define IS_SYNC(inode) (__IS_FLG(inode, MS_SYNCHRONOUS) || ((inode)->i_flags & S_SYNC))
156 #define IS_MANDLOCK(inode) __IS_FLG(inode, MS_MANDLOCK)
158 #define IS_QUOTAINIT(inode) ((inode)->i_flags & S_QUOTA)
159 #define IS_NOQUOTA(inode) ((inode)->i_flags & S_NOQUOTA)
160 #define IS_APPEND(inode) ((inode)->i_flags & S_APPEND)
161 #define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE)
162 #define IS_NOATIME(inode) (__IS_FLG(inode, MS_NOATIME) || ((inode)->i_flags & S_NOATIME))
163 #define IS_NODIRATIME(inode) __IS_FLG(inode, MS_NODIRATIME)
165 #define IS_DEADDIR(inode) ((inode)->i_flags & S_DEAD)
167 /* the read-only stuff doesn't really belong here, but any other place is
168 probably as bad and I don't want to create yet another include file. */
170 #define BLKROSET _IO(0x12,93) /* set device read-only (0 = read-write) */
171 #define BLKROGET _IO(0x12,94) /* get read-only status (0 = read_write) */
172 #define BLKRRPART _IO(0x12,95) /* re-read partition table */
173 #define BLKGETSIZE _IO(0x12,96) /* return device size /512 (long *arg) */
174 #define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */
175 #define BLKRASET _IO(0x12,98) /* Set read ahead for block device */
176 #define BLKRAGET _IO(0x12,99) /* get current read ahead setting */
177 #define BLKFRASET _IO(0x12,100)/* set filesystem (mm/filemap.c) read-ahead */
178 #define BLKFRAGET _IO(0x12,101)/* get filesystem (mm/filemap.c) read-ahead */
179 #define BLKSECTSET _IO(0x12,102)/* set max sectors per request (ll_rw_blk.c) */
180 #define BLKSECTGET _IO(0x12,103)/* get max sectors per request (ll_rw_blk.c) */
181 #define BLKSSZGET _IO(0x12,104)/* get block device sector size */
183 #define BLKPG _IO(0x12,105)/* See blkpg.h */
184 #define BLKELVGET _IOR(0x12,106,sizeof(blkelv_ioctl_arg_t))/* elevator get */
185 #define BLKELVSET _IOW(0x12,107,sizeof(blkelv_ioctl_arg_t))/* elevator set */
186 /* This was here just to show that the number is taken -
187 probably all these _IO(0x12,*) ioctls should be moved to blkpg.h. */
189 /* A jump here: 108-111 have been used for various private purposes. */
190 #define BLKBSZGET _IOR(0x12,112,sizeof(int))
191 #define BLKBSZSET _IOW(0x12,113,sizeof(int))
192 #define BLKGETSIZE64 _IOR(0x12,114,sizeof(u64)) /* return device size in bytes (u64 *arg) */
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 */
200 #include <asm/semaphore.h>
201 #include <asm/byteorder.h>
203 extern void update_atime (struct inode *);
204 #define UPDATE_ATIME(inode) update_atime (inode)
206 extern void buffer_init(unsigned long);
207 extern void inode_init(unsigned long);
208 extern void mnt_init(unsigned long);
209 extern void files_init(unsigned long mempages);
213 BH_Uptodate, /* 1 if the buffer contains valid data */
214 BH_Dirty, /* 1 if the buffer is dirty */
215 BH_Lock, /* 1 if the buffer is locked */
216 BH_Req, /* 0 if the buffer has been invalidated */
217 BH_Mapped, /* 1 if the buffer has a disk mapping */
218 BH_New, /* 1 if the buffer is new and not yet written out */
219 BH_Async, /* 1 if the buffer is under end_buffer_io_async I/O */
220 BH_Wait_IO, /* 1 if we should write out this buffer */
221 BH_Launder, /* 1 if we can throttle on this buffer */
222 BH_Attached, /* 1 if b_inode_buffers is linked into a list */
223 BH_JBD, /* 1 if it has an attached journal_head */
225 BH_PrivateStart,/* not a state bit, but the first bit available
226 * for private allocation by other entities
230 #define MAX_BUF_PER_PAGE (PAGE_CACHE_SIZE / 512)
233 * Try to keep the most commonly used fields in single cache lines (16
234 * bytes) to improve performance. This ordering should be
235 * particularly beneficial on 32-bit processors.
237 * We use the first 16 bytes for the data which is used in searches
238 * over the block hash lists (ie. getblk() and friends).
240 * The second 16 bytes we use for lru buffer scans, as used by
241 * sync_buffers() and refill_freelist(). -- sct
244 /* First cache line: */
245 struct buffer_head *b_next; /* Hash queue list */
246 unsigned long b_blocknr; /* block number */
247 unsigned short b_size; /* block size */
248 unsigned short b_list; /* List that this buffer appears */
249 kdev_t b_dev; /* device (B_FREE = free) */
251 atomic_t b_count; /* users using this block */
252 kdev_t b_rdev; /* Real device */
253 unsigned long b_state; /* buffer state bitmap (see above) */
254 unsigned long b_flushtime; /* Time when (dirty) buffer should be written */
256 struct buffer_head *b_next_free;/* lru/free list linkage */
257 struct buffer_head *b_prev_free;/* doubly linked list of buffers */
258 struct buffer_head *b_this_page;/* circular list of buffers in one page */
259 struct buffer_head *b_reqnext; /* request queue */
261 struct buffer_head **b_pprev; /* doubly linked list of hash-queue */
262 char * b_data; /* pointer to data block */
263 struct page *b_page; /* the page this bh is mapped to */
264 void (*b_end_io)(struct buffer_head *bh, int uptodate); /* I/O completion */
265 void *b_private; /* reserved for b_end_io */
267 unsigned long b_rsector; /* Real buffer location on disk */
268 wait_queue_head_t b_wait;
270 struct list_head b_inode_buffers; /* doubly linked list of inode dirty buffers */
273 typedef void (bh_end_io_t)(struct buffer_head *bh, int uptodate);
274 void init_buffer(struct buffer_head *, bh_end_io_t *, void *);
276 #define __buffer_state(bh, state) (((bh)->b_state & (1UL << BH_##state)) != 0)
278 #define buffer_uptodate(bh) __buffer_state(bh,Uptodate)
279 #define buffer_dirty(bh) __buffer_state(bh,Dirty)
280 #define buffer_locked(bh) __buffer_state(bh,Lock)
281 #define buffer_req(bh) __buffer_state(bh,Req)
282 #define buffer_mapped(bh) __buffer_state(bh,Mapped)
283 #define buffer_new(bh) __buffer_state(bh,New)
284 #define buffer_async(bh) __buffer_state(bh,Async)
285 #define buffer_launder(bh) __buffer_state(bh,Launder)
287 #define bh_offset(bh) ((unsigned long)(bh)->b_data & ~PAGE_MASK)
289 extern void set_bh_page(struct buffer_head *bh, struct page *page, unsigned long offset);
291 #define touch_buffer(bh) mark_page_accessed(bh->b_page)
294 #include <linux/pipe_fs_i.h>
295 #include <linux/minix_fs_i.h>
296 #include <linux/ext2_fs_i.h>
297 #include <linux/ext3_fs_i.h>
298 #include <linux/hpfs_fs_i.h>
299 #include <linux/ntfs_fs_i.h>
300 #include <linux/msdos_fs_i.h>
301 #include <linux/umsdos_fs_i.h>
302 #include <linux/iso_fs_i.h>
303 #include <linux/nfs_fs_i.h>
304 #include <linux/sysv_fs_i.h>
305 #include <linux/affs_fs_i.h>
306 #include <linux/ufs_fs_i.h>
307 #include <linux/efs_fs_i.h>
308 #include <linux/coda_fs_i.h>
309 #include <linux/romfs_fs_i.h>
310 #include <linux/shmem_fs.h>
311 #include <linux/smb_fs_i.h>
312 #include <linux/hfs_fs_i.h>
313 #include <linux/adfs_fs_i.h>
314 #include <linux/qnx4_fs_i.h>
315 #include <linux/reiserfs_fs_i.h>
316 #include <linux/bfs_fs_i.h>
317 #include <linux/udf_fs_i.h>
318 #include <linux/ncp_fs_i.h>
319 #include <linux/proc_fs_i.h>
320 #include <linux/usbdev_fs_i.h>
321 #include <linux/jffs2_fs_i.h>
322 #include <linux/cramfs_fs_sb.h>
325 * Attribute flags. These should be or-ed together to figure out what
332 #define ATTR_ATIME 16
333 #define ATTR_MTIME 32
334 #define ATTR_CTIME 64
335 #define ATTR_ATIME_SET 128
336 #define ATTR_MTIME_SET 256
337 #define ATTR_FORCE 512 /* Not a change, but a change it */
338 #define ATTR_ATTR_FLAG 1024
341 * This is the Inode Attributes structure, used for notify_change(). It
342 * uses the above definitions as flags, to know which values have changed.
343 * Also, in this manner, a Filesystem can look at only the values it cares
344 * about. Basically, these are the attributes that the VFS layer can
345 * request to change from the FS layer.
347 * Derek Atkins <warlord@MIT.EDU> 94-10-20
350 unsigned int ia_valid;
358 unsigned int ia_attr_flags;
362 * This is the inode attributes flag definitions
364 #define ATTR_FLAG_SYNCRONOUS 1 /* Syncronous write */
365 #define ATTR_FLAG_NOATIME 2 /* Don't update atime */
366 #define ATTR_FLAG_APPEND 4 /* Append-only file */
367 #define ATTR_FLAG_IMMUTABLE 8 /* Immutable file */
368 #define ATTR_FLAG_NODIRATIME 16 /* Don't update atime for directory */
371 * Includes for diskquotas and mount structures.
373 #include <linux/quota.h>
374 #include <linux/mount.h>
377 * oh the beauties of C type declarations.
380 struct address_space;
383 struct address_space_operations {
384 int (*writepage)(struct page *);
385 int (*readpage)(struct file *, struct page *);
386 int (*sync_page)(struct page *);
388 * ext3 requires that a successful prepare_write() call be followed
389 * by a commit_write() call - they must be balanced
391 int (*prepare_write)(struct file *, struct page *, unsigned, unsigned);
392 int (*commit_write)(struct file *, struct page *, unsigned, unsigned);
393 /* Unfortunately this kludge is needed for FIBMAP. Don't use it */
394 int (*bmap)(struct address_space *, long);
395 int (*flushpage) (struct page *, unsigned long);
396 int (*releasepage) (struct page *, int);
397 #define KERNEL_HAS_O_DIRECT /* this is for modules out of the kernel */
398 int (*direct_IO)(int, struct inode *, struct kiobuf *, unsigned long, int);
399 void (*removepage)(struct page *); /* called when page gets removed from the inode */
402 struct address_space {
403 struct list_head clean_pages; /* list of clean pages */
404 struct list_head dirty_pages; /* list of dirty pages */
405 struct list_head locked_pages; /* list of locked pages */
406 unsigned long nrpages; /* number of total pages */
407 struct address_space_operations *a_ops; /* methods */
408 struct inode *host; /* owner: inode, block_device */
409 struct vm_area_struct *i_mmap; /* list of private mappings */
410 struct vm_area_struct *i_mmap_shared; /* list of shared mappings */
411 spinlock_t i_shared_lock; /* and spinlock protecting it */
412 int gfp_mask; /* how to allocate the pages */
416 struct list_head hash;
420 struct semaphore sem;
423 struct block_device {
424 struct list_head bd_hash;
426 struct inode * bd_inode;
427 dev_t bd_dev; /* not a kdev_t - it's a search key */
429 const struct block_device_operations *bd_op;
430 struct semaphore bd_sem; /* open/close mutex */
431 struct list_head bd_inodes;
435 struct list_head i_hash;
436 struct list_head i_list;
437 struct list_head i_dentry;
439 struct list_head i_dirty_buffers;
440 struct list_head i_dirty_data_buffers;
454 unsigned int i_blkbits;
455 unsigned long i_blksize;
456 unsigned long i_blocks;
457 unsigned long i_version;
458 struct semaphore i_sem;
459 struct semaphore i_zombie;
460 struct inode_operations *i_op;
461 struct file_operations *i_fop; /* former ->i_op->default_file_ops */
462 struct super_block *i_sb;
463 wait_queue_head_t i_wait;
464 struct file_lock *i_flock;
465 struct address_space *i_mapping;
466 struct address_space i_data;
467 struct dquot *i_dquot[MAXQUOTAS];
468 /* These three should probably be a union */
469 struct list_head i_devices;
470 struct pipe_inode_info *i_pipe;
471 struct block_device *i_bdev;
472 struct char_device *i_cdev;
474 unsigned long i_dnotify_mask; /* Directory notify events */
475 struct dnotify_struct *i_dnotify; /* for directory notifications */
477 unsigned long i_state;
479 unsigned int i_flags;
480 unsigned char i_sock;
482 atomic_t i_writecount;
483 unsigned int i_attr_flags;
486 struct minix_inode_info minix_i;
487 struct ext2_inode_info ext2_i;
488 struct ext3_inode_info ext3_i;
489 struct hpfs_inode_info hpfs_i;
490 struct ntfs_inode_info ntfs_i;
491 struct msdos_inode_info msdos_i;
492 struct umsdos_inode_info umsdos_i;
493 struct iso_inode_info isofs_i;
494 struct nfs_inode_info nfs_i;
495 struct sysv_inode_info sysv_i;
496 struct affs_inode_info affs_i;
497 struct ufs_inode_info ufs_i;
498 struct efs_inode_info efs_i;
499 struct romfs_inode_info romfs_i;
500 struct shmem_inode_info shmem_i;
501 struct coda_inode_info coda_i;
502 struct smb_inode_info smbfs_i;
503 struct hfs_inode_info hfs_i;
504 struct adfs_inode_info adfs_i;
505 struct qnx4_inode_info qnx4_i;
506 struct reiserfs_inode_info reiserfs_i;
507 struct bfs_inode_info bfs_i;
508 struct udf_inode_info udf_i;
509 struct ncp_inode_info ncpfs_i;
510 struct proc_inode_info proc_i;
511 struct socket socket_i;
512 struct usbdev_inode_info usbdev_i;
513 struct jffs2_inode_info jffs2_i;
519 int pid; /* pid or -pgrp where SIGIO should be sent */
520 uid_t uid, euid; /* uid/euid of process setting the owner */
521 int signum; /* posix.1b rt signal to be delivered on IO */
525 struct list_head f_list;
526 struct dentry *f_dentry;
527 struct vfsmount *f_vfsmnt;
528 struct file_operations *f_op;
530 unsigned int f_flags;
533 unsigned long f_reada, f_ramax, f_raend, f_ralen, f_rawin;
534 struct fown_struct f_owner;
535 unsigned int f_uid, f_gid;
538 unsigned long f_version;
540 /* needed for tty driver, and maybe others */
543 /* preallocated helper kiobuf to speedup O_DIRECT */
544 struct kiobuf *f_iobuf;
547 extern spinlock_t files_lock;
548 #define file_list_lock() spin_lock(&files_lock);
549 #define file_list_unlock() spin_unlock(&files_lock);
551 #define get_file(x) atomic_inc(&(x)->f_count)
552 #define file_count(x) atomic_read(&(x)->f_count)
554 extern int init_private_file(struct file *, struct dentry *, int);
556 #define MAX_NON_LFS ((1UL<<31) - 1)
558 /* Page cache limit. The filesystems should put that into their s_maxbytes
559 limits, otherwise bad things can happen in VM. */
560 #if BITS_PER_LONG==32
561 #define MAX_LFS_FILESIZE (((u64)PAGE_CACHE_SIZE << (BITS_PER_LONG-1))-1)
562 #elif BITS_PER_LONG==64
563 #define MAX_LFS_FILESIZE 0x7fffffffffffffff
568 #define FL_BROKEN 4 /* broken flock() emulation */
569 #define FL_ACCESS 8 /* for processes suspended by mandatory locking */
570 #define FL_LOCKD 16 /* lock held by rpc.lockd */
571 #define FL_LEASE 32 /* lease held on this file */
574 * The POSIX file lock owner is determined by
575 * the "struct files_struct" in the thread group
576 * (or NULL for no owner - BSD locks).
578 * Lockd stuffs a "host" pointer into this.
580 typedef struct files_struct *fl_owner_t;
583 struct file_lock *fl_next; /* singly linked list for this inode */
584 struct list_head fl_link; /* doubly linked list of all locks */
585 struct list_head fl_block; /* circular list of blocked processes */
588 wait_queue_head_t fl_wait;
589 struct file *fl_file;
590 unsigned char fl_flags;
591 unsigned char fl_type;
595 void (*fl_notify)(struct file_lock *); /* unblock callback */
596 void (*fl_insert)(struct file_lock *); /* lock insertion callback */
597 void (*fl_remove)(struct file_lock *); /* lock removal callback */
599 struct fasync_struct * fl_fasync; /* for lease break notifications */
600 unsigned long fl_break_time; /* for nonblocking lease breaks */
603 struct nfs_lock_info nfs_fl;
607 /* The following constant reflects the upper bound of the file/locking space */
609 #define INT_LIMIT(x) (~((x)1 << (sizeof(x)*8 - 1)))
610 #define OFFSET_MAX INT_LIMIT(loff_t)
611 #define OFFT_OFFSET_MAX INT_LIMIT(off_t)
614 extern struct list_head file_lock_list;
616 #include <linux/fcntl.h>
618 extern int fcntl_getlk(unsigned int, struct flock *);
619 extern int fcntl_setlk(unsigned int, unsigned int, struct flock *);
621 extern int fcntl_getlk64(unsigned int, struct flock64 *);
622 extern int fcntl_setlk64(unsigned int, unsigned int, struct flock64 *);
625 extern void locks_init_lock(struct file_lock *);
626 extern void locks_copy_lock(struct file_lock *, struct file_lock *);
627 extern void locks_remove_posix(struct file *, fl_owner_t);
628 extern void locks_remove_flock(struct file *);
629 extern struct file_lock *posix_test_lock(struct file *, struct file_lock *);
630 extern int posix_lock_file(struct file *, struct file_lock *, unsigned int);
631 extern void posix_block_lock(struct file_lock *, struct file_lock *);
632 extern void posix_unblock_lock(struct file_lock *);
633 extern int posix_locks_deadlock(struct file_lock *, struct file_lock *);
634 extern int __get_lease(struct inode *inode, unsigned int flags);
635 extern time_t lease_get_mtime(struct inode *);
636 extern int lock_may_read(struct inode *, loff_t start, unsigned long count);
637 extern int lock_may_write(struct inode *, loff_t start, unsigned long count);
639 struct fasync_struct {
642 struct fasync_struct *fa_next; /* singly linked list */
643 struct file *fa_file;
646 #define FASYNC_MAGIC 0x4601
648 /* SMP safe fasync helpers: */
649 extern int fasync_helper(int, struct file *, int, struct fasync_struct **);
650 /* can be called from interrupts */
651 extern void kill_fasync(struct fasync_struct **, int, int);
652 /* only for net: no internal synchronization */
653 extern void __kill_fasync(struct fasync_struct *, int, int);
656 struct dentry *dentry;
657 struct vfsmount *mnt;
663 #define DQUOT_USR_ENABLED 0x01 /* User diskquotas enabled */
664 #define DQUOT_GRP_ENABLED 0x02 /* Group diskquotas enabled */
666 struct quota_mount_options
668 unsigned int flags; /* Flags for diskquotas on this device */
669 struct semaphore dqio_sem; /* lock device while I/O in progress */
670 struct semaphore dqoff_sem; /* serialize quota_off() and quota_on() on device */
671 struct file *files[MAXQUOTAS]; /* fp's to quotafiles */
672 time_t inode_expire[MAXQUOTAS]; /* expiretime for inode-quota */
673 time_t block_expire[MAXQUOTAS]; /* expiretime for block-quota */
674 char rsquash[MAXQUOTAS]; /* for quotas threat root as any other user */
681 #define MNT_FORCE 0x00000001 /* Attempt to forcibily umount */
682 #define MNT_DETACH 0x00000002 /* Just detach from the tree */
684 #include <linux/minix_fs_sb.h>
685 #include <linux/ext2_fs_sb.h>
686 #include <linux/ext3_fs_sb.h>
687 #include <linux/hpfs_fs_sb.h>
688 #include <linux/ntfs_fs_sb.h>
689 #include <linux/msdos_fs_sb.h>
690 #include <linux/iso_fs_sb.h>
691 #include <linux/nfs_fs_sb.h>
692 #include <linux/sysv_fs_sb.h>
693 #include <linux/affs_fs_sb.h>
694 #include <linux/ufs_fs_sb.h>
695 #include <linux/efs_fs_sb.h>
696 #include <linux/romfs_fs_sb.h>
697 #include <linux/smb_fs_sb.h>
698 #include <linux/hfs_fs_sb.h>
699 #include <linux/adfs_fs_sb.h>
700 #include <linux/qnx4_fs_sb.h>
701 #include <linux/reiserfs_fs_sb.h>
702 #include <linux/bfs_fs_sb.h>
703 #include <linux/udf_fs_sb.h>
704 #include <linux/ncp_fs_sb.h>
705 #include <linux/usbdev_fs_sb.h>
706 #include <linux/cramfs_fs_sb.h>
707 #include <linux/jffs2_fs_sb.h>
709 extern struct list_head super_blocks;
710 extern spinlock_t sb_lock;
712 #define sb_entry(list) list_entry((list), struct super_block, s_list)
713 #define S_BIAS (1<<30)
715 struct list_head s_list; /* Keep this first */
717 unsigned long s_blocksize;
718 unsigned char s_blocksize_bits;
719 unsigned char s_dirt;
720 unsigned long long s_maxbytes; /* Max file size */
721 struct file_system_type *s_type;
722 struct super_operations *s_op;
723 struct dquot_operations *dq_op;
724 unsigned long s_flags;
725 unsigned long s_magic;
726 struct dentry *s_root;
727 struct rw_semaphore s_umount;
728 struct semaphore s_lock;
732 struct list_head s_dirty; /* dirty inodes */
733 struct list_head s_locked_inodes;/* inodes being synced */
734 struct list_head s_files;
736 struct block_device *s_bdev;
737 struct list_head s_instances;
738 struct quota_mount_options s_dquot; /* Diskquota specific options */
741 struct minix_sb_info minix_sb;
742 struct ext2_sb_info ext2_sb;
743 struct ext3_sb_info ext3_sb;
744 struct hpfs_sb_info hpfs_sb;
745 struct ntfs_sb_info ntfs_sb;
746 struct msdos_sb_info msdos_sb;
747 struct isofs_sb_info isofs_sb;
748 struct nfs_sb_info nfs_sb;
749 struct sysv_sb_info sysv_sb;
750 struct affs_sb_info affs_sb;
751 struct ufs_sb_info ufs_sb;
752 struct efs_sb_info efs_sb;
753 struct shmem_sb_info shmem_sb;
754 struct romfs_sb_info romfs_sb;
755 struct smb_sb_info smbfs_sb;
756 struct hfs_sb_info hfs_sb;
757 struct adfs_sb_info adfs_sb;
758 struct qnx4_sb_info qnx4_sb;
759 struct reiserfs_sb_info reiserfs_sb;
760 struct bfs_sb_info bfs_sb;
761 struct udf_sb_info udf_sb;
762 struct ncp_sb_info ncpfs_sb;
763 struct usbdev_sb_info usbdevfs_sb;
764 struct jffs2_sb_info jffs2_sb;
765 struct cramfs_sb_info cramfs_sb;
769 * The next field is for VFS *only*. No filesystems have any business
770 * even looking at it. You had been warned.
772 struct semaphore s_vfs_rename_sem; /* Kludge */
774 /* The next field is used by knfsd when converting a (inode number based)
775 * file handle into a dentry. As it builds a path in the dcache tree from
776 * the bottom up, there may for a time be a subpath of dentrys which is not
777 * connected to the main tree. This semaphore ensure that there is only ever
778 * one such free path per filesystem. Note that unconnected files (or other
779 * non-directories) are allowed, but not unconnected diretories.
781 struct semaphore s_nfsd_free_path_sem;
785 * VFS helper functions..
787 extern int vfs_create(struct inode *, struct dentry *, int);
788 extern int vfs_mkdir(struct inode *, struct dentry *, int);
789 extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t);
790 extern int vfs_symlink(struct inode *, struct dentry *, const char *);
791 extern int vfs_link(struct dentry *, struct inode *, struct dentry *);
792 extern int vfs_rmdir(struct inode *, struct dentry *);
793 extern int vfs_unlink(struct inode *, struct dentry *);
794 extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
810 * This is the "filldir" function type, used by readdir() to let
811 * the kernel specify what kind of dirent layout it wants to have.
812 * This allows the kernel to read directories into kernel space or
813 * to have different dirent layouts depending on the binary type.
815 typedef int (*filldir_t)(void *, const char *, int, loff_t, ino_t, unsigned);
817 struct block_device_operations {
818 int (*open) (struct inode *, struct file *);
819 int (*release) (struct inode *, struct file *);
820 int (*ioctl) (struct inode *, struct file *, unsigned, unsigned long);
821 int (*check_media_change) (kdev_t);
822 int (*revalidate) (kdev_t);
823 struct module *owner;
828 * read, write, poll, fsync, readv, writev can be called
829 * without the big kernel lock held in all filesystems.
831 struct file_operations {
832 struct module *owner;
833 loff_t (*llseek) (struct file *, loff_t, int);
834 ssize_t (*read) (struct file *, char *, size_t, loff_t *);
835 ssize_t (*write) (struct file *, const char *, size_t, loff_t *);
836 int (*readdir) (struct file *, void *, filldir_t);
837 unsigned int (*poll) (struct file *, struct poll_table_struct *);
838 int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);
839 int (*mmap) (struct file *, struct vm_area_struct *);
840 int (*open) (struct inode *, struct file *);
841 int (*flush) (struct file *);
842 int (*release) (struct inode *, struct file *);
843 int (*fsync) (struct file *, struct dentry *, int datasync);
844 int (*fasync) (int, struct file *, int);
845 int (*lock) (struct file *, int, struct file_lock *);
846 ssize_t (*readv) (struct file *, const struct iovec *, unsigned long, loff_t *);
847 ssize_t (*writev) (struct file *, const struct iovec *, unsigned long, loff_t *);
848 ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
849 unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
852 struct inode_operations {
853 int (*create) (struct inode *,struct dentry *,int);
854 struct dentry * (*lookup) (struct inode *,struct dentry *);
855 int (*link) (struct dentry *,struct inode *,struct dentry *);
856 int (*unlink) (struct inode *,struct dentry *);
857 int (*symlink) (struct inode *,struct dentry *,const char *);
858 int (*mkdir) (struct inode *,struct dentry *,int);
859 int (*rmdir) (struct inode *,struct dentry *);
860 int (*mknod) (struct inode *,struct dentry *,int,int);
861 int (*rename) (struct inode *, struct dentry *,
862 struct inode *, struct dentry *);
863 int (*readlink) (struct dentry *, char *,int);
864 int (*follow_link) (struct dentry *, struct nameidata *);
865 void (*truncate) (struct inode *);
866 int (*permission) (struct inode *, int);
867 int (*revalidate) (struct dentry *);
868 int (*setattr) (struct dentry *, struct iattr *);
869 int (*getattr) (struct dentry *, struct iattr *);
870 int (*setxattr) (struct dentry *, const char *, void *, size_t, int);
871 ssize_t (*getxattr) (struct dentry *, const char *, void *, size_t);
872 ssize_t (*listxattr) (struct dentry *, char *, size_t);
873 int (*removexattr) (struct dentry *, const char *);
879 * NOTE: write_inode, delete_inode, clear_inode, put_inode can be called
880 * without the big kernel lock held in all filesystems.
882 struct super_operations {
883 struct inode *(*alloc_inode)(struct super_block *sb);
884 void (*destroy_inode)(struct inode *);
886 void (*read_inode) (struct inode *);
888 /* reiserfs kludge. reiserfs needs 64 bits of information to
889 ** find an inode. We are using the read_inode2 call to get
890 ** that information. We don't like this, and are waiting on some
891 ** VFS changes for the real solution.
892 ** iget4 calls read_inode2, iff it is defined
894 void (*read_inode2) (struct inode *, void *) ;
895 void (*dirty_inode) (struct inode *);
896 void (*write_inode) (struct inode *, int);
897 void (*put_inode) (struct inode *);
898 void (*delete_inode) (struct inode *);
899 void (*put_super) (struct super_block *);
900 void (*write_super) (struct super_block *);
901 int (*sync_fs) (struct super_block *);
902 void (*write_super_lockfs) (struct super_block *);
903 void (*unlockfs) (struct super_block *);
904 int (*statfs) (struct super_block *, struct statfs *);
905 int (*remount_fs) (struct super_block *, int *, char *);
906 void (*clear_inode) (struct inode *);
907 void (*umount_begin) (struct super_block *);
909 /* Following are for knfsd to interact with "interesting" filesystems
910 * Currently just reiserfs, but possibly FAT and others later
912 * fh_to_dentry is given a filehandle fragement with length, and a type flag
913 * and must return a dentry for the referenced object or, if "parent" is
914 * set, a dentry for the parent of the object.
915 * If a dentry cannot be found, a "root" dentry should be created and
916 * flaged as DCACHE_NFSD_DISCONNECTED. nfsd_iget is an example implementation.
918 * dentry_to_fh is given a dentry and must generate the filesys specific
919 * part of the file handle. Available length is passed in *lenp and used
920 * length should be returned therein.
921 * If need_parent is set, then dentry_to_fh should encode sufficient information
922 * to find the (current) parent.
923 * dentry_to_fh should return a 1byte "type" which will be passed back in
924 * the fhtype arguement to fh_to_dentry. Type of 0 is reserved.
925 * If filesystem was exportable before the introduction of fh_to_dentry,
926 * types 1 and 2 should be used is that same way as the generic code.
927 * Type 255 means error.
929 * Lengths are in units of 4bytes, not bytes.
931 struct dentry * (*fh_to_dentry)(struct super_block *sb, __u32 *fh, int len, int fhtype, int parent);
932 int (*dentry_to_fh)(struct dentry *, __u32 *fh, int *lenp, int need_parent);
933 int (*show_options)(struct seq_file *, struct vfsmount *);
936 /* Inode state bits.. */
937 #define I_DIRTY_SYNC 1 /* Not dirty enough for O_DATASYNC */
938 #define I_DIRTY_DATASYNC 2 /* Data-related inode changes pending */
939 #define I_DIRTY_PAGES 4 /* Data-related inode changes pending */
944 #define I_DIRTY (I_DIRTY_SYNC | I_DIRTY_DATASYNC | I_DIRTY_PAGES)
946 extern void __mark_inode_dirty(struct inode *, int);
947 static inline void mark_inode_dirty(struct inode *inode)
949 __mark_inode_dirty(inode, I_DIRTY);
952 static inline void mark_inode_dirty_sync(struct inode *inode)
954 __mark_inode_dirty(inode, I_DIRTY_SYNC);
957 static inline void mark_inode_dirty_pages(struct inode *inode)
959 __mark_inode_dirty(inode, I_DIRTY_PAGES);
962 struct dquot_operations {
963 void (*initialize) (struct inode *, short);
964 void (*drop) (struct inode *);
965 int (*alloc_block) (struct inode *, unsigned long, char);
966 int (*alloc_inode) (const struct inode *, unsigned long);
967 void (*free_block) (struct inode *, unsigned long);
968 void (*free_inode) (const struct inode *, unsigned long);
969 int (*transfer) (struct inode *, struct iattr *);
972 struct file_system_type {
975 struct super_block *(*read_super) (struct super_block *, void *, int);
976 struct module *owner;
977 struct file_system_type * next;
978 struct list_head fs_supers;
981 #define DECLARE_FSTYPE(var,type,read,flags) \
982 struct file_system_type var = { \
986 owner: THIS_MODULE, \
989 #define DECLARE_FSTYPE_DEV(var,type,read) \
990 DECLARE_FSTYPE(var,type,read,FS_REQUIRES_DEV)
992 /* Alas, no aliases. Too much hassle with bringing module.h everywhere */
993 #define fops_get(fops) \
994 (((fops) && (fops)->owner) \
995 ? ( try_inc_mod_count((fops)->owner) ? (fops) : NULL ) \
998 #define fops_put(fops) \
1000 if ((fops) && (fops)->owner) \
1001 __MOD_DEC_USE_COUNT((fops)->owner); \
1004 extern int register_filesystem(struct file_system_type *);
1005 extern int unregister_filesystem(struct file_system_type *);
1006 extern struct vfsmount *kern_mount(struct file_system_type *);
1007 extern int may_umount(struct vfsmount *);
1008 extern long do_mount(char *, char *, char *, unsigned long, void *);
1010 #define kern_umount mntput
1012 extern int vfs_statfs(struct super_block *, struct statfs *);
1014 /* Return value for VFS lock functions - tells locks.c to lock conventionally
1015 * REALLY kosha for root NFS and nfs_lock
1017 #define LOCK_USE_CLNT 1
1019 #define FLOCK_VERIFY_READ 1
1020 #define FLOCK_VERIFY_WRITE 2
1022 extern int locks_mandatory_locked(struct inode *);
1023 extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
1026 * Candidates for mandatory locking have the setgid bit set
1027 * but no group execute bit - an otherwise meaningless combination.
1029 #define MANDATORY_LOCK(inode) \
1030 (IS_MANDLOCK(inode) && ((inode)->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID)
1032 static inline int locks_verify_locked(struct inode *inode)
1034 if (MANDATORY_LOCK(inode))
1035 return locks_mandatory_locked(inode);
1039 static inline int locks_verify_area(int read_write, struct inode *inode,
1040 struct file *filp, loff_t offset,
1043 if (inode->i_flock && MANDATORY_LOCK(inode))
1044 return locks_mandatory_area(read_write, inode, filp, offset, count);
1048 static inline int locks_verify_truncate(struct inode *inode,
1052 if (inode->i_flock && MANDATORY_LOCK(inode))
1053 return locks_mandatory_area(
1054 FLOCK_VERIFY_WRITE, inode, filp,
1055 size < inode->i_size ? size : inode->i_size,
1056 (size < inode->i_size ? inode->i_size - size
1057 : size - inode->i_size)
1062 static inline int get_lease(struct inode *inode, unsigned int mode)
1065 return __get_lease(inode, mode);
1071 asmlinkage long sys_open(const char *, int, int);
1072 asmlinkage long sys_close(unsigned int); /* yes, it's really unsigned */
1073 extern int do_truncate(struct dentry *, loff_t start);
1075 extern struct file *filp_open(const char *, int, int);
1076 extern struct file * dentry_open(struct dentry *, struct vfsmount *, int);
1077 extern int filp_close(struct file *, fl_owner_t id);
1078 extern char * getname(const char *);
1081 extern void vfs_caches_init(unsigned long);
1083 #define __getname() kmem_cache_alloc(names_cachep, SLAB_KERNEL)
1084 #define putname(name) kmem_cache_free(names_cachep, (void *)(name))
1086 enum {BDEV_FILE, BDEV_SWAP, BDEV_FS, BDEV_RAW};
1087 extern int register_blkdev(unsigned int, const char *, struct block_device_operations *);
1088 extern int unregister_blkdev(unsigned int, const char *);
1089 extern struct block_device *bdget(dev_t);
1090 extern int bd_acquire(struct inode *inode);
1091 extern void bd_forget(struct inode *inode);
1092 extern void bdput(struct block_device *);
1093 extern struct char_device *cdget(dev_t);
1094 extern void cdput(struct char_device *);
1095 extern int blkdev_open(struct inode *, struct file *);
1096 extern int blkdev_close(struct inode *, struct file *);
1097 extern struct file_operations def_blk_fops;
1098 extern struct address_space_operations def_blk_aops;
1099 extern struct file_operations def_fifo_fops;
1100 extern int ioctl_by_bdev(struct block_device *, unsigned, unsigned long);
1101 extern int blkdev_get(struct block_device *, mode_t, unsigned, int);
1102 extern int blkdev_put(struct block_device *, int);
1105 extern const struct block_device_operations *get_blkfops(unsigned int);
1106 extern int register_chrdev(unsigned int, const char *, struct file_operations *);
1107 extern int unregister_chrdev(unsigned int, const char *);
1108 extern int chrdev_open(struct inode *, struct file *);
1109 extern const char * bdevname(kdev_t);
1110 extern const char * cdevname(kdev_t);
1111 extern const char * kdevname(kdev_t);
1112 extern void init_special_inode(struct inode *, umode_t, int);
1114 /* Invalid inode operations -- fs/bad_inode.c */
1115 extern void make_bad_inode(struct inode *);
1116 extern int is_bad_inode(struct inode *);
1118 extern struct file_operations read_fifo_fops;
1119 extern struct file_operations write_fifo_fops;
1120 extern struct file_operations rdwr_fifo_fops;
1121 extern struct file_operations read_pipe_fops;
1122 extern struct file_operations write_pipe_fops;
1123 extern struct file_operations rdwr_pipe_fops;
1125 extern int fs_may_remount_ro(struct super_block *);
1127 extern int FASTCALL(try_to_free_buffers(struct page *, unsigned int));
1128 extern void refile_buffer(struct buffer_head * buf);
1129 extern void create_empty_buffers(struct page *, kdev_t, unsigned long);
1130 extern void end_buffer_io_sync(struct buffer_head *bh, int uptodate);
1132 /* reiserfs_writepage needs this */
1133 extern void set_buffer_async_io(struct buffer_head *bh) ;
1136 #define BUF_LOCKED 1 /* Buffers scheduled for write */
1137 #define BUF_DIRTY 2 /* Dirty buffers, not yet scheduled for write */
1140 static inline void get_bh(struct buffer_head * bh)
1142 atomic_inc(&(bh)->b_count);
1145 static inline void put_bh(struct buffer_head *bh)
1147 smp_mb__before_atomic_dec();
1148 atomic_dec(&bh->b_count);
1152 * This is called by bh->b_end_io() handlers when I/O has completed.
1154 static inline void mark_buffer_uptodate(struct buffer_head * bh, int on)
1157 set_bit(BH_Uptodate, &bh->b_state);
1159 clear_bit(BH_Uptodate, &bh->b_state);
1162 #define atomic_set_buffer_clean(bh) test_and_clear_bit(BH_Dirty, &(bh)->b_state)
1164 static inline void __mark_buffer_clean(struct buffer_head *bh)
1169 static inline void mark_buffer_clean(struct buffer_head * bh)
1171 if (atomic_set_buffer_clean(bh))
1172 __mark_buffer_clean(bh);
1175 extern void FASTCALL(__mark_dirty(struct buffer_head *bh));
1176 extern void FASTCALL(__mark_buffer_dirty(struct buffer_head *bh));
1177 extern void FASTCALL(mark_buffer_dirty(struct buffer_head *bh));
1179 extern void FASTCALL(buffer_insert_list(struct buffer_head *, struct list_head *));
1181 static inline void buffer_insert_inode_queue(struct buffer_head *bh, struct inode *inode)
1183 buffer_insert_list(bh, &inode->i_dirty_buffers);
1186 static inline void buffer_insert_inode_data_queue(struct buffer_head *bh, struct inode *inode)
1188 buffer_insert_list(bh, &inode->i_dirty_data_buffers);
1191 static inline int atomic_set_buffer_dirty(struct buffer_head *bh)
1193 return test_and_set_bit(BH_Dirty, &bh->b_state);
1196 static inline void mark_buffer_async(struct buffer_head * bh, int on)
1199 set_bit(BH_Async, &bh->b_state);
1201 clear_bit(BH_Async, &bh->b_state);
1204 static inline void set_buffer_attached(struct buffer_head *bh)
1206 set_bit(BH_Attached, &bh->b_state);
1209 static inline void clear_buffer_attached(struct buffer_head *bh)
1211 clear_bit(BH_Attached, &bh->b_state);
1214 static inline int buffer_attached(struct buffer_head *bh)
1216 return test_bit(BH_Attached, &bh->b_state);
1220 * If an error happens during the make_request, this function
1221 * has to be recalled. It marks the buffer as clean and not
1222 * uptodate, and it notifys the upper layer about the end
1225 static inline void buffer_IO_error(struct buffer_head * bh)
1227 mark_buffer_clean(bh);
1229 * b_end_io has to clear the BH_Uptodate bitflag in the error case!
1231 bh->b_end_io(bh, 0);
1234 static inline void mark_buffer_dirty_inode(struct buffer_head *bh, struct inode *inode)
1236 mark_buffer_dirty(bh);
1237 buffer_insert_inode_queue(bh, inode);
1240 extern void set_buffer_flushtime(struct buffer_head *);
1241 extern void balance_dirty(void);
1242 extern int check_disk_change(kdev_t);
1243 extern int invalidate_inodes(struct super_block *);
1244 extern int invalidate_device(kdev_t, int);
1245 extern void invalidate_inode_pages(struct inode *);
1246 extern void invalidate_inode_pages2(struct address_space *);
1247 extern void invalidate_inode_buffers(struct inode *);
1248 #define invalidate_buffers(dev) __invalidate_buffers((dev), 0)
1249 #define destroy_buffers(dev) __invalidate_buffers((dev), 1)
1250 extern void invalidate_bdev(struct block_device *, int);
1251 extern void __invalidate_buffers(kdev_t dev, int);
1252 extern void sync_inodes(kdev_t);
1253 extern void sync_unlocked_inodes(void);
1254 extern void write_inode_now(struct inode *, int);
1255 extern int sync_buffers(kdev_t, int);
1256 extern void sync_dev(kdev_t);
1257 extern int fsync_dev(kdev_t);
1258 extern int fsync_super(struct super_block *);
1259 extern int fsync_no_super(kdev_t);
1260 extern void sync_inodes_sb(struct super_block *);
1261 extern int fsync_buffers_list(struct list_head *);
1262 static inline int fsync_inode_buffers(struct inode *inode)
1264 return fsync_buffers_list(&inode->i_dirty_buffers);
1266 static inline int fsync_inode_data_buffers(struct inode *inode)
1268 return fsync_buffers_list(&inode->i_dirty_data_buffers);
1270 extern int inode_has_buffers(struct inode *);
1271 extern int filemap_fdatasync(struct address_space *);
1272 extern int filemap_fdatawait(struct address_space *);
1273 extern void sync_supers(kdev_t dev, int wait);
1274 extern int bmap(struct inode *, int);
1275 extern int notify_change(struct dentry *, struct iattr *);
1276 extern int permission(struct inode *, int);
1277 extern int vfs_permission(struct inode *, int);
1278 extern int get_write_access(struct inode *);
1279 extern int deny_write_access(struct file *);
1280 static inline void put_write_access(struct inode * inode)
1282 atomic_dec(&inode->i_writecount);
1284 static inline void allow_write_access(struct file *file)
1287 atomic_inc(&file->f_dentry->d_inode->i_writecount);
1289 extern int do_pipe(int *);
1291 extern int open_namei(const char *, int, int, struct nameidata *);
1293 extern int kernel_read(struct file *, unsigned long, char *, unsigned long);
1294 extern struct file * open_exec(const char *);
1296 /* fs/dcache.c -- generic fs support functions */
1297 extern int is_subdir(struct dentry *, struct dentry *);
1298 extern ino_t find_inode_number(struct dentry *, struct qstr *);
1301 * Kernel pointers have redundant information, so we can use a
1302 * scheme where we can return either an error code or a dentry
1303 * pointer with the same return value.
1305 * This should be a per-architecture thing, to allow different
1306 * error and pointer decisions.
1308 static inline void *ERR_PTR(long error)
1310 return (void *) error;
1313 static inline long PTR_ERR(const void *ptr)
1318 static inline long IS_ERR(const void *ptr)
1320 return (unsigned long)ptr > (unsigned long)-1000L;
1324 * The bitmask for a lookup event:
1325 * - follow links at the end
1326 * - require a directory
1327 * - ending slashes ok even for nonexistent files
1328 * - internal "there are more path compnents" flag
1330 #define LOOKUP_FOLLOW (1)
1331 #define LOOKUP_DIRECTORY (2)
1332 #define LOOKUP_CONTINUE (4)
1333 #define LOOKUP_POSITIVE (8)
1334 #define LOOKUP_PARENT (16)
1335 #define LOOKUP_NOALT (32)
1337 * Type of the last component on LOOKUP_PARENT
1339 enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT, LAST_BIND};
1342 * "descriptor" for what we're up to with a read for sendfile().
1343 * This allows us to use the same read code yet
1344 * have multiple different users of the data that
1345 * we read from a file.
1347 * The simplest case just copies the data to user
1355 } read_descriptor_t;
1357 typedef int (*read_actor_t)(read_descriptor_t *, struct page *, unsigned long, unsigned long);
1359 /* needed for stackable file system support */
1360 extern loff_t default_llseek(struct file *file, loff_t offset, int origin);
1362 extern int FASTCALL(__user_walk(const char *, unsigned, struct nameidata *));
1363 extern int FASTCALL(path_init(const char *, unsigned, struct nameidata *));
1364 extern int FASTCALL(path_walk(const char *, struct nameidata *));
1365 extern int FASTCALL(path_lookup(const char *, unsigned, struct nameidata *));
1366 extern int FASTCALL(link_path_walk(const char *, struct nameidata *));
1367 extern void path_release(struct nameidata *);
1368 extern int follow_down(struct vfsmount **, struct dentry **);
1369 extern int follow_up(struct vfsmount **, struct dentry **);
1370 extern struct dentry * lookup_one_len(const char *, struct dentry *, int);
1371 extern struct dentry * lookup_hash(struct qstr *, struct dentry *);
1372 #define user_path_walk(name,nd) __user_walk(name, LOOKUP_FOLLOW|LOOKUP_POSITIVE, nd)
1373 #define user_path_walk_link(name,nd) __user_walk(name, LOOKUP_POSITIVE, nd)
1375 extern void inode_init_once(struct inode *);
1376 extern void iput(struct inode *);
1377 extern void force_delete(struct inode *);
1378 extern struct inode * igrab(struct inode *);
1379 extern ino_t iunique(struct super_block *, ino_t);
1381 typedef int (*find_inode_t)(struct inode *, unsigned long, void *);
1382 extern struct inode * iget4(struct super_block *, unsigned long, find_inode_t, void *);
1383 static inline struct inode *iget(struct super_block *sb, unsigned long ino)
1385 return iget4(sb, ino, NULL, NULL);
1388 extern void clear_inode(struct inode *);
1389 extern struct inode *new_inode(struct super_block *sb);
1390 extern void remove_suid(struct inode *inode);
1392 extern void insert_inode_hash(struct inode *);
1393 extern void remove_inode_hash(struct inode *);
1394 extern struct file * get_empty_filp(void);
1395 extern void file_move(struct file *f, struct list_head *list);
1396 extern struct buffer_head * get_hash_table(kdev_t, int, int);
1397 extern struct buffer_head * getblk(kdev_t, int, int);
1398 extern void ll_rw_block(int, int, struct buffer_head * bh[]);
1399 extern void submit_bh(int, struct buffer_head *);
1400 extern int is_read_only(kdev_t);
1401 extern void __brelse(struct buffer_head *);
1402 static inline void brelse(struct buffer_head *buf)
1407 extern void __bforget(struct buffer_head *);
1408 static inline void bforget(struct buffer_head *buf)
1413 extern int set_blocksize(kdev_t, int);
1414 extern int sb_set_blocksize(struct super_block *, int);
1415 extern int sb_min_blocksize(struct super_block *, int);
1416 extern struct buffer_head * bread(kdev_t, int, int);
1417 static inline struct buffer_head * sb_bread(struct super_block *sb, int block)
1419 return bread(sb->s_dev, block, sb->s_blocksize);
1421 static inline struct buffer_head * sb_getblk(struct super_block *sb, int block)
1423 return getblk(sb->s_dev, block, sb->s_blocksize);
1425 static inline struct buffer_head * sb_get_hash_table(struct super_block *sb, int block)
1427 return get_hash_table(sb->s_dev, block, sb->s_blocksize);
1429 extern void wakeup_bdflush(void);
1430 extern void put_unused_buffer_head(struct buffer_head * bh);
1431 extern struct buffer_head * get_unused_buffer_head(int async);
1433 extern int brw_page(int, struct page *, kdev_t, int [], int);
1435 typedef int (get_block_t)(struct inode*,long,struct buffer_head*,int);
1437 /* Generic buffer handling for block filesystems.. */
1438 extern int try_to_release_page(struct page * page, int gfp_mask);
1439 extern int discard_bh_page(struct page *, unsigned long, int);
1440 #define block_flushpage(page, offset) discard_bh_page(page, offset, 1)
1441 #define block_invalidate_page(page) discard_bh_page(page, 0, 0)
1442 extern int block_symlink(struct inode *, const char *, int);
1443 extern int block_write_full_page(struct page*, get_block_t*);
1444 extern int block_read_full_page(struct page*, get_block_t*);
1445 extern int block_prepare_write(struct page*, unsigned, unsigned, get_block_t*);
1446 extern int cont_prepare_write(struct page*, unsigned, unsigned, get_block_t*,
1448 extern int generic_cont_expand(struct inode *inode, loff_t size) ;
1449 extern int block_commit_write(struct page *page, unsigned from, unsigned to);
1450 extern int block_sync_page(struct page *);
1452 int generic_block_bmap(struct address_space *, long, get_block_t *);
1453 int generic_commit_write(struct file *, struct page *, unsigned, unsigned);
1454 int block_truncate_page(struct address_space *, loff_t, get_block_t *);
1455 extern int generic_direct_IO(int, struct inode *, struct kiobuf *, unsigned long, int, get_block_t *);
1456 extern int waitfor_one_page(struct page *);
1457 extern int writeout_one_page(struct page *);
1459 extern int generic_file_mmap(struct file *, struct vm_area_struct *);
1460 extern int file_read_actor(read_descriptor_t * desc, struct page *page, unsigned long offset, unsigned long size);
1461 extern ssize_t generic_file_read(struct file *, char *, size_t, loff_t *);
1462 extern ssize_t generic_file_write(struct file *, const char *, size_t, loff_t *);
1463 extern void do_generic_file_read(struct file *, loff_t *, read_descriptor_t *, read_actor_t);
1464 extern loff_t no_llseek(struct file *file, loff_t offset, int origin);
1465 extern loff_t generic_file_llseek(struct file *file, loff_t offset, int origin);
1466 extern ssize_t generic_read_dir(struct file *, char *, size_t, loff_t *);
1467 extern int generic_file_open(struct inode * inode, struct file * filp);
1469 extern struct file_operations generic_ro_fops;
1471 extern int vfs_readlink(struct dentry *, char *, int, const char *);
1472 extern int vfs_follow_link(struct nameidata *, const char *);
1473 extern int page_readlink(struct dentry *, char *, int);
1474 extern int page_follow_link(struct dentry *, struct nameidata *);
1475 extern struct inode_operations page_symlink_inode_operations;
1477 extern int vfs_readdir(struct file *, filldir_t, void *);
1478 extern int dcache_dir_open(struct inode *, struct file *);
1479 extern int dcache_dir_close(struct inode *, struct file *);
1480 extern loff_t dcache_dir_lseek(struct file *, loff_t, int);
1481 extern int dcache_dir_fsync(struct file *, struct dentry *, int);
1482 extern int dcache_readdir(struct file *, void *, filldir_t);
1483 extern struct file_operations dcache_dir_ops;
1485 extern struct file_system_type *get_fs_type(const char *name);
1486 extern struct super_block *get_super(kdev_t);
1487 extern void drop_super(struct super_block *sb);
1488 static inline int is_mounted(kdev_t dev)
1490 struct super_block *sb = get_super(dev);
1497 unsigned long generate_cluster(kdev_t, int b[], int);
1498 unsigned long generate_cluster_swab32(kdev_t, int b[], int);
1499 extern kdev_t ROOT_DEV;
1500 extern char root_device_name[];
1503 extern void show_buffers(void);
1505 #ifdef CONFIG_BLK_DEV_INITRD
1506 extern unsigned int real_root_dev;
1509 extern ssize_t char_read(struct file *, char *, size_t, loff_t *);
1510 extern ssize_t block_read(struct file *, char *, size_t, loff_t *);
1511 extern int read_ahead[];
1513 extern ssize_t char_write(struct file *, const char *, size_t, loff_t *);
1514 extern ssize_t block_write(struct file *, const char *, size_t, loff_t *);
1516 extern int file_fsync(struct file *, struct dentry *, int);
1517 extern int generic_buffer_fdatasync(struct inode *inode, unsigned long start_idx, unsigned long end_idx);
1518 extern int generic_osync_inode(struct inode *, int);
1519 #define OSYNC_METADATA (1<<0)
1520 #define OSYNC_DATA (1<<1)
1521 #define OSYNC_INODE (1<<2)
1523 extern int inode_change_ok(struct inode *, struct iattr *);
1524 extern int inode_setattr(struct inode *, struct iattr *);
1527 * Common dentry functions for inclusion in the VFS
1528 * or in other stackable file systems. Some of these
1529 * functions were in linux/fs/ C (VFS) files.
1534 * Locking the parent is needed to:
1535 * - serialize directory operations
1536 * - make sure the parent doesn't change from
1537 * under us in the middle of an operation.
1539 * NOTE! Right now we'd rather use a "struct inode"
1540 * for this, but as I expect things to move toward
1541 * using dentries instead for most things it is
1542 * probably better to start with the conceptually
1543 * better interface of relying on a path of dentries.
1545 static inline struct dentry *lock_parent(struct dentry *dentry)
1547 struct dentry *dir = dget(dentry->d_parent);
1549 down(&dir->d_inode->i_sem);
1553 static inline struct dentry *get_parent(struct dentry *dentry)
1555 return dget(dentry->d_parent);
1558 static inline void unlock_dir(struct dentry *dir)
1560 up(&dir->d_inode->i_sem);
1565 * Whee.. Deadlock country. Happily there are only two VFS
1566 * operations that does this..
1568 static inline void double_down(struct semaphore *s1, struct semaphore *s2)
1571 if ((unsigned long) s1 < (unsigned long) s2) {
1572 struct semaphore *tmp = s2;
1581 * Ewwwwwwww... _triple_ lock. We are guaranteed that the 3rd argument is
1582 * not equal to 1st and not equal to 2nd - the first case (target is parent of
1583 * source) would be already caught, the second is plain impossible (target is
1584 * its own parent and that case would be caught even earlier). Very messy.
1585 * I _think_ that it works, but no warranties - please, look it through.
1586 * Pox on bloody lusers who mandated overwriting rename() for directories...
1589 static inline void triple_down(struct semaphore *s1,
1590 struct semaphore *s2,
1591 struct semaphore *s3)
1594 if ((unsigned long) s1 < (unsigned long) s2) {
1595 if ((unsigned long) s1 < (unsigned long) s3) {
1596 struct semaphore *tmp = s3;
1599 if ((unsigned long) s1 < (unsigned long) s2) {
1600 struct semaphore *tmp = s2;
1604 if ((unsigned long) s1 < (unsigned long) s3) {
1605 struct semaphore *tmp = s3;
1608 if ((unsigned long) s2 < (unsigned long) s3) {
1609 struct semaphore *tmp = s3;
1614 } else if ((unsigned long) s2 < (unsigned long) s3) {
1615 struct semaphore *tmp = s3;
1622 static inline void double_up(struct semaphore *s1, struct semaphore *s2)
1629 static inline void triple_up(struct semaphore *s1,
1630 struct semaphore *s2,
1631 struct semaphore *s3)
1639 static inline void double_lock(struct dentry *d1, struct dentry *d2)
1641 double_down(&d1->d_inode->i_sem, &d2->d_inode->i_sem);
1644 static inline void double_unlock(struct dentry *d1, struct dentry *d2)
1646 double_up(&d1->d_inode->i_sem,&d2->d_inode->i_sem);
1651 #endif /* __KERNEL__ */
1653 #endif /* _LINUX_FS_H */