fs.h 13 KB

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