PageRenderTime 50ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/fs/ext4/ext4.h

https://github.com/mstsirkin/linux
C Header | 1376 lines | 946 code | 129 blank | 301 comment | 29 complexity | 15798e5c50300f04c9d9692a091036f8 MD5 | raw file
  1. /*
  2. * ext4.h
  3. *
  4. * Copyright (C) 1992, 1993, 1994, 1995
  5. * Remy Card (card@masi.ibp.fr)
  6. * Laboratoire MASI - Institut Blaise Pascal
  7. * Universite Pierre et Marie Curie (Paris VI)
  8. *
  9. * from
  10. *
  11. * linux/include/linux/minix_fs.h
  12. *
  13. * Copyright (C) 1991, 1992 Linus Torvalds
  14. */
  15. #ifndef _EXT4_H
  16. #define _EXT4_H
  17. #include <linux/types.h>
  18. #include <linux/blkdev.h>
  19. #include <linux/magic.h>
  20. #include <linux/jbd2.h>
  21. #include <linux/quota.h>
  22. #include <linux/rwsem.h>
  23. #include <linux/rbtree.h>
  24. #include <linux/seqlock.h>
  25. #include <linux/mutex.h>
  26. #include <linux/timer.h>
  27. #include <linux/wait.h>
  28. #include <linux/blockgroup_lock.h>
  29. #include <linux/percpu_counter.h>
  30. #ifdef __KERNEL__
  31. #include <linux/compat.h>
  32. #endif
  33. /*
  34. * The fourth extended filesystem constants/structures
  35. */
  36. /*
  37. * Define EXT4FS_DEBUG to produce debug messages
  38. */
  39. #undef EXT4FS_DEBUG
  40. /*
  41. * Debug code
  42. */
  43. #ifdef EXT4FS_DEBUG
  44. #define ext4_debug(f, a...) \
  45. do { \
  46. printk(KERN_DEBUG "EXT4-fs DEBUG (%s, %d): %s:", \
  47. __FILE__, __LINE__, __func__); \
  48. printk(KERN_DEBUG f, ## a); \
  49. } while (0)
  50. #else
  51. #define ext4_debug(f, a...) do {} while (0)
  52. #endif
  53. #define EXT4_ERROR_INODE(inode, fmt, a...) \
  54. ext4_error_inode((inode), __func__, __LINE__, 0, (fmt), ## a)
  55. #define EXT4_ERROR_INODE_BLOCK(inode, block, fmt, a...) \
  56. ext4_error_inode((inode), __func__, __LINE__, (block), (fmt), ## a)
  57. #define EXT4_ERROR_FILE(file, block, fmt, a...) \
  58. ext4_error_file((file), __func__, __LINE__, (block), (fmt), ## a)
  59. /* data type for block offset of block group */
  60. typedef int ext4_grpblk_t;
  61. /* data type for filesystem-wide blocks number */
  62. typedef unsigned long long ext4_fsblk_t;
  63. /* data type for file logical block number */
  64. typedef __u32 ext4_lblk_t;
  65. /* data type for block group number */
  66. typedef unsigned int ext4_group_t;
  67. /*
  68. * Flags used in mballoc's allocation_context flags field.
  69. *
  70. * Also used to show what's going on for debugging purposes when the
  71. * flag field is exported via the traceport interface
  72. */
  73. /* prefer goal again. length */
  74. #define EXT4_MB_HINT_MERGE 0x0001
  75. /* blocks already reserved */
  76. #define EXT4_MB_HINT_RESERVED 0x0002
  77. /* metadata is being allocated */
  78. #define EXT4_MB_HINT_METADATA 0x0004
  79. /* first blocks in the file */
  80. #define EXT4_MB_HINT_FIRST 0x0008
  81. /* search for the best chunk */
  82. #define EXT4_MB_HINT_BEST 0x0010
  83. /* data is being allocated */
  84. #define EXT4_MB_HINT_DATA 0x0020
  85. /* don't preallocate (for tails) */
  86. #define EXT4_MB_HINT_NOPREALLOC 0x0040
  87. /* allocate for locality group */
  88. #define EXT4_MB_HINT_GROUP_ALLOC 0x0080
  89. /* allocate goal blocks or none */
  90. #define EXT4_MB_HINT_GOAL_ONLY 0x0100
  91. /* goal is meaningful */
  92. #define EXT4_MB_HINT_TRY_GOAL 0x0200
  93. /* blocks already pre-reserved by delayed allocation */
  94. #define EXT4_MB_DELALLOC_RESERVED 0x0400
  95. /* We are doing stream allocation */
  96. #define EXT4_MB_STREAM_ALLOC 0x0800
  97. /* Use reserved root blocks if needed */
  98. #define EXT4_MB_USE_ROOT_BLOCKS 0x1000
  99. struct ext4_allocation_request {
  100. /* target inode for block we're allocating */
  101. struct inode *inode;
  102. /* how many blocks we want to allocate */
  103. unsigned int len;
  104. /* logical block in target inode */
  105. ext4_lblk_t logical;
  106. /* the closest logical allocated block to the left */
  107. ext4_lblk_t lleft;
  108. /* the closest logical allocated block to the right */
  109. ext4_lblk_t lright;
  110. /* phys. target (a hint) */
  111. ext4_fsblk_t goal;
  112. /* phys. block for the closest logical allocated block to the left */
  113. ext4_fsblk_t pleft;
  114. /* phys. block for the closest logical allocated block to the right */
  115. ext4_fsblk_t pright;
  116. /* flags. see above EXT4_MB_HINT_* */
  117. unsigned int flags;
  118. };
  119. /*
  120. * Logical to physical block mapping, used by ext4_map_blocks()
  121. *
  122. * This structure is used to pass requests into ext4_map_blocks() as
  123. * well as to store the information returned by ext4_map_blocks(). It
  124. * takes less room on the stack than a struct buffer_head.
  125. */
  126. #define EXT4_MAP_NEW (1 << BH_New)
  127. #define EXT4_MAP_MAPPED (1 << BH_Mapped)
  128. #define EXT4_MAP_UNWRITTEN (1 << BH_Unwritten)
  129. #define EXT4_MAP_BOUNDARY (1 << BH_Boundary)
  130. #define EXT4_MAP_UNINIT (1 << BH_Uninit)
  131. #define EXT4_MAP_FLAGS (EXT4_MAP_NEW | EXT4_MAP_MAPPED |\
  132. EXT4_MAP_UNWRITTEN | EXT4_MAP_BOUNDARY |\
  133. EXT4_MAP_UNINIT)
  134. struct ext4_map_blocks {
  135. ext4_fsblk_t m_pblk;
  136. ext4_lblk_t m_lblk;
  137. unsigned int m_len;
  138. unsigned int m_flags;
  139. };
  140. /*
  141. * For delayed allocation tracking
  142. */
  143. struct mpage_da_data {
  144. struct inode *inode;
  145. sector_t b_blocknr; /* start block number of extent */
  146. size_t b_size; /* size of extent */
  147. unsigned long b_state; /* state of the extent */
  148. unsigned long first_page, next_page; /* extent of pages */
  149. struct writeback_control *wbc;
  150. int io_done;
  151. int pages_written;
  152. int retval;
  153. };
  154. /*
  155. * Flags for ext4_io_end->flags
  156. */
  157. #define EXT4_IO_END_UNWRITTEN 0x0001
  158. #define EXT4_IO_END_ERROR 0x0002
  159. #define EXT4_IO_END_QUEUED 0x0004
  160. struct ext4_io_page {
  161. struct page *p_page;
  162. atomic_t p_count;
  163. };
  164. #define MAX_IO_PAGES 128
  165. typedef struct ext4_io_end {
  166. struct list_head list; /* per-file finished IO list */
  167. struct inode *inode; /* file being written to */
  168. unsigned int flag; /* unwritten or not */
  169. struct page *page; /* page struct for buffer write */
  170. loff_t offset; /* offset in the file */
  171. ssize_t size; /* size of the extent */
  172. struct work_struct work; /* data work queue */
  173. struct kiocb *iocb; /* iocb struct for AIO */
  174. int result; /* error value for AIO */
  175. int num_io_pages;
  176. struct ext4_io_page *pages[MAX_IO_PAGES];
  177. } ext4_io_end_t;
  178. struct ext4_io_submit {
  179. int io_op;
  180. struct bio *io_bio;
  181. ext4_io_end_t *io_end;
  182. struct ext4_io_page *io_page;
  183. sector_t io_next_block;
  184. };
  185. /*
  186. * Special inodes numbers
  187. */
  188. #define EXT4_BAD_INO 1 /* Bad blocks inode */
  189. #define EXT4_ROOT_INO 2 /* Root inode */
  190. #define EXT4_USR_QUOTA_INO 3 /* User quota inode */
  191. #define EXT4_GRP_QUOTA_INO 4 /* Group quota inode */
  192. #define EXT4_BOOT_LOADER_INO 5 /* Boot loader inode */
  193. #define EXT4_UNDEL_DIR_INO 6 /* Undelete directory inode */
  194. #define EXT4_RESIZE_INO 7 /* Reserved group descriptors inode */
  195. #define EXT4_JOURNAL_INO 8 /* Journal inode */
  196. /* First non-reserved inode for old ext4 filesystems */
  197. #define EXT4_GOOD_OLD_FIRST_INO 11
  198. /*
  199. * Maximal count of links to a file
  200. */
  201. #define EXT4_LINK_MAX 65000
  202. /*
  203. * Macro-instructions used to manage several block sizes
  204. */
  205. #define EXT4_MIN_BLOCK_SIZE 1024
  206. #define EXT4_MAX_BLOCK_SIZE 65536
  207. #define EXT4_MIN_BLOCK_LOG_SIZE 10
  208. #define EXT4_MAX_BLOCK_LOG_SIZE 16
  209. #ifdef __KERNEL__
  210. # define EXT4_BLOCK_SIZE(s) ((s)->s_blocksize)
  211. #else
  212. # define EXT4_BLOCK_SIZE(s) (EXT4_MIN_BLOCK_SIZE << (s)->s_log_block_size)
  213. #endif
  214. #define EXT4_ADDR_PER_BLOCK(s) (EXT4_BLOCK_SIZE(s) / sizeof(__u32))
  215. #ifdef __KERNEL__
  216. # define EXT4_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)
  217. #else
  218. # define EXT4_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10)
  219. #endif
  220. #ifdef __KERNEL__
  221. #define EXT4_ADDR_PER_BLOCK_BITS(s) (EXT4_SB(s)->s_addr_per_block_bits)
  222. #define EXT4_INODE_SIZE(s) (EXT4_SB(s)->s_inode_size)
  223. #define EXT4_FIRST_INO(s) (EXT4_SB(s)->s_first_ino)
  224. #else
  225. #define EXT4_INODE_SIZE(s) (((s)->s_rev_level == EXT4_GOOD_OLD_REV) ? \
  226. EXT4_GOOD_OLD_INODE_SIZE : \
  227. (s)->s_inode_size)
  228. #define EXT4_FIRST_INO(s) (((s)->s_rev_level == EXT4_GOOD_OLD_REV) ? \
  229. EXT4_GOOD_OLD_FIRST_INO : \
  230. (s)->s_first_ino)
  231. #endif
  232. #define EXT4_BLOCK_ALIGN(size, blkbits) ALIGN((size), (1 << (blkbits)))
  233. /*
  234. * Structure of a blocks group descriptor
  235. */
  236. struct ext4_group_desc
  237. {
  238. __le32 bg_block_bitmap_lo; /* Blocks bitmap block */
  239. __le32 bg_inode_bitmap_lo; /* Inodes bitmap block */
  240. __le32 bg_inode_table_lo; /* Inodes table block */
  241. __le16 bg_free_blocks_count_lo;/* Free blocks count */
  242. __le16 bg_free_inodes_count_lo;/* Free inodes count */
  243. __le16 bg_used_dirs_count_lo; /* Directories count */
  244. __le16 bg_flags; /* EXT4_BG_flags (INODE_UNINIT, etc) */
  245. __u32 bg_reserved[2]; /* Likely block/inode bitmap checksum */
  246. __le16 bg_itable_unused_lo; /* Unused inodes count */
  247. __le16 bg_checksum; /* crc16(sb_uuid+group+desc) */
  248. __le32 bg_block_bitmap_hi; /* Blocks bitmap block MSB */
  249. __le32 bg_inode_bitmap_hi; /* Inodes bitmap block MSB */
  250. __le32 bg_inode_table_hi; /* Inodes table block MSB */
  251. __le16 bg_free_blocks_count_hi;/* Free blocks count MSB */
  252. __le16 bg_free_inodes_count_hi;/* Free inodes count MSB */
  253. __le16 bg_used_dirs_count_hi; /* Directories count MSB */
  254. __le16 bg_itable_unused_hi; /* Unused inodes count MSB */
  255. __u32 bg_reserved2[3];
  256. };
  257. /*
  258. * Structure of a flex block group info
  259. */
  260. struct flex_groups {
  261. atomic_t free_inodes;
  262. atomic_t free_blocks;
  263. atomic_t used_dirs;
  264. };
  265. #define EXT4_BG_INODE_UNINIT 0x0001 /* Inode table/bitmap not in use */
  266. #define EXT4_BG_BLOCK_UNINIT 0x0002 /* Block bitmap not in use */
  267. #define EXT4_BG_INODE_ZEROED 0x0004 /* On-disk itable initialized to zero */
  268. /*
  269. * Macro-instructions used to manage group descriptors
  270. */
  271. #define EXT4_MIN_DESC_SIZE 32
  272. #define EXT4_MIN_DESC_SIZE_64BIT 64
  273. #define EXT4_MAX_DESC_SIZE EXT4_MIN_BLOCK_SIZE
  274. #define EXT4_DESC_SIZE(s) (EXT4_SB(s)->s_desc_size)
  275. #ifdef __KERNEL__
  276. # define EXT4_BLOCKS_PER_GROUP(s) (EXT4_SB(s)->s_blocks_per_group)
  277. # define EXT4_DESC_PER_BLOCK(s) (EXT4_SB(s)->s_desc_per_block)
  278. # define EXT4_INODES_PER_GROUP(s) (EXT4_SB(s)->s_inodes_per_group)
  279. # define EXT4_DESC_PER_BLOCK_BITS(s) (EXT4_SB(s)->s_desc_per_block_bits)
  280. #else
  281. # define EXT4_BLOCKS_PER_GROUP(s) ((s)->s_blocks_per_group)
  282. # define EXT4_DESC_PER_BLOCK(s) (EXT4_BLOCK_SIZE(s) / EXT4_DESC_SIZE(s))
  283. # define EXT4_INODES_PER_GROUP(s) ((s)->s_inodes_per_group)
  284. #endif
  285. /*
  286. * Constants relative to the data blocks
  287. */
  288. #define EXT4_NDIR_BLOCKS 12
  289. #define EXT4_IND_BLOCK EXT4_NDIR_BLOCKS
  290. #define EXT4_DIND_BLOCK (EXT4_IND_BLOCK + 1)
  291. #define EXT4_TIND_BLOCK (EXT4_DIND_BLOCK + 1)
  292. #define EXT4_N_BLOCKS (EXT4_TIND_BLOCK + 1)
  293. /*
  294. * Inode flags
  295. */
  296. #define EXT4_SECRM_FL 0x00000001 /* Secure deletion */
  297. #define EXT4_UNRM_FL 0x00000002 /* Undelete */
  298. #define EXT4_COMPR_FL 0x00000004 /* Compress file */
  299. #define EXT4_SYNC_FL 0x00000008 /* Synchronous updates */
  300. #define EXT4_IMMUTABLE_FL 0x00000010 /* Immutable file */
  301. #define EXT4_APPEND_FL 0x00000020 /* writes to file may only append */
  302. #define EXT4_NODUMP_FL 0x00000040 /* do not dump file */
  303. #define EXT4_NOATIME_FL 0x00000080 /* do not update atime */
  304. /* Reserved for compression usage... */
  305. #define EXT4_DIRTY_FL 0x00000100
  306. #define EXT4_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */
  307. #define EXT4_NOCOMPR_FL 0x00000400 /* Don't compress */
  308. #define EXT4_ECOMPR_FL 0x00000800 /* Compression error */
  309. /* End compression flags --- maybe not all used */
  310. #define EXT4_INDEX_FL 0x00001000 /* hash-indexed directory */
  311. #define EXT4_IMAGIC_FL 0x00002000 /* AFS directory */
  312. #define EXT4_JOURNAL_DATA_FL 0x00004000 /* file data should be journaled */
  313. #define EXT4_NOTAIL_FL 0x00008000 /* file tail should not be merged */
  314. #define EXT4_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */
  315. #define EXT4_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/
  316. #define EXT4_HUGE_FILE_FL 0x00040000 /* Set to each huge file */
  317. #define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */
  318. #define EXT4_EA_INODE_FL 0x00200000 /* Inode used for large EA */
  319. #define EXT4_EOFBLOCKS_FL 0x00400000 /* Blocks allocated beyond EOF */
  320. #define EXT4_RESERVED_FL 0x80000000 /* reserved for ext4 lib */
  321. #define EXT4_FL_USER_VISIBLE 0x004BDFFF /* User visible flags */
  322. #define EXT4_FL_USER_MODIFIABLE 0x004B80FF /* User modifiable flags */
  323. /* Flags that should be inherited by new inodes from their parent. */
  324. #define EXT4_FL_INHERITED (EXT4_SECRM_FL | EXT4_UNRM_FL | EXT4_COMPR_FL |\
  325. EXT4_SYNC_FL | EXT4_IMMUTABLE_FL | EXT4_APPEND_FL |\
  326. EXT4_NODUMP_FL | EXT4_NOATIME_FL |\
  327. EXT4_NOCOMPR_FL | EXT4_JOURNAL_DATA_FL |\
  328. EXT4_NOTAIL_FL | EXT4_DIRSYNC_FL)
  329. /* Flags that are appropriate for regular files (all but dir-specific ones). */
  330. #define EXT4_REG_FLMASK (~(EXT4_DIRSYNC_FL | EXT4_TOPDIR_FL))
  331. /* Flags that are appropriate for non-directories/regular files. */
  332. #define EXT4_OTHER_FLMASK (EXT4_NODUMP_FL | EXT4_NOATIME_FL)
  333. /* Mask out flags that are inappropriate for the given type of inode. */
  334. static inline __u32 ext4_mask_flags(umode_t mode, __u32 flags)
  335. {
  336. if (S_ISDIR(mode))
  337. return flags;
  338. else if (S_ISREG(mode))
  339. return flags & EXT4_REG_FLMASK;
  340. else
  341. return flags & EXT4_OTHER_FLMASK;
  342. }
  343. /*
  344. * Inode flags used for atomic set/get
  345. */
  346. enum {
  347. EXT4_INODE_SECRM = 0, /* Secure deletion */
  348. EXT4_INODE_UNRM = 1, /* Undelete */
  349. EXT4_INODE_COMPR = 2, /* Compress file */
  350. EXT4_INODE_SYNC = 3, /* Synchronous updates */
  351. EXT4_INODE_IMMUTABLE = 4, /* Immutable file */
  352. EXT4_INODE_APPEND = 5, /* writes to file may only append */
  353. EXT4_INODE_NODUMP = 6, /* do not dump file */
  354. EXT4_INODE_NOATIME = 7, /* do not update atime */
  355. /* Reserved for compression usage... */
  356. EXT4_INODE_DIRTY = 8,
  357. EXT4_INODE_COMPRBLK = 9, /* One or more compressed clusters */
  358. EXT4_INODE_NOCOMPR = 10, /* Don't compress */
  359. EXT4_INODE_ECOMPR = 11, /* Compression error */
  360. /* End compression flags --- maybe not all used */
  361. EXT4_INODE_INDEX = 12, /* hash-indexed directory */
  362. EXT4_INODE_IMAGIC = 13, /* AFS directory */
  363. EXT4_INODE_JOURNAL_DATA = 14, /* file data should be journaled */
  364. EXT4_INODE_NOTAIL = 15, /* file tail should not be merged */
  365. EXT4_INODE_DIRSYNC = 16, /* dirsync behaviour (directories only) */
  366. EXT4_INODE_TOPDIR = 17, /* Top of directory hierarchies*/
  367. EXT4_INODE_HUGE_FILE = 18, /* Set to each huge file */
  368. EXT4_INODE_EXTENTS = 19, /* Inode uses extents */
  369. EXT4_INODE_EA_INODE = 21, /* Inode used for large EA */
  370. EXT4_INODE_EOFBLOCKS = 22, /* Blocks allocated beyond EOF */
  371. EXT4_INODE_RESERVED = 31, /* reserved for ext4 lib */
  372. };
  373. #define TEST_FLAG_VALUE(FLAG) (EXT4_##FLAG##_FL == (1 << EXT4_INODE_##FLAG))
  374. #define CHECK_FLAG_VALUE(FLAG) if (!TEST_FLAG_VALUE(FLAG)) { \
  375. printk(KERN_EMERG "EXT4 flag fail: " #FLAG ": %d %d\n", \
  376. EXT4_##FLAG##_FL, EXT4_INODE_##FLAG); BUG_ON(1); }
  377. /*
  378. * Since it's pretty easy to mix up bit numbers and hex values, and we
  379. * can't do a compile-time test for ENUM values, we use a run-time
  380. * test to make sure that EXT4_XXX_FL is consistent with respect to
  381. * EXT4_INODE_XXX. If all is well the printk and BUG_ON will all drop
  382. * out so it won't cost any extra space in the compiled kernel image.
  383. * But it's important that these values are the same, since we are
  384. * using EXT4_INODE_XXX to test for the flag values, but EXT4_XX_FL
  385. * must be consistent with the values of FS_XXX_FL defined in
  386. * include/linux/fs.h and the on-disk values found in ext2, ext3, and
  387. * ext4 filesystems, and of course the values defined in e2fsprogs.
  388. *
  389. * It's not paranoia if the Murphy's Law really *is* out to get you. :-)
  390. */
  391. static inline void ext4_check_flag_values(void)
  392. {
  393. CHECK_FLAG_VALUE(SECRM);
  394. CHECK_FLAG_VALUE(UNRM);
  395. CHECK_FLAG_VALUE(COMPR);
  396. CHECK_FLAG_VALUE(SYNC);
  397. CHECK_FLAG_VALUE(IMMUTABLE);
  398. CHECK_FLAG_VALUE(APPEND);
  399. CHECK_FLAG_VALUE(NODUMP);
  400. CHECK_FLAG_VALUE(NOATIME);
  401. CHECK_FLAG_VALUE(DIRTY);
  402. CHECK_FLAG_VALUE(COMPRBLK);
  403. CHECK_FLAG_VALUE(NOCOMPR);
  404. CHECK_FLAG_VALUE(ECOMPR);
  405. CHECK_FLAG_VALUE(INDEX);
  406. CHECK_FLAG_VALUE(IMAGIC);
  407. CHECK_FLAG_VALUE(JOURNAL_DATA);
  408. CHECK_FLAG_VALUE(NOTAIL);
  409. CHECK_FLAG_VALUE(DIRSYNC);
  410. CHECK_FLAG_VALUE(TOPDIR);
  411. CHECK_FLAG_VALUE(HUGE_FILE);
  412. CHECK_FLAG_VALUE(EXTENTS);
  413. CHECK_FLAG_VALUE(EA_INODE);
  414. CHECK_FLAG_VALUE(EOFBLOCKS);
  415. CHECK_FLAG_VALUE(RESERVED);
  416. }
  417. /* Used to pass group descriptor data when online resize is done */
  418. struct ext4_new_group_input {
  419. __u32 group; /* Group number for this data */
  420. __u64 block_bitmap; /* Absolute block number of block bitmap */
  421. __u64 inode_bitmap; /* Absolute block number of inode bitmap */
  422. __u64 inode_table; /* Absolute block number of inode table start */
  423. __u32 blocks_count; /* Total number of blocks in this group */
  424. __u16 reserved_blocks; /* Number of reserved blocks in this group */
  425. __u16 unused;
  426. };
  427. #if defined(__KERNEL__) && defined(CONFIG_COMPAT)
  428. struct compat_ext4_new_group_input {
  429. u32 group;
  430. compat_u64 block_bitmap;
  431. compat_u64 inode_bitmap;
  432. compat_u64 inode_table;
  433. u32 blocks_count;
  434. u16 reserved_blocks;
  435. u16 unused;
  436. };
  437. #endif
  438. /* The struct ext4_new_group_input in kernel space, with free_blocks_count */
  439. struct ext4_new_group_data {
  440. __u32 group;
  441. __u64 block_bitmap;
  442. __u64 inode_bitmap;
  443. __u64 inode_table;
  444. __u32 blocks_count;
  445. __u16 reserved_blocks;
  446. __u16 unused;
  447. __u32 free_blocks_count;
  448. };
  449. /*
  450. * Flags used by ext4_map_blocks()
  451. */
  452. /* Allocate any needed blocks and/or convert an unitialized
  453. extent to be an initialized ext4 */
  454. #define EXT4_GET_BLOCKS_CREATE 0x0001
  455. /* Request the creation of an unitialized extent */
  456. #define EXT4_GET_BLOCKS_UNINIT_EXT 0x0002
  457. #define EXT4_GET_BLOCKS_CREATE_UNINIT_EXT (EXT4_GET_BLOCKS_UNINIT_EXT|\
  458. EXT4_GET_BLOCKS_CREATE)
  459. /* Caller is from the delayed allocation writeout path,
  460. so set the magic i_delalloc_reserve_flag after taking the
  461. inode allocation semaphore for */
  462. #define EXT4_GET_BLOCKS_DELALLOC_RESERVE 0x0004
  463. /* caller is from the direct IO path, request to creation of an
  464. unitialized extents if not allocated, split the uninitialized
  465. extent if blocks has been preallocated already*/
  466. #define EXT4_GET_BLOCKS_PRE_IO 0x0008
  467. #define EXT4_GET_BLOCKS_CONVERT 0x0010
  468. #define EXT4_GET_BLOCKS_IO_CREATE_EXT (EXT4_GET_BLOCKS_PRE_IO|\
  469. EXT4_GET_BLOCKS_CREATE_UNINIT_EXT)
  470. /* Convert extent to initialized after IO complete */
  471. #define EXT4_GET_BLOCKS_IO_CONVERT_EXT (EXT4_GET_BLOCKS_CONVERT|\
  472. EXT4_GET_BLOCKS_CREATE_UNINIT_EXT)
  473. /* Punch out blocks of an extent */
  474. #define EXT4_GET_BLOCKS_PUNCH_OUT_EXT 0x0020
  475. /* Don't normalize allocation size (used for fallocate) */
  476. #define EXT4_GET_BLOCKS_NO_NORMALIZE 0x0040
  477. /*
  478. * Flags used by ext4_free_blocks
  479. */
  480. #define EXT4_FREE_BLOCKS_METADATA 0x0001
  481. #define EXT4_FREE_BLOCKS_FORGET 0x0002
  482. #define EXT4_FREE_BLOCKS_VALIDATED 0x0004
  483. #define EXT4_FREE_BLOCKS_NO_QUOT_UPDATE 0x0008
  484. /*
  485. * ioctl commands
  486. */
  487. #define EXT4_IOC_GETFLAGS FS_IOC_GETFLAGS
  488. #define EXT4_IOC_SETFLAGS FS_IOC_SETFLAGS
  489. #define EXT4_IOC_GETVERSION _IOR('f', 3, long)
  490. #define EXT4_IOC_SETVERSION _IOW('f', 4, long)
  491. #define EXT4_IOC_GETVERSION_OLD FS_IOC_GETVERSION
  492. #define EXT4_IOC_SETVERSION_OLD FS_IOC_SETVERSION
  493. #ifdef CONFIG_JBD2_DEBUG
  494. #define EXT4_IOC_WAIT_FOR_READONLY _IOR('f', 99, long)
  495. #endif
  496. #define EXT4_IOC_GETRSVSZ _IOR('f', 5, long)
  497. #define EXT4_IOC_SETRSVSZ _IOW('f', 6, long)
  498. #define EXT4_IOC_GROUP_EXTEND _IOW('f', 7, unsigned long)
  499. #define EXT4_IOC_GROUP_ADD _IOW('f', 8, struct ext4_new_group_input)
  500. #define EXT4_IOC_MIGRATE _IO('f', 9)
  501. /* note ioctl 10 reserved for an early version of the FIEMAP ioctl */
  502. /* note ioctl 11 reserved for filesystem-independent FIEMAP ioctl */
  503. #define EXT4_IOC_ALLOC_DA_BLKS _IO('f', 12)
  504. #define EXT4_IOC_MOVE_EXT _IOWR('f', 15, struct move_extent)
  505. #if defined(__KERNEL__) && defined(CONFIG_COMPAT)
  506. /*
  507. * ioctl commands in 32 bit emulation
  508. */
  509. #define EXT4_IOC32_GETFLAGS FS_IOC32_GETFLAGS
  510. #define EXT4_IOC32_SETFLAGS FS_IOC32_SETFLAGS
  511. #define EXT4_IOC32_GETVERSION _IOR('f', 3, int)
  512. #define EXT4_IOC32_SETVERSION _IOW('f', 4, int)
  513. #define EXT4_IOC32_GETRSVSZ _IOR('f', 5, int)
  514. #define EXT4_IOC32_SETRSVSZ _IOW('f', 6, int)
  515. #define EXT4_IOC32_GROUP_EXTEND _IOW('f', 7, unsigned int)
  516. #define EXT4_IOC32_GROUP_ADD _IOW('f', 8, struct compat_ext4_new_group_input)
  517. #ifdef CONFIG_JBD2_DEBUG
  518. #define EXT4_IOC32_WAIT_FOR_READONLY _IOR('f', 99, int)
  519. #endif
  520. #define EXT4_IOC32_GETVERSION_OLD FS_IOC32_GETVERSION
  521. #define EXT4_IOC32_SETVERSION_OLD FS_IOC32_SETVERSION
  522. #endif
  523. /* Max physical block we can address w/o extents */
  524. #define EXT4_MAX_BLOCK_FILE_PHYS 0xFFFFFFFF
  525. /*
  526. * Structure of an inode on the disk
  527. */
  528. struct ext4_inode {
  529. __le16 i_mode; /* File mode */
  530. __le16 i_uid; /* Low 16 bits of Owner Uid */
  531. __le32 i_size_lo; /* Size in bytes */
  532. __le32 i_atime; /* Access time */
  533. __le32 i_ctime; /* Inode Change time */
  534. __le32 i_mtime; /* Modification time */
  535. __le32 i_dtime; /* Deletion Time */
  536. __le16 i_gid; /* Low 16 bits of Group Id */
  537. __le16 i_links_count; /* Links count */
  538. __le32 i_blocks_lo; /* Blocks count */
  539. __le32 i_flags; /* File flags */
  540. union {
  541. struct {
  542. __le32 l_i_version;
  543. } linux1;
  544. struct {
  545. __u32 h_i_translator;
  546. } hurd1;
  547. struct {
  548. __u32 m_i_reserved1;
  549. } masix1;
  550. } osd1; /* OS dependent 1 */
  551. __le32 i_block[EXT4_N_BLOCKS];/* Pointers to blocks */
  552. __le32 i_generation; /* File version (for NFS) */
  553. __le32 i_file_acl_lo; /* File ACL */
  554. __le32 i_size_high;
  555. __le32 i_obso_faddr; /* Obsoleted fragment address */
  556. union {
  557. struct {
  558. __le16 l_i_blocks_high; /* were l_i_reserved1 */
  559. __le16 l_i_file_acl_high;
  560. __le16 l_i_uid_high; /* these 2 fields */
  561. __le16 l_i_gid_high; /* were reserved2[0] */
  562. __u32 l_i_reserved2;
  563. } linux2;
  564. struct {
  565. __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */
  566. __u16 h_i_mode_high;
  567. __u16 h_i_uid_high;
  568. __u16 h_i_gid_high;
  569. __u32 h_i_author;
  570. } hurd2;
  571. struct {
  572. __le16 h_i_reserved1; /* Obsoleted fragment number/size which are removed in ext4 */
  573. __le16 m_i_file_acl_high;
  574. __u32 m_i_reserved2[2];
  575. } masix2;
  576. } osd2; /* OS dependent 2 */
  577. __le16 i_extra_isize;
  578. __le16 i_pad1;
  579. __le32 i_ctime_extra; /* extra Change time (nsec << 2 | epoch) */
  580. __le32 i_mtime_extra; /* extra Modification time(nsec << 2 | epoch) */
  581. __le32 i_atime_extra; /* extra Access time (nsec << 2 | epoch) */
  582. __le32 i_crtime; /* File Creation time */
  583. __le32 i_crtime_extra; /* extra FileCreationtime (nsec << 2 | epoch) */
  584. __le32 i_version_hi; /* high 32 bits for 64-bit version */
  585. };
  586. struct move_extent {
  587. __u32 reserved; /* should be zero */
  588. __u32 donor_fd; /* donor file descriptor */
  589. __u64 orig_start; /* logical start offset in block for orig */
  590. __u64 donor_start; /* logical start offset in block for donor */
  591. __u64 len; /* block length to be moved */
  592. __u64 moved_len; /* moved block length */
  593. };
  594. #define EXT4_EPOCH_BITS 2
  595. #define EXT4_EPOCH_MASK ((1 << EXT4_EPOCH_BITS) - 1)
  596. #define EXT4_NSEC_MASK (~0UL << EXT4_EPOCH_BITS)
  597. /*
  598. * Extended fields will fit into an inode if the filesystem was formatted
  599. * with large inodes (-I 256 or larger) and there are not currently any EAs
  600. * consuming all of the available space. For new inodes we always reserve
  601. * enough space for the kernel's known extended fields, but for inodes
  602. * created with an old kernel this might not have been the case. None of
  603. * the extended inode fields is critical for correct filesystem operation.
  604. * This macro checks if a certain field fits in the inode. Note that
  605. * inode-size = GOOD_OLD_INODE_SIZE + i_extra_isize
  606. */
  607. #define EXT4_FITS_IN_INODE(ext4_inode, einode, field) \
  608. ((offsetof(typeof(*ext4_inode), field) + \
  609. sizeof((ext4_inode)->field)) \
  610. <= (EXT4_GOOD_OLD_INODE_SIZE + \
  611. (einode)->i_extra_isize)) \
  612. static inline __le32 ext4_encode_extra_time(struct timespec *time)
  613. {
  614. return cpu_to_le32((sizeof(time->tv_sec) > 4 ?
  615. (time->tv_sec >> 32) & EXT4_EPOCH_MASK : 0) |
  616. ((time->tv_nsec << EXT4_EPOCH_BITS) & EXT4_NSEC_MASK));
  617. }
  618. static inline void ext4_decode_extra_time(struct timespec *time, __le32 extra)
  619. {
  620. if (sizeof(time->tv_sec) > 4)
  621. time->tv_sec |= (__u64)(le32_to_cpu(extra) & EXT4_EPOCH_MASK)
  622. << 32;
  623. time->tv_nsec = (le32_to_cpu(extra) & EXT4_NSEC_MASK) >> EXT4_EPOCH_BITS;
  624. }
  625. #define EXT4_INODE_SET_XTIME(xtime, inode, raw_inode) \
  626. do { \
  627. (raw_inode)->xtime = cpu_to_le32((inode)->xtime.tv_sec); \
  628. if (EXT4_FITS_IN_INODE(raw_inode, EXT4_I(inode), xtime ## _extra)) \
  629. (raw_inode)->xtime ## _extra = \
  630. ext4_encode_extra_time(&(inode)->xtime); \
  631. } while (0)
  632. #define EXT4_EINODE_SET_XTIME(xtime, einode, raw_inode) \
  633. do { \
  634. if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime)) \
  635. (raw_inode)->xtime = cpu_to_le32((einode)->xtime.tv_sec); \
  636. if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime ## _extra)) \
  637. (raw_inode)->xtime ## _extra = \
  638. ext4_encode_extra_time(&(einode)->xtime); \
  639. } while (0)
  640. #define EXT4_INODE_GET_XTIME(xtime, inode, raw_inode) \
  641. do { \
  642. (inode)->xtime.tv_sec = (signed)le32_to_cpu((raw_inode)->xtime); \
  643. if (EXT4_FITS_IN_INODE(raw_inode, EXT4_I(inode), xtime ## _extra)) \
  644. ext4_decode_extra_time(&(inode)->xtime, \
  645. raw_inode->xtime ## _extra); \
  646. else \
  647. (inode)->xtime.tv_nsec = 0; \
  648. } while (0)
  649. #define EXT4_EINODE_GET_XTIME(xtime, einode, raw_inode) \
  650. do { \
  651. if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime)) \
  652. (einode)->xtime.tv_sec = \
  653. (signed)le32_to_cpu((raw_inode)->xtime); \
  654. if (EXT4_FITS_IN_INODE(raw_inode, einode, xtime ## _extra)) \
  655. ext4_decode_extra_time(&(einode)->xtime, \
  656. raw_inode->xtime ## _extra); \
  657. else \
  658. (einode)->xtime.tv_nsec = 0; \
  659. } while (0)
  660. #define i_disk_version osd1.linux1.l_i_version
  661. #if defined(__KERNEL__) || defined(__linux__)
  662. #define i_reserved1 osd1.linux1.l_i_reserved1
  663. #define i_file_acl_high osd2.linux2.l_i_file_acl_high
  664. #define i_blocks_high osd2.linux2.l_i_blocks_high
  665. #define i_uid_low i_uid
  666. #define i_gid_low i_gid
  667. #define i_uid_high osd2.linux2.l_i_uid_high
  668. #define i_gid_high osd2.linux2.l_i_gid_high
  669. #define i_reserved2 osd2.linux2.l_i_reserved2
  670. #elif defined(__GNU__)
  671. #define i_translator osd1.hurd1.h_i_translator
  672. #define i_uid_high osd2.hurd2.h_i_uid_high
  673. #define i_gid_high osd2.hurd2.h_i_gid_high
  674. #define i_author osd2.hurd2.h_i_author
  675. #elif defined(__masix__)
  676. #define i_reserved1 osd1.masix1.m_i_reserved1
  677. #define i_file_acl_high osd2.masix2.m_i_file_acl_high
  678. #define i_reserved2 osd2.masix2.m_i_reserved2
  679. #endif /* defined(__KERNEL__) || defined(__linux__) */
  680. /*
  681. * storage for cached extent
  682. * If ec_len == 0, then the cache is invalid.
  683. * If ec_start == 0, then the cache represents a gap (null mapping)
  684. */
  685. struct ext4_ext_cache {
  686. ext4_fsblk_t ec_start;
  687. ext4_lblk_t ec_block;
  688. __u32 ec_len; /* must be 32bit to return holes */
  689. };
  690. /*
  691. * fourth extended file system inode data in memory
  692. */
  693. struct ext4_inode_info {
  694. __le32 i_data[15]; /* unconverted */
  695. __u32 i_dtime;
  696. ext4_fsblk_t i_file_acl;
  697. /*
  698. * i_block_group is the number of the block group which contains
  699. * this file's inode. Constant across the lifetime of the inode,
  700. * it is ued for making block allocation decisions - we try to
  701. * place a file's data blocks near its inode block, and new inodes
  702. * near to their parent directory's inode.
  703. */
  704. ext4_group_t i_block_group;
  705. ext4_lblk_t i_dir_start_lookup;
  706. #if (BITS_PER_LONG < 64)
  707. unsigned long i_state_flags; /* Dynamic state flags */
  708. #endif
  709. unsigned long i_flags;
  710. #ifdef CONFIG_EXT4_FS_XATTR
  711. /*
  712. * Extended attributes can be read independently of the main file
  713. * data. Taking i_mutex even when reading would cause contention
  714. * between readers of EAs and writers of regular file data, so
  715. * instead we synchronize on xattr_sem when reading or changing
  716. * EAs.
  717. */
  718. struct rw_semaphore xattr_sem;
  719. #endif
  720. struct list_head i_orphan; /* unlinked but open inodes */
  721. /*
  722. * i_disksize keeps track of what the inode size is ON DISK, not
  723. * in memory. During truncate, i_size is set to the new size by
  724. * the VFS prior to calling ext4_truncate(), but the filesystem won't
  725. * set i_disksize to 0 until the truncate is actually under way.
  726. *
  727. * The intent is that i_disksize always represents the blocks which
  728. * are used by this file. This allows recovery to restart truncate
  729. * on orphans if we crash during truncate. We actually write i_disksize
  730. * into the on-disk inode when writing inodes out, instead of i_size.
  731. *
  732. * The only time when i_disksize and i_size may be different is when
  733. * a truncate is in progress. The only things which change i_disksize
  734. * are ext4_get_block (growth) and ext4_truncate (shrinkth).
  735. */
  736. loff_t i_disksize;
  737. /*
  738. * i_data_sem is for serialising ext4_truncate() against
  739. * ext4_getblock(). In the 2.4 ext2 design, great chunks of inode's
  740. * data tree are chopped off during truncate. We can't do that in
  741. * ext4 because whenever we perform intermediate commits during
  742. * truncate, the inode and all the metadata blocks *must* be in a
  743. * consistent state which allows truncation of the orphans to restart
  744. * during recovery. Hence we must fix the get_block-vs-truncate race
  745. * by other means, so we have i_data_sem.
  746. */
  747. struct rw_semaphore i_data_sem;
  748. struct inode vfs_inode;
  749. struct jbd2_inode *jinode;
  750. struct ext4_ext_cache i_cached_extent;
  751. /*
  752. * File creation time. Its function is same as that of
  753. * struct timespec i_{a,c,m}time in the generic inode.
  754. */
  755. struct timespec i_crtime;
  756. /* mballoc */
  757. struct list_head i_prealloc_list;
  758. spinlock_t i_prealloc_lock;
  759. /* ialloc */
  760. ext4_group_t i_last_alloc_group;
  761. /* allocation reservation info for delalloc */
  762. unsigned int i_reserved_data_blocks;
  763. unsigned int i_reserved_meta_blocks;
  764. unsigned int i_allocated_meta_blocks;
  765. ext4_lblk_t i_da_metadata_calc_last_lblock;
  766. int i_da_metadata_calc_len;
  767. /* on-disk additional length */
  768. __u16 i_extra_isize;
  769. #ifdef CONFIG_QUOTA
  770. /* quota space reservation, managed internally by quota code */
  771. qsize_t i_reserved_quota;
  772. #endif
  773. /* completed IOs that might need unwritten extents handling */
  774. struct list_head i_completed_io_list;
  775. spinlock_t i_completed_io_lock;
  776. atomic_t i_ioend_count; /* Number of outstanding io_end structs */
  777. /* current io_end structure for async DIO write*/
  778. ext4_io_end_t *cur_aio_dio;
  779. atomic_t i_aiodio_unwritten; /* Nr. of inflight conversions pending */
  780. spinlock_t i_block_reservation_lock;
  781. /*
  782. * Transactions that contain inode's metadata needed to complete
  783. * fsync and fdatasync, respectively.
  784. */
  785. tid_t i_sync_tid;
  786. tid_t i_datasync_tid;
  787. };
  788. /*
  789. * File system states
  790. */
  791. #define EXT4_VALID_FS 0x0001 /* Unmounted cleanly */
  792. #define EXT4_ERROR_FS 0x0002 /* Errors detected */
  793. #define EXT4_ORPHAN_FS 0x0004 /* Orphans being recovered */
  794. /*
  795. * Misc. filesystem flags
  796. */
  797. #define EXT2_FLAGS_SIGNED_HASH 0x0001 /* Signed dirhash in use */
  798. #define EXT2_FLAGS_UNSIGNED_HASH 0x0002 /* Unsigned dirhash in use */
  799. #define EXT2_FLAGS_TEST_FILESYS 0x0004 /* to test development code */
  800. /*
  801. * Mount flags
  802. */
  803. #define EXT4_MOUNT_OLDALLOC 0x00002 /* Don't use the new Orlov allocator */
  804. #define EXT4_MOUNT_GRPID 0x00004 /* Create files with directory's group */
  805. #define EXT4_MOUNT_DEBUG 0x00008 /* Some debugging messages */
  806. #define EXT4_MOUNT_ERRORS_CONT 0x00010 /* Continue on errors */
  807. #define EXT4_MOUNT_ERRORS_RO 0x00020 /* Remount fs ro on errors */
  808. #define EXT4_MOUNT_ERRORS_PANIC 0x00040 /* Panic on errors */
  809. #define EXT4_MOUNT_MINIX_DF 0x00080 /* Mimics the Minix statfs */
  810. #define EXT4_MOUNT_NOLOAD 0x00100 /* Don't use existing journal*/
  811. #define EXT4_MOUNT_DATA_FLAGS 0x00C00 /* Mode for data writes: */
  812. #define EXT4_MOUNT_JOURNAL_DATA 0x00400 /* Write data to journal */
  813. #define EXT4_MOUNT_ORDERED_DATA 0x00800 /* Flush data before commit */
  814. #define EXT4_MOUNT_WRITEBACK_DATA 0x00C00 /* No data ordering */
  815. #define EXT4_MOUNT_UPDATE_JOURNAL 0x01000 /* Update the journal format */
  816. #define EXT4_MOUNT_NO_UID32 0x02000 /* Disable 32-bit UIDs */
  817. #define EXT4_MOUNT_XATTR_USER 0x04000 /* Extended user attributes */
  818. #define EXT4_MOUNT_POSIX_ACL 0x08000 /* POSIX Access Control Lists */
  819. #define EXT4_MOUNT_NO_AUTO_DA_ALLOC 0x10000 /* No auto delalloc mapping */
  820. #define EXT4_MOUNT_BARRIER 0x20000 /* Use block barriers */
  821. #define EXT4_MOUNT_QUOTA 0x80000 /* Some quota option set */
  822. #define EXT4_MOUNT_USRQUOTA 0x100000 /* "old" user quota */
  823. #define EXT4_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */
  824. #define EXT4_MOUNT_DIOREAD_NOLOCK 0x400000 /* Enable support for dio read nolocking */
  825. #define EXT4_MOUNT_JOURNAL_CHECKSUM 0x800000 /* Journal checksums */
  826. #define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT 0x1000000 /* Journal Async Commit */
  827. #define EXT4_MOUNT_I_VERSION 0x2000000 /* i_version support */
  828. #define EXT4_MOUNT_MBLK_IO_SUBMIT 0x4000000 /* multi-block io submits */
  829. #define EXT4_MOUNT_DELALLOC 0x8000000 /* Delalloc support */
  830. #define EXT4_MOUNT_DATA_ERR_ABORT 0x10000000 /* Abort on file data write */
  831. #define EXT4_MOUNT_BLOCK_VALIDITY 0x20000000 /* Block validity checking */
  832. #define EXT4_MOUNT_DISCARD 0x40000000 /* Issue DISCARD requests */
  833. #define EXT4_MOUNT_INIT_INODE_TABLE 0x80000000 /* Initialize uninitialized itables */
  834. #define clear_opt(sb, opt) EXT4_SB(sb)->s_mount_opt &= \
  835. ~EXT4_MOUNT_##opt
  836. #define set_opt(sb, opt) EXT4_SB(sb)->s_mount_opt |= \
  837. EXT4_MOUNT_##opt
  838. #define test_opt(sb, opt) (EXT4_SB(sb)->s_mount_opt & \
  839. EXT4_MOUNT_##opt)
  840. #define clear_opt2(sb, opt) EXT4_SB(sb)->s_mount_opt2 &= \
  841. ~EXT4_MOUNT2_##opt
  842. #define set_opt2(sb, opt) EXT4_SB(sb)->s_mount_opt2 |= \
  843. EXT4_MOUNT2_##opt
  844. #define test_opt2(sb, opt) (EXT4_SB(sb)->s_mount_opt2 & \
  845. EXT4_MOUNT2_##opt)
  846. #define ext4_set_bit __test_and_set_bit_le
  847. #define ext4_set_bit_atomic ext2_set_bit_atomic
  848. #define ext4_clear_bit __test_and_clear_bit_le
  849. #define ext4_clear_bit_atomic ext2_clear_bit_atomic
  850. #define ext4_test_bit test_bit_le
  851. #define ext4_find_first_zero_bit find_first_zero_bit_le
  852. #define ext4_find_next_zero_bit find_next_zero_bit_le
  853. #define ext4_find_next_bit find_next_bit_le
  854. extern void ext4_set_bits(void *bm, int cur, int len);
  855. /*
  856. * Maximal mount counts between two filesystem checks
  857. */
  858. #define EXT4_DFL_MAX_MNT_COUNT 20 /* Allow 20 mounts */
  859. #define EXT4_DFL_CHECKINTERVAL 0 /* Don't use interval check */
  860. /*
  861. * Behaviour when detecting errors
  862. */
  863. #define EXT4_ERRORS_CONTINUE 1 /* Continue execution */
  864. #define EXT4_ERRORS_RO 2 /* Remount fs read-only */
  865. #define EXT4_ERRORS_PANIC 3 /* Panic */
  866. #define EXT4_ERRORS_DEFAULT EXT4_ERRORS_CONTINUE
  867. /*
  868. * Structure of the super block
  869. */
  870. struct ext4_super_block {
  871. /*00*/ __le32 s_inodes_count; /* Inodes count */
  872. __le32 s_blocks_count_lo; /* Blocks count */
  873. __le32 s_r_blocks_count_lo; /* Reserved blocks count */
  874. __le32 s_free_blocks_count_lo; /* Free blocks count */
  875. /*10*/ __le32 s_free_inodes_count; /* Free inodes count */
  876. __le32 s_first_data_block; /* First Data Block */
  877. __le32 s_log_block_size; /* Block size */
  878. __le32 s_obso_log_frag_size; /* Obsoleted fragment size */
  879. /*20*/ __le32 s_blocks_per_group; /* # Blocks per group */
  880. __le32 s_obso_frags_per_group; /* Obsoleted fragments per group */
  881. __le32 s_inodes_per_group; /* # Inodes per group */
  882. __le32 s_mtime; /* Mount time */
  883. /*30*/ __le32 s_wtime; /* Write time */
  884. __le16 s_mnt_count; /* Mount count */
  885. __le16 s_max_mnt_count; /* Maximal mount count */
  886. __le16 s_magic; /* Magic signature */
  887. __le16 s_state; /* File system state */
  888. __le16 s_errors; /* Behaviour when detecting errors */
  889. __le16 s_minor_rev_level; /* minor revision level */
  890. /*40*/ __le32 s_lastcheck; /* time of last check */
  891. __le32 s_checkinterval; /* max. time between checks */
  892. __le32 s_creator_os; /* OS */
  893. __le32 s_rev_level; /* Revision level */
  894. /*50*/ __le16 s_def_resuid; /* Default uid for reserved blocks */
  895. __le16 s_def_resgid; /* Default gid for reserved blocks */
  896. /*
  897. * These fields are for EXT4_DYNAMIC_REV superblocks only.
  898. *
  899. * Note: the difference between the compatible feature set and
  900. * the incompatible feature set is that if there is a bit set
  901. * in the incompatible feature set that the kernel doesn't
  902. * know about, it should refuse to mount the filesystem.
  903. *
  904. * e2fsck's requirements are more strict; if it doesn't know
  905. * about a feature in either the compatible or incompatible
  906. * feature set, it must abort and not try to meddle with
  907. * things it doesn't understand...
  908. */
  909. __le32 s_first_ino; /* First non-reserved inode */
  910. __le16 s_inode_size; /* size of inode structure */
  911. __le16 s_block_group_nr; /* block group # of this superblock */
  912. __le32 s_feature_compat; /* compatible feature set */
  913. /*60*/ __le32 s_feature_incompat; /* incompatible feature set */
  914. __le32 s_feature_ro_compat; /* readonly-compatible feature set */
  915. /*68*/ __u8 s_uuid[16]; /* 128-bit uuid for volume */
  916. /*78*/ char s_volume_name[16]; /* volume name */
  917. /*88*/ char s_last_mounted[64]; /* directory where last mounted */
  918. /*C8*/ __le32 s_algorithm_usage_bitmap; /* For compression */
  919. /*
  920. * Performance hints. Directory preallocation should only
  921. * happen if the EXT4_FEATURE_COMPAT_DIR_PREALLOC flag is on.
  922. */
  923. __u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/
  924. __u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */
  925. __le16 s_reserved_gdt_blocks; /* Per group desc for online growth */
  926. /*
  927. * Journaling support valid if EXT4_FEATURE_COMPAT_HAS_JOURNAL set.
  928. */
  929. /*D0*/ __u8 s_journal_uuid[16]; /* uuid of journal superblock */
  930. /*E0*/ __le32 s_journal_inum; /* inode number of journal file */
  931. __le32 s_journal_dev; /* device number of journal file */
  932. __le32 s_last_orphan; /* start of list of inodes to delete */
  933. __le32 s_hash_seed[4]; /* HTREE hash seed */
  934. __u8 s_def_hash_version; /* Default hash version to use */
  935. __u8 s_jnl_backup_type;
  936. __le16 s_desc_size; /* size of group descriptor */
  937. /*100*/ __le32 s_default_mount_opts;
  938. __le32 s_first_meta_bg; /* First metablock block group */
  939. __le32 s_mkfs_time; /* When the filesystem was created */
  940. __le32 s_jnl_blocks[17]; /* Backup of the journal inode */
  941. /* 64bit support valid if EXT4_FEATURE_COMPAT_64BIT */
  942. /*150*/ __le32 s_blocks_count_hi; /* Blocks count */
  943. __le32 s_r_blocks_count_hi; /* Reserved blocks count */
  944. __le32 s_free_blocks_count_hi; /* Free blocks count */
  945. __le16 s_min_extra_isize; /* All inodes have at least # bytes */
  946. __le16 s_want_extra_isize; /* New inodes should reserve # bytes */
  947. __le32 s_flags; /* Miscellaneous flags */
  948. __le16 s_raid_stride; /* RAID stride */
  949. __le16 s_mmp_update_interval; /* # seconds to wait in MMP checking */
  950. __le64 s_mmp_block; /* Block for multi-mount protection */
  951. __le32 s_raid_stripe_width; /* blocks on all data disks (N*stride)*/
  952. __u8 s_log_groups_per_flex; /* FLEX_BG group size */
  953. __u8 s_reserved_char_pad;
  954. __le16 s_reserved_pad;
  955. __le64 s_kbytes_written; /* nr of lifetime kilobytes written */
  956. __le32 s_snapshot_inum; /* Inode number of active snapshot */
  957. __le32 s_snapshot_id; /* sequential ID of active snapshot */
  958. __le64 s_snapshot_r_blocks_count; /* reserved blocks for active
  959. snapshot's future use */
  960. __le32 s_snapshot_list; /* inode number of the head of the
  961. on-disk snapshot list */
  962. #define EXT4_S_ERR_START offsetof(struct ext4_super_block, s_error_count)
  963. __le32 s_error_count; /* number of fs errors */
  964. __le32 s_first_error_time; /* first time an error happened */
  965. __le32 s_first_error_ino; /* inode involved in first error */
  966. __le64 s_first_error_block; /* block involved of first error */
  967. __u8 s_first_error_func[32]; /* function where the error happened */
  968. __le32 s_first_error_line; /* line number where error happened */
  969. __le32 s_last_error_time; /* most recent time of an error */
  970. __le32 s_last_error_ino; /* inode involved in last error */
  971. __le32 s_last_error_line; /* line number where error happened */
  972. __le64 s_last_error_block; /* block involved of last error */
  973. __u8 s_last_error_func[32]; /* function where the error happened */
  974. #define EXT4_S_ERR_END offsetof(struct ext4_super_block, s_mount_opts)
  975. __u8 s_mount_opts[64];
  976. __le32 s_reserved[112]; /* Padding to the end of the block */
  977. };
  978. #define EXT4_S_ERR_LEN (EXT4_S_ERR_END - EXT4_S_ERR_START)
  979. #ifdef __KERNEL__
  980. /*
  981. * run-time mount flags
  982. */
  983. #define EXT4_MF_MNTDIR_SAMPLED 0x0001
  984. #define EXT4_MF_FS_ABORTED 0x0002 /* Fatal error detected */
  985. /*
  986. * fourth extended-fs super-block data in memory
  987. */
  988. struct ext4_sb_info {
  989. unsigned long s_desc_size; /* Size of a group descriptor in bytes */
  990. unsigned long s_inodes_per_block;/* Number of inodes per block */
  991. unsigned long s_blocks_per_group;/* Number of blocks in a group */
  992. unsigned long s_inodes_per_group;/* Number of inodes in a group */
  993. unsigned long s_itb_per_group; /* Number of inode table blocks per group */
  994. unsigned long s_gdb_count; /* Number of group descriptor blocks */
  995. unsigned long s_desc_per_block; /* Number of group descriptors per block */
  996. ext4_group_t s_groups_count; /* Number of groups in the fs */
  997. ext4_group_t s_blockfile_groups;/* Groups acceptable for non-extent files */
  998. unsigned long s_overhead_last; /* Last calculated overhead */
  999. unsigned long s_blocks_last; /* Last seen block count */
  1000. loff_t s_bitmap_maxbytes; /* max bytes for bitmap files */
  1001. struct buffer_head * s_sbh; /* Buffer containing the super block */
  1002. struct ext4_super_block *s_es; /* Pointer to the super block in the buffer */
  1003. struct buffer_head **s_group_desc;
  1004. unsigned int s_mount_opt;
  1005. unsigned int s_mount_opt2;
  1006. unsigned int s_mount_flags;
  1007. ext4_fsblk_t s_sb_block;
  1008. uid_t s_resuid;
  1009. gid_t s_resgid;
  1010. unsigned short s_mount_state;
  1011. unsigned short s_pad;
  1012. int s_addr_per_block_bits;
  1013. int s_desc_per_block_bits;
  1014. int s_inode_size;
  1015. int s_first_ino;
  1016. unsigned int s_inode_readahead_blks;
  1017. unsigned int s_inode_goal;
  1018. spinlock_t s_next_gen_lock;
  1019. u32 s_next_generation;
  1020. u32 s_hash_seed[4];
  1021. int s_def_hash_version;
  1022. int s_hash_unsigned; /* 3 if hash should be signed, 0 if not */
  1023. struct percpu_counter s_freeblocks_counter;
  1024. struct percpu_counter s_freeinodes_counter;
  1025. struct percpu_counter s_dirs_counter;
  1026. struct percpu_counter s_dirtyblocks_counter;
  1027. struct blockgroup_lock *s_blockgroup_lock;
  1028. struct proc_dir_entry *s_proc;
  1029. struct kobject s_kobj;
  1030. struct completion s_kobj_unregister;
  1031. /* Journaling */
  1032. struct journal_s *s_journal;
  1033. struct list_head s_orphan;
  1034. struct mutex s_orphan_lock;
  1035. unsigned long s_resize_flags; /* Flags indicating if there
  1036. is a resizer */
  1037. unsigned long s_commit_interval;
  1038. u32 s_max_batch_time;
  1039. u32 s_min_batch_time;
  1040. struct block_device *journal_bdev;
  1041. #ifdef CONFIG_JBD2_DEBUG
  1042. struct timer_list turn_ro_timer; /* For turning read-only (crash simulation) */
  1043. wait_queue_head_t ro_wait_queue; /* For people waiting for the fs to go read-only */
  1044. #endif
  1045. #ifdef CONFIG_QUOTA
  1046. char *s_qf_names[MAXQUOTAS]; /* Names of quota files with journalled quota */
  1047. int s_jquota_fmt; /* Format of quota to use */
  1048. #endif
  1049. unsigned int s_want_extra_isize; /* New inodes should reserve # bytes */
  1050. struct rb_root system_blks;
  1051. #ifdef EXTENTS_STATS
  1052. /* ext4 extents stats */
  1053. unsigned long s_ext_min;
  1054. unsigned long s_ext_max;
  1055. unsigned long s_depth_max;
  1056. spinlock_t s_ext_stats_lock;
  1057. unsigned long s_ext_blocks;
  1058. unsigned long s_ext_extents;
  1059. #endif
  1060. /* ext4 extent cache stats */
  1061. unsigned long extent_cache_hits;
  1062. unsigned long extent_cache_misses;
  1063. /* for buddy allocator */
  1064. struct ext4_group_info ***s_group_info;
  1065. struct inode *s_buddy_cache;
  1066. spinlock_t s_md_lock;
  1067. unsigned short *s_mb_offsets;
  1068. unsigned int *s_mb_maxs;
  1069. /* tunables */
  1070. unsigned long s_stripe;
  1071. unsigned int s_mb_stream_request;
  1072. unsigned int s_mb_max_to_scan;
  1073. unsigned int s_mb_min_to_scan;
  1074. unsigned int s_mb_stats;
  1075. unsigned int s_mb_order2_reqs;
  1076. unsigned int s_mb_group_prealloc;
  1077. unsigned int s_max_writeback_mb_bump;
  1078. /* where last allocation was done - for stream allocation */
  1079. unsigned long s_mb_last_group;
  1080. unsigned long s_mb_last_start;
  1081. /* stats for buddy allocator */
  1082. atomic_t s_bal_reqs; /* number of reqs with len > 1 */
  1083. atomic_t s_bal_success; /* we found long enough chunks */
  1084. atomic_t s_bal_allocated; /* in blocks */
  1085. atomic_t s_bal_ex_scanned; /* total extents scanned */
  1086. atomic_t s_bal_goals; /* goal hits */
  1087. atomic_t s_bal_breaks; /* too long searches */
  1088. atomic_t s_bal_2orders; /* 2^order hits */
  1089. spinlock_t s_bal_lock;
  1090. unsigned long s_mb_buddies_generated;
  1091. unsigned long long s_mb_generation_time;
  1092. atomic_t s_mb_lost_chunks;
  1093. atomic_t s_mb_preallocated;
  1094. atomic_t s_mb_discarded;
  1095. atomic_t s_lock_busy;
  1096. /* locality groups */
  1097. struct ext4_locality_group __percpu *s_locality_groups;
  1098. /* for write statistics */
  1099. unsigned long s_sectors_written_start;
  1100. u64 s_kbytes_written;
  1101. unsigned int s_log_groups_per_flex;
  1102. struct flex_groups *s_flex_groups;
  1103. /* workqueue for dio unwritten */
  1104. struct workqueue_struct *dio_unwritten_wq;
  1105. /* timer for periodic error stats printing */
  1106. struct timer_list s_err_report;
  1107. /* Lazy inode table initialization info */
  1108. struct ext4_li_request *s_li_request;
  1109. /* Wait multiplier for lazy initialization thread */
  1110. unsigned int s_li_wait_mult;
  1111. /* Kernel thread for multiple mount protection */
  1112. struct task_struct *s_mmp_tsk;
  1113. /* record the last minlen when FITRIM is called. */
  1114. atomic_t s_last_trim_minblks;
  1115. };
  1116. static inline struct ext4_sb_info *EXT4_SB(struct super_block *sb)
  1117. {
  1118. return sb->s_fs_info;
  1119. }
  1120. static inline struct ext4_inode_info *EXT4_I(struct inode *inode)
  1121. {
  1122. return container_of(inode, struct ext4_inode_info, vfs_inode);
  1123. }
  1124. static inline struct timespec ext4_current_time(struct inode *inode)
  1125. {
  1126. return (inode->i_sb->s_time_gran < NSEC_PER_SEC) ?
  1127. current_fs_time(inode->i_sb) : CURRENT_TIME_SEC;
  1128. }
  1129. static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino)
  1130. {
  1131. return ino == EXT4_ROOT_INO ||
  1132. ino == EXT4_JOURNAL_INO ||
  1133. ino == EXT4_RESIZE_INO ||
  1134. (ino >= EXT4_FIRST_INO(sb) &&
  1135. ino <= le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count));
  1136. }
  1137. /*
  1138. * Inode dynamic state flags
  1139. */
  1140. enum {
  1141. EXT4_STATE_JDATA, /* journaled data exists */
  1142. EXT4_STATE_NEW, /* inode is newly created */
  1143. EXT4_STATE_XATTR, /* has in-inode xattrs */
  1144. EXT4_STATE_NO_EXPAND, /* No space for expansion */
  1145. EXT4_STATE_DA_ALLOC_CLOSE, /* Alloc DA blks on close */
  1146. EXT4_STATE_EXT_MIGRATE, /* Inode is migrating */
  1147. EXT4_STATE_DIO_UNWRITTEN, /* need convert on dio done*/
  1148. EXT4_STATE_NEWENTRY, /* File just added to dir */
  1149. EXT4_STATE_DELALLOC_RESERVED, /* blks already reserved for delalloc */
  1150. };
  1151. #define EXT4_INODE_BIT_FNS(name, field, offset) \
  1152. static inline int ext4_test_inode_##name(struct inode *inode, int bit) \
  1153. { \
  1154. return test_bit(bit + (offset), &EXT4_I(inode)->i_##field); \
  1155. } \
  1156. static inline void ext4_set_inode_##name(struct inode *inode, int bit) \
  1157. { \
  1158. set_bit(bit + (offset), &EXT4_I(inode)->i_##field); \
  1159. } \
  1160. static inline void ext4_clear_inode_##name(struct inode *inode, int bit) \
  1161. { \
  1162. clear_bit(bit + (offset), &EXT4_I(inode)->i_##field); \
  1163. }
  1164. EXT4_INODE_BIT_FNS(flag, flags, 0)
  1165. #if (BITS_PER_LONG < 64)
  1166. EXT4_INODE_BIT_FNS(state, state_flags, 0)
  1167. static inline void ext4_clear_state_flags(struct ext4_inode_info *ei)
  1168. {
  1169. (ei)->i_state_flags = 0;
  1170. }
  1171. #else
  1172. EXT4_INODE_BIT_FNS(state, flags, 32)
  1173. static inline void ext4_clear_state_flags(struct ext4_inode_info *ei)
  1174. {
  1175. /* We depend on the fact that callers will set i_flags */
  1176. }
  1177. #endif
  1178. #else
  1179. /* Assume that user mode programs are passing in an ext4fs superblock, not
  1180. * a kernel struct super_block. This will allow us to call the feature-test
  1181. * macros from user land. */
  1182. #define EXT4_SB(sb) (sb)
  1183. #endif
  1184. #define NEXT_ORPHAN(inode) EXT4_I(inode)->i_dtime
  1185. /*
  1186. * Codes for operating systems
  1187. */
  1188. #define EXT4_OS_LINUX 0
  1189. #define EXT4_OS_HURD 1
  1190. #define EXT4_OS_MASIX 2
  1191. #define EXT4_OS_FREEBSD 3
  1192. #define EXT4_OS_LITES 4
  1193. /*
  1194. * Revision levels
  1195. */
  1196. #define EXT4_GOOD_OLD_REV 0 /* The good old (original) format */
  1197. #define EXT4_DYNAMIC_REV 1 /* V2 format w/ dynamic inode sizes */
  1198. #define EXT4_CURRENT_REV EXT4_GOOD_OLD_REV
  1199. #define EXT4_MAX_SUPP_REV EXT4_DYNAMIC_REV
  1200. #define EXT4_GOOD_OLD_INODE_SIZE 128
  1201. /*
  1202. * Feature set definitions
  1203. */
  1204. #define EXT4_HAS_COMPAT_FEATURE(sb,mask) \
  1205. ((EXT4_SB(sb)->s_es->s_feature_compat & cpu_to_le32(mask)) != 0)
  1206. #define EXT4_HAS_RO_COMPAT_FEATURE(sb,mask) \
  1207. ((EXT4_SB(sb)->s_es->s_feature_ro_compat & cpu_to_le32(mask)) != 0)
  1208. #define EXT4_HAS_INCOMPAT_FEATURE(sb,mask) \
  1209. ((EXT4_SB(sb)->s_es->s_feature_incompat & cpu_to_le32(mask)) != 0)
  1210. #define EXT4_SET_COMPAT_FEATURE(sb,mask) \
  1211. EXT4_SB(sb)->s_es->s_feature_compat |= cpu_to_le32(mask)
  1212. #define EXT4_SET_RO_COMPAT_FEATURE(sb,mask) \
  1213. EXT4_SB(sb)->s_es->s_feature_ro_compat |= cpu_to_le32(mask)
  1214. #define EXT4_SET_INCOMPAT_FEATURE(sb,mask) \
  1215. EXT4_SB(sb)->s_es->s_feature_incompat |= cpu_to_le32(mask)
  1216. #define EXT4_CLEAR_COMPAT_FEATURE(sb,mask) \
  1217. EXT4_SB(sb)->s_es->s_feature_compat &= ~cpu_to_le32(mask)
  1218. #define EXT4_CLEAR_RO_COMPAT_FEATURE(sb,mask) \
  1219. EXT4_SB(sb)->s_es->s_feature_ro_compat &= ~cpu_to_le32(mask)
  1220. #define EXT4_CLEAR_INCOMPAT_FEATURE(sb,mask) \
  1221. EXT4_SB(sb)->s_es->s_feature_incompat &= ~cpu_to_le32(mask)
  1222. #define EXT4_FEATURE_COMPAT_DIR_PREALLOC 0x0001
  1223. #define EXT4_FEATURE_COMPAT_IMAGIC_INODES 0x0002
  1224. #define EXT4_FEATURE_COMPAT_HAS_JOURNAL 0x0004
  1225. #define EXT4_FEATURE_COMPAT_EXT_ATTR 0x0008
  1226. #define EXT4_FEATURE_COMPAT_RESIZE_INODE 0x0010
  1227. #define EXT4_FEATURE_COMPAT_DIR_INDEX 0x0020
  1228. #define EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
  1229. #define EXT4_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
  1230. #define EXT4_FEATURE_RO_COMPAT_BTREE_DIR 0x0004
  1231. #define EXT4_FEATURE_RO_COMPAT_HUGE_FILE 0x0008
  1232. #define EXT4_FEATURE_RO_COMPAT_GDT_CSUM 0x0010
  1233. #define EXT4_FEATURE_RO_COMPAT_DIR_NLINK 0x0020
  1234. #define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE 0x0040
  1235. #define EXT4_FEATURE_RO_COMPAT_QUOTA 0x0100
  1236. #define EXT4_FEATURE_INCOMPAT_COMPRESSION 0x0001
  1237. #define EXT4_FEATURE_INCOMPAT_FILETYPE 0x0002
  1238. #define EXT4_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */
  1239. #define EXT4_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */
  1240. #define EXT4_FEATURE_INCOMPAT_META_BG 0x0010
  1241. #define EXT4_FEATURE_INCOMPAT_EXTENTS 0x0040 /* extents support */
  1242. #define EXT4_FEATURE_INCOMPAT_64BIT 0x0080
  1243. #define EXT4_FEATURE_INCOMPAT_MMP 0x0100
  1244. #define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200
  1245. #define EXT4_FEATURE_INCOMPAT_EA_INODE 0x0400 /* EA in inode */
  1246. #define EXT4_FEATURE_INCOMPAT_DIRDATA 0x1000 /* data in dirent */
  1247. #define EXT