fs.h 16 KB

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