| 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 | * | 
|---|
| 10 | * Some programs (notably those using select()) may have to be | 
|---|
| 11 | * recompiled to take full advantage of the new limits.. | 
|---|
| 12 | */ | 
|---|
| 13 |  | 
|---|
| 14 | #include <linux/types.h> | 
|---|
| 15 | #include <linux/fcntl.h> | 
|---|
| 16 | #include <linux/signal.h> | 
|---|
| 17 | #include <linux/kdev_t.h> | 
|---|
| 18 | #include <linux/wait.h> | 
|---|
| 19 | #include <linux/list.h> | 
|---|
| 20 | #include <linux/dcache.h> | 
|---|
| 21 | #include <linux/vmalloc.h> | 
|---|
| 22 | #include <linux/tqueue.h> | 
|---|
| 23 |  | 
|---|
| 24 | #define FALSE   0 | 
|---|
| 25 | #define TRUE    1 | 
|---|
| 26 |  | 
|---|
| 27 | /* Fixed constants first: */ | 
|---|
| 28 | #undef NR_OPEN | 
|---|
| 29 | #define NR_OPEN (1024*1024)     /* Absolute upper limit on fd num */ | 
|---|
| 30 | #define INR_OPEN 1024           /* Initial setting for nfile rlimits */ | 
|---|
| 31 |  | 
|---|
| 32 | #define BLOCK_SIZE_BITS 10 | 
|---|
| 33 | #define BLOCK_SIZE (1<<BLOCK_SIZE_BITS) | 
|---|
| 34 |  | 
|---|
| 35 | #include <asm/semaphore.h> | 
|---|
| 36 | #include <asm/bitops.h> | 
|---|
| 37 |  | 
|---|
| 38 | #define NR_FILE  8192   /* this can well be larger on a larger system */ | 
|---|
| 39 | #define NR_RESERVED_FILES 10 /* reserved for root */ | 
|---|
| 40 | #define NR_SUPER 256 | 
|---|
| 41 |  | 
|---|
| 42 | #define MAY_EXEC 1 | 
|---|
| 43 | #define MAY_WRITE 2 | 
|---|
| 44 | #define MAY_READ 4 | 
|---|
| 45 |  | 
|---|
| 46 | #define FMODE_READ 1 | 
|---|
| 47 | #define FMODE_WRITE 2 | 
|---|
| 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 */ | 
|---|
| 65 | #define FS_REQUIRES_DEV 1 | 
|---|
| 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; | 
|---|
| 169 | struct file_operations  *f_op; | 
|---|
| 170 | atomic_t                f_count; | 
|---|
| 171 | unsigned int            f_flags; | 
|---|
| 172 | mode_t                  f_mode; | 
|---|
| 173 | loff_t                  f_pos; | 
|---|
| 174 | unsigned long           f_reada, f_ramax, f_raend, f_ralen, f_rawin; | 
|---|
| 175 | struct fown_struct      f_owner; | 
|---|
| 176 | unsigned int            f_uid, f_gid; | 
|---|
| 177 | int                     f_error; | 
|---|
| 178 |  | 
|---|
| 179 | unsigned long           f_version; | 
|---|
| 180 |  | 
|---|
| 181 | /* needed for tty driver, and maybe others */ | 
|---|
| 182 | void                    *private_data; | 
|---|
| 183 | }; | 
|---|
| 184 |  | 
|---|
| 185 | struct inode { | 
|---|
| 186 | #ifdef TARGET_OS2 | 
|---|
| 187 | kdev_t                  i_rdev; | 
|---|
| 188 | struct semaphore        i_sem; | 
|---|
| 189 | #else | 
|---|
| 190 | void * i_hash; | 
|---|
| 191 | void * i_list; | 
|---|
| 192 | void * i_dentry; | 
|---|
| 193 | unsigned long           i_ino; | 
|---|
| 194 | unsigned int            i_count; | 
|---|
| 195 | kdev_t                  i_dev; | 
|---|
| 196 | umode_t                 i_mode; | 
|---|
| 197 | nlink_t                 i_nlink; | 
|---|
| 198 | uid_t                   i_uid; | 
|---|
| 199 | gid_t                   i_gid; | 
|---|
| 200 | kdev_t                  i_rdev; | 
|---|
| 201 | loff_t                  i_size; | 
|---|
| 202 | time_t                  i_atime; | 
|---|
| 203 | time_t                  i_mtime; | 
|---|
| 204 | time_t                  i_ctime; | 
|---|
| 205 | unsigned long           i_blksize; | 
|---|
| 206 | unsigned long           i_blocks; | 
|---|
| 207 | unsigned long           i_version; | 
|---|
| 208 | struct semaphore        i_sem; | 
|---|
| 209 | struct inode_operations *i_op; | 
|---|
| 210 | struct super_block      *i_sb; | 
|---|
| 211 | struct file_lock        *i_flock; | 
|---|
| 212 | struct vm_area_struct   *i_mmap; | 
|---|
| 213 | struct pipe_inode_info  *i_pipe; | 
|---|
| 214 | unsigned long           i_state; | 
|---|
| 215 |  | 
|---|
| 216 | unsigned int            i_flags; | 
|---|
| 217 | unsigned char           i_sock; | 
|---|
| 218 |  | 
|---|
| 219 | atomic_t                i_writecount; | 
|---|
| 220 | unsigned int            i_attr_flags; | 
|---|
| 221 | __u32                   i_generation; | 
|---|
| 222 | union { | 
|---|
| 223 | void                            *generic_ip; | 
|---|
| 224 | } u; | 
|---|
| 225 | #endif | 
|---|
| 226 | }; | 
|---|
| 227 |  | 
|---|
| 228 | typedef int (*filldir_t)(void *, const char *, int, off_t, ino_t); | 
|---|
| 229 |  | 
|---|
| 230 | struct file_operations { | 
|---|
| 231 | loff_t (*llseek) (struct file *, loff_t, int); | 
|---|
| 232 | int (*read) (struct file *, char *, size_t, loff_t *); | 
|---|
| 233 | int (*write) (struct file *, const char *, size_t, loff_t *); | 
|---|
| 234 | int (*readdir) (struct file *, void *, filldir_t); | 
|---|
| 235 | unsigned int (*poll) (struct file *, struct poll_table_struct *); | 
|---|
| 236 | int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long); | 
|---|
| 237 | int (*mmap) (struct file *, struct vm_area_struct *); | 
|---|
| 238 | int (*open) (struct inode *, struct file *); | 
|---|
| 239 | int (*flush) (struct file *); | 
|---|
| 240 | int (*release) (struct inode *, struct file *); | 
|---|
| 241 | int (*fsync) (struct file *, struct dentry *); | 
|---|
| 242 | int (*fasync) (int, struct file *, int); | 
|---|
| 243 | int (*check_media_change) (kdev_t dev); | 
|---|
| 244 | int (*revalidate) (kdev_t dev); | 
|---|
| 245 | int (*lock) (struct file *, int, struct file_lock *); | 
|---|
| 246 | }; | 
|---|
| 247 |  | 
|---|
| 248 | /* Inode state bits.. */ | 
|---|
| 249 | #define I_DIRTY         1 | 
|---|
| 250 | #define I_LOCK          2 | 
|---|
| 251 | #define I_FREEING       4 | 
|---|
| 252 |  | 
|---|
| 253 | #include <linux/poll.h> | 
|---|
| 254 |  | 
|---|
| 255 |  | 
|---|
| 256 | extern int register_chrdev(unsigned int, const char *, struct file_operations *); | 
|---|
| 257 | extern int unregister_chrdev(unsigned int, const char *); | 
|---|
| 258 |  | 
|---|
| 259 | extern int fasync_helper(int, struct file *, int, struct fasync_struct **); | 
|---|
| 260 | extern void kill_fasync(struct fasync_struct *, int, int); | 
|---|
| 261 |  | 
|---|
| 262 | #endif /* _LINUX_FS_H */ | 
|---|