ext2.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 1992, 1993, 1994, 1995
  4. * Remy Card (card@masi.ibp.fr)
  5. * Laboratoire MASI - Institut Blaise Pascal
  6. * Universite Pierre et Marie Curie (Paris VI)
  7. *
  8. * from
  9. *
  10. * linux/include/linux/minix_fs.h
  11. *
  12. * Copyright (C) 1991, 1992 Linus Torvalds
  13. */
  14. #include <linux/fs.h>
  15. #include <linux/ext2_fs.h>
  16. #include <linux/blockgroup_lock.h>
  17. #include <linux/percpu_counter.h>
  18. #include <linux/rbtree.h>
  19. /* XXX Here for now... not interested in restructing headers JUST now */
  20. /* data type for block offset of block group */
  21. typedef int ext2_grpblk_t;
  22. /* data type for filesystem-wide blocks number */
  23. typedef unsigned long ext2_fsblk_t;
  24. #define E2FSBLK "%lu"
  25. struct ext2_reserve_window {
  26. ext2_fsblk_t _rsv_start; /* First byte reserved */
  27. ext2_fsblk_t _rsv_end; /* Last byte reserved or 0 */
  28. };
  29. struct ext2_reserve_window_node {
  30. struct rb_node rsv_node;
  31. __u32 rsv_goal_size;
  32. __u32 rsv_alloc_hit;
  33. struct ext2_reserve_window rsv_window;
  34. };
  35. struct ext2_block_alloc_info {
  36. /* information about reservation window */
  37. struct ext2_reserve_window_node rsv_window_node;
  38. /*
  39. * was i_next_alloc_block in ext2_inode_info
  40. * is the logical (file-relative) number of the
  41. * most-recently-allocated block in this file.
  42. * We use this for detecting linearly ascending allocation requests.
  43. */
  44. __u32 last_alloc_logical_block;
  45. /*
  46. * Was i_next_alloc_goal in ext2_inode_info
  47. * is the *physical* companion to i_next_alloc_block.
  48. * it is the physical block number of the block which was most-recently
  49. * allocated to this file. This gives us the goal (target) for the next
  50. * allocation when we detect linearly ascending requests.
  51. */
  52. ext2_fsblk_t last_alloc_physical_block;
  53. };
  54. #define rsv_start rsv_window._rsv_start
  55. #define rsv_end rsv_window._rsv_end
  56. struct mb_cache;
  57. /*
  58. * second extended-fs super-block data in memory
  59. */
  60. struct ext2_sb_info {
  61. unsigned long s_frag_size; /* Size of a fragment in bytes */
  62. unsigned long s_frags_per_block;/* Number of fragments per block */
  63. unsigned long s_inodes_per_block;/* Number of inodes per block */
  64. unsigned long s_frags_per_group;/* Number of fragments in a group */
  65. unsigned long s_blocks_per_group;/* Number of blocks in a group */
  66. unsigned long s_inodes_per_group;/* Number of inodes in a group */
  67. unsigned long s_itb_per_group; /* Number of inode table blocks per group */
  68. unsigned long s_gdb_count; /* Number of group descriptor blocks */
  69. unsigned long s_desc_per_block; /* Number of group descriptors per block */
  70. unsigned long s_groups_count; /* Number of groups in the fs */
  71. unsigned long s_overhead_last; /* Last calculated overhead */
  72. unsigned long s_blocks_last; /* Last seen block count */
  73. struct buffer_head * s_sbh; /* Buffer containing the super block */
  74. struct ext2_super_block * s_es; /* Pointer to the super block in the buffer */
  75. struct buffer_head ** s_group_desc;
  76. unsigned long s_mount_opt;
  77. unsigned long s_sb_block;
  78. kuid_t s_resuid;
  79. kgid_t s_resgid;
  80. unsigned short s_mount_state;
  81. unsigned short s_pad;
  82. int s_addr_per_block_bits;
  83. int s_desc_per_block_bits;
  84. int s_inode_size;
  85. int s_first_ino;
  86. spinlock_t s_next_gen_lock;
  87. u32 s_next_generation;
  88. unsigned long s_dir_count;
  89. u8 *s_debts;
  90. struct percpu_counter s_freeblocks_counter;
  91. struct percpu_counter s_freeinodes_counter;
  92. struct percpu_counter s_dirs_counter;
  93. struct blockgroup_lock *s_blockgroup_lock;
  94. /* root of the per fs reservation window tree */
  95. spinlock_t s_rsv_window_lock;
  96. struct rb_root s_rsv_window_root;
  97. struct ext2_reserve_window_node s_rsv_window_head;
  98. /*
  99. * s_lock protects against concurrent modifications of s_mount_state,
  100. * s_blocks_last, s_overhead_last and the content of superblock's
  101. * buffer pointed to by sbi->s_es.
  102. *
  103. * Note: It is used in ext2_show_options() to provide a consistent view
  104. * of the mount options.
  105. */
  106. spinlock_t s_lock;
  107. struct mb_cache *s_ea_block_cache;
  108. struct dax_device *s_daxdev;
  109. };
  110. static inline spinlock_t *
  111. sb_bgl_lock(struct ext2_sb_info *sbi, unsigned int block_group)
  112. {
  113. return bgl_lock_ptr(sbi->s_blockgroup_lock, block_group);
  114. }
  115. /*
  116. * Define EXT2FS_DEBUG to produce debug messages
  117. */
  118. #undef EXT2FS_DEBUG
  119. /*
  120. * Define EXT2_RESERVATION to reserve data blocks for expanding files
  121. */
  122. #define EXT2_DEFAULT_RESERVE_BLOCKS 8
  123. /*max window size: 1024(direct blocks) + 3([t,d]indirect blocks) */
  124. #define EXT2_MAX_RESERVE_BLOCKS 1027
  125. #define EXT2_RESERVE_WINDOW_NOT_ALLOCATED 0
  126. /*
  127. * The second extended file system version
  128. */
  129. #define EXT2FS_DATE "95/08/09"
  130. #define EXT2FS_VERSION "0.5b"
  131. /*
  132. * Debug code
  133. */
  134. #ifdef EXT2FS_DEBUG
  135. # define ext2_debug(f, a...) { \
  136. printk ("EXT2-fs DEBUG (%s, %d): %s:", \
  137. __FILE__, __LINE__, __func__); \
  138. printk (f, ## a); \
  139. }
  140. #else
  141. # define ext2_debug(f, a...) /**/
  142. #endif
  143. /*
  144. * Special inode numbers
  145. */
  146. #define EXT2_BAD_INO 1 /* Bad blocks inode */
  147. #define EXT2_ROOT_INO 2 /* Root inode */
  148. #define EXT2_BOOT_LOADER_INO 5 /* Boot loader inode */
  149. #define EXT2_UNDEL_DIR_INO 6 /* Undelete directory inode */
  150. /* First non-reserved inode for old ext2 filesystems */
  151. #define EXT2_GOOD_OLD_FIRST_INO 11
  152. static inline struct ext2_sb_info *EXT2_SB(struct super_block *sb)
  153. {
  154. return sb->s_fs_info;
  155. }
  156. /*
  157. * Macro-instructions used to manage several block sizes
  158. */
  159. #define EXT2_MIN_BLOCK_SIZE 1024
  160. #define EXT2_MAX_BLOCK_SIZE 4096
  161. #define EXT2_MIN_BLOCK_LOG_SIZE 10
  162. #define EXT2_BLOCK_SIZE(s) ((s)->s_blocksize)
  163. #define EXT2_ADDR_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (__u32))
  164. #define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)
  165. #define EXT2_ADDR_PER_BLOCK_BITS(s) (EXT2_SB(s)->s_addr_per_block_bits)
  166. #define EXT2_INODE_SIZE(s) (EXT2_SB(s)->s_inode_size)
  167. #define EXT2_FIRST_INO(s) (EXT2_SB(s)->s_first_ino)
  168. /*
  169. * Macro-instructions used to manage fragments
  170. */
  171. #define EXT2_MIN_FRAG_SIZE 1024
  172. #define EXT2_MAX_FRAG_SIZE 4096
  173. #define EXT2_MIN_FRAG_LOG_SIZE 10
  174. #define EXT2_FRAG_SIZE(s) (EXT2_SB(s)->s_frag_size)
  175. #define EXT2_FRAGS_PER_BLOCK(s) (EXT2_SB(s)->s_frags_per_block)
  176. /*
  177. * Structure of a blocks group descriptor
  178. */
  179. struct ext2_group_desc
  180. {
  181. __le32 bg_block_bitmap; /* Blocks bitmap block */
  182. __le32 bg_inode_bitmap; /* Inodes bitmap block */
  183. __le32 bg_inode_table; /* Inodes table block */
  184. __le16 bg_free_blocks_count; /* Free blocks count */
  185. __le16 bg_free_inodes_count; /* Free inodes count */
  186. __le16 bg_used_dirs_count; /* Directories count */
  187. __le16 bg_pad;
  188. __le32 bg_reserved[3];
  189. };
  190. /*
  191. * Macro-instructions used to manage group descriptors
  192. */
  193. #define EXT2_BLOCKS_PER_GROUP(s) (EXT2_SB(s)->s_blocks_per_group)
  194. #define EXT2_DESC_PER_BLOCK(s) (EXT2_SB(s)->s_desc_per_block)
  195. #define EXT2_INODES_PER_GROUP(s) (EXT2_SB(s)->s_inodes_per_group)
  196. #define EXT2_DESC_PER_BLOCK_BITS(s) (EXT2_SB(s)->s_desc_per_block_bits)
  197. /*
  198. * Constants relative to the data blocks
  199. */
  200. #define EXT2_NDIR_BLOCKS 12
  201. #define EXT2_IND_BLOCK EXT2_NDIR_BLOCKS
  202. #define EXT2_DIND_BLOCK (EXT2_IND_BLOCK + 1)
  203. #define EXT2_TIND_BLOCK (EXT2_DIND_BLOCK + 1)
  204. #define EXT2_N_BLOCKS (EXT2_TIND_BLOCK + 1)
  205. /*
  206. * Inode flags (GETFLAGS/SETFLAGS)
  207. */
  208. #define EXT2_SECRM_FL FS_SECRM_FL /* Secure deletion */
  209. #define EXT2_UNRM_FL FS_UNRM_FL /* Undelete */
  210. #define EXT2_COMPR_FL FS_COMPR_FL /* Compress file */
  211. #define EXT2_SYNC_FL FS_SYNC_FL /* Synchronous updates */
  212. #define EXT2_IMMUTABLE_FL FS_IMMUTABLE_FL /* Immutable file */
  213. #define EXT2_APPEND_FL FS_APPEND_FL /* writes to file may only append */
  214. #define EXT2_NODUMP_FL FS_NODUMP_FL /* do not dump file */
  215. #define EXT2_NOATIME_FL FS_NOATIME_FL /* do not update atime */
  216. /* Reserved for compression usage... */
  217. #define EXT2_DIRTY_FL FS_DIRTY_FL
  218. #define EXT2_COMPRBLK_FL FS_COMPRBLK_FL /* One or more compressed clusters */
  219. #define EXT2_NOCOMP_FL FS_NOCOMP_FL /* Don't compress */
  220. #define EXT2_ECOMPR_FL FS_ECOMPR_FL /* Compression error */
  221. /* End compression flags --- maybe not all used */
  222. #define EXT2_BTREE_FL FS_BTREE_FL /* btree format dir */
  223. #define EXT2_INDEX_FL FS_INDEX_FL /* hash-indexed directory */
  224. #define EXT2_IMAGIC_FL FS_IMAGIC_FL /* AFS directory */
  225. #define EXT2_JOURNAL_DATA_FL FS_JOURNAL_DATA_FL /* Reserved for ext3 */
  226. #define EXT2_NOTAIL_FL FS_NOTAIL_FL /* file tail should not be merged */
  227. #define EXT2_DIRSYNC_FL FS_DIRSYNC_FL /* dirsync behaviour (directories only) */
  228. #define EXT2_TOPDIR_FL FS_TOPDIR_FL /* Top of directory hierarchies*/
  229. #define EXT2_RESERVED_FL FS_RESERVED_FL /* reserved for ext2 lib */
  230. #define EXT2_FL_USER_VISIBLE FS_FL_USER_VISIBLE /* User visible flags */
  231. #define EXT2_FL_USER_MODIFIABLE FS_FL_USER_MODIFIABLE /* User modifiable flags */
  232. /* Flags that should be inherited by new inodes from their parent. */
  233. #define EXT2_FL_INHERITED (EXT2_SECRM_FL | EXT2_UNRM_FL | EXT2_COMPR_FL |\
  234. EXT2_SYNC_FL | EXT2_NODUMP_FL |\
  235. EXT2_NOATIME_FL | EXT2_COMPRBLK_FL |\
  236. EXT2_NOCOMP_FL | EXT2_JOURNAL_DATA_FL |\
  237. EXT2_NOTAIL_FL | EXT2_DIRSYNC_FL)
  238. /* Flags that are appropriate for regular files (all but dir-specific ones). */
  239. #define EXT2_REG_FLMASK (~(EXT2_DIRSYNC_FL | EXT2_TOPDIR_FL))
  240. /* Flags that are appropriate for non-directories/regular files. */
  241. #define EXT2_OTHER_FLMASK (EXT2_NODUMP_FL | EXT2_NOATIME_FL)
  242. /* Mask out flags that are inappropriate for the given type of inode. */
  243. static inline __u32 ext2_mask_flags(umode_t mode, __u32 flags)
  244. {
  245. if (S_ISDIR(mode))
  246. return flags;
  247. else if (S_ISREG(mode))
  248. return flags & EXT2_REG_FLMASK;
  249. else
  250. return flags & EXT2_OTHER_FLMASK;
  251. }
  252. /*
  253. * ioctl commands
  254. */
  255. #define EXT2_IOC_GETFLAGS FS_IOC_GETFLAGS
  256. #define EXT2_IOC_SETFLAGS FS_IOC_SETFLAGS
  257. #define EXT2_IOC_GETVERSION FS_IOC_GETVERSION
  258. #define EXT2_IOC_SETVERSION FS_IOC_SETVERSION
  259. #define EXT2_IOC_GETRSVSZ _IOR('f', 5, long)
  260. #define EXT2_IOC_SETRSVSZ _IOW('f', 6, long)
  261. /*
  262. * ioctl commands in 32 bit emulation
  263. */
  264. #define EXT2_IOC32_GETFLAGS FS_IOC32_GETFLAGS
  265. #define EXT2_IOC32_SETFLAGS FS_IOC32_SETFLAGS
  266. #define EXT2_IOC32_GETVERSION FS_IOC32_GETVERSION
  267. #define EXT2_IOC32_SETVERSION FS_IOC32_SETVERSION
  268. /*
  269. * Structure of an inode on the disk
  270. */
  271. struct ext2_inode {
  272. __le16 i_mode; /* File mode */
  273. __le16 i_uid; /* Low 16 bits of Owner Uid */
  274. __le32 i_size; /* Size in bytes */
  275. __le32 i_atime; /* Access time */
  276. __le32 i_ctime; /* Creation time */
  277. __le32 i_mtime; /* Modification time */
  278. __le32 i_dtime; /* Deletion Time */
  279. __le16 i_gid; /* Low 16 bits of Group Id */
  280. __le16 i_links_count; /* Links count */
  281. __le32 i_blocks; /* Blocks count */
  282. __le32 i_flags; /* File flags */
  283. union {
  284. struct {
  285. __le32 l_i_reserved1;
  286. } linux1;
  287. struct {
  288. __le32 h_i_translator;
  289. } hurd1;
  290. struct {
  291. __le32 m_i_reserved1;
  292. } masix1;
  293. } osd1; /* OS dependent 1 */
  294. __le32 i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
  295. __le32 i_generation; /* File version (for NFS) */
  296. __le32 i_file_acl; /* File ACL */
  297. __le32 i_dir_acl; /* Directory ACL */
  298. __le32 i_faddr; /* Fragment address */
  299. union {
  300. struct {
  301. __u8 l_i_frag; /* Fragment number */
  302. __u8 l_i_fsize; /* Fragment size */
  303. __u16 i_pad1;
  304. __le16 l_i_uid_high; /* these 2 fields */
  305. __le16 l_i_gid_high; /* were reserved2[0] */
  306. __u32 l_i_reserved2;
  307. } linux2;
  308. struct {
  309. __u8 h_i_frag; /* Fragment number */
  310. __u8 h_i_fsize; /* Fragment size */
  311. __le16 h_i_mode_high;
  312. __le16 h_i_uid_high;
  313. __le16 h_i_gid_high;
  314. __le32 h_i_author;
  315. } hurd2;
  316. struct {
  317. __u8 m_i_frag; /* Fragment number */
  318. __u8 m_i_fsize; /* Fragment size */
  319. __u16 m_pad1;
  320. __u32 m_i_reserved2[2];
  321. } masix2;
  322. } osd2; /* OS dependent 2 */
  323. };
  324. #define i_size_high i_dir_acl
  325. #define i_reserved1 osd1.linux1.l_i_reserved1
  326. #define i_frag osd2.linux2.l_i_frag
  327. #define i_fsize osd2.linux2.l_i_fsize
  328. #define i_uid_low i_uid
  329. #define i_gid_low i_gid
  330. #define i_uid_high osd2.linux2.l_i_uid_high
  331. #define i_gid_high osd2.linux2.l_i_gid_high
  332. #define i_reserved2 osd2.linux2.l_i_reserved2
  333. /*
  334. * File system states
  335. */
  336. #define EXT2_VALID_FS 0x0001 /* Unmounted cleanly */
  337. #define EXT2_ERROR_FS 0x0002 /* Errors detected */
  338. #define EFSCORRUPTED EUCLEAN /* Filesystem is corrupted */
  339. /*
  340. * Mount flags
  341. */
  342. #define EXT2_MOUNT_OLDALLOC 0x000002 /* Don't use the new Orlov allocator */
  343. #define EXT2_MOUNT_GRPID 0x000004 /* Create files with directory's group */
  344. #define EXT2_MOUNT_DEBUG 0x000008 /* Some debugging messages */
  345. #define EXT2_MOUNT_ERRORS_CONT 0x000010 /* Continue on errors */
  346. #define EXT2_MOUNT_ERRORS_RO 0x000020 /* Remount fs ro on errors */
  347. #define EXT2_MOUNT_ERRORS_PANIC 0x000040 /* Panic on errors */
  348. #define EXT2_MOUNT_MINIX_DF 0x000080 /* Mimics the Minix statfs */
  349. #define EXT2_MOUNT_NOBH 0x000100 /* No buffer_heads */
  350. #define EXT2_MOUNT_NO_UID32 0x000200 /* Disable 32-bit UIDs */
  351. #define EXT2_MOUNT_XATTR_USER 0x004000 /* Extended user attributes */
  352. #define EXT2_MOUNT_POSIX_ACL 0x008000 /* POSIX Access Control Lists */
  353. #define EXT2_MOUNT_XIP 0x010000 /* Obsolete, use DAX */
  354. #define EXT2_MOUNT_USRQUOTA 0x020000 /* user quota */
  355. #define EXT2_MOUNT_GRPQUOTA 0x040000 /* group quota */
  356. #define EXT2_MOUNT_RESERVATION 0x080000 /* Preallocation */
  357. #define EXT2_MOUNT_DAX 0x100000 /* Direct Access */
  358. #define clear_opt(o, opt) o &= ~EXT2_MOUNT_##opt
  359. #define set_opt(o, opt) o |= EXT2_MOUNT_##opt
  360. #define test_opt(sb, opt) (EXT2_SB(sb)->s_mount_opt & \
  361. EXT2_MOUNT_##opt)
  362. /*
  363. * Maximal mount counts between two filesystem checks
  364. */
  365. #define EXT2_DFL_MAX_MNT_COUNT 20 /* Allow 20 mounts */
  366. #define EXT2_DFL_CHECKINTERVAL 0 /* Don't use interval check */
  367. /*
  368. * Behaviour when detecting errors
  369. */
  370. #define EXT2_ERRORS_CONTINUE 1 /* Continue execution */
  371. #define EXT2_ERRORS_RO 2 /* Remount fs read-only */
  372. #define EXT2_ERRORS_PANIC 3 /* Panic */
  373. #define EXT2_ERRORS_DEFAULT EXT2_ERRORS_CONTINUE
  374. /*
  375. * Structure of the super block
  376. */
  377. struct ext2_super_block {
  378. __le32 s_inodes_count; /* Inodes count */
  379. __le32 s_blocks_count; /* Blocks count */
  380. __le32 s_r_blocks_count; /* Reserved blocks count */
  381. __le32 s_free_blocks_count; /* Free blocks count */
  382. __le32 s_free_inodes_count; /* Free inodes count */
  383. __le32 s_first_data_block; /* First Data Block */
  384. __le32 s_log_block_size; /* Block size */
  385. __le32 s_log_frag_size; /* Fragment size */
  386. __le32 s_blocks_per_group; /* # Blocks per group */
  387. __le32 s_frags_per_group; /* # Fragments per group */
  388. __le32 s_inodes_per_group; /* # Inodes per group */
  389. __le32 s_mtime; /* Mount time */
  390. __le32 s_wtime; /* Write time */
  391. __le16 s_mnt_count; /* Mount count */
  392. __le16 s_max_mnt_count; /* Maximal mount count */
  393. __le16 s_magic; /* Magic signature */
  394. __le16 s_state; /* File system state */
  395. __le16 s_errors; /* Behaviour when detecting errors */
  396. __le16 s_minor_rev_level; /* minor revision level */
  397. __le32 s_lastcheck; /* time of last check */
  398. __le32 s_checkinterval; /* max. time between checks */
  399. __le32 s_creator_os; /* OS */
  400. __le32 s_rev_level; /* Revision level */
  401. __le16 s_def_resuid; /* Default uid for reserved blocks */
  402. __le16 s_def_resgid; /* Default gid for reserved blocks */
  403. /*
  404. * These fields are for EXT2_DYNAMIC_REV superblocks only.
  405. *
  406. * Note: the difference between the compatible feature set and
  407. * the incompatible feature set is that if there is a bit set
  408. * in the incompatible feature set that the kernel doesn't
  409. * know about, it should refuse to mount the filesystem.
  410. *
  411. * e2fsck's requirements are more strict; if it doesn't know
  412. * about a feature in either the compatible or incompatible
  413. * feature set, it must abort and not try to meddle with
  414. * things it doesn't understand...
  415. */
  416. __le32 s_first_ino; /* First non-reserved inode */
  417. __le16 s_inode_size; /* size of inode structure */
  418. __le16 s_block_group_nr; /* block group # of this superblock */
  419. __le32 s_feature_compat; /* compatible feature set */
  420. __le32 s_feature_incompat; /* incompatible feature set */
  421. __le32 s_feature_ro_compat; /* readonly-compatible feature set */
  422. __u8 s_uuid[16]; /* 128-bit uuid for volume */
  423. char s_volume_name[16]; /* volume name */
  424. char s_last_mounted[64]; /* directory where last mounted */
  425. __le32 s_algorithm_usage_bitmap; /* For compression */
  426. /*
  427. * Performance hints. Directory preallocation should only
  428. * happen if the EXT2_COMPAT_PREALLOC flag is on.
  429. */
  430. __u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/
  431. __u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */
  432. __u16 s_padding1;
  433. /*
  434. * Journaling support valid if EXT3_FEATURE_COMPAT_HAS_JOURNAL set.
  435. */
  436. __u8 s_journal_uuid[16]; /* uuid of journal superblock */
  437. __u32 s_journal_inum; /* inode number of journal file */
  438. __u32 s_journal_dev; /* device number of journal file */
  439. __u32 s_last_orphan; /* start of list of inodes to delete */
  440. __u32 s_hash_seed[4]; /* HTREE hash seed */
  441. __u8 s_def_hash_version; /* Default hash version to use */
  442. __u8 s_reserved_char_pad;
  443. __u16 s_reserved_word_pad;
  444. __le32 s_default_mount_opts;
  445. __le32 s_first_meta_bg; /* First metablock block group */
  446. __u32 s_reserved[190]; /* Padding to the end of the block */
  447. };
  448. /*
  449. * Codes for operating systems
  450. */
  451. #define EXT2_OS_LINUX 0
  452. #define EXT2_OS_HURD 1
  453. #define EXT2_OS_MASIX 2
  454. #define EXT2_OS_FREEBSD 3
  455. #define EXT2_OS_LITES 4
  456. /*
  457. * Revision levels
  458. */
  459. #define EXT2_GOOD_OLD_REV 0 /* The good old (original) format */
  460. #define EXT2_DYNAMIC_REV 1 /* V2 format w/ dynamic inode sizes */
  461. #define EXT2_CURRENT_REV EXT2_GOOD_OLD_REV
  462. #define EXT2_MAX_SUPP_REV EXT2_DYNAMIC_REV
  463. #define EXT2_GOOD_OLD_INODE_SIZE 128
  464. /*
  465. * Feature set definitions
  466. */
  467. #define EXT2_HAS_COMPAT_FEATURE(sb,mask) \
  468. ( EXT2_SB(sb)->s_es->s_feature_compat & cpu_to_le32(mask) )
  469. #define EXT2_HAS_RO_COMPAT_FEATURE(sb,mask) \
  470. ( EXT2_SB(sb)->s_es->s_feature_ro_compat & cpu_to_le32(mask) )
  471. #define EXT2_HAS_INCOMPAT_FEATURE(sb,mask) \
  472. ( EXT2_SB(sb)->s_es->s_feature_incompat & cpu_to_le32(mask) )
  473. #define EXT2_SET_COMPAT_FEATURE(sb,mask) \
  474. EXT2_SB(sb)->s_es->s_feature_compat |= cpu_to_le32(mask)
  475. #define EXT2_SET_RO_COMPAT_FEATURE(sb,mask) \
  476. EXT2_SB(sb)->s_es->s_feature_ro_compat |= cpu_to_le32(mask)
  477. #define EXT2_SET_INCOMPAT_FEATURE(sb,mask) \
  478. EXT2_SB(sb)->s_es->s_feature_incompat |= cpu_to_le32(mask)
  479. #define EXT2_CLEAR_COMPAT_FEATURE(sb,mask) \
  480. EXT2_SB(sb)->s_es->s_feature_compat &= ~cpu_to_le32(mask)
  481. #define EXT2_CLEAR_RO_COMPAT_FEATURE(sb,mask) \
  482. EXT2_SB(sb)->s_es->s_feature_ro_compat &= ~cpu_to_le32(mask)
  483. #define EXT2_CLEAR_INCOMPAT_FEATURE(sb,mask) \
  484. EXT2_SB(sb)->s_es->s_feature_incompat &= ~cpu_to_le32(mask)
  485. #define EXT2_FEATURE_COMPAT_DIR_PREALLOC 0x0001
  486. #define EXT2_FEATURE_COMPAT_IMAGIC_INODES 0x0002
  487. #define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004
  488. #define EXT2_FEATURE_COMPAT_EXT_ATTR 0x0008
  489. #define EXT2_FEATURE_COMPAT_RESIZE_INO 0x0010
  490. #define EXT2_FEATURE_COMPAT_DIR_INDEX 0x0020
  491. #define EXT2_FEATURE_COMPAT_ANY 0xffffffff
  492. #define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
  493. #define EXT2_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
  494. #define EXT2_FEATURE_RO_COMPAT_BTREE_DIR 0x0004
  495. #define EXT2_FEATURE_RO_COMPAT_ANY 0xffffffff
  496. #define EXT2_FEATURE_INCOMPAT_COMPRESSION 0x0001
  497. #define EXT2_FEATURE_INCOMPAT_FILETYPE 0x0002
  498. #define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004
  499. #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008
  500. #define EXT2_FEATURE_INCOMPAT_META_BG 0x0010
  501. #define EXT2_FEATURE_INCOMPAT_ANY 0xffffffff
  502. #define EXT2_FEATURE_COMPAT_SUPP EXT2_FEATURE_COMPAT_EXT_ATTR
  503. #define EXT2_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE| \
  504. EXT2_FEATURE_INCOMPAT_META_BG)
  505. #define EXT2_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
  506. EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
  507. EXT2_FEATURE_RO_COMPAT_BTREE_DIR)
  508. #define EXT2_FEATURE_RO_COMPAT_UNSUPPORTED ~EXT2_FEATURE_RO_COMPAT_SUPP
  509. #define EXT2_FEATURE_INCOMPAT_UNSUPPORTED ~EXT2_FEATURE_INCOMPAT_SUPP
  510. /*
  511. * Default values for user and/or group using reserved blocks
  512. */
  513. #define EXT2_DEF_RESUID 0
  514. #define EXT2_DEF_RESGID 0
  515. /*
  516. * Default mount options
  517. */
  518. #define EXT2_DEFM_DEBUG 0x0001
  519. #define EXT2_DEFM_BSDGROUPS 0x0002
  520. #define EXT2_DEFM_XATTR_USER 0x0004
  521. #define EXT2_DEFM_ACL 0x0008
  522. #define EXT2_DEFM_UID16 0x0010
  523. /* Not used by ext2, but reserved for use by ext3 */
  524. #define EXT3_DEFM_JMODE 0x0060
  525. #define EXT3_DEFM_JMODE_DATA 0x0020
  526. #define EXT3_DEFM_JMODE_ORDERED 0x0040
  527. #define EXT3_DEFM_JMODE_WBACK 0x0060
  528. /*
  529. * Structure of a directory entry
  530. */
  531. struct ext2_dir_entry {
  532. __le32 inode; /* Inode number */
  533. __le16 rec_len; /* Directory entry length */
  534. __le16 name_len; /* Name length */
  535. char name[]; /* File name, up to EXT2_NAME_LEN */
  536. };
  537. /*
  538. * The new version of the directory entry. Since EXT2 structures are
  539. * stored in intel byte order, and the name_len field could never be
  540. * bigger than 255 chars, it's safe to reclaim the extra byte for the
  541. * file_type field.
  542. */
  543. struct ext2_dir_entry_2 {
  544. __le32 inode; /* Inode number */
  545. __le16 rec_len; /* Directory entry length */
  546. __u8 name_len; /* Name length */
  547. __u8 file_type;
  548. char name[]; /* File name, up to EXT2_NAME_LEN */
  549. };
  550. /*
  551. * EXT2_DIR_PAD defines the directory entries boundaries
  552. *
  553. * NOTE: It must be a multiple of 4
  554. */
  555. #define EXT2_DIR_PAD 4
  556. #define EXT2_DIR_ROUND (EXT2_DIR_PAD - 1)
  557. #define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \
  558. ~EXT2_DIR_ROUND)
  559. #define EXT2_MAX_REC_LEN ((1<<16)-1)
  560. static inline void verify_offsets(void)
  561. {
  562. #define A(x,y) BUILD_BUG_ON(x != offsetof(struct ext2_super_block, y));
  563. A(EXT2_SB_MAGIC_OFFSET, s_magic);
  564. A(EXT2_SB_BLOCKS_OFFSET, s_blocks_count);
  565. A(EXT2_SB_BSIZE_OFFSET, s_log_block_size);
  566. #undef A
  567. }
  568. /*
  569. * ext2 mount options
  570. */
  571. struct ext2_mount_options {
  572. unsigned long s_mount_opt;
  573. kuid_t s_resuid;
  574. kgid_t s_resgid;
  575. };
  576. /*
  577. * second extended file system inode data in memory
  578. */
  579. struct ext2_inode_info {
  580. __le32 i_data[15];
  581. __u32 i_flags;
  582. __u32 i_faddr;
  583. __u8 i_frag_no;
  584. __u8 i_frag_size;
  585. __u16 i_state;
  586. __u32 i_file_acl;
  587. __u32 i_dir_acl;
  588. __u32 i_dtime;
  589. /*
  590. * i_block_group is the number of the block group which contains
  591. * this file's inode. Constant across the lifetime of the inode,
  592. * it is used for making block allocation decisions - we try to
  593. * place a file's data blocks near its inode block, and new inodes
  594. * near to their parent directory's inode.
  595. */
  596. __u32 i_block_group;
  597. /* block reservation info */
  598. struct ext2_block_alloc_info *i_block_alloc_info;
  599. __u32 i_dir_start_lookup;
  600. #ifdef CONFIG_EXT2_FS_XATTR
  601. /*
  602. * Extended attributes can be read independently of the main file
  603. * data. Taking i_mutex even when reading would cause contention
  604. * between readers of EAs and writers of regular file data, so
  605. * instead we synchronize on xattr_sem when reading or changing
  606. * EAs.
  607. */
  608. struct rw_semaphore xattr_sem;
  609. #endif
  610. rwlock_t i_meta_lock;
  611. #ifdef CONFIG_FS_DAX
  612. struct rw_semaphore dax_sem;
  613. #endif
  614. /*
  615. * truncate_mutex is for serialising ext2_truncate() against
  616. * ext2_getblock(). It also protects the internals of the inode's
  617. * reservation data structures: ext2_reserve_window and
  618. * ext2_reserve_window_node.
  619. */
  620. struct mutex truncate_mutex;
  621. struct inode vfs_inode;
  622. struct list_head i_orphan; /* unlinked but open inodes */
  623. #ifdef CONFIG_QUOTA
  624. struct dquot *i_dquot[MAXQUOTAS];
  625. #endif
  626. };
  627. #ifdef CONFIG_FS_DAX
  628. #define dax_sem_down_write(ext2_inode) down_write(&(ext2_inode)->dax_sem)
  629. #define dax_sem_up_write(ext2_inode) up_write(&(ext2_inode)->dax_sem)
  630. #else
  631. #define dax_sem_down_write(ext2_inode)
  632. #define dax_sem_up_write(ext2_inode)
  633. #endif
  634. /*
  635. * Inode dynamic state flags
  636. */
  637. #define EXT2_STATE_NEW 0x00000001 /* inode is newly created */
  638. /*
  639. * Function prototypes
  640. */
  641. /*
  642. * Ok, these declarations are also in <linux/kernel.h> but none of the
  643. * ext2 source programs needs to include it so they are duplicated here.
  644. */
  645. static inline struct ext2_inode_info *EXT2_I(struct inode *inode)
  646. {
  647. return container_of(inode, struct ext2_inode_info, vfs_inode);
  648. }
  649. /* balloc.c */
  650. extern int ext2_bg_has_super(struct super_block *sb, int group);
  651. extern unsigned long ext2_bg_num_gdb(struct super_block *sb, int group);
  652. extern ext2_fsblk_t ext2_new_block(struct inode *, unsigned long, int *);
  653. extern ext2_fsblk_t ext2_new_blocks(struct inode *, unsigned long,
  654. unsigned long *, int *);
  655. extern int ext2_data_block_valid(struct ext2_sb_info *sbi, ext2_fsblk_t start_blk,
  656. unsigned int count);
  657. extern void ext2_free_blocks (struct inode *, unsigned long,
  658. unsigned long);
  659. extern unsigned long ext2_count_free_blocks (struct super_block *);
  660. extern unsigned long ext2_count_dirs (struct super_block *);
  661. extern struct ext2_group_desc * ext2_get_group_desc(struct super_block * sb,
  662. unsigned int block_group,
  663. struct buffer_head ** bh);
  664. extern void ext2_discard_reservation (struct inode *);
  665. extern int ext2_should_retry_alloc(struct super_block *sb, int *retries);
  666. extern void ext2_init_block_alloc_info(struct inode *);
  667. extern void ext2_rsv_window_add(struct super_block *sb, struct ext2_reserve_window_node *rsv);
  668. /* dir.c */
  669. extern int ext2_add_link (struct dentry *, struct inode *);
  670. extern int ext2_inode_by_name(struct inode *dir,
  671. const struct qstr *child, ino_t *ino);
  672. extern int ext2_make_empty(struct inode *, struct inode *);
  673. extern struct ext2_dir_entry_2 * ext2_find_entry (struct inode *,const struct qstr *, struct page **);
  674. extern int ext2_delete_entry (struct ext2_dir_entry_2 *, struct page *);
  675. extern int ext2_empty_dir (struct inode *);
  676. extern struct ext2_dir_entry_2 * ext2_dotdot (struct inode *, struct page **);
  677. extern void ext2_set_link(struct inode *, struct ext2_dir_entry_2 *, struct page *, struct inode *, int);
  678. /* ialloc.c */
  679. extern struct inode * ext2_new_inode (struct inode *, umode_t, const struct qstr *);
  680. extern void ext2_free_inode (struct inode *);
  681. extern unsigned long ext2_count_free_inodes (struct super_block *);
  682. extern unsigned long ext2_count_free (struct buffer_head *, unsigned);
  683. /* inode.c */
  684. extern struct inode *ext2_iget (struct super_block *, unsigned long);
  685. extern int ext2_write_inode (struct inode *, struct writeback_control *);
  686. extern void ext2_evict_inode(struct inode *);
  687. extern int ext2_get_block(struct inode *, sector_t, struct buffer_head *, int);
  688. extern int ext2_setattr (struct dentry *, struct iattr *);
  689. extern int ext2_getattr (const struct path *, struct kstat *, u32, unsigned int);
  690. extern void ext2_set_inode_flags(struct inode *inode);
  691. extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
  692. u64 start, u64 len);
  693. /* ioctl.c */
  694. extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
  695. extern long ext2_compat_ioctl(struct file *, unsigned int, unsigned long);
  696. /* namei.c */
  697. struct dentry *ext2_get_parent(struct dentry *child);
  698. /* super.c */
  699. extern __printf(3, 4)
  700. void ext2_error(struct super_block *, const char *, const char *, ...);
  701. extern __printf(3, 4)
  702. void ext2_msg(struct super_block *, const char *, const char *, ...);
  703. extern void ext2_update_dynamic_rev (struct super_block *sb);
  704. extern void ext2_sync_super(struct super_block *sb, struct ext2_super_block *es,
  705. int wait);
  706. /*
  707. * Inodes and files operations
  708. */
  709. /* dir.c */
  710. extern const struct file_operations ext2_dir_operations;
  711. /* file.c */
  712. extern int ext2_fsync(struct file *file, loff_t start, loff_t end,
  713. int datasync);
  714. extern const struct inode_operations ext2_file_inode_operations;
  715. extern const struct file_operations ext2_file_operations;
  716. /* inode.c */
  717. extern void ext2_set_file_ops(struct inode *inode);
  718. extern const struct address_space_operations ext2_aops;
  719. extern const struct address_space_operations ext2_nobh_aops;
  720. extern const struct iomap_ops ext2_iomap_ops;
  721. /* namei.c */
  722. extern const struct inode_operations ext2_dir_inode_operations;
  723. extern const struct inode_operations ext2_special_inode_operations;
  724. /* symlink.c */
  725. extern const struct inode_operations ext2_fast_symlink_inode_operations;
  726. extern const struct inode_operations ext2_symlink_inode_operations;
  727. static inline ext2_fsblk_t
  728. ext2_group_first_block_no(struct super_block *sb, unsigned long group_no)
  729. {
  730. return group_no * (ext2_fsblk_t)EXT2_BLOCKS_PER_GROUP(sb) +
  731. le32_to_cpu(EXT2_SB(sb)->s_es->s_first_data_block);
  732. }
  733. static inline ext2_fsblk_t
  734. ext2_group_last_block_no(struct super_block *sb, unsigned long group_no)
  735. {
  736. struct ext2_sb_info *sbi = EXT2_SB(sb);
  737. if (group_no == sbi->s_groups_count - 1)
  738. return le32_to_cpu(sbi->s_es->s_blocks_count) - 1;
  739. else
  740. return ext2_group_first_block_no(sb, group_no) +
  741. EXT2_BLOCKS_PER_GROUP(sb) - 1;
  742. }
  743. #define ext2_set_bit __test_and_set_bit_le
  744. #define ext2_clear_bit __test_and_clear_bit_le
  745. #define ext2_test_bit test_bit_le
  746. #define ext2_find_first_zero_bit find_first_zero_bit_le
  747. #define ext2_find_next_zero_bit find_next_zero_bit_le