Import 2.3.99pre9-1
[davej-history.git] / include / linux / fs.h
blob4eb593aba061342ee6f71c669119d0e3ca3884de
1 #ifndef _LINUX_FS_H
2 #define _LINUX_FS_H
4 /*
5 * This file has definitions for some important file table
6 * structures etc.
7 */
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: */
42 #undef NR_OPEN
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 extern int max_files, nr_files, nr_free_files;
51 extern int max_super_blocks, nr_super_blocks;
53 #define NR_FILE 8192 /* this can well be larger on a larger system */
54 #define NR_RESERVED_FILES 10 /* reserved for root */
55 #define NR_SUPER 256
57 #define MAY_EXEC 1
58 #define MAY_WRITE 2
59 #define MAY_READ 4
61 #define FMODE_READ 1
62 #define FMODE_WRITE 2
64 #define READ 0
65 #define WRITE 1
66 #define READA 2 /* read-ahead - don't block if no resources */
67 #define SPECIAL 4 /* For non-blockdevice requests in request queue */
69 #define WRITERAW 5 /* raw write - don't play with buffer lists */
71 #define NIL_FILP ((struct file *)0)
72 #define SEL_IN 1
73 #define SEL_OUT 2
74 #define SEL_EX 4
76 /* public flags for file_system_type */
77 #define FS_REQUIRES_DEV 1
78 #define FS_NO_DCACHE 2 /* Only dcache the necessary things. */
79 #define FS_NO_PRELIM 4 /* prevent preloading of dentries, even if
80 * FS_NO_DCACHE is not set.
82 #define FS_SINGLE 8 /*
83 * Filesystem that can have only one superblock;
84 * kernel-wide vfsmnt is kept in ->kern_mnt.
86 #define FS_NOMOUNT 16 /* Never mount from userland */
88 * These are the fs-independent mount-flags: up to 16 flags are supported
90 #define MS_RDONLY 1 /* Mount read-only */
91 #define MS_NOSUID 2 /* Ignore suid and sgid bits */
92 #define MS_NODEV 4 /* Disallow access to device special files */
93 #define MS_NOEXEC 8 /* Disallow program execution */
94 #define MS_SYNCHRONOUS 16 /* Writes are synced at once */
95 #define MS_REMOUNT 32 /* Alter flags of a mounted FS */
96 #define MS_MANDLOCK 64 /* Allow mandatory locks on an FS */
97 #define S_QUOTA 128 /* Quota initialized for file/directory/symlink */
98 #define S_APPEND 256 /* Append-only file */
99 #define S_IMMUTABLE 512 /* Immutable file */
100 #define MS_NOATIME 1024 /* Do not update access times. */
101 #define MS_NODIRATIME 2048 /* Do not update directory access times */
103 #define MS_ODD_RENAME 32768 /* Temporary stuff; will go away as soon
104 * as nfs_rename() will be cleaned up
106 #define S_DEAD (1<<16) /* removed, but still open directory */
109 * Flags that can be altered by MS_REMOUNT
111 #define MS_RMT_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|\
112 MS_SYNCHRONOUS|MS_MANDLOCK|MS_NOATIME|MS_NODIRATIME)
115 * Magic mount flag number. Has to be or-ed to the flag values.
117 #define MS_MGC_VAL 0xC0ED0000 /* magic flag number to indicate "new" flags */
118 #define MS_MGC_MSK 0xffff0000 /* magic flag number mask */
121 * Note that nosuid etc flags are inode-specific: setting some file-system
122 * flags just means all the inodes inherit those flags by default. It might be
123 * possible to override it selectively if you really wanted to with some
124 * ioctl() that is not currently implemented.
126 * Exception: MS_RDONLY is always applied to the entire file system.
128 * Unfortunately, it is possible to change a filesystems flags with it mounted
129 * with files in use. This means that all of the inodes will not have their
130 * i_flags updated. Hence, i_flags no longer inherit the superblock mount
131 * flags, so these have to be checked separately. -- rmk@arm.uk.linux.org
133 #define __IS_FLG(inode,flg) (((inode)->i_sb && (inode)->i_sb->s_flags & (flg)) \
134 || (inode)->i_flags & (flg))
136 #define IS_RDONLY(inode) (((inode)->i_sb) && ((inode)->i_sb->s_flags & MS_RDONLY))
137 #define IS_NOSUID(inode) __IS_FLG(inode, MS_NOSUID)
138 #define IS_NODEV(inode) __IS_FLG(inode, MS_NODEV)
139 #define IS_NOEXEC(inode) __IS_FLG(inode, MS_NOEXEC)
140 #define IS_SYNC(inode) __IS_FLG(inode, MS_SYNCHRONOUS)
141 #define IS_MANDLOCK(inode) __IS_FLG(inode, MS_MANDLOCK)
143 #define IS_QUOTAINIT(inode) ((inode)->i_flags & S_QUOTA)
144 #define IS_APPEND(inode) ((inode)->i_flags & S_APPEND)
145 #define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE)
146 #define IS_NOATIME(inode) __IS_FLG(inode, MS_NOATIME)
147 #define IS_NODIRATIME(inode) __IS_FLG(inode, MS_NODIRATIME)
149 #define IS_DEADDIR(inode) ((inode)->i_flags & S_DEAD)
151 /* the read-only stuff doesn't really belong here, but any other place is
152 probably as bad and I don't want to create yet another include file. */
154 #define BLKROSET _IO(0x12,93) /* set device read-only (0 = read-write) */
155 #define BLKROGET _IO(0x12,94) /* get read-only status (0 = read_write) */
156 #define BLKRRPART _IO(0x12,95) /* re-read partition table */
157 #define BLKGETSIZE _IO(0x12,96) /* return device size */
158 #define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */
159 #define BLKRASET _IO(0x12,98) /* Set read ahead for block device */
160 #define BLKRAGET _IO(0x12,99) /* get current read ahead setting */
161 #define BLKFRASET _IO(0x12,100)/* set filesystem (mm/filemap.c) read-ahead */
162 #define BLKFRAGET _IO(0x12,101)/* get filesystem (mm/filemap.c) read-ahead */
163 #define BLKSECTSET _IO(0x12,102)/* set max sectors per request (ll_rw_blk.c) */
164 #define BLKSECTGET _IO(0x12,103)/* get max sectors per request (ll_rw_blk.c) */
165 #define BLKSSZGET _IO(0x12,104)/* get block device sector size */
166 #if 0
167 #define BLKPG _IO(0x12,105)/* See blkpg.h */
168 #define BLKELVGET _IO(0x12,106)/* elevator get */
169 #define BLKELVSET _IO(0x12,107)/* elevator set */
170 /* This was here just to show that the number is taken -
171 probably all these _IO(0x12,*) ioctls should be moved to blkpg.h. */
172 #endif
175 #define BMAP_IOCTL 1 /* obsolete - kept for compatibility */
176 #define FIBMAP _IO(0x00,1) /* bmap access */
177 #define FIGETBSZ _IO(0x00,2) /* get the block size used for bmap */
179 #ifdef __KERNEL__
181 #include <asm/semaphore.h>
182 #include <asm/byteorder.h>
184 extern void update_atime (struct inode *);
185 #define UPDATE_ATIME(inode) update_atime (inode)
187 extern void buffer_init(unsigned long);
188 extern void inode_init(unsigned long);
189 extern void file_table_init(void);
190 extern void dcache_init(unsigned long);
192 /* bh state bits */
193 #define BH_Uptodate 0 /* 1 if the buffer contains valid data */
194 #define BH_Dirty 1 /* 1 if the buffer is dirty */
195 #define BH_Lock 2 /* 1 if the buffer is locked */
196 #define BH_Req 3 /* 0 if the buffer has been invalidated */
197 #define BH_Mapped 4 /* 1 if the buffer has a disk mapping */
198 #define BH_New 5 /* 1 if the buffer is new and not yet written out */
199 #define BH_Protected 6 /* 1 if the buffer is protected */
202 * Try to keep the most commonly used fields in single cache lines (16
203 * bytes) to improve performance. This ordering should be
204 * particularly beneficial on 32-bit processors.
206 * We use the first 16 bytes for the data which is used in searches
207 * over the block hash lists (ie. getblk() and friends).
209 * The second 16 bytes we use for lru buffer scans, as used by
210 * sync_buffers() and refill_freelist(). -- sct
212 struct buffer_head {
213 /* First cache line: */
214 struct buffer_head *b_next; /* Hash queue list */
215 unsigned long b_blocknr; /* block number */
216 unsigned short b_size; /* block size */
217 unsigned short b_list; /* List that this buffer appears */
218 kdev_t b_dev; /* device (B_FREE = free) */
220 atomic_t b_count; /* users using this block */
221 kdev_t b_rdev; /* Real device */
222 unsigned long b_state; /* buffer state bitmap (see above) */
223 unsigned long b_flushtime; /* Time when (dirty) buffer should be written */
225 struct buffer_head *b_next_free;/* lru/free list linkage */
226 struct buffer_head *b_prev_free;/* doubly linked list of buffers */
227 struct buffer_head *b_this_page;/* circular list of buffers in one page */
228 struct buffer_head *b_reqnext; /* request queue */
230 struct buffer_head **b_pprev; /* doubly linked list of hash-queue */
231 char * b_data; /* pointer to data block (512 byte) */
232 struct page *b_page; /* the page this bh is mapped to */
233 void (*b_end_io)(struct buffer_head *bh, int uptodate); /* I/O completion */
234 void *b_dev_id;
236 unsigned long b_rsector; /* Real buffer location on disk */
237 wait_queue_head_t b_wait;
238 struct kiobuf * b_kiobuf; /* kiobuf which owns this IO */
241 typedef void (bh_end_io_t)(struct buffer_head *bh, int uptodate);
242 void init_buffer(struct buffer_head *, bh_end_io_t *, void *);
244 #define __buffer_state(bh, state) (((bh)->b_state & (1UL << BH_##state)) != 0)
246 #define buffer_uptodate(bh) __buffer_state(bh,Uptodate)
247 #define buffer_dirty(bh) __buffer_state(bh,Dirty)
248 #define buffer_locked(bh) __buffer_state(bh,Lock)
249 #define buffer_req(bh) __buffer_state(bh,Req)
250 #define buffer_mapped(bh) __buffer_state(bh,Mapped)
251 #define buffer_new(bh) __buffer_state(bh,New)
252 #define buffer_protected(bh) __buffer_state(bh,Protected)
254 #define bh_offset(bh) ((unsigned long)(bh)->b_data & ~PAGE_MASK)
256 extern void set_bh_page(struct buffer_head *bh, struct page *page, unsigned long offset);
258 #define touch_buffer(bh) SetPageReferenced(bh->b_page)
261 #include <linux/pipe_fs_i.h>
262 #include <linux/minix_fs_i.h>
263 #include <linux/ext2_fs_i.h>
264 #include <linux/hpfs_fs_i.h>
265 #include <linux/ntfs_fs_i.h>
266 #include <linux/msdos_fs_i.h>
267 #include <linux/umsdos_fs_i.h>
268 #include <linux/iso_fs_i.h>
269 #include <linux/nfs_fs_i.h>
270 #include <linux/sysv_fs_i.h>
271 #include <linux/affs_fs_i.h>
272 #include <linux/ufs_fs_i.h>
273 #include <linux/efs_fs_i.h>
274 #include <linux/coda_fs_i.h>
275 #include <linux/romfs_fs_i.h>
276 #include <linux/smb_fs_i.h>
277 #include <linux/hfs_fs_i.h>
278 #include <linux/adfs_fs_i.h>
279 #include <linux/qnx4_fs_i.h>
280 #include <linux/bfs_fs_i.h>
281 #include <linux/udf_fs_i.h>
282 #include <linux/ncp_fs_i.h>
283 #include <linux/proc_fs_i.h>
284 #include <linux/usbdev_fs_i.h>
287 * Attribute flags. These should be or-ed together to figure out what
288 * has been changed!
290 #define ATTR_MODE 1
291 #define ATTR_UID 2
292 #define ATTR_GID 4
293 #define ATTR_SIZE 8
294 #define ATTR_ATIME 16
295 #define ATTR_MTIME 32
296 #define ATTR_CTIME 64
297 #define ATTR_ATIME_SET 128
298 #define ATTR_MTIME_SET 256
299 #define ATTR_FORCE 512 /* Not a change, but a change it */
300 #define ATTR_ATTR_FLAG 1024
303 * This is the Inode Attributes structure, used for notify_change(). It
304 * uses the above definitions as flags, to know which values have changed.
305 * Also, in this manner, a Filesystem can look at only the values it cares
306 * about. Basically, these are the attributes that the VFS layer can
307 * request to change from the FS layer.
309 * Derek Atkins <warlord@MIT.EDU> 94-10-20
311 struct iattr {
312 unsigned int ia_valid;
313 umode_t ia_mode;
314 uid_t ia_uid;
315 gid_t ia_gid;
316 loff_t ia_size;
317 time_t ia_atime;
318 time_t ia_mtime;
319 time_t ia_ctime;
320 unsigned int ia_attr_flags;
324 * This is the inode attributes flag definitions
326 #define ATTR_FLAG_SYNCRONOUS 1 /* Syncronous write */
327 #define ATTR_FLAG_NOATIME 2 /* Don't update atime */
328 #define ATTR_FLAG_APPEND 4 /* Append-only file */
329 #define ATTR_FLAG_IMMUTABLE 8 /* Immutable file */
330 #define ATTR_FLAG_NODIRATIME 16 /* Don't update atime for directory */
333 * Includes for diskquotas and mount structures.
335 #include <linux/quota.h>
336 #include <linux/mount.h>
339 * oh the beauties of C type declarations.
341 struct page;
342 struct address_space;
344 struct address_space_operations {
345 int (*writepage)(struct file *, struct page *);
346 int (*readpage)(struct file *, struct page *);
347 int (*sync_page)(struct page *);
348 int (*prepare_write)(struct file *, struct page *, unsigned, unsigned);
349 int (*commit_write)(struct file *, struct page *, unsigned, unsigned);
350 /* Unfortunately this kludge is needed for FIBMAP. Don't use it */
351 int (*bmap)(struct address_space *, long);
354 struct address_space {
355 struct list_head pages; /* list of pages */
356 unsigned long nrpages; /* number of pages */
357 struct address_space_operations *a_ops; /* methods */
358 void *host; /* owner: inode, block_device */
359 struct vm_area_struct *i_mmap; /* list of mappings */
360 spinlock_t i_shared_lock; /* and spinlock protecting it */
363 struct block_device {
364 struct list_head bd_hash;
365 atomic_t bd_count;
366 /* struct address_space bd_data; */
367 dev_t bd_dev; /* not a kdev_t - it's a search key */
368 atomic_t bd_openers;
369 const struct block_device_operations *bd_op;
370 struct semaphore bd_sem; /* open/close mutex */
373 struct inode {
374 struct list_head i_hash;
375 struct list_head i_list;
376 struct list_head i_dentry;
378 unsigned long i_ino;
379 unsigned int i_count;
380 kdev_t i_dev;
381 umode_t i_mode;
382 nlink_t i_nlink;
383 uid_t i_uid;
384 gid_t i_gid;
385 kdev_t i_rdev;
386 loff_t i_size;
387 time_t i_atime;
388 time_t i_mtime;
389 time_t i_ctime;
390 unsigned long i_blksize;
391 unsigned long i_blocks;
392 unsigned long i_version;
393 struct semaphore i_sem;
394 struct semaphore i_zombie;
395 struct inode_operations *i_op;
396 struct file_operations *i_fop; /* former ->i_op->default_file_ops */
397 struct super_block *i_sb;
398 wait_queue_head_t i_wait;
399 struct file_lock *i_flock;
400 struct address_space *i_mapping;
401 struct address_space i_data;
402 struct dquot *i_dquot[MAXQUOTAS];
403 struct pipe_inode_info *i_pipe;
404 struct block_device *i_bdev;
406 unsigned long i_state;
408 unsigned int i_flags;
409 unsigned char i_sock;
411 atomic_t i_writecount;
412 unsigned int i_attr_flags;
413 __u32 i_generation;
414 union {
415 struct minix_inode_info minix_i;
416 struct ext2_inode_info ext2_i;
417 struct hpfs_inode_info hpfs_i;
418 struct ntfs_inode_info ntfs_i;
419 struct msdos_inode_info msdos_i;
420 struct umsdos_inode_info umsdos_i;
421 struct iso_inode_info isofs_i;
422 struct nfs_inode_info nfs_i;
423 struct sysv_inode_info sysv_i;
424 struct affs_inode_info affs_i;
425 struct ufs_inode_info ufs_i;
426 struct efs_inode_info efs_i;
427 struct romfs_inode_info romfs_i;
428 struct coda_inode_info coda_i;
429 struct smb_inode_info smbfs_i;
430 struct hfs_inode_info hfs_i;
431 struct adfs_inode_info adfs_i;
432 struct qnx4_inode_info qnx4_i;
433 struct bfs_inode_info bfs_i;
434 struct udf_inode_info udf_i;
435 struct ncp_inode_info ncpfs_i;
436 struct proc_inode_info proc_i;
437 struct socket socket_i;
438 struct usbdev_inode_info usbdev_i;
439 void *generic_ip;
440 } u;
443 /* Inode state bits.. */
444 #define I_DIRTY 1
445 #define I_LOCK 2
446 #define I_FREEING 4
447 #define I_CLEAR 8
449 extern void __mark_inode_dirty(struct inode *);
450 static inline void mark_inode_dirty(struct inode *inode)
452 if (!(inode->i_state & I_DIRTY))
453 __mark_inode_dirty(inode);
456 struct fown_struct {
457 int pid; /* pid or -pgrp where SIGIO should be sent */
458 uid_t uid, euid; /* uid/euid of process setting the owner */
459 int signum; /* posix.1b rt signal to be delivered on IO */
462 struct file {
463 struct list_head f_list;
464 struct dentry *f_dentry;
465 struct vfsmount *f_vfsmnt;
466 struct file_operations *f_op;
467 atomic_t f_count;
468 unsigned int f_flags;
469 mode_t f_mode;
470 loff_t f_pos;
471 unsigned long f_reada, f_ramax, f_raend, f_ralen, f_rawin;
472 struct fown_struct f_owner;
473 unsigned int f_uid, f_gid;
474 int f_error;
476 unsigned long f_version;
478 /* needed for tty driver, and maybe others */
479 void *private_data;
481 extern spinlock_t files_lock;
482 #define file_list_lock() spin_lock(&files_lock);
483 #define file_list_unlock() spin_unlock(&files_lock);
485 #define get_file(x) atomic_inc(&(x)->f_count)
486 #define file_count(x) atomic_read(&(x)->f_count)
488 extern int init_private_file(struct file *, struct dentry *, int);
490 #define FL_POSIX 1
491 #define FL_FLOCK 2
492 #define FL_BROKEN 4 /* broken flock() emulation */
493 #define FL_ACCESS 8 /* for processes suspended by mandatory locking */
494 #define FL_LOCKD 16 /* lock held by rpc.lockd */
497 * The POSIX file lock owner is determined by
498 * the "struct files_struct" in the thread group
499 * (or NULL for no owner - BSD locks).
501 * Lockd stuffs a "host" pointer into this.
503 typedef struct files_struct *fl_owner_t;
505 struct file_lock {
506 struct file_lock *fl_next; /* singly linked list for this inode */
507 struct file_lock *fl_nextlink; /* doubly linked list of all locks */
508 struct file_lock *fl_prevlink; /* used to simplify lock removal */
509 struct file_lock *fl_nextblock; /* circular list of blocked processes */
510 struct file_lock *fl_prevblock;
511 fl_owner_t fl_owner;
512 unsigned int fl_pid;
513 wait_queue_head_t fl_wait;
514 struct file *fl_file;
515 unsigned char fl_flags;
516 unsigned char fl_type;
517 loff_t fl_start;
518 loff_t fl_end;
520 void (*fl_notify)(struct file_lock *); /* unblock callback */
521 void (*fl_insert)(struct file_lock *); /* lock insertion callback */
522 void (*fl_remove)(struct file_lock *); /* lock removal callback */
524 union {
525 struct nfs_lock_info nfs_fl;
526 } fl_u;
529 /* The following constant reflects the upper bound of the file/locking space */
530 #ifndef OFFSET_MAX
531 #define INT_LIMIT(x) (~((x)1 << (sizeof(x)*8 - 1)))
532 #define OFFSET_MAX INT_LIMIT(loff_t)
533 #endif
535 extern struct file_lock *file_lock_table;
537 #include <linux/fcntl.h>
539 extern int fcntl_getlk(unsigned int, struct flock *);
540 extern int fcntl_setlk(unsigned int, unsigned int, struct flock *);
542 /* fs/locks.c */
543 extern void locks_remove_posix(struct file *, fl_owner_t);
544 extern void locks_remove_flock(struct file *);
545 extern struct file_lock *posix_test_lock(struct file *, struct file_lock *);
546 extern int posix_lock_file(struct file *, struct file_lock *, unsigned int);
547 extern void posix_block_lock(struct file_lock *, struct file_lock *);
548 extern void posix_unblock_lock(struct file_lock *);
550 struct fasync_struct {
551 int magic;
552 int fa_fd;
553 struct fasync_struct *fa_next; /* singly linked list */
554 struct file *fa_file;
557 struct nameidata {
558 struct dentry *dentry;
559 struct vfsmount *mnt;
560 struct qstr last;
561 unsigned int flags;
562 int last_type;
565 #define FASYNC_MAGIC 0x4601
567 extern int fasync_helper(int, struct file *, int, struct fasync_struct **);
569 #define DQUOT_USR_ENABLED 0x01 /* User diskquotas enabled */
570 #define DQUOT_GRP_ENABLED 0x02 /* Group diskquotas enabled */
572 struct quota_mount_options
574 unsigned int flags; /* Flags for diskquotas on this device */
575 struct semaphore dqio_sem; /* lock device while I/O in progress */
576 struct semaphore dqoff_sem; /* serialize quota_off() and quota_on() on device */
577 struct file *files[MAXQUOTAS]; /* fp's to quotafiles */
578 time_t inode_expire[MAXQUOTAS]; /* expiretime for inode-quota */
579 time_t block_expire[MAXQUOTAS]; /* expiretime for block-quota */
580 char rsquash[MAXQUOTAS]; /* for quotas threat root as any other user */
584 * Umount options
587 #define MNT_FORCE 0x00000001 /* Attempt to forcibily umount */
589 #include <linux/minix_fs_sb.h>
590 #include <linux/ext2_fs_sb.h>
591 #include <linux/hpfs_fs_sb.h>
592 #include <linux/ntfs_fs_sb.h>
593 #include <linux/msdos_fs_sb.h>
594 #include <linux/iso_fs_sb.h>
595 #include <linux/nfs_fs_sb.h>
596 #include <linux/sysv_fs_sb.h>
597 #include <linux/affs_fs_sb.h>
598 #include <linux/ufs_fs_sb.h>
599 #include <linux/efs_fs_sb.h>
600 #include <linux/romfs_fs_sb.h>
601 #include <linux/smb_fs_sb.h>
602 #include <linux/hfs_fs_sb.h>
603 #include <linux/adfs_fs_sb.h>
604 #include <linux/qnx4_fs_sb.h>
605 #include <linux/bfs_fs_sb.h>
606 #include <linux/udf_fs_sb.h>
607 #include <linux/ncp_fs_sb.h>
608 #include <linux/usbdev_fs_sb.h>
610 extern struct list_head super_blocks;
612 #define sb_entry(list) list_entry((list), struct super_block, s_list)
613 struct super_block {
614 struct list_head s_list; /* Keep this first */
615 kdev_t s_dev;
616 unsigned long s_blocksize;
617 unsigned char s_blocksize_bits;
618 unsigned char s_lock;
619 unsigned char s_dirt;
620 struct file_system_type *s_type;
621 struct super_operations *s_op;
622 struct dquot_operations *dq_op;
623 unsigned long s_flags;
624 unsigned long s_magic;
625 struct dentry *s_root;
626 wait_queue_head_t s_wait;
628 struct list_head s_dirty; /* dirty inodes */
629 struct list_head s_files;
631 struct block_device *s_bdev;
632 struct list_head s_mounts; /* vfsmount(s) of this one */
633 struct quota_mount_options s_dquot; /* Diskquota specific options */
635 union {
636 struct minix_sb_info minix_sb;
637 struct ext2_sb_info ext2_sb;
638 struct hpfs_sb_info hpfs_sb;
639 struct ntfs_sb_info ntfs_sb;
640 struct msdos_sb_info msdos_sb;
641 struct isofs_sb_info isofs_sb;
642 struct nfs_sb_info nfs_sb;
643 struct sysv_sb_info sysv_sb;
644 struct affs_sb_info affs_sb;
645 struct ufs_sb_info ufs_sb;
646 struct efs_sb_info efs_sb;
647 struct romfs_sb_info romfs_sb;
648 struct smb_sb_info smbfs_sb;
649 struct hfs_sb_info hfs_sb;
650 struct adfs_sb_info adfs_sb;
651 struct qnx4_sb_info qnx4_sb;
652 struct bfs_sb_info bfs_sb;
653 struct udf_sb_info udf_sb;
654 struct ncp_sb_info ncpfs_sb;
655 struct usbdev_sb_info usbdevfs_sb;
656 void *generic_sbp;
657 } u;
659 * The next field is for VFS *only*. No filesystems have any business
660 * even looking at it. You had been warned.
662 struct semaphore s_vfs_rename_sem; /* Kludge */
664 /* The next field is used by knfsd when converting a (inode number based)
665 * file handle into a dentry. As it builds a path in the dcache tree from
666 * the bottom up, there may for a time be a subpath of dentrys which is not
667 * connected to the main tree. This semaphore ensure that there is only ever
668 * one such free path per filesystem. Note that unconnected files (or other
669 * non-directories) are allowed, but not unconnected diretories.
671 struct semaphore s_nfsd_free_path_sem;
675 * VFS helper functions..
677 extern int vfs_create(struct inode *, struct dentry *, int);
678 extern int vfs_mkdir(struct inode *, struct dentry *, int);
679 extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t);
680 extern int vfs_symlink(struct inode *, struct dentry *, const char *);
681 extern int vfs_link(struct dentry *, struct inode *, struct dentry *);
682 extern int vfs_rmdir(struct inode *, struct dentry *);
683 extern int vfs_unlink(struct inode *, struct dentry *);
684 extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
687 * This is the "filldir" function type, used by readdir() to let
688 * the kernel specify what kind of dirent layout it wants to have.
689 * This allows the kernel to read directories into kernel space or
690 * to have different dirent layouts depending on the binary type.
692 typedef int (*filldir_t)(void *, const char *, int, off_t, ino_t);
694 struct block_device_operations {
695 int (*open) (struct inode *, struct file *);
696 int (*release) (struct inode *, struct file *);
697 int (*ioctl) (struct inode *, struct file *, unsigned, unsigned long);
698 int (*check_media_change) (kdev_t);
699 int (*revalidate) (kdev_t);
703 * NOTE:
704 * read, write, poll, fsync, readv, writev can be called
705 * without the big kernel lock held in all filesystems.
707 struct file_operations {
708 loff_t (*llseek) (struct file *, loff_t, int);
709 ssize_t (*read) (struct file *, char *, size_t, loff_t *);
710 ssize_t (*write) (struct file *, const char *, size_t, loff_t *);
711 int (*readdir) (struct file *, void *, filldir_t);
712 unsigned int (*poll) (struct file *, struct poll_table_struct *);
713 int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);
714 int (*mmap) (struct file *, struct vm_area_struct *);
715 int (*open) (struct inode *, struct file *);
716 int (*flush) (struct file *);
717 int (*release) (struct inode *, struct file *);
718 int (*fsync) (struct file *, struct dentry *);
719 int (*fasync) (int, struct file *, int);
720 int (*lock) (struct file *, int, struct file_lock *);
721 ssize_t (*readv) (struct file *, const struct iovec *, unsigned long, loff_t *);
722 ssize_t (*writev) (struct file *, const struct iovec *, unsigned long, loff_t *);
725 struct inode_operations {
726 int (*create) (struct inode *,struct dentry *,int);
727 struct dentry * (*lookup) (struct inode *,struct dentry *);
728 int (*link) (struct dentry *,struct inode *,struct dentry *);
729 int (*unlink) (struct inode *,struct dentry *);
730 int (*symlink) (struct inode *,struct dentry *,const char *);
731 int (*mkdir) (struct inode *,struct dentry *,int);
732 int (*rmdir) (struct inode *,struct dentry *);
733 int (*mknod) (struct inode *,struct dentry *,int,int);
734 int (*rename) (struct inode *, struct dentry *,
735 struct inode *, struct dentry *);
736 int (*readlink) (struct dentry *, char *,int);
737 int (*follow_link) (struct dentry *, struct nameidata *);
738 void (*truncate) (struct inode *);
739 int (*permission) (struct inode *, int);
740 int (*revalidate) (struct dentry *);
741 int (*setattr) (struct dentry *, struct iattr *);
742 int (*getattr) (struct dentry *, struct iattr *);
746 * NOTE: write_inode, delete_inode, clear_inode, put_inode can be called
747 * without the big kernel lock held in all filesystems.
749 struct super_operations {
750 void (*read_inode) (struct inode *);
751 void (*write_inode) (struct inode *);
752 void (*put_inode) (struct inode *);
753 void (*delete_inode) (struct inode *);
754 void (*put_super) (struct super_block *);
755 void (*write_super) (struct super_block *);
756 int (*statfs) (struct super_block *, struct statfs *);
757 int (*remount_fs) (struct super_block *, int *, char *);
758 void (*clear_inode) (struct inode *);
759 void (*umount_begin) (struct super_block *);
762 struct dquot_operations {
763 void (*initialize) (struct inode *, short);
764 void (*drop) (struct inode *);
765 int (*alloc_block) (const struct inode *, unsigned long, char);
766 int (*alloc_inode) (const struct inode *, unsigned long);
767 void (*free_block) (const struct inode *, unsigned long);
768 void (*free_inode) (const struct inode *, unsigned long);
769 int (*transfer) (struct dentry *, struct iattr *);
772 struct file_system_type {
773 const char *name;
774 int fs_flags;
775 struct super_block *(*read_super) (struct super_block *, void *, int);
776 struct module *owner;
777 struct vfsmount *kern_mnt; /* For kernel mount, if it's FS_SINGLE fs */
778 struct file_system_type * next;
781 #define DECLARE_FSTYPE(var,type,read,flags) \
782 struct file_system_type var = { \
783 name: type, \
784 read_super: read, \
785 fs_flags: flags, \
786 owner: THIS_MODULE, \
789 #define DECLARE_FSTYPE_DEV(var,type,read) \
790 DECLARE_FSTYPE(var,type,read,FS_REQUIRES_DEV)
792 extern int register_filesystem(struct file_system_type *);
793 extern int unregister_filesystem(struct file_system_type *);
794 extern struct vfsmount *kern_mount(struct file_system_type *);
795 extern void kern_umount(struct vfsmount *);
796 extern int may_umount(struct vfsmount *);
798 extern int vfs_statfs(struct super_block *, struct statfs *);
800 /* Return value for VFS lock functions - tells locks.c to lock conventionally
801 * REALLY kosha for root NFS and nfs_lock
803 #define LOCK_USE_CLNT 1
805 #define FLOCK_VERIFY_READ 1
806 #define FLOCK_VERIFY_WRITE 2
808 extern int locks_mandatory_locked(struct inode *);
809 extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
812 * Candidates for mandatory locking have the setgid bit set
813 * but no group execute bit - an otherwise meaningless combination.
815 #define MANDATORY_LOCK(inode) \
816 (IS_MANDLOCK(inode) && ((inode)->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID)
818 static inline int locks_verify_locked(struct inode *inode)
820 if (MANDATORY_LOCK(inode))
821 return locks_mandatory_locked(inode);
822 return 0;
825 static inline int locks_verify_area(int read_write, struct inode *inode,
826 struct file *filp, loff_t offset,
827 size_t count)
829 if (inode->i_flock && MANDATORY_LOCK(inode))
830 return locks_mandatory_area(read_write, inode, filp, offset, count);
831 return 0;
834 static inline int locks_verify_truncate(struct inode *inode,
835 struct file *filp,
836 loff_t size)
838 if (inode->i_flock && MANDATORY_LOCK(inode))
839 return locks_mandatory_area(
840 FLOCK_VERIFY_WRITE, inode, filp,
841 size < inode->i_size ? size : inode->i_size,
842 abs(inode->i_size - size)
844 return 0;
848 /* fs/open.c */
850 asmlinkage long sys_open(const char *, int, int);
851 asmlinkage long sys_close(unsigned int); /* yes, it's really unsigned */
852 extern int do_close(unsigned int, int); /* yes, it's really unsigned */
853 extern int do_truncate(struct dentry *, loff_t start);
854 extern int get_unused_fd(void);
855 extern void __put_unused_fd(struct files_struct *, unsigned int); /* locked outside */
856 extern void put_unused_fd(unsigned int); /* locked inside */
858 extern struct file *filp_open(const char *, int, int);
859 extern struct file * dentry_open(struct dentry *, struct vfsmount *, int);
860 extern int filp_close(struct file *, fl_owner_t id);
861 extern char * getname(const char *);
862 #define __getname() ((char *) __get_free_page(GFP_KERNEL))
863 #define putname(name) free_page((unsigned long)(name))
865 enum {BDEV_FILE, BDEV_SWAP, BDEV_FS, BDEV_RAW};
866 extern void kill_fasync(struct fasync_struct *, int, int);
867 extern int register_blkdev(unsigned int, const char *, struct block_device_operations *);
868 extern int unregister_blkdev(unsigned int, const char *);
869 extern struct block_device *bdget(dev_t);
870 extern void bdput(struct block_device *);
871 extern int blkdev_open(struct inode *, struct file *);
872 extern int blkdev_close(struct inode * inode, struct file * filp);
873 extern struct file_operations def_blk_fops;
874 extern struct file_operations def_fifo_fops;
875 extern int ioctl_by_bdev(struct block_device *, unsigned, unsigned long);
876 extern int blkdev_get(struct block_device *, mode_t, unsigned, int);
877 extern int blkdev_put(struct block_device *, int);
879 /* fs/devices.c */
880 extern const struct block_device_operations *get_blkfops(unsigned int);
881 extern struct file_operations *get_chrfops(unsigned int, unsigned int);
882 extern int register_chrdev(unsigned int, const char *, struct file_operations *);
883 extern int unregister_chrdev(unsigned int, const char *);
884 extern int chrdev_open(struct inode *, struct file *);
885 extern const char * bdevname(kdev_t);
886 extern const char * cdevname(kdev_t);
887 extern const char * kdevname(kdev_t);
888 extern void init_special_inode(struct inode *, umode_t, int);
890 /* Invalid inode operations -- fs/bad_inode.c */
891 extern void make_bad_inode(struct inode *);
892 extern int is_bad_inode(struct inode *);
894 extern struct file_operations read_fifo_fops;
895 extern struct file_operations write_fifo_fops;
896 extern struct file_operations rdwr_fifo_fops;
897 extern struct file_operations read_pipe_fops;
898 extern struct file_operations write_pipe_fops;
899 extern struct file_operations rdwr_pipe_fops;
901 extern int fs_may_remount_ro(struct super_block *);
903 extern int try_to_free_buffers(struct page *);
904 extern void refile_buffer(struct buffer_head * buf);
906 #define BUF_CLEAN 0
907 #define BUF_LOCKED 1 /* Buffers scheduled for write */
908 #define BUF_DIRTY 2 /* Dirty buffers, not yet scheduled for write */
909 #define BUF_PROTECTED 3 /* Ramdisk persistent storage */
910 #define NR_LIST 4
913 * This is called by bh->b_end_io() handlers when I/O has completed.
915 static inline void mark_buffer_uptodate(struct buffer_head * bh, int on)
917 if (on)
918 set_bit(BH_Uptodate, &bh->b_state);
919 else
920 clear_bit(BH_Uptodate, &bh->b_state);
923 #define atomic_set_buffer_clean(bh) test_and_clear_bit(BH_Dirty, &(bh)->b_state)
925 static inline void __mark_buffer_clean(struct buffer_head *bh)
927 refile_buffer(bh);
930 static inline void mark_buffer_clean(struct buffer_head * bh)
932 if (atomic_set_buffer_clean(bh))
933 __mark_buffer_clean(bh);
936 #define atomic_set_buffer_protected(bh) test_and_set_bit(BH_Protected, &(bh)->b_state)
938 static inline void __mark_buffer_protected(struct buffer_head *bh)
940 refile_buffer(bh);
943 static inline void mark_buffer_protected(struct buffer_head * bh)
945 if (!atomic_set_buffer_protected(bh))
946 __mark_buffer_protected(bh);
949 extern void FASTCALL(__mark_buffer_dirty(struct buffer_head *bh, int flag));
950 extern void FASTCALL(mark_buffer_dirty(struct buffer_head *bh, int flag));
952 #define atomic_set_buffer_dirty(bh) test_and_set_bit(BH_Dirty, &(bh)->b_state)
954 extern void balance_dirty(kdev_t);
955 extern int check_disk_change(kdev_t);
956 extern int invalidate_inodes(struct super_block *);
957 extern void invalidate_inode_pages(struct inode *);
958 #define invalidate_buffers(dev) __invalidate_buffers((dev), 0)
959 #define destroy_buffers(dev) __invalidate_buffers((dev), 1)
960 extern void __invalidate_buffers(kdev_t dev, int);
961 extern void sync_inodes(kdev_t);
962 extern void write_inode_now(struct inode *);
963 extern void sync_dev(kdev_t);
964 extern int fsync_dev(kdev_t);
965 extern void sync_supers(kdev_t);
966 extern int bmap(struct inode *, int);
967 extern int notify_change(struct dentry *, struct iattr *);
968 extern int permission(struct inode *, int);
969 extern int get_write_access(struct inode *);
970 extern void put_write_access(struct inode *);
971 extern int do_pipe(int *);
973 extern int open_namei(const char *, int, int, struct nameidata *);
975 extern int kernel_read(struct file *, unsigned long, char *, unsigned long);
976 extern struct file * open_exec(const char *);
978 /* fs/dcache.c -- generic fs support functions */
979 extern int is_subdir(struct dentry *, struct dentry *);
980 extern ino_t find_inode_number(struct dentry *, struct qstr *);
983 * Kernel pointers have redundant information, so we can use a
984 * scheme where we can return either an error code or a dentry
985 * pointer with the same return value.
987 * This should be a per-architecture thing, to allow different
988 * error and pointer decisions.
990 #define ERR_PTR(err) ((void *)((long)(err)))
991 #define PTR_ERR(ptr) ((long)(ptr))
992 #define IS_ERR(ptr) ((unsigned long)(ptr) > (unsigned long)(-1000))
995 * The bitmask for a lookup event:
996 * - follow links at the end
997 * - require a directory
998 * - ending slashes ok even for nonexistent files
999 * - internal "there are more path compnents" flag
1001 #define LOOKUP_FOLLOW (1)
1002 #define LOOKUP_DIRECTORY (2)
1003 #define LOOKUP_CONTINUE (4)
1004 #define LOOKUP_POSITIVE (8)
1005 #define LOOKUP_PARENT (16)
1006 #define LOOKUP_NOALT (32)
1008 * Type of the last component on LOOKUP_PARENT
1010 enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT };
1013 * "descriptor" for what we're up to with a read for sendfile().
1014 * This allows us to use the same read code yet
1015 * have multiple different users of the data that
1016 * we read from a file.
1018 * The simplest case just copies the data to user
1019 * mode.
1021 typedef struct {
1022 size_t written;
1023 size_t count;
1024 char * buf;
1025 int error;
1026 } read_descriptor_t;
1028 typedef int (*read_actor_t)(read_descriptor_t *, struct page *, unsigned long, unsigned long);
1030 /* needed for stackable file system support */
1031 extern loff_t default_llseek(struct file *file, loff_t offset, int origin);
1033 extern int __user_walk(const char *, unsigned, struct nameidata *);
1034 extern int path_init(const char *, unsigned, struct nameidata *);
1035 extern int path_walk(const char *, struct nameidata *);
1036 extern void path_release(struct nameidata *);
1037 extern int follow_down(struct vfsmount **, struct dentry **);
1038 extern int follow_up(struct vfsmount **, struct dentry **);
1039 extern struct dentry * lookup_one(const char *, struct dentry *);
1040 extern struct dentry * lookup_hash(struct qstr *, struct dentry *);
1041 #define user_path_walk(name,nd) __user_walk(name, LOOKUP_FOLLOW|LOOKUP_POSITIVE, nd)
1042 #define user_path_walk_link(name,nd) __user_walk(name, LOOKUP_POSITIVE, nd)
1044 extern void iput(struct inode *);
1045 extern struct inode * igrab(struct inode *);
1046 extern ino_t iunique(struct super_block *, ino_t);
1048 typedef int (*find_inode_t)(struct inode *, unsigned long, void *);
1049 extern struct inode * iget4(struct super_block *, unsigned long, find_inode_t, void *);
1050 static inline struct inode *iget(struct super_block *sb, unsigned long ino)
1052 return iget4(sb, ino, NULL, NULL);
1055 extern void clear_inode(struct inode *);
1056 extern struct inode * get_empty_inode(void);
1058 extern void insert_inode_hash(struct inode *);
1059 extern void remove_inode_hash(struct inode *);
1060 extern struct file * get_empty_filp(void);
1061 extern void file_move(struct file *f, struct list_head *list);
1062 extern void file_moveto(struct file *new, struct file *old);
1063 extern struct buffer_head * get_hash_table(kdev_t, int, int);
1064 extern struct buffer_head * getblk(kdev_t, int, int);
1065 extern void ll_rw_block(int, int, struct buffer_head * bh[]);
1066 extern int is_read_only(kdev_t);
1067 extern void __brelse(struct buffer_head *);
1068 static inline void brelse(struct buffer_head *buf)
1070 if (buf)
1071 __brelse(buf);
1073 extern void __bforget(struct buffer_head *);
1074 static inline void bforget(struct buffer_head *buf)
1076 if (buf)
1077 __bforget(buf);
1079 extern void set_blocksize(kdev_t, int);
1080 extern unsigned int get_hardblocksize(kdev_t);
1081 extern struct buffer_head * bread(kdev_t, int, int);
1082 extern struct buffer_head * breada(kdev_t, int, int, unsigned int, unsigned int);
1083 extern void wakeup_bdflush(int wait);
1085 extern int brw_page(int, struct page *, kdev_t, int [], int);
1087 typedef int (get_block_t)(struct inode*,long,struct buffer_head*,int);
1089 /* Generic buffer handling for block filesystems.. */
1090 extern int block_flushpage(struct page *, unsigned long);
1091 extern int block_fsync(struct file *filp, struct dentry *dentry);
1092 extern int block_symlink(struct inode *, const char *, int);
1093 extern int block_write_full_page(struct page*, get_block_t*);
1094 extern int block_read_full_page(struct page*, get_block_t*);
1095 extern int block_prepare_write(struct page*, unsigned, unsigned, get_block_t*);
1096 extern int cont_prepare_write(struct page*, unsigned, unsigned, get_block_t*,
1097 unsigned long *);
1098 extern int block_sync_page(struct page *);
1100 int generic_block_bmap(struct address_space *, long, get_block_t *);
1101 int generic_commit_write(struct file *, struct page *, unsigned, unsigned);
1103 extern int generic_file_mmap(struct file *, struct vm_area_struct *);
1104 extern ssize_t generic_file_read(struct file *, char *, size_t, loff_t *);
1105 extern ssize_t generic_file_write(struct file *, const char *, size_t, loff_t *);
1106 extern void do_generic_file_read(struct file *, loff_t *, read_descriptor_t *, read_actor_t);
1108 extern ssize_t generic_read_dir(struct file *, char *, size_t, loff_t *);
1110 extern struct file_operations generic_ro_fops;
1112 extern int vfs_readlink(struct dentry *, char *, int, const char *);
1113 extern int vfs_follow_link(struct nameidata *, const char *);
1114 extern int page_readlink(struct dentry *, char *, int);
1115 extern int page_follow_link(struct dentry *, struct nameidata *);
1116 extern struct inode_operations page_symlink_inode_operations;
1118 extern int vfs_readdir(struct file *, filldir_t, void *);
1120 extern struct super_block *get_super(kdev_t);
1121 struct super_block *get_empty_super(void);
1122 extern void put_super(kdev_t);
1123 unsigned long generate_cluster(kdev_t, int b[], int);
1124 unsigned long generate_cluster_swab32(kdev_t, int b[], int);
1125 extern kdev_t ROOT_DEV;
1126 extern char root_device_name[];
1129 extern void show_buffers(void);
1130 extern void mount_root(void);
1132 #ifdef CONFIG_BLK_DEV_INITRD
1133 extern kdev_t real_root_dev;
1134 extern int change_root(kdev_t, const char *);
1135 #endif
1137 extern ssize_t char_read(struct file *, char *, size_t, loff_t *);
1138 extern ssize_t block_read(struct file *, char *, size_t, loff_t *);
1139 extern int read_ahead[];
1141 extern ssize_t char_write(struct file *, const char *, size_t, loff_t *);
1142 extern ssize_t block_write(struct file *, const char *, size_t, loff_t *);
1144 extern int file_fsync(struct file *, struct dentry *);
1145 extern int generic_buffer_fdatasync(struct inode *inode, unsigned long start_idx, unsigned long end_idx);
1147 extern int inode_change_ok(struct inode *, struct iattr *);
1148 extern void inode_setattr(struct inode *, struct iattr *);
1151 * Common dentry functions for inclusion in the VFS
1152 * or in other stackable file systems. Some of these
1153 * functions were in linux/fs/ C (VFS) files.
1158 * We need to do a check-parent every time
1159 * after we have locked the parent - to verify
1160 * that the parent is still our parent and
1161 * that we are still hashed onto it..
1163 * This is required in case two processes race
1164 * on removing (or moving) the same entry: the
1165 * parent lock will serialize them, but the
1166 * other process will be too late..
1168 #define check_parent(dir, dentry) \
1169 ((dir) == (dentry)->d_parent && !d_unhashed(dentry))
1172 * Locking the parent is needed to:
1173 * - serialize directory operations
1174 * - make sure the parent doesn't change from
1175 * under us in the middle of an operation.
1177 * NOTE! Right now we'd rather use a "struct inode"
1178 * for this, but as I expect things to move toward
1179 * using dentries instead for most things it is
1180 * probably better to start with the conceptually
1181 * better interface of relying on a path of dentries.
1183 static inline struct dentry *lock_parent(struct dentry *dentry)
1185 struct dentry *dir = dget(dentry->d_parent);
1187 down(&dir->d_inode->i_sem);
1188 return dir;
1191 static inline struct dentry *get_parent(struct dentry *dentry)
1193 return dget(dentry->d_parent);
1196 static inline void unlock_dir(struct dentry *dir)
1198 up(&dir->d_inode->i_sem);
1199 dput(dir);
1203 * Whee.. Deadlock country. Happily there are only two VFS
1204 * operations that does this..
1206 static inline void double_down(struct semaphore *s1, struct semaphore *s2)
1208 if (s1 != s2) {
1209 if ((unsigned long) s1 < (unsigned long) s2) {
1210 struct semaphore *tmp = s2;
1211 s2 = s1; s1 = tmp;
1213 down(s1);
1215 down(s2);
1219 * Ewwwwwwww... _triple_ lock. We are guaranteed that the 3rd argument is
1220 * not equal to 1st and not equal to 2nd - the first case (target is parent of
1221 * source) would be already caught, the second is plain impossible (target is
1222 * its own parent and that case would be caught even earlier). Very messy.
1223 * I _think_ that it works, but no warranties - please, look it through.
1224 * Pox on bloody lusers who mandated overwriting rename() for directories...
1227 static inline void triple_down(struct semaphore *s1,
1228 struct semaphore *s2,
1229 struct semaphore *s3)
1231 if (s1 != s2) {
1232 if ((unsigned long) s1 < (unsigned long) s2) {
1233 if ((unsigned long) s1 < (unsigned long) s3) {
1234 struct semaphore *tmp = s3;
1235 s3 = s1; s1 = tmp;
1237 if ((unsigned long) s1 < (unsigned long) s2) {
1238 struct semaphore *tmp = s2;
1239 s2 = s1; s1 = tmp;
1241 } else {
1242 if ((unsigned long) s1 < (unsigned long) s3) {
1243 struct semaphore *tmp = s3;
1244 s3 = s1; s1 = tmp;
1246 if ((unsigned long) s2 < (unsigned long) s3) {
1247 struct semaphore *tmp = s3;
1248 s3 = s2; s2 = tmp;
1251 down(s1);
1252 } else if ((unsigned long) s2 < (unsigned long) s3) {
1253 struct semaphore *tmp = s3;
1254 s3 = s2; s2 = tmp;
1256 down(s2);
1257 down(s3);
1260 static inline void double_up(struct semaphore *s1, struct semaphore *s2)
1262 up(s1);
1263 if (s1 != s2)
1264 up(s2);
1267 static inline void triple_up(struct semaphore *s1,
1268 struct semaphore *s2,
1269 struct semaphore *s3)
1271 up(s1);
1272 if (s1 != s2)
1273 up(s2);
1274 up(s3);
1277 static inline void double_lock(struct dentry *d1, struct dentry *d2)
1279 double_down(&d1->d_inode->i_sem, &d2->d_inode->i_sem);
1282 static inline void double_unlock(struct dentry *d1, struct dentry *d2)
1284 double_up(&d1->d_inode->i_sem,&d2->d_inode->i_sem);
1285 dput(d1);
1286 dput(d2);
1289 #endif /* __KERNEL__ */
1291 #endif /* _LINUX_FS_H */