1 #ifndef _LINUX_FS_H 2 #define _LINUX_FS_H 3 4 /* 5 * This file has definitions for some important file table 6 * structures etc. 7 */ 8 9 #include <linux/limits.h> 10 #include <linux/ioctl.h> 11 #include <linux/blk_types.h> 12 #include <linux/types.h> 13 14 /* 15 * It's silly to have NR_OPEN bigger than NR_FILE, but you can change 16 * the file limit at runtime and only root can increase the per-process 17 * nr_file rlimit, so it's safe to set up a ridiculously high absolute 18 * upper limit on files-per-process. 19 * 20 * Some programs (notably those using select()) may have to be 21 * recompiled to take full advantage of the new limits.. 22 */ 23 24 /* Fixed constants first: */ 25 #undef NR_OPEN 26 #define INR_OPEN_CUR 1024 /* Initial setting for nfile rlimits */ 27 #define INR_OPEN_MAX 4096 /* Hard limit for nfile rlimits */ 28 29 #define BLOCK_SIZE_BITS 10 30 #define BLOCK_SIZE (1<<BLOCK_SIZE_BITS) 31 32 #define SEEK_SET 0 /* seek relative to beginning of file */ 33 #define SEEK_CUR 1 /* seek relative to current file position */ 34 #define SEEK_END 2 /* seek relative to end of file */ 35 #define SEEK_DATA 3 /* seek to the next data */ 36 #define SEEK_HOLE 4 /* seek to the next hole */ 37 #define SEEK_MAX SEEK_HOLE 38 39 struct fstrim_range { 40 __u64 start; 41 __u64 len; 42 __u64 minlen; 43 }; 44 45 /* And dynamically-tunable limits and defaults: */ 46 struct files_stat_struct { 47 unsigned long nr_files; /* read only */ 48 unsigned long nr_free_files; /* read only */ 49 unsigned long max_files; /* tunable */ 50 }; 51 52 struct inodes_stat_t { 53 int nr_inodes; 54 int nr_unused; 55 int dummy[5]; /* padding for sysctl ABI compatibility */ 56 }; 57 58 59 #define NR_FILE 8192 /* this can well be larger on a larger system */ 60 61 #define MAY_EXEC 0x00000001 62 #define MAY_WRITE 0x00000002 63 #define MAY_READ 0x00000004 64 #define MAY_APPEND 0x00000008 65 #define MAY_ACCESS 0x00000010 66 #define MAY_OPEN 0x00000020 67 #define MAY_CHDIR 0x00000040 68 /* called from RCU mode, don't block */ 69 #define MAY_NOT_BLOCK 0x00000080 70 71 /* 72 * flags in file.f_mode. Note that FMODE_READ and FMODE_WRITE must correspond 73 * to O_WRONLY and O_RDWR via the strange trick in __dentry_open() 74 */ 75 76 /* file is open for reading */ 77 #define FMODE_READ ((fmode_t)0x1) 78 /* file is open for writing */ 79 #define FMODE_WRITE ((fmode_t)0x2) 80 /* file is seekable */ 81 #define FMODE_LSEEK ((fmode_t)0x4) 82 /* file can be accessed using pread */ 83 #define FMODE_PREAD ((fmode_t)0x8) 84 /* file can be accessed using pwrite */ 85 #define FMODE_PWRITE ((fmode_t)0x10) 86 /* File is opened for execution with sys_execve / sys_uselib */ 87 #define FMODE_EXEC ((fmode_t)0x20) 88 /* File is opened with O_NDELAY (only set for block devices) */ 89 #define FMODE_NDELAY ((fmode_t)0x40) 90 /* File is opened with O_EXCL (only set for block devices) */ 91 #define FMODE_EXCL ((fmode_t)0x80) 92 /* File is opened using open(.., 3, ..) and is writeable only for ioctls 93 (specialy hack for floppy.c) */ 94 #define FMODE_WRITE_IOCTL ((fmode_t)0x100) 95 96 /* 97 * Don't update ctime and mtime. 98 * 99 * Currently a special hack for the XFS open_by_handle ioctl, but we'll 100 * hopefully graduate it to a proper O_CMTIME flag supported by open(2) soon. 101 */ 102 #define FMODE_NOCMTIME ((fmode_t)0x800) 103 104 /* Expect random access pattern */ 105 #define FMODE_RANDOM ((fmode_t)0x1000) 106 107 /* File is huge (eg. /dev/kmem): treat loff_t as unsigned */ 108 #define FMODE_UNSIGNED_OFFSET ((fmode_t)0x2000) 109 110 /* File is opened with O_PATH; almost nothing can be done with it */ 111 #define FMODE_PATH ((fmode_t)0x4000) 112 113 /* File was opened by fanotify and shouldn't generate fanotify events */ 114 #define FMODE_NONOTIFY ((fmode_t)0x1000000) 115 116 /* 117 * The below are the various read and write types that we support. Some of 118 * them include behavioral modifiers that send information down to the 119 * block layer and IO scheduler. Terminology: 120 * 121 * The block layer uses device plugging to defer IO a little bit, in 122 * the hope that we will see more IO very shortly. This increases 123 * coalescing of adjacent IO and thus reduces the number of IOs we 124 * have to send to the device. It also allows for better queuing, 125 * if the IO isn't mergeable. If the caller is going to be waiting 126 * for the IO, then he must ensure that the device is unplugged so 127 * that the IO is dispatched to the driver. 128 * 129 * All IO is handled async in Linux. This is fine for background 130 * writes, but for reads or writes that someone waits for completion 131 * on, we want to notify the block layer and IO scheduler so that they 132 * know about it. That allows them to make better scheduling 133 * decisions. So when the below references 'sync' and 'async', it 134 * is referencing this priority hint. 135 * 136 * With that in mind, the available types are: 137 * 138 * READ A normal read operation. Device will be plugged. 139 * READ_SYNC A synchronous read. Device is not plugged, caller can 140 * immediately wait on this read without caring about 141 * unplugging. 142 * READA Used for read-ahead operations. Lower priority, and the 143 * block layer could (in theory) choose to ignore this 144 * request if it runs into resource problems. 145 * WRITE A normal async write. Device will be plugged. 146 * WRITE_SYNC Synchronous write. Identical to WRITE, but passes down 147 * the hint that someone will be waiting on this IO 148 * shortly. The write equivalent of READ_SYNC. 149 * WRITE_ODIRECT Special case write for O_DIRECT only. 150 * WRITE_FLUSH Like WRITE_SYNC but with preceding cache flush. 151 * WRITE_FUA Like WRITE_SYNC but data is guaranteed to be on 152 * non-volatile media on completion. 153 * WRITE_FLUSH_FUA Combination of WRITE_FLUSH and FUA. The IO is preceded 154 * by a cache flush and data is guaranteed to be on 155 * non-volatile media on completion. 156 * 157 */ 158 #define RW_MASK REQ_WRITE 159 #define RWA_MASK REQ_RAHEAD 160 161 #define READ 0 162 #define WRITE RW_MASK 163 #define READA RWA_MASK 164 165 #define READ_SYNC (READ | REQ_SYNC) 166 #define WRITE_SYNC (WRITE | REQ_SYNC | REQ_NOIDLE) 167 #define WRITE_ODIRECT (WRITE | REQ_SYNC) 168 #define WRITE_FLUSH (WRITE | REQ_SYNC | REQ_NOIDLE | REQ_FLUSH) 169 #define WRITE_FUA (WRITE | REQ_SYNC | REQ_NOIDLE | REQ_FUA) 170 #define WRITE_FLUSH_FUA (WRITE | REQ_SYNC | REQ_NOIDLE | REQ_FLUSH | REQ_FUA) 171 172 #define SEL_IN 1 173 #define SEL_OUT 2 174 #define SEL_EX 4 175 176 /* public flags for file_system_type */ 177 #define FS_REQUIRES_DEV 1 178 #define FS_BINARY_MOUNTDATA 2 179 #define FS_HAS_SUBTYPE 4 180 #define FS_REVAL_DOT 16384 /* Check the paths ".", ".." for staleness */ 181 #define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move() 182 * during rename() internally. 183 */ 184 185 /* 186 * These are the fs-independent mount-flags: up to 32 flags are supported 187 */ 188 #define MS_RDONLY 1 /* Mount read-only */ 189 #define MS_NOSUID 2 /* Ignore suid and sgid bits */ 190 #define MS_NODEV 4 /* Disallow access to device special files */ 191 #define MS_NOEXEC 8 /* Disallow program execution */ 192 #define MS_SYNCHRONOUS 16 /* Writes are synced at once */ 193 #define MS_REMOUNT 32 /* Alter flags of a mounted FS */ 194 #define MS_MANDLOCK 64 /* Allow mandatory locks on an FS */ 195 #define MS_DIRSYNC 128 /* Directory modifications are synchronous */ 196 #define MS_NOATIME 1024 /* Do not update access times. */ 197 #define MS_NODIRATIME 2048 /* Do not update directory access times */ 198 #define MS_BIND 4096 199 #define MS_MOVE 8192 200 #define MS_REC 16384 201 #define MS_VERBOSE 32768 /* War is peace. Verbosity is silence. 202 MS_VERBOSE is deprecated. */ 203 #define MS_SILENT 32768 204 #define MS_POSIXACL (1<<16) /* VFS does not apply the umask */ 205 #define MS_UNBINDABLE (1<<17) /* change to unbindable */ 206 #define MS_PRIVATE (1<<18) /* change to private */ 207 #define MS_SLAVE (1<<19) /* change to slave */ 208 #define MS_SHARED (1<<20) /* change to shared */ 209 #define MS_RELATIME (1<<21) /* Update atime relative to mtime/ctime. */ 210 #define MS_KERNMOUNT (1<<22) /* this is a kern_mount call */ 211 #define MS_I_VERSION (1<<23) /* Update inode I_version field */ 212 #define MS_STRICTATIME (1<<24) /* Always perform atime updates */ 213 #define MS_NOSEC (1<<28) 214 #define MS_BORN (1<<29) 215 #define MS_ACTIVE (1<<30) 216 #define MS_NOUSER (1<<31) 217 218 /* 219 * Superblock flags that can be altered by MS_REMOUNT 220 */ 221 #define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_I_VERSION) 222 223 /* 224 * Old magic mount flag and mask 225 */ 226 #define MS_MGC_VAL 0xC0ED0000 227 #define MS_MGC_MSK 0xffff0000 228 229 /* Inode flags - they have nothing to superblock flags now */ 230 231 #define S_SYNC 1 /* Writes are synced at once */ 232 #define S_NOATIME 2 /* Do not update access times */ 233 #define S_APPEND 4 /* Append-only file */ 234 #define S_IMMUTABLE 8 /* Immutable file */ 235 #define S_DEAD 16 /* removed, but still open directory */ 236 #define S_NOQUOTA 32 /* Inode is not counted to quota */ 237 #define S_DIRSYNC 64 /* Directory modifications are synchronous */ 238 #define S_NOCMTIME 128 /* Do not update file c/mtime */ 239 #define S_SWAPFILE 256 /* Do not truncate: swapon got its bmaps */ 240 #define S_PRIVATE 512 /* Inode is fs-internal */ 241 #define S_IMA 1024 /* Inode has an associated IMA struct */ 242 #define S_AUTOMOUNT 2048 /* Automount/referral quasi-directory */ 243 #define S_NOSEC 4096 /* no suid or xattr security attributes */ 244 245 /* 246 * Note that nosuid etc flags are inode-specific: setting some file-system 247 * flags just means all the inodes inherit those flags by default. It might be 248 * possible to override it selectively if you really wanted to with some 249 * ioctl() that is not currently implemented. 250 * 251 * Exception: MS_RDONLY is always applied to the entire file system. 252 * 253 * Unfortunately, it is possible to change a filesystems flags with it mounted 254 * with files in use. This means that all of the inodes will not have their 255 * i_flags updated. Hence, i_flags no longer inherit the superblock mount 256 * flags, so these have to be checked separately. -- rmk (at) arm.uk.linux.org 257 */ 258 #define __IS_FLG(inode,flg) ((inode)->i_sb->s_flags & (flg)) 259 260 #define IS_RDONLY(inode) ((inode)->i_sb->s_flags & MS_RDONLY) 261 #define IS_SYNC(inode) (__IS_FLG(inode, MS_SYNCHRONOUS) || \ 262 ((inode)->i_flags & S_SYNC)) 263 #define IS_DIRSYNC(inode) (__IS_FLG(inode, MS_SYNCHRONOUS|MS_DIRSYNC) || \ 264 ((inode)->i_flags & (S_SYNC|S_DIRSYNC))) 265 #define IS_MANDLOCK(inode) __IS_FLG(inode, MS_MANDLOCK) 266 #define IS_NOATIME(inode) __IS_FLG(inode, MS_RDONLY|MS_NOATIME) 267 #define IS_I_VERSION(inode) __IS_FLG(inode, MS_I_VERSION) 268 269 #define IS_NOQUOTA(inode) ((inode)->i_flags & S_NOQUOTA) 270 #define IS_APPEND(inode) ((inode)->i_flags & S_APPEND) 271 #define IS_IMMUTABLE(inode) ((inode)->i_flags & S_IMMUTABLE) 272 #define IS_POSIXACL(inode) __IS_FLG(inode, MS_POSIXACL) 273 274 #define IS_DEADDIR(inode) ((inode)->i_flags & S_DEAD) 275 #define IS_NOCMTIME(inode) ((inode)->i_flags & S_NOCMTIME) 276 #define IS_SWAPFILE(inode) ((inode)->i_flags & S_SWAPFILE) 277 #define IS_PRIVATE(inode) ((inode)->i_flags & S_PRIVATE) 278 #define IS_IMA(inode) ((inode)->i_flags & S_IMA) 279 #define IS_AUTOMOUNT(inode) ((inode)->i_flags & S_AUTOMOUNT) 280 #define IS_NOSEC(inode) ((inode)->i_flags & S_NOSEC) 281 282 /* the read-only stuff doesn't really belong here, but any other place is 283 probably as bad and I don't want to create yet another include file. */ 284 285 #define BLKROSET _IO(0x12,93) /* set device read-only (0 = read-write) */ 286 #define BLKROGET _IO(0x12,94) /* get read-only status (0 = read_write) */ 287 #define BLKRRPART _IO(0x12,95) /* re-read partition table */ 288 #define BLKGETSIZE _IO(0x12,96) /* return device size /512 (long *arg) */ 289 #define BLKFLSBUF _IO(0x12,97) /* flush buffer cache */ 290 #define BLKRASET _IO(0x12,98) /* set read ahead for block device */ 291 #define BLKRAGET _IO(0x12,99) /* get current read ahead setting */ 292 #define BLKFRASET _IO(0x12,100)/* set filesystem (mm/filemap.c) read-ahead */ 293 #define BLKFRAGET _IO(0x12,101)/* get filesystem (mm/filemap.c) read-ahead */ 294 #define BLKSECTSET _IO(0x12,102)/* set max sectors per request (ll_rw_blk.c) */ 295 #define BLKSECTGET _IO(0x12,103)/* get max sectors per request (ll_rw_blk.c) */ 296 #define BLKSSZGET _IO(0x12,104)/* get block device sector size */ 297 #if 0 298 #define BLKPG _IO(0x12,105)/* See blkpg.h */ 299 300 /* Some people are morons. Do not use sizeof! */ 301 302 #define BLKELVGET _IOR(0x12,106,size_t)/* elevator get */ 303 #define BLKELVSET _IOW(0x12,107,size_t)/* elevator set */ 304 /* This was here just to show that the number is taken - 305 probably all these _IO(0x12,*) ioctls should be moved to blkpg.h. */ 306 #endif 307 /* A jump here: 108-111 have been used for various private purposes. */ 308 #define BLKBSZGET _IOR(0x12,112,size_t) 309 #define BLKBSZSET _IOW(0x12,113,size_t) 310 #define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size in bytes (u64 *arg) */ 311 #define BLKTRACESETUP _IOWR(0x12,115,struct blk_user_trace_setup) 312 #define BLKTRACESTART _IO(0x12,116) 313 #define BLKTRACESTOP _IO(0x12,117) 314 #define BLKTRACETEARDOWN _IO(0x12,118) 315 #define BLKDISCARD _IO(0x12,119) 316 #define BLKIOMIN _IO(0x12,120) 317 #define BLKIOOPT _IO(0x12,121) 318 #define BLKALIGNOFF _IO(0x12,122) 319 #define BLKPBSZGET _IO(0x12,123) 320 #define BLKDISCARDZEROES _IO(0x12,124) 321 #define BLKSECDISCARD _IO(0x12,125) 322 323 #define BMAP_IOCTL 1 /* obsolete - kept for compatibility */ 324 #define FIBMAP _IO(0x00,1) /* bmap access */ 325 #define FIGETBSZ _IO(0x00,2) /* get the block size used for bmap */ 326 #define FIFREEZE _IOWR('X', 119, int) /* Freeze */ 327 #define FITHAW _IOWR('X', 120, int) /* Thaw */ 328 #define FITRIM _IOWR('X', 121, struct fstrim_range) /* Trim */ 329 330 #define FS_IOC_GETFLAGS _IOR('f', 1, long) 331 #define FS_IOC_SETFLAGS _IOW('f', 2, long) 332 #define FS_IOC_GETVERSION _IOR('v', 1, long) 333 #define FS_IOC_SETVERSION _IOW('v', 2, long) 334 #define FS_IOC_FIEMAP _IOWR('f', 11, struct fiemap) 335 #define FS_IOC32_GETFLAGS _IOR('f', 1, int) 336 #define FS_IOC32_SETFLAGS _IOW('f', 2, int) 337 #define FS_IOC32_GETVERSION _IOR('v', 1, int) 338 #define FS_IOC32_SETVERSION _IOW('v', 2, int) 339 340 /* 341 * Inode flags (FS_IOC_GETFLAGS / FS_IOC_SETFLAGS) 342 */ 343 #define FS_SECRM_FL 0x00000001 /* Secure deletion */ 344 #define FS_UNRM_FL 0x00000002 /* Undelete */ 345 #define FS_COMPR_FL 0x00000004 /* Compress file */ 346 #define FS_SYNC_FL 0x00000008 /* Synchronous updates */ 347 #define FS_IMMUTABLE_FL 0x00000010 /* Immutable file */ 348 #define FS_APPEND_FL 0x00000020 /* writes to file may only append */ 349 #define FS_NODUMP_FL 0x00000040 /* do not dump file */ 350 #define FS_NOATIME_FL 0x00000080 /* do not update atime */ 351 /* Reserved for compression usage... */ 352 #define FS_DIRTY_FL 0x00000100 353 #define FS_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */ 354 #define FS_NOCOMP_FL 0x00000400 /* Don't compress */ 355 #define FS_ECOMPR_FL 0x00000800 /* Compression error */ 356 /* End compression flags --- maybe not all used */ 357 #define FS_BTREE_FL 0x00001000 /* btree format dir */ 358 #define FS_INDEX_FL 0x00001000 /* hash-indexed directory */ 359 #define FS_IMAGIC_FL 0x00002000 /* AFS directory */ 360 #define FS_JOURNAL_DATA_FL 0x00004000 /* Reserved for ext3 */ 361 #define FS_NOTAIL_FL 0x00008000 /* file tail should not be merged */ 362 #define FS_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */ 363 #define FS_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/ 364 #define FS_EXTENT_FL 0x00080000 /* Extents */ 365 #define FS_DIRECTIO_FL 0x00100000 /* Use direct i/o */ 366 #define FS_NOCOW_FL 0x00800000 /* Do not cow file */ 367 #define FS_RESERVED_FL 0x80000000 /* reserved for ext2 lib */ 368 369 #define FS_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */ 370 #define FS_FL_USER_MODIFIABLE 0x000380FF /* User modifiable flags */ 371 372 373 #define SYNC_FILE_RANGE_WAIT_BEFORE 1 374 #define SYNC_FILE_RANGE_WRITE 2 375 #define SYNC_FILE_RANGE_WAIT_AFTER 4 376 377 #endif /* _LINUX_FS_H */ 378