- pre3:
[davej-history.git] / include / linux / fs.h
blob17f2502cc14168fa1957c28f3cf6a69e0cf48d41
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 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;
56 extern int max_super_blocks, nr_super_blocks;
58 #define NR_FILE 8192 /* this can well be larger on a larger system */
59 #define NR_RESERVED_FILES 10 /* reserved for root */
60 #define NR_SUPER 256
62 #define MAY_EXEC 1
63 #define MAY_WRITE 2
64 #define MAY_READ 4
66 #define FMODE_READ 1
67 #define FMODE_WRITE 2
69 #define READ 0
70 #define WRITE 1
71 #define READA 2 /* read-ahead - don't block if no resources */
72 #define SPECIAL 4 /* For non-blockdevice requests in request queue */
74 #define SEL_IN 1
75 #define SEL_OUT 2
76 #define SEL_EX 4
78 /* public flags for file_system_type */
79 #define FS_REQUIRES_DEV 1
80 #define FS_NO_DCACHE 2 /* Only dcache the necessary things. */
81 #define FS_NO_PRELIM 4 /* prevent preloading of dentries, even if
82 * FS_NO_DCACHE is not set.
84 #define FS_SINGLE 8 /*
85 * Filesystem that can have only one superblock;
86 * kernel-wide vfsmnt is placed in ->kern_mnt by
87 * kern_mount() which must be called _after_
88 * register_filesystem().
90 #define FS_NOMOUNT 16 /* Never mount from userland */
91 #define FS_LITTER 32 /* Keeps the tree in dcache */
92 #define FS_ODD_RENAME 32768 /* Temporary stuff; will go away as soon
93 * as nfs_rename() will be cleaned up
96 * These are the fs-independent mount-flags: up to 16 flags are supported
98 #define MS_RDONLY 1 /* Mount read-only */
99 #define MS_NOSUID 2 /* Ignore suid and sgid bits */
100 #define MS_NODEV 4 /* Disallow access to device special files */
101 #define MS_NOEXEC 8 /* Disallow program execution */
102 #define MS_SYNCHRONOUS 16 /* Writes are synced at once */
103 #define MS_REMOUNT 32 /* Alter flags of a mounted FS */
104 #define MS_MANDLOCK 64 /* Allow mandatory locks on an FS */
105 #define MS_NOATIME 1024 /* Do not update access times. */
106 #define MS_NODIRATIME 2048 /* Do not update directory access times */
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 */
120 /* Inode flags - they have nothing to superblock flags now */
122 #define S_SYNC 1 /* Writes are synced at once */
123 #define S_NOATIME 2 /* Do not update access times */
124 #define S_QUOTA 4 /* Quota initialized for file */
125 #define S_APPEND 8 /* Append-only file */
126 #define S_IMMUTABLE 16 /* Immutable file */
127 #define S_DEAD 32 /* removed, but still open directory */
130 * Note that nosuid etc flags are inode-specific: setting some file-system
131 * flags just means all the inodes inherit those flags by default. It might be
132 * possible to override it selectively if you really wanted to with some
133 * ioctl() that is not currently implemented.
135 * Exception: MS_RDONLY is always applied to the entire file system.
137 * Unfortunately, it is possible to change a filesystems flags with it mounted
138 * with files in use. This means that all of the inodes will not have their
139 * i_flags updated. Hence, i_flags no longer inherit the superblock mount
140 * flags, so these have to be checked separately. -- rmk@arm.uk.linux.org
142 #define __IS_FLG(inode,flg) ((inode)->i_sb->s_flags & (flg))
144 #define IS_RDONLY(inode) ((inode)->i_sb->s_flags & MS_RDONLY)
145 #define IS_NOSUID(inode) __IS_FLG(inode, MS_NOSUID)
146 #define IS_NODEV(inode) __IS_FLG(inode, MS_NODEV)
147 #define IS_NOEXEC(inode) __IS_FLG(inode, MS_NOEXEC)
148 #define IS_SYNC(inode) (__IS_FLG(inode, MS_SYNCHRONOUS) || ((inode)->i_flags & S_SYNC))
149 #define IS_MANDLOCK(inode) __IS_FLG(inode, MS_MANDLOCK)
151 #define IS_QUOTAINIT(inode) ((inode)->i_flags & S_QUOTA)
152 #define IS_APPEND(inode) ((inode)->i_flags & S_APPEND)
153 #define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE)
154 #define IS_NOATIME(inode) (__IS_FLG(inode, MS_NOATIME) || ((inode)->i_flags & S_NOATIME))
155 #define IS_NODIRATIME(inode) __IS_FLG(inode, MS_NODIRATIME)
157 #define IS_DEADDIR(inode) ((inode)->i_flags & S_DEAD)
159 /* the read-only stuff doesn't really belong here, but any other place is
160 probably as bad and I don't want to create yet another include file. */
162 #define BLKROSET _IO(0x12,93) /* set device read-only (0 = read-write) */
163 #define BLKROGET _IO(0x12,94) /* get read-only status (0 = read_write) */
164 #define BLKRRPART _IO(0x12,95) /* re-read partition table */
165 #define BLKGETSIZE _IO(0x12,96) /* return device size */
166 #define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */
167 #define BLKRASET _IO(0x12,98) /* Set read ahead for block device */
168 #define BLKRAGET _IO(0x12,99) /* get current read ahead setting */
169 #define BLKFRASET _IO(0x12,100)/* set filesystem (mm/filemap.c) read-ahead */
170 #define BLKFRAGET _IO(0x12,101)/* get filesystem (mm/filemap.c) read-ahead */
171 #define BLKSECTSET _IO(0x12,102)/* set max sectors per request (ll_rw_blk.c) */
172 #define BLKSECTGET _IO(0x12,103)/* get max sectors per request (ll_rw_blk.c) */
173 #define BLKSSZGET _IO(0x12,104)/* get block device sector size */
174 #if 0
175 #define BLKPG _IO(0x12,105)/* See blkpg.h */
176 #define BLKELVGET _IOR(0x12,106,sizeof(blkelv_ioctl_arg_t))/* elevator get */
177 #define BLKELVSET _IOW(0x12,107,sizeof(blkelv_ioctl_arg_t))/* elevator set */
178 /* This was here just to show that the number is taken -
179 probably all these _IO(0x12,*) ioctls should be moved to blkpg.h. */
180 #endif
183 #define BMAP_IOCTL 1 /* obsolete - kept for compatibility */
184 #define FIBMAP _IO(0x00,1) /* bmap access */
185 #define FIGETBSZ _IO(0x00,2) /* get the block size used for bmap */
187 #ifdef __KERNEL__
189 #include <asm/semaphore.h>
190 #include <asm/byteorder.h>
192 extern void update_atime (struct inode *);
193 #define UPDATE_ATIME(inode) update_atime (inode)
195 extern void buffer_init(unsigned long);
196 extern void inode_init(unsigned long);
198 /* bh state bits */
199 #define BH_Uptodate 0 /* 1 if the buffer contains valid data */
200 #define BH_Dirty 1 /* 1 if the buffer is dirty */
201 #define BH_Lock 2 /* 1 if the buffer is locked */
202 #define BH_Req 3 /* 0 if the buffer has been invalidated */
203 #define BH_Mapped 4 /* 1 if the buffer has a disk mapping */
204 #define BH_New 5 /* 1 if the buffer is new and not yet written out */
205 #define BH_Protected 6 /* 1 if the buffer is protected */
208 * Try to keep the most commonly used fields in single cache lines (16
209 * bytes) to improve performance. This ordering should be
210 * particularly beneficial on 32-bit processors.
212 * We use the first 16 bytes for the data which is used in searches
213 * over the block hash lists (ie. getblk() and friends).
215 * The second 16 bytes we use for lru buffer scans, as used by
216 * sync_buffers() and refill_freelist(). -- sct
218 struct buffer_head {
219 /* First cache line: */
220 struct buffer_head *b_next; /* Hash queue list */
221 unsigned long b_blocknr; /* block number */
222 unsigned short b_size; /* block size */
223 unsigned short b_list; /* List that this buffer appears */
224 kdev_t b_dev; /* device (B_FREE = free) */
226 atomic_t b_count; /* users using this block */
227 kdev_t b_rdev; /* Real device */
228 unsigned long b_state; /* buffer state bitmap (see above) */
229 unsigned long b_flushtime; /* Time when (dirty) buffer should be written */
231 struct buffer_head *b_next_free;/* lru/free list linkage */
232 struct buffer_head *b_prev_free;/* doubly linked list of buffers */
233 struct buffer_head *b_this_page;/* circular list of buffers in one page */
234 struct buffer_head *b_reqnext; /* request queue */
236 struct buffer_head **b_pprev; /* doubly linked list of hash-queue */
237 char * b_data; /* pointer to data block (512 byte) */
238 struct page *b_page; /* the page this bh is mapped to */
239 void (*b_end_io)(struct buffer_head *bh, int uptodate); /* I/O completion */
240 void *b_private; /* reserved for b_end_io */
242 unsigned long b_rsector; /* Real buffer location on disk */
243 wait_queue_head_t b_wait;
246 typedef void (bh_end_io_t)(struct buffer_head *bh, int uptodate);
247 void init_buffer(struct buffer_head *, bh_end_io_t *, void *);
249 #define __buffer_state(bh, state) (((bh)->b_state & (1UL << BH_##state)) != 0)
251 #define buffer_uptodate(bh) __buffer_state(bh,Uptodate)
252 #define buffer_dirty(bh) __buffer_state(bh,Dirty)
253 #define buffer_locked(bh) __buffer_state(bh,Lock)
254 #define buffer_req(bh) __buffer_state(bh,Req)
255 #define buffer_mapped(bh) __buffer_state(bh,Mapped)
256 #define buffer_new(bh) __buffer_state(bh,New)
257 #define buffer_protected(bh) __buffer_state(bh,Protected)
259 #define bh_offset(bh) ((unsigned long)(bh)->b_data & ~PAGE_MASK)
261 extern void set_bh_page(struct buffer_head *bh, struct page *page, unsigned long offset);
263 #define touch_buffer(bh) SetPageReferenced(bh->b_page)
266 #include <linux/pipe_fs_i.h>
267 #include <linux/minix_fs_i.h>
268 #include <linux/ext2_fs_i.h>
269 #include <linux/hpfs_fs_i.h>
270 #include <linux/ntfs_fs_i.h>
271 #include <linux/msdos_fs_i.h>
272 #include <linux/umsdos_fs_i.h>
273 #include <linux/iso_fs_i.h>
274 #include <linux/nfs_fs_i.h>
275 #include <linux/sysv_fs_i.h>
276 #include <linux/affs_fs_i.h>
277 #include <linux/ufs_fs_i.h>
278 #include <linux/efs_fs_i.h>
279 #include <linux/coda_fs_i.h>
280 #include <linux/romfs_fs_i.h>
281 #include <linux/smb_fs_i.h>
282 #include <linux/hfs_fs_i.h>
283 #include <linux/adfs_fs_i.h>
284 #include <linux/qnx4_fs_i.h>
285 #include <linux/bfs_fs_i.h>
286 #include <linux/udf_fs_i.h>
287 #include <linux/ncp_fs_i.h>
288 #include <linux/proc_fs_i.h>
289 #include <linux/usbdev_fs_i.h>
292 * Attribute flags. These should be or-ed together to figure out what
293 * has been changed!
295 #define ATTR_MODE 1
296 #define ATTR_UID 2
297 #define ATTR_GID 4
298 #define ATTR_SIZE 8
299 #define ATTR_ATIME 16
300 #define ATTR_MTIME 32
301 #define ATTR_CTIME 64
302 #define ATTR_ATIME_SET 128
303 #define ATTR_MTIME_SET 256
304 #define ATTR_FORCE 512 /* Not a change, but a change it */
305 #define ATTR_ATTR_FLAG 1024
308 * This is the Inode Attributes structure, used for notify_change(). It
309 * uses the above definitions as flags, to know which values have changed.
310 * Also, in this manner, a Filesystem can look at only the values it cares
311 * about. Basically, these are the attributes that the VFS layer can
312 * request to change from the FS layer.
314 * Derek Atkins <warlord@MIT.EDU> 94-10-20
316 struct iattr {
317 unsigned int ia_valid;
318 umode_t ia_mode;
319 uid_t ia_uid;
320 gid_t ia_gid;
321 loff_t ia_size;
322 time_t ia_atime;
323 time_t ia_mtime;
324 time_t ia_ctime;
325 unsigned int ia_attr_flags;
329 * This is the inode attributes flag definitions
331 #define ATTR_FLAG_SYNCRONOUS 1 /* Syncronous write */
332 #define ATTR_FLAG_NOATIME 2 /* Don't update atime */
333 #define ATTR_FLAG_APPEND 4 /* Append-only file */
334 #define ATTR_FLAG_IMMUTABLE 8 /* Immutable file */
335 #define ATTR_FLAG_NODIRATIME 16 /* Don't update atime for directory */
338 * Includes for diskquotas and mount structures.
340 #include <linux/quota.h>
341 #include <linux/mount.h>
344 * oh the beauties of C type declarations.
346 struct page;
347 struct address_space;
349 struct address_space_operations {
350 int (*writepage)(struct file *, struct page *);
351 int (*readpage)(struct file *, struct page *);
352 int (*sync_page)(struct page *);
353 int (*prepare_write)(struct file *, struct page *, unsigned, unsigned);
354 int (*commit_write)(struct file *, struct page *, unsigned, unsigned);
355 /* Unfortunately this kludge is needed for FIBMAP. Don't use it */
356 int (*bmap)(struct address_space *, long);
359 struct address_space {
360 struct list_head pages; /* list of pages */
361 unsigned long nrpages; /* number of pages */
362 struct address_space_operations *a_ops; /* methods */
363 void *host; /* owner: inode, block_device */
364 struct vm_area_struct *i_mmap; /* list of private mappings */
365 struct vm_area_struct *i_mmap_shared; /* list of shared mappings */
366 spinlock_t i_shared_lock; /* and spinlock protecting it */
369 struct block_device {
370 struct list_head bd_hash;
371 atomic_t bd_count;
372 /* struct address_space bd_data; */
373 dev_t bd_dev; /* not a kdev_t - it's a search key */
374 atomic_t bd_openers;
375 const struct block_device_operations *bd_op;
376 struct semaphore bd_sem; /* open/close mutex */
379 struct inode {
380 struct list_head i_hash;
381 struct list_head i_list;
382 struct list_head i_dentry;
384 unsigned long i_ino;
385 atomic_t i_count;
386 kdev_t i_dev;
387 umode_t i_mode;
388 nlink_t i_nlink;
389 uid_t i_uid;
390 gid_t i_gid;
391 kdev_t i_rdev;
392 loff_t i_size;
393 time_t i_atime;
394 time_t i_mtime;
395 time_t i_ctime;
396 unsigned long i_blksize;
397 unsigned long i_blocks;
398 unsigned long i_version;
399 struct semaphore i_sem;
400 struct semaphore i_zombie;
401 struct inode_operations *i_op;
402 struct file_operations *i_fop; /* former ->i_op->default_file_ops */
403 struct super_block *i_sb;
404 wait_queue_head_t i_wait;
405 struct file_lock *i_flock;
406 struct address_space *i_mapping;
407 struct address_space i_data;
408 struct dquot *i_dquot[MAXQUOTAS];
409 struct pipe_inode_info *i_pipe;
410 struct block_device *i_bdev;
412 unsigned long i_state;
414 unsigned int i_flags;
415 unsigned char i_sock;
417 atomic_t i_writecount;
418 unsigned int i_attr_flags;
419 __u32 i_generation;
420 union {
421 struct minix_inode_info minix_i;
422 struct ext2_inode_info ext2_i;
423 struct hpfs_inode_info hpfs_i;
424 struct ntfs_inode_info ntfs_i;
425 struct msdos_inode_info msdos_i;
426 struct umsdos_inode_info umsdos_i;
427 struct iso_inode_info isofs_i;
428 struct nfs_inode_info nfs_i;
429 struct sysv_inode_info sysv_i;
430 struct affs_inode_info affs_i;
431 struct ufs_inode_info ufs_i;
432 struct efs_inode_info efs_i;
433 struct romfs_inode_info romfs_i;
434 struct coda_inode_info coda_i;
435 struct smb_inode_info smbfs_i;
436 struct hfs_inode_info hfs_i;
437 struct adfs_inode_info adfs_i;
438 struct qnx4_inode_info qnx4_i;
439 struct bfs_inode_info bfs_i;
440 struct udf_inode_info udf_i;
441 struct ncp_inode_info ncpfs_i;
442 struct proc_inode_info proc_i;
443 struct socket socket_i;
444 struct usbdev_inode_info usbdev_i;
445 void *generic_ip;
446 } u;
449 /* Inode state bits.. */
450 #define I_DIRTY 1
451 #define I_LOCK 2
452 #define I_FREEING 4
453 #define I_CLEAR 8
455 extern void __mark_inode_dirty(struct inode *);
456 static inline void mark_inode_dirty(struct inode *inode)
458 if (!(inode->i_state & I_DIRTY))
459 __mark_inode_dirty(inode);
462 struct fown_struct {
463 int pid; /* pid or -pgrp where SIGIO should be sent */
464 uid_t uid, euid; /* uid/euid of process setting the owner */
465 int signum; /* posix.1b rt signal to be delivered on IO */
468 struct file {
469 struct list_head f_list;
470 struct dentry *f_dentry;
471 struct vfsmount *f_vfsmnt;
472 struct file_operations *f_op;
473 atomic_t f_count;
474 unsigned int f_flags;
475 mode_t f_mode;
476 loff_t f_pos;
477 unsigned long f_reada, f_ramax, f_raend, f_ralen, f_rawin;
478 struct fown_struct f_owner;
479 unsigned int f_uid, f_gid;
480 int f_error;
482 unsigned long f_version;
484 /* needed for tty driver, and maybe others */
485 void *private_data;
487 extern spinlock_t files_lock;
488 #define file_list_lock() spin_lock(&files_lock);
489 #define file_list_unlock() spin_unlock(&files_lock);
491 #define get_file(x) atomic_inc(&(x)->f_count)
492 #define file_count(x) atomic_read(&(x)->f_count)
494 extern int init_private_file(struct file *, struct dentry *, int);
496 #define FL_POSIX 1
497 #define FL_FLOCK 2
498 #define FL_BROKEN 4 /* broken flock() emulation */
499 #define FL_ACCESS 8 /* for processes suspended by mandatory locking */
500 #define FL_LOCKD 16 /* lock held by rpc.lockd */
503 * The POSIX file lock owner is determined by
504 * the "struct files_struct" in the thread group
505 * (or NULL for no owner - BSD locks).
507 * Lockd stuffs a "host" pointer into this.
509 typedef struct files_struct *fl_owner_t;
511 struct file_lock {
512 struct file_lock *fl_next; /* singly linked list for this inode */
513 struct list_head fl_link; /* doubly linked list of all locks */
514 struct list_head fl_block; /* circular list of blocked processes */
515 fl_owner_t fl_owner;
516 unsigned int fl_pid;
517 wait_queue_head_t fl_wait;
518 struct file *fl_file;
519 unsigned char fl_flags;
520 unsigned char fl_type;
521 loff_t fl_start;
522 loff_t fl_end;
524 void (*fl_notify)(struct file_lock *); /* unblock callback */
525 void (*fl_insert)(struct file_lock *); /* lock insertion callback */
526 void (*fl_remove)(struct file_lock *); /* lock removal callback */
528 union {
529 struct nfs_lock_info nfs_fl;
530 } fl_u;
533 /* The following constant reflects the upper bound of the file/locking space */
534 #ifndef OFFSET_MAX
535 #define INT_LIMIT(x) (~((x)1 << (sizeof(x)*8 - 1)))
536 #define OFFSET_MAX INT_LIMIT(loff_t)
537 #define OFFT_OFFSET_MAX INT_LIMIT(off_t)
538 #endif
540 extern struct list_head file_lock_list;
542 #include <linux/fcntl.h>
544 extern int fcntl_getlk(unsigned int, struct flock *);
545 extern int fcntl_setlk(unsigned int, unsigned int, struct flock *);
547 extern int fcntl_getlk64(unsigned int, struct flock64 *);
548 extern int fcntl_setlk64(unsigned int, unsigned int, struct flock64 *);
550 /* fs/locks.c */
551 extern void locks_remove_posix(struct file *, fl_owner_t);
552 extern void locks_remove_flock(struct file *);
553 extern struct file_lock *posix_test_lock(struct file *, struct file_lock *);
554 extern int posix_lock_file(struct file *, struct file_lock *, unsigned int);
555 extern void posix_block_lock(struct file_lock *, struct file_lock *);
556 extern void posix_unblock_lock(struct file_lock *);
558 struct fasync_struct {
559 int magic;
560 int fa_fd;
561 struct fasync_struct *fa_next; /* singly linked list */
562 struct file *fa_file;
565 #define FASYNC_MAGIC 0x4601
567 /* SMP safe fasync helpers: */
568 extern int fasync_helper(int, struct file *, int, struct fasync_struct **);
569 /* can be called from interrupts */
570 extern void kill_fasync(struct fasync_struct **, int, int);
571 /* only for net: no internal synchronization */
572 extern void __kill_fasync(struct fasync_struct *, int, int);
574 struct nameidata {
575 struct dentry *dentry;
576 struct vfsmount *mnt;
577 struct qstr last;
578 unsigned int flags;
579 int last_type;
582 #define DQUOT_USR_ENABLED 0x01 /* User diskquotas enabled */
583 #define DQUOT_GRP_ENABLED 0x02 /* Group diskquotas enabled */
585 struct quota_mount_options
587 unsigned int flags; /* Flags for diskquotas on this device */
588 struct semaphore dqio_sem; /* lock device while I/O in progress */
589 struct semaphore dqoff_sem; /* serialize quota_off() and quota_on() on device */
590 struct file *files[MAXQUOTAS]; /* fp's to quotafiles */
591 time_t inode_expire[MAXQUOTAS]; /* expiretime for inode-quota */
592 time_t block_expire[MAXQUOTAS]; /* expiretime for block-quota */
593 char rsquash[MAXQUOTAS]; /* for quotas threat root as any other user */
597 * Umount options
600 #define MNT_FORCE 0x00000001 /* Attempt to forcibily umount */
602 #include <linux/minix_fs_sb.h>
603 #include <linux/ext2_fs_sb.h>
604 #include <linux/hpfs_fs_sb.h>
605 #include <linux/ntfs_fs_sb.h>
606 #include <linux/msdos_fs_sb.h>
607 #include <linux/iso_fs_sb.h>
608 #include <linux/nfs_fs_sb.h>
609 #include <linux/sysv_fs_sb.h>
610 #include <linux/affs_fs_sb.h>
611 #include <linux/ufs_fs_sb.h>
612 #include <linux/efs_fs_sb.h>
613 #include <linux/romfs_fs_sb.h>
614 #include <linux/smb_fs_sb.h>
615 #include <linux/hfs_fs_sb.h>
616 #include <linux/adfs_fs_sb.h>
617 #include <linux/qnx4_fs_sb.h>
618 #include <linux/bfs_fs_sb.h>
619 #include <linux/udf_fs_sb.h>
620 #include <linux/ncp_fs_sb.h>
621 #include <linux/usbdev_fs_sb.h>
623 extern struct list_head super_blocks;
625 #define sb_entry(list) list_entry((list), struct super_block, s_list)
626 struct super_block {
627 struct list_head s_list; /* Keep this first */
628 kdev_t s_dev;
629 unsigned long s_blocksize;
630 unsigned char s_blocksize_bits;
631 unsigned char s_lock;
632 unsigned char s_dirt;
633 struct file_system_type *s_type;
634 struct super_operations *s_op;
635 struct dquot_operations *dq_op;
636 unsigned long s_flags;
637 unsigned long s_magic;
638 struct dentry *s_root;
639 wait_queue_head_t s_wait;
641 struct list_head s_dirty; /* dirty inodes */
642 struct list_head s_files;
644 struct block_device *s_bdev;
645 struct list_head s_mounts; /* vfsmount(s) of this one */
646 struct quota_mount_options s_dquot; /* Diskquota specific options */
648 union {
649 struct minix_sb_info minix_sb;
650 struct ext2_sb_info ext2_sb;
651 struct hpfs_sb_info hpfs_sb;
652 struct ntfs_sb_info ntfs_sb;
653 struct msdos_sb_info msdos_sb;
654 struct isofs_sb_info isofs_sb;
655 struct nfs_sb_info nfs_sb;
656 struct sysv_sb_info sysv_sb;
657 struct affs_sb_info affs_sb;
658 struct ufs_sb_info ufs_sb;
659 struct efs_sb_info efs_sb;
660 struct romfs_sb_info romfs_sb;
661 struct smb_sb_info smbfs_sb;
662 struct hfs_sb_info hfs_sb;
663 struct adfs_sb_info adfs_sb;
664 struct qnx4_sb_info qnx4_sb;
665 struct bfs_sb_info bfs_sb;
666 struct udf_sb_info udf_sb;
667 struct ncp_sb_info ncpfs_sb;
668 struct usbdev_sb_info usbdevfs_sb;
669 void *generic_sbp;
670 } u;
672 * The next field is for VFS *only*. No filesystems have any business
673 * even looking at it. You had been warned.
675 struct semaphore s_vfs_rename_sem; /* Kludge */
677 /* The next field is used by knfsd when converting a (inode number based)
678 * file handle into a dentry. As it builds a path in the dcache tree from
679 * the bottom up, there may for a time be a subpath of dentrys which is not
680 * connected to the main tree. This semaphore ensure that there is only ever
681 * one such free path per filesystem. Note that unconnected files (or other
682 * non-directories) are allowed, but not unconnected diretories.
684 struct semaphore s_nfsd_free_path_sem;
688 * VFS helper functions..
690 extern int vfs_create(struct inode *, struct dentry *, int);
691 extern int vfs_mkdir(struct inode *, struct dentry *, int);
692 extern int vfs_mknod(struct inode *, struct dentry *, int, dev_t);
693 extern int vfs_symlink(struct inode *, struct dentry *, const char *);
694 extern int vfs_link(struct dentry *, struct inode *, struct dentry *);
695 extern int vfs_rmdir(struct inode *, struct dentry *);
696 extern int vfs_unlink(struct inode *, struct dentry *);
697 extern int vfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
700 * File types
702 #define DT_UNKNOWN 0
703 #define DT_FIFO 1
704 #define DT_CHR 2
705 #define DT_DIR 4
706 #define DT_BLK 6
707 #define DT_REG 8
708 #define DT_LNK 10
709 #define DT_SOCK 12
710 #define DT_WHT 14
713 * This is the "filldir" function type, used by readdir() to let
714 * the kernel specify what kind of dirent layout it wants to have.
715 * This allows the kernel to read directories into kernel space or
716 * to have different dirent layouts depending on the binary type.
718 typedef int (*filldir_t)(void *, const char *, int, off_t, ino_t, unsigned);
720 struct block_device_operations {
721 int (*open) (struct inode *, struct file *);
722 int (*release) (struct inode *, struct file *);
723 int (*ioctl) (struct inode *, struct file *, unsigned, unsigned long);
724 int (*check_media_change) (kdev_t);
725 int (*revalidate) (kdev_t);
729 * NOTE:
730 * read, write, poll, fsync, readv, writev can be called
731 * without the big kernel lock held in all filesystems.
733 struct file_operations {
734 struct module *owner;
735 loff_t (*llseek) (struct file *, loff_t, int);
736 ssize_t (*read) (struct file *, char *, size_t, loff_t *);
737 ssize_t (*write) (struct file *, const char *, size_t, loff_t *);
738 int (*readdir) (struct file *, void *, filldir_t);
739 unsigned int (*poll) (struct file *, struct poll_table_struct *);
740 int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);
741 int (*mmap) (struct file *, struct vm_area_struct *);
742 int (*open) (struct inode *, struct file *);
743 int (*flush) (struct file *);
744 int (*release) (struct inode *, struct file *);
745 int (*fsync) (struct file *, struct dentry *, int datasync);
746 int (*fasync) (int, struct file *, int);
747 int (*lock) (struct file *, int, struct file_lock *);
748 ssize_t (*readv) (struct file *, const struct iovec *, unsigned long, loff_t *);
749 ssize_t (*writev) (struct file *, const struct iovec *, unsigned long, loff_t *);
752 struct inode_operations {
753 int (*create) (struct inode *,struct dentry *,int);
754 struct dentry * (*lookup) (struct inode *,struct dentry *);
755 int (*link) (struct dentry *,struct inode *,struct dentry *);
756 int (*unlink) (struct inode *,struct dentry *);
757 int (*symlink) (struct inode *,struct dentry *,const char *);
758 int (*mkdir) (struct inode *,struct dentry *,int);
759 int (*rmdir) (struct inode *,struct dentry *);
760 int (*mknod) (struct inode *,struct dentry *,int,int);
761 int (*rename) (struct inode *, struct dentry *,
762 struct inode *, struct dentry *);
763 int (*readlink) (struct dentry *, char *,int);
764 int (*follow_link) (struct dentry *, struct nameidata *);
765 void (*truncate) (struct inode *);
766 int (*permission) (struct inode *, int);
767 int (*revalidate) (struct dentry *);
768 int (*setattr) (struct dentry *, struct iattr *);
769 int (*getattr) (struct dentry *, struct iattr *);
773 * NOTE: write_inode, delete_inode, clear_inode, put_inode can be called
774 * without the big kernel lock held in all filesystems.
776 struct super_operations {
777 void (*read_inode) (struct inode *);
778 void (*write_inode) (struct inode *, int);
779 void (*put_inode) (struct inode *);
780 void (*delete_inode) (struct inode *);
781 void (*put_super) (struct super_block *);
782 void (*write_super) (struct super_block *);
783 int (*statfs) (struct super_block *, struct statfs *);
784 int (*remount_fs) (struct super_block *, int *, char *);
785 void (*clear_inode) (struct inode *);
786 void (*umount_begin) (struct super_block *);
789 struct dquot_operations {
790 void (*initialize) (struct inode *, short);
791 void (*drop) (struct inode *);
792 int (*alloc_block) (const struct inode *, unsigned long, char);
793 int (*alloc_inode) (const struct inode *, unsigned long);
794 void (*free_block) (const struct inode *, unsigned long);
795 void (*free_inode) (const struct inode *, unsigned long);
796 int (*transfer) (struct dentry *, struct iattr *);
799 struct file_system_type {
800 const char *name;
801 int fs_flags;
802 struct super_block *(*read_super) (struct super_block *, void *, int);
803 struct module *owner;
804 struct vfsmount *kern_mnt; /* For kernel mount, if it's FS_SINGLE fs */
805 struct file_system_type * next;
808 #define DECLARE_FSTYPE(var,type,read,flags) \
809 struct file_system_type var = { \
810 name: type, \
811 read_super: read, \
812 fs_flags: flags, \
813 owner: THIS_MODULE, \
816 #define DECLARE_FSTYPE_DEV(var,type,read) \
817 DECLARE_FSTYPE(var,type,read,FS_REQUIRES_DEV)
819 /* Alas, no aliases. Too much hassle with bringing module.h everywhere */
820 #define fops_get(fops) \
821 (((fops) && (fops)->owner) \
822 ? ( try_inc_mod_count((fops)->owner) ? (fops) : NULL ) \
823 : (fops))
825 #define fops_put(fops) \
826 do { \
827 if ((fops) && (fops)->owner) \
828 __MOD_DEC_USE_COUNT((fops)->owner); \
829 } while(0)
831 extern int register_filesystem(struct file_system_type *);
832 extern int unregister_filesystem(struct file_system_type *);
833 extern struct vfsmount *kern_mount(struct file_system_type *);
834 extern void kern_umount(struct vfsmount *);
835 extern int may_umount(struct vfsmount *);
836 extern long do_mount(char *, char *, char *, unsigned long, void *);
839 extern int vfs_statfs(struct super_block *, struct statfs *);
841 /* Return value for VFS lock functions - tells locks.c to lock conventionally
842 * REALLY kosha for root NFS and nfs_lock
844 #define LOCK_USE_CLNT 1
846 #define FLOCK_VERIFY_READ 1
847 #define FLOCK_VERIFY_WRITE 2
849 extern int locks_mandatory_locked(struct inode *);
850 extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
853 * Candidates for mandatory locking have the setgid bit set
854 * but no group execute bit - an otherwise meaningless combination.
856 #define MANDATORY_LOCK(inode) \
857 (IS_MANDLOCK(inode) && ((inode)->i_mode & (S_ISGID | S_IXGRP)) == S_ISGID)
859 static inline int locks_verify_locked(struct inode *inode)
861 if (MANDATORY_LOCK(inode))
862 return locks_mandatory_locked(inode);
863 return 0;
866 static inline int locks_verify_area(int read_write, struct inode *inode,
867 struct file *filp, loff_t offset,
868 size_t count)
870 if (inode->i_flock && MANDATORY_LOCK(inode))
871 return locks_mandatory_area(read_write, inode, filp, offset, count);
872 return 0;
875 static inline int locks_verify_truncate(struct inode *inode,
876 struct file *filp,
877 loff_t size)
879 if (inode->i_flock && MANDATORY_LOCK(inode))
880 return locks_mandatory_area(
881 FLOCK_VERIFY_WRITE, inode, filp,
882 size < inode->i_size ? size : inode->i_size,
883 (size < inode->i_size ? inode->i_size - size
884 : size - inode->i_size)
886 return 0;
890 /* fs/open.c */
892 asmlinkage long sys_open(const char *, int, int);
893 asmlinkage long sys_close(unsigned int); /* yes, it's really unsigned */
894 extern int do_truncate(struct dentry *, loff_t start);
896 extern struct file *filp_open(const char *, int, int);
897 extern struct file * dentry_open(struct dentry *, struct vfsmount *, int);
898 extern int filp_close(struct file *, fl_owner_t id);
899 extern char * getname(const char *);
901 /* fs/dcache.c */
902 extern void vfs_caches_init(unsigned long);
904 #define __getname() kmem_cache_alloc(names_cachep, SLAB_KERNEL)
905 #define putname(name) kmem_cache_free(names_cachep, (void *)(name))
907 enum {BDEV_FILE, BDEV_SWAP, BDEV_FS, BDEV_RAW};
908 extern int register_blkdev(unsigned int, const char *, struct block_device_operations *);
909 extern int unregister_blkdev(unsigned int, const char *);
910 extern struct block_device *bdget(dev_t);
911 extern void bdput(struct block_device *);
912 extern int blkdev_open(struct inode *, struct file *);
913 extern struct file_operations def_blk_fops;
914 extern struct file_operations def_fifo_fops;
915 extern int ioctl_by_bdev(struct block_device *, unsigned, unsigned long);
916 extern int blkdev_get(struct block_device *, mode_t, unsigned, int);
917 extern int blkdev_put(struct block_device *, int);
919 /* fs/devices.c */
920 extern const struct block_device_operations *get_blkfops(unsigned int);
921 extern int register_chrdev(unsigned int, const char *, struct file_operations *);
922 extern int unregister_chrdev(unsigned int, const char *);
923 extern int chrdev_open(struct inode *, struct file *);
924 extern const char * bdevname(kdev_t);
925 extern const char * cdevname(kdev_t);
926 extern const char * kdevname(kdev_t);
927 extern void init_special_inode(struct inode *, umode_t, int);
929 /* Invalid inode operations -- fs/bad_inode.c */
930 extern void make_bad_inode(struct inode *);
931 extern int is_bad_inode(struct inode *);
933 extern struct file_operations read_fifo_fops;
934 extern struct file_operations write_fifo_fops;
935 extern struct file_operations rdwr_fifo_fops;
936 extern struct file_operations read_pipe_fops;
937 extern struct file_operations write_pipe_fops;
938 extern struct file_operations rdwr_pipe_fops;
940 extern int fs_may_remount_ro(struct super_block *);
942 extern int try_to_free_buffers(struct page *, int);
943 extern void refile_buffer(struct buffer_head * buf);
945 #define BUF_CLEAN 0
946 #define BUF_LOCKED 1 /* Buffers scheduled for write */
947 #define BUF_DIRTY 2 /* Dirty buffers, not yet scheduled for write */
948 #define BUF_PROTECTED 3 /* Ramdisk persistent storage */
949 #define NR_LIST 4
952 * This is called by bh->b_end_io() handlers when I/O has completed.
954 static inline void mark_buffer_uptodate(struct buffer_head * bh, int on)
956 if (on)
957 set_bit(BH_Uptodate, &bh->b_state);
958 else
959 clear_bit(BH_Uptodate, &bh->b_state);
962 #define atomic_set_buffer_clean(bh) test_and_clear_bit(BH_Dirty, &(bh)->b_state)
964 static inline void __mark_buffer_clean(struct buffer_head *bh)
966 refile_buffer(bh);
969 static inline void mark_buffer_clean(struct buffer_head * bh)
971 if (atomic_set_buffer_clean(bh))
972 __mark_buffer_clean(bh);
975 #define atomic_set_buffer_protected(bh) test_and_set_bit(BH_Protected, &(bh)->b_state)
977 static inline void __mark_buffer_protected(struct buffer_head *bh)
979 refile_buffer(bh);
982 static inline void mark_buffer_protected(struct buffer_head * bh)
984 if (!atomic_set_buffer_protected(bh))
985 __mark_buffer_protected(bh);
988 extern void FASTCALL(__mark_buffer_dirty(struct buffer_head *bh, int flag));
989 extern void FASTCALL(mark_buffer_dirty(struct buffer_head *bh, int flag));
991 #define atomic_set_buffer_dirty(bh) test_and_set_bit(BH_Dirty, &(bh)->b_state)
994 * If an error happens during the make_request, this function
995 * has to be recalled. It marks the buffer as clean and not
996 * uptodate, and it notifys the upper layer about the end
997 * of the I/O.
999 static inline void buffer_IO_error(struct buffer_head * bh)
1001 mark_buffer_clean(bh);
1003 * b_end_io has to clear the BH_Uptodate bitflag in the error case!
1005 bh->b_end_io(bh, 0);
1008 extern void balance_dirty(kdev_t);
1009 extern int check_disk_change(kdev_t);
1010 extern int invalidate_inodes(struct super_block *);
1011 extern void invalidate_inode_pages(struct inode *);
1012 #define invalidate_buffers(dev) __invalidate_buffers((dev), 0)
1013 #define destroy_buffers(dev) __invalidate_buffers((dev), 1)
1014 extern void __invalidate_buffers(kdev_t dev, int);
1015 extern void sync_inodes(kdev_t);
1016 extern void write_inode_now(struct inode *, int);
1017 extern void sync_dev(kdev_t);
1018 extern int fsync_dev(kdev_t);
1019 extern void sync_supers(kdev_t);
1020 extern int bmap(struct inode *, int);
1021 extern int notify_change(struct dentry *, struct iattr *);
1022 extern int permission(struct inode *, int);
1023 extern int get_write_access(struct inode *);
1024 extern int deny_write_access(struct file *);
1025 static inline void put_write_access(struct inode * inode)
1027 atomic_dec(&inode->i_writecount);
1029 static inline void allow_write_access(struct file *file)
1031 if (file)
1032 atomic_inc(&file->f_dentry->d_inode->i_writecount);
1034 extern int do_pipe(int *);
1036 extern int open_namei(const char *, int, int, struct nameidata *);
1038 extern int kernel_read(struct file *, unsigned long, char *, unsigned long);
1039 extern struct file * open_exec(const char *);
1041 /* fs/dcache.c -- generic fs support functions */
1042 extern int is_subdir(struct dentry *, struct dentry *);
1043 extern ino_t find_inode_number(struct dentry *, struct qstr *);
1046 * Kernel pointers have redundant information, so we can use a
1047 * scheme where we can return either an error code or a dentry
1048 * pointer with the same return value.
1050 * This should be a per-architecture thing, to allow different
1051 * error and pointer decisions.
1053 #define ERR_PTR(err) ((void *)((long)(err)))
1054 #define PTR_ERR(ptr) ((long)(ptr))
1055 #define IS_ERR(ptr) ((unsigned long)(ptr) > (unsigned long)(-1000))
1058 * The bitmask for a lookup event:
1059 * - follow links at the end
1060 * - require a directory
1061 * - ending slashes ok even for nonexistent files
1062 * - internal "there are more path compnents" flag
1064 #define LOOKUP_FOLLOW (1)
1065 #define LOOKUP_DIRECTORY (2)
1066 #define LOOKUP_CONTINUE (4)
1067 #define LOOKUP_POSITIVE (8)
1068 #define LOOKUP_PARENT (16)
1069 #define LOOKUP_NOALT (32)
1071 * Type of the last component on LOOKUP_PARENT
1073 enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT, LAST_BIND};
1076 * "descriptor" for what we're up to with a read for sendfile().
1077 * This allows us to use the same read code yet
1078 * have multiple different users of the data that
1079 * we read from a file.
1081 * The simplest case just copies the data to user
1082 * mode.
1084 typedef struct {
1085 size_t written;
1086 size_t count;
1087 char * buf;
1088 int error;
1089 } read_descriptor_t;
1091 typedef int (*read_actor_t)(read_descriptor_t *, struct page *, unsigned long, unsigned long);
1093 /* needed for stackable file system support */
1094 extern loff_t default_llseek(struct file *file, loff_t offset, int origin);
1096 extern int __user_walk(const char *, unsigned, struct nameidata *);
1097 extern int path_init(const char *, unsigned, struct nameidata *);
1098 extern int path_walk(const char *, struct nameidata *);
1099 extern void path_release(struct nameidata *);
1100 extern int follow_down(struct vfsmount **, struct dentry **);
1101 extern int follow_up(struct vfsmount **, struct dentry **);
1102 extern struct dentry * lookup_one(const char *, struct dentry *);
1103 extern struct dentry * lookup_hash(struct qstr *, struct dentry *);
1104 #define user_path_walk(name,nd) __user_walk(name, LOOKUP_FOLLOW|LOOKUP_POSITIVE, nd)
1105 #define user_path_walk_link(name,nd) __user_walk(name, LOOKUP_POSITIVE, nd)
1107 extern void iput(struct inode *);
1108 extern void force_delete(struct inode *);
1109 extern struct inode * igrab(struct inode *);
1110 extern ino_t iunique(struct super_block *, ino_t);
1112 typedef int (*find_inode_t)(struct inode *, unsigned long, void *);
1113 extern struct inode * iget4(struct super_block *, unsigned long, find_inode_t, void *);
1114 static inline struct inode *iget(struct super_block *sb, unsigned long ino)
1116 return iget4(sb, ino, NULL, NULL);
1119 extern void clear_inode(struct inode *);
1120 extern struct inode * get_empty_inode(void);
1122 extern void insert_inode_hash(struct inode *);
1123 extern void remove_inode_hash(struct inode *);
1124 extern struct file * get_empty_filp(void);
1125 extern void file_move(struct file *f, struct list_head *list);
1126 extern void file_moveto(struct file *new, struct file *old);
1127 extern struct buffer_head * get_hash_table(kdev_t, int, int);
1128 extern struct buffer_head * getblk(kdev_t, int, int);
1129 extern void ll_rw_block(int, int, struct buffer_head * bh[]);
1130 extern int is_read_only(kdev_t);
1131 extern void __brelse(struct buffer_head *);
1132 static inline void brelse(struct buffer_head *buf)
1134 if (buf)
1135 __brelse(buf);
1137 extern void __bforget(struct buffer_head *);
1138 static inline void bforget(struct buffer_head *buf)
1140 if (buf)
1141 __bforget(buf);
1143 extern void set_blocksize(kdev_t, int);
1144 extern unsigned int get_hardblocksize(kdev_t);
1145 extern struct buffer_head * bread(kdev_t, int, int);
1146 extern struct buffer_head * breada(kdev_t, int, int, unsigned int, unsigned int);
1147 extern void wakeup_bdflush(int wait);
1149 extern int brw_page(int, struct page *, kdev_t, int [], int);
1151 typedef int (get_block_t)(struct inode*,long,struct buffer_head*,int);
1153 /* Generic buffer handling for block filesystems.. */
1154 extern int block_flushpage(struct page *, unsigned long);
1155 extern int block_symlink(struct inode *, const char *, int);
1156 extern int block_write_full_page(struct page*, get_block_t*);
1157 extern int block_read_full_page(struct page*, get_block_t*);
1158 extern int block_prepare_write(struct page*, unsigned, unsigned, get_block_t*);
1159 extern int cont_prepare_write(struct page*, unsigned, unsigned, get_block_t*,
1160 unsigned long *);
1161 extern int block_sync_page(struct page *);
1163 int generic_block_bmap(struct address_space *, long, get_block_t *);
1164 int generic_commit_write(struct file *, struct page *, unsigned, unsigned);
1165 int block_zero_page(struct address_space *mapping, loff_t, unsigned);
1167 extern int generic_file_mmap(struct file *, struct vm_area_struct *);
1168 extern ssize_t generic_file_read(struct file *, char *, size_t, loff_t *);
1169 extern ssize_t generic_file_write(struct file *, const char *, size_t, loff_t *);
1170 extern void do_generic_file_read(struct file *, loff_t *, read_descriptor_t *, read_actor_t);
1172 extern ssize_t generic_read_dir(struct file *, char *, size_t, loff_t *);
1174 extern struct file_operations generic_ro_fops;
1176 extern int vfs_readlink(struct dentry *, char *, int, const char *);
1177 extern int vfs_follow_link(struct nameidata *, const char *);
1178 extern int page_readlink(struct dentry *, char *, int);
1179 extern int page_follow_link(struct dentry *, struct nameidata *);
1180 extern struct inode_operations page_symlink_inode_operations;
1182 extern int vfs_readdir(struct file *, filldir_t, void *);
1183 extern int dcache_readdir(struct file *, void *, filldir_t);
1185 extern struct file_system_type *get_fs_type(const char *name);
1186 extern struct super_block *get_super(kdev_t);
1187 struct super_block *get_empty_super(void);
1188 extern void put_super(kdev_t);
1189 unsigned long generate_cluster(kdev_t, int b[], int);
1190 unsigned long generate_cluster_swab32(kdev_t, int b[], int);
1191 extern kdev_t ROOT_DEV;
1192 extern char root_device_name[];
1195 extern void show_buffers(void);
1196 extern void mount_root(void);
1198 #ifdef CONFIG_BLK_DEV_INITRD
1199 extern kdev_t real_root_dev;
1200 extern int change_root(kdev_t, const char *);
1201 #endif
1203 extern ssize_t char_read(struct file *, char *, size_t, loff_t *);
1204 extern ssize_t block_read(struct file *, char *, size_t, loff_t *);
1205 extern int read_ahead[];
1207 extern ssize_t char_write(struct file *, const char *, size_t, loff_t *);
1208 extern ssize_t block_write(struct file *, const char *, size_t, loff_t *);
1210 extern int file_fsync(struct file *, struct dentry *, int);
1211 extern int generic_buffer_fdatasync(struct inode *inode, unsigned long start_idx, unsigned long end_idx);
1213 extern int inode_change_ok(struct inode *, struct iattr *);
1214 extern void inode_setattr(struct inode *, struct iattr *);
1217 * Common dentry functions for inclusion in the VFS
1218 * or in other stackable file systems. Some of these
1219 * functions were in linux/fs/ C (VFS) files.
1224 * Locking the parent is needed to:
1225 * - serialize directory operations
1226 * - make sure the parent doesn't change from
1227 * under us in the middle of an operation.
1229 * NOTE! Right now we'd rather use a "struct inode"
1230 * for this, but as I expect things to move toward
1231 * using dentries instead for most things it is
1232 * probably better to start with the conceptually
1233 * better interface of relying on a path of dentries.
1235 static inline struct dentry *lock_parent(struct dentry *dentry)
1237 struct dentry *dir = dget(dentry->d_parent);
1239 down(&dir->d_inode->i_sem);
1240 return dir;
1243 static inline struct dentry *get_parent(struct dentry *dentry)
1245 return dget(dentry->d_parent);
1248 static inline void unlock_dir(struct dentry *dir)
1250 up(&dir->d_inode->i_sem);
1251 dput(dir);
1255 * Whee.. Deadlock country. Happily there are only two VFS
1256 * operations that does this..
1258 static inline void double_down(struct semaphore *s1, struct semaphore *s2)
1260 if (s1 != s2) {
1261 if ((unsigned long) s1 < (unsigned long) s2) {
1262 struct semaphore *tmp = s2;
1263 s2 = s1; s1 = tmp;
1265 down(s1);
1267 down(s2);
1271 * Ewwwwwwww... _triple_ lock. We are guaranteed that the 3rd argument is
1272 * not equal to 1st and not equal to 2nd - the first case (target is parent of
1273 * source) would be already caught, the second is plain impossible (target is
1274 * its own parent and that case would be caught even earlier). Very messy.
1275 * I _think_ that it works, but no warranties - please, look it through.
1276 * Pox on bloody lusers who mandated overwriting rename() for directories...
1279 static inline void triple_down(struct semaphore *s1,
1280 struct semaphore *s2,
1281 struct semaphore *s3)
1283 if (s1 != s2) {
1284 if ((unsigned long) s1 < (unsigned long) s2) {
1285 if ((unsigned long) s1 < (unsigned long) s3) {
1286 struct semaphore *tmp = s3;
1287 s3 = s1; s1 = tmp;
1289 if ((unsigned long) s1 < (unsigned long) s2) {
1290 struct semaphore *tmp = s2;
1291 s2 = s1; s1 = tmp;
1293 } else {
1294 if ((unsigned long) s1 < (unsigned long) s3) {
1295 struct semaphore *tmp = s3;
1296 s3 = s1; s1 = tmp;
1298 if ((unsigned long) s2 < (unsigned long) s3) {
1299 struct semaphore *tmp = s3;
1300 s3 = s2; s2 = tmp;
1303 down(s1);
1304 } else if ((unsigned long) s2 < (unsigned long) s3) {
1305 struct semaphore *tmp = s3;
1306 s3 = s2; s2 = tmp;
1308 down(s2);
1309 down(s3);
1312 static inline void double_up(struct semaphore *s1, struct semaphore *s2)
1314 up(s1);
1315 if (s1 != s2)
1316 up(s2);
1319 static inline void triple_up(struct semaphore *s1,
1320 struct semaphore *s2,
1321 struct semaphore *s3)
1323 up(s1);
1324 if (s1 != s2)
1325 up(s2);
1326 up(s3);
1329 static inline void double_lock(struct dentry *d1, struct dentry *d2)
1331 double_down(&d1->d_inode->i_sem, &d2->d_inode->i_sem);
1334 static inline void double_unlock(struct dentry *d1, struct dentry *d2)
1336 double_up(&d1->d_inode->i_sem,&d2->d_inode->i_sem);
1337 dput(d1);
1338 dput(d2);
1341 #endif /* __KERNEL__ */
1343 #endif /* _LINUX_FS_H */