[32] | 1 | #ifndef _LINUX_FS_H
|
---|
| 2 | #define _LINUX_FS_H
|
---|
| 3 |
|
---|
| 4 | /*
|
---|
| 5 | * It's silly to have NR_OPEN bigger than NR_FILE, but you can change
|
---|
| 6 | * the file limit at runtime and only root can increase the per-process
|
---|
| 7 | * nr_file rlimit, so it's safe to set up a ridiculously high absolute
|
---|
| 8 | * upper limit on files-per-process.
|
---|
| 9 | *
|
---|
[598] | 10 | * Some programs (notably those using select()) may have to be
|
---|
| 11 | * recompiled to take full advantage of the new limits..
|
---|
[32] | 12 | */
|
---|
| 13 |
|
---|
[679] | 14 | #include <linux/init.h>
|
---|
[32] | 15 | #include <linux/types.h>
|
---|
| 16 | #include <linux/fcntl.h>
|
---|
| 17 | #include <linux/signal.h>
|
---|
| 18 | #include <linux/kdev_t.h>
|
---|
| 19 | #include <linux/wait.h>
|
---|
| 20 | #include <linux/list.h>
|
---|
| 21 | #include <linux/dcache.h>
|
---|
| 22 | #include <linux/vmalloc.h>
|
---|
[679] | 23 | #include <linux/pid.h>
|
---|
| 24 | #include <linux/err.h>
|
---|
| 25 | #include <linux/workqueue.h>
|
---|
[32] | 26 |
|
---|
| 27 | #define FALSE 0
|
---|
| 28 | #define TRUE 1
|
---|
| 29 |
|
---|
| 30 | /* Fixed constants first: */
|
---|
| 31 | #undef NR_OPEN
|
---|
| 32 | #define NR_OPEN (1024*1024) /* Absolute upper limit on fd num */
|
---|
| 33 | #define INR_OPEN 1024 /* Initial setting for nfile rlimits */
|
---|
| 34 |
|
---|
| 35 | #define BLOCK_SIZE_BITS 10
|
---|
| 36 | #define BLOCK_SIZE (1<<BLOCK_SIZE_BITS)
|
---|
| 37 |
|
---|
| 38 | #include <asm/semaphore.h>
|
---|
| 39 | #include <asm/bitops.h>
|
---|
| 40 |
|
---|
| 41 | #define NR_FILE 8192 /* this can well be larger on a larger system */
|
---|
| 42 | #define NR_RESERVED_FILES 10 /* reserved for root */
|
---|
| 43 | #define NR_SUPER 256
|
---|
| 44 |
|
---|
| 45 | #define MAY_EXEC 1
|
---|
| 46 | #define MAY_WRITE 2
|
---|
| 47 | #define MAY_READ 4
|
---|
| 48 |
|
---|
| 49 | #define READ 0
|
---|
| 50 | #define WRITE 1
|
---|
| 51 | #define READA 2 /* read-ahead - don't block if no resources */
|
---|
| 52 |
|
---|
| 53 | #define WRITERAW 5 /* raw write - don't play with buffer lists */
|
---|
| 54 |
|
---|
| 55 | #ifndef NULL
|
---|
| 56 | #define NULL ((void *) 0)
|
---|
| 57 | #endif
|
---|
| 58 |
|
---|
| 59 | #define NIL_FILP ((struct file *)0)
|
---|
| 60 | #define SEL_IN 1
|
---|
| 61 | #define SEL_OUT 2
|
---|
| 62 | #define SEL_EX 4
|
---|
| 63 |
|
---|
| 64 | /* public flags for file_system_type */
|
---|
[598] | 65 | #define FS_REQUIRES_DEV 1
|
---|
[32] | 66 | #define FS_NO_DCACHE 2 /* Only dcache the necessary things. */
|
---|
| 67 | #define FS_NO_PRELIM 4 /* prevent preloading of dentries, even if
|
---|
| 68 | * FS_NO_DCACHE is not set.
|
---|
| 69 | */
|
---|
| 70 | #define FS_IBASKET 8 /* FS does callback to free_ibasket() if space gets low. */
|
---|
| 71 |
|
---|
| 72 | /*
|
---|
| 73 | * These are the fs-independent mount-flags: up to 16 flags are supported
|
---|
| 74 | */
|
---|
| 75 | #define MS_RDONLY 1 /* Mount read-only */
|
---|
| 76 | #define MS_NOSUID 2 /* Ignore suid and sgid bits */
|
---|
| 77 | #define MS_NODEV 4 /* Disallow access to device special files */
|
---|
| 78 | #define MS_NOEXEC 8 /* Disallow program execution */
|
---|
| 79 | #define MS_SYNCHRONOUS 16 /* Writes are synced at once */
|
---|
| 80 | #define MS_REMOUNT 32 /* Alter flags of a mounted FS */
|
---|
| 81 | #define MS_MANDLOCK 64 /* Allow mandatory locks on an FS */
|
---|
| 82 | #define S_QUOTA 128 /* Quota initialized for file/directory/symlink */
|
---|
| 83 | #define S_APPEND 256 /* Append-only file */
|
---|
| 84 | #define S_IMMUTABLE 512 /* Immutable file */
|
---|
| 85 | #define MS_NOATIME 1024 /* Do not update access times. */
|
---|
| 86 | #define MS_NODIRATIME 2048 /* Do not update directory access times */
|
---|
| 87 |
|
---|
| 88 | #define MS_ODD_RENAME 32768 /* Temporary stuff; will go away as soon
|
---|
| 89 | * as nfs_rename() will be cleaned up
|
---|
| 90 | */
|
---|
| 91 |
|
---|
| 92 | /*
|
---|
| 93 | * Flags that can be altered by MS_REMOUNT
|
---|
| 94 | */
|
---|
| 95 | #define MS_RMT_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|\
|
---|
| 96 | MS_SYNCHRONOUS|MS_MANDLOCK|MS_NOATIME|MS_NODIRATIME)
|
---|
| 97 |
|
---|
| 98 | /*
|
---|
| 99 | * Magic mount flag number. Has to be or-ed to the flag values.
|
---|
| 100 | */
|
---|
| 101 | #define MS_MGC_VAL 0xC0ED0000 /* magic flag number to indicate "new" flags */
|
---|
| 102 | #define MS_MGC_MSK 0xffff0000 /* magic flag number mask */
|
---|
| 103 |
|
---|
| 104 | /*
|
---|
| 105 | * Note that nosuid etc flags are inode-specific: setting some file-system
|
---|
| 106 | * flags just means all the inodes inherit those flags by default. It might be
|
---|
| 107 | * possible to override it selectively if you really wanted to with some
|
---|
| 108 | * ioctl() that is not currently implemented.
|
---|
| 109 | *
|
---|
| 110 | * Exception: MS_RDONLY is always applied to the entire file system.
|
---|
| 111 | *
|
---|
| 112 | * Unfortunately, it is possible to change a filesystems flags with it mounted
|
---|
| 113 | * with files in use. This means that all of the inodes will not have their
|
---|
| 114 | * i_flags updated. Hence, i_flags no longer inherit the superblock mount
|
---|
| 115 | * flags, so these have to be checked separately. -- rmk@arm.uk.linux.org
|
---|
| 116 | */
|
---|
| 117 | #define __IS_FLG(inode,flg) (((inode)->i_sb && (inode)->i_sb->s_flags & (flg)) \
|
---|
| 118 | || (inode)->i_flags & (flg))
|
---|
| 119 |
|
---|
| 120 | #define IS_RDONLY(inode) (((inode)->i_sb) && ((inode)->i_sb->s_flags & MS_RDONLY))
|
---|
| 121 | #define IS_NOSUID(inode) __IS_FLG(inode, MS_NOSUID)
|
---|
| 122 | #define IS_NODEV(inode) __IS_FLG(inode, MS_NODEV)
|
---|
| 123 | #define IS_NOEXEC(inode) __IS_FLG(inode, MS_NOEXEC)
|
---|
| 124 | #define IS_SYNC(inode) __IS_FLG(inode, MS_SYNCHRONOUS)
|
---|
| 125 | #define IS_MANDLOCK(inode) __IS_FLG(inode, MS_MANDLOCK)
|
---|
| 126 |
|
---|
| 127 | #define IS_QUOTAINIT(inode) ((inode)->i_flags & S_QUOTA)
|
---|
| 128 | #define IS_APPEND(inode) ((inode)->i_flags & S_APPEND)
|
---|
| 129 | #define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE)
|
---|
| 130 | #define IS_NOATIME(inode) __IS_FLG(inode, MS_NOATIME)
|
---|
| 131 | #define IS_NODIRATIME(inode) __IS_FLG(inode, MS_NODIRATIME)
|
---|
| 132 |
|
---|
| 133 |
|
---|
| 134 | /* the read-only stuff doesn't really belong here, but any other place is
|
---|
| 135 | probably as bad and I don't want to create yet another include file. */
|
---|
| 136 |
|
---|
| 137 | #define BLKROSET _IO(0x12,93) /* set device read-only (0 = read-write) */
|
---|
| 138 | #define BLKROGET _IO(0x12,94) /* get read-only status (0 = read_write) */
|
---|
| 139 | #define BLKRRPART _IO(0x12,95) /* re-read partition table */
|
---|
| 140 | #define BLKGETSIZE _IO(0x12,96) /* return device size */
|
---|
| 141 | #define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */
|
---|
| 142 | #define BLKRASET _IO(0x12,98) /* Set read ahead for block device */
|
---|
| 143 | #define BLKRAGET _IO(0x12,99) /* get current read ahead setting */
|
---|
| 144 | #define BLKFRASET _IO(0x12,100)/* set filesystem (mm/filemap.c) read-ahead */
|
---|
| 145 | #define BLKFRAGET _IO(0x12,101)/* get filesystem (mm/filemap.c) read-ahead */
|
---|
| 146 | #define BLKSECTSET _IO(0x12,102)/* set max sectors per request (ll_rw_blk.c) */
|
---|
| 147 | #define BLKSECTGET _IO(0x12,103)/* get max sectors per request (ll_rw_blk.c) */
|
---|
| 148 | #define BLKSSZGET _IO(0x12,104)/* get block device sector size */
|
---|
| 149 | #if 0
|
---|
| 150 | #define BLKPG _IO(0x12,105)/* See blkpg.h */
|
---|
| 151 | /* This was here just to show that the number is taken -
|
---|
| 152 | probably all these _IO(0x12,*) ioctls should be moved to blkpg.h. */
|
---|
| 153 | #endif
|
---|
| 154 |
|
---|
| 155 |
|
---|
| 156 | #define BMAP_IOCTL 1 /* obsolete - kept for compatibility */
|
---|
| 157 | #define FIBMAP _IO(0x00,1) /* bmap access */
|
---|
| 158 | #define FIGETBSZ _IO(0x00,2) /* get the block size used for bmap */
|
---|
| 159 |
|
---|
| 160 | struct fown_struct {
|
---|
| 161 | int pid; /* pid or -pgrp where SIGIO should be sent */
|
---|
| 162 | uid_t uid, euid; /* uid/euid of process setting the owner */
|
---|
| 163 | int signum; /* posix.1b rt signal to be delivered on IO */
|
---|
| 164 | };
|
---|
| 165 |
|
---|
| 166 | struct file {
|
---|
| 167 | void * f_list;
|
---|
| 168 | struct dentry *f_dentry;
|
---|
[679] | 169 | const struct file_operations *f_op;
|
---|
| 170 | struct inode *f_inode; /* cached value */
|
---|
| 171 | spinlock_t f_lock;
|
---|
[32] | 172 | atomic_t f_count;
|
---|
| 173 | unsigned int f_flags;
|
---|
| 174 | mode_t f_mode;
|
---|
| 175 | loff_t f_pos;
|
---|
| 176 | unsigned long f_reada, f_ramax, f_raend, f_ralen, f_rawin;
|
---|
| 177 | struct fown_struct f_owner;
|
---|
| 178 | unsigned int f_uid, f_gid;
|
---|
| 179 | int f_error;
|
---|
| 180 |
|
---|
| 181 | unsigned long f_version;
|
---|
| 182 |
|
---|
| 183 | /* needed for tty driver, and maybe others */
|
---|
| 184 | void *private_data;
|
---|
| 185 | };
|
---|
| 186 |
|
---|
| 187 | struct inode {
|
---|
| 188 | void * i_hash;
|
---|
| 189 | void * i_list;
|
---|
| 190 | void * i_dentry;
|
---|
| 191 | unsigned long i_ino;
|
---|
| 192 | unsigned int i_count;
|
---|
| 193 | kdev_t i_dev;
|
---|
| 194 | umode_t i_mode;
|
---|
| 195 | nlink_t i_nlink;
|
---|
| 196 | uid_t i_uid;
|
---|
| 197 | gid_t i_gid;
|
---|
| 198 | kdev_t i_rdev;
|
---|
| 199 | loff_t i_size;
|
---|
| 200 | time_t i_atime;
|
---|
| 201 | time_t i_mtime;
|
---|
| 202 | time_t i_ctime;
|
---|
| 203 | unsigned long i_blksize;
|
---|
| 204 | unsigned long i_blocks;
|
---|
| 205 | unsigned long i_version;
|
---|
| 206 | struct semaphore i_sem;
|
---|
| 207 | struct inode_operations *i_op;
|
---|
| 208 | struct super_block *i_sb;
|
---|
| 209 | struct file_lock *i_flock;
|
---|
| 210 | struct vm_area_struct *i_mmap;
|
---|
| 211 | struct pipe_inode_info *i_pipe;
|
---|
| 212 | unsigned long i_state;
|
---|
| 213 |
|
---|
| 214 | unsigned int i_flags;
|
---|
| 215 | unsigned char i_sock;
|
---|
| 216 |
|
---|
| 217 | atomic_t i_writecount;
|
---|
| 218 | unsigned int i_attr_flags;
|
---|
| 219 | __u32 i_generation;
|
---|
| 220 | union {
|
---|
| 221 | void *generic_ip;
|
---|
| 222 | } u;
|
---|
| 223 | };
|
---|
| 224 |
|
---|
| 225 | typedef int (*filldir_t)(void *, const char *, int, off_t, ino_t);
|
---|
| 226 |
|
---|
| 227 | struct file_operations {
|
---|
[445] | 228 | struct module *owner;
|
---|
[32] | 229 | loff_t (*llseek) (struct file *, loff_t, int);
|
---|
| 230 | int (*read) (struct file *, char *, size_t, loff_t *);
|
---|
| 231 | int (*write) (struct file *, const char *, size_t, loff_t *);
|
---|
[679] | 232 | ssize_t (*read_iter) (struct kiocb *, struct iov_iter *);
|
---|
| 233 | ssize_t (*write_iter) (struct kiocb *, struct iov_iter *);
|
---|
[32] | 234 | int (*readdir) (struct file *, void *, filldir_t);
|
---|
| 235 | unsigned int (*poll) (struct file *, struct poll_table_struct *);
|
---|
[679] | 236 | long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
|
---|
| 237 | long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
|
---|
[32] | 238 | int (*mmap) (struct file *, struct vm_area_struct *);
|
---|
| 239 | int (*open) (struct inode *, struct file *);
|
---|
| 240 | int (*flush) (struct file *);
|
---|
| 241 | int (*release) (struct inode *, struct file *);
|
---|
| 242 | int (*fsync) (struct file *, struct dentry *);
|
---|
| 243 | int (*fasync) (int, struct file *, int);
|
---|
| 244 | int (*check_media_change) (kdev_t dev);
|
---|
| 245 | int (*revalidate) (kdev_t dev);
|
---|
| 246 | int (*lock) (struct file *, int, struct file_lock *);
|
---|
| 247 | };
|
---|
| 248 |
|
---|
| 249 | /* Inode state bits.. */
|
---|
| 250 | #define I_DIRTY 1
|
---|
| 251 | #define I_LOCK 2
|
---|
| 252 | #define I_FREEING 4
|
---|
| 253 |
|
---|
| 254 | #include <linux/poll.h>
|
---|
| 255 |
|
---|
| 256 |
|
---|
[679] | 257 | extern int register_chrdev(unsigned int, const char *, const struct file_operations *);
|
---|
[32] | 258 | extern int unregister_chrdev(unsigned int, const char *);
|
---|
| 259 |
|
---|
| 260 | extern int fasync_helper(int, struct file *, int, struct fasync_struct **);
|
---|
[679] | 261 | extern void kill_fasync(struct fasync_struct **, int, int);
|
---|
[32] | 262 |
|
---|
[446] | 263 |
|
---|
[679] | 264 | /* Alas, no aliases. Too much hassle with bringing module.h everywhere */
|
---|
| 265 | #define fops_get(fops) \
|
---|
| 266 | (((fops) && try_module_get((fops)->owner) ? (fops) : NULL))
|
---|
| 267 | #define fops_put(fops) \
|
---|
| 268 | do { if (fops) module_put((fops)->owner); } while(0)
|
---|
| 269 | /*
|
---|
| 270 | * This one is to be used *ONLY* from ->open() instances.
|
---|
| 271 | * fops must be non-NULL, pinned down *and* module dependencies
|
---|
| 272 | * should be sufficient to pin the caller down as well.
|
---|
| 273 | */
|
---|
| 274 | #define replace_fops(f, fops) \
|
---|
| 275 | do { \
|
---|
| 276 | struct file *__file = (f); \
|
---|
| 277 | fops_put(__file->f_op); \
|
---|
| 278 | } while(0)
|
---|
| 279 |
|
---|
[446] | 280 | #define minor(a) MINOR(a)
|
---|
| 281 | #define major(a) MAJOR(a)
|
---|
| 282 | #define iminor(x) minor((x)->i_rdev)
|
---|
[441] | 283 | #define imajor(x) major((x)->i_rdev)
|
---|
| 284 |
|
---|
[598] | 285 | #define no_llseek NULL
|
---|
| 286 | #define nonseekable_open(i,f) 0
|
---|
| 287 |
|
---|
[679] | 288 | struct kiocb {
|
---|
| 289 | struct file *ki_filp;
|
---|
| 290 | loff_t ki_pos;
|
---|
| 291 | void (*ki_complete)(struct kiocb *iocb, long ret, long ret2);
|
---|
| 292 | void *private;
|
---|
| 293 | int ki_flags;
|
---|
| 294 | };
|
---|
| 295 |
|
---|
| 296 | extern int stream_open(struct inode * inode, struct file * filp);
|
---|
| 297 |
|
---|
| 298 | /*
|
---|
| 299 | * flags in file.f_mode. Note that FMODE_READ and FMODE_WRITE must correspond
|
---|
| 300 | * to O_WRONLY and O_RDWR via the strange trick in do_dentry_open()
|
---|
| 301 | */
|
---|
| 302 |
|
---|
| 303 | /* file is open for reading */
|
---|
| 304 | #define FMODE_READ (( fmode_t)0x1)
|
---|
| 305 | /* file is open for writing */
|
---|
| 306 | #define FMODE_WRITE (( fmode_t)0x2)
|
---|
| 307 | /* file is seekable */
|
---|
| 308 | #define FMODE_LSEEK (( fmode_t)0x4)
|
---|
| 309 | /* file can be accessed using pread */
|
---|
| 310 | #define FMODE_PREAD (( fmode_t)0x8)
|
---|
| 311 | /* file can be accessed using pwrite */
|
---|
| 312 | #define FMODE_PWRITE (( fmode_t)0x10)
|
---|
| 313 | /* File is opened for execution with sys_execve / sys_uselib */
|
---|
| 314 | #define FMODE_EXEC (( fmode_t)0x20)
|
---|
| 315 | /* File is opened with O_NDELAY (only set for block devices) */
|
---|
| 316 | #define FMODE_NDELAY (( fmode_t)0x40)
|
---|
| 317 | /* File is opened with O_EXCL (only set for block devices) */
|
---|
| 318 | #define FMODE_EXCL (( fmode_t)0x80)
|
---|
| 319 | /* File is opened using open(.., 3, ..) and is writeable only for ioctls
|
---|
| 320 | (specialy hack for floppy.c) */
|
---|
| 321 | #define FMODE_WRITE_IOCTL (( fmode_t)0x100)
|
---|
| 322 | /* 32bit hashes as llseek() offset (for directories) */
|
---|
| 323 | #define FMODE_32BITHASH (( fmode_t)0x200)
|
---|
| 324 | /* 64bit hashes as llseek() offset (for directories) */
|
---|
| 325 | #define FMODE_64BITHASH (( fmode_t)0x400)
|
---|
| 326 |
|
---|
| 327 | /* File needs atomic accesses to f_pos */
|
---|
| 328 | #define FMODE_ATOMIC_POS (( fmode_t)0x8000)
|
---|
| 329 |
|
---|
| 330 | /* File is stream-like */
|
---|
| 331 | #define FMODE_STREAM (( fmode_t)0x200000)
|
---|
| 332 |
|
---|
| 333 | static inline struct inode *file_inode(const struct file *f)
|
---|
| 334 | {
|
---|
| 335 | return f->f_inode;
|
---|
| 336 | }
|
---|
| 337 |
|
---|
[772] | 338 | #define MAX_RW_COUNT (INT_MAX & PAGE_MASK)
|
---|
| 339 |
|
---|
[32] | 340 | #endif /* _LINUX_FS_H */
|
---|