ext2.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  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 the the physical block number of the block which was most-recentl
  49. * allocated to this file. This give 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_CHECK 0x000001 /* Do mount-time checks */
  343. #define EXT2_MOUNT_OLDALLOC 0x000002 /* Don't use the new Orlov allocator */
  344. #define EXT2_MOUNT_GRPID 0x000004 /* Create files with directory's group */
  345. #define EXT2_MOUNT_DEBUG 0x000008 /* Some debugging messages */
  346. #define EXT2_MOUNT_ERRORS_CONT 0x000010 /* Continue on errors */
  347. #define EXT2_MOUNT_ERRORS_RO 0x000020 /* Remount fs ro on errors */
  348. #define EXT2_MOUNT_ERRORS_PANIC 0x000040 /* Panic on errors */
  349. #define EXT2_MOUNT_MINIX_DF 0x000080 /* Mimics the Minix statfs */
  350. #define EXT2_MOUNT_NOBH 0x000100 /* No buffer_heads */
  351. #define EXT2_MOUNT_NO_UID32 0x000200 /* Disable 32-bit UIDs */
  352. #define EXT2_MOUNT_XATTR_USER 0x004000 /* Extended user attributes */
  353. #define EXT2_MOUNT_POSIX_ACL 0x008000 /* POSIX Access Control Lists */
  354. #define EXT2_MOUNT_XIP 0x010000 /* Obsolete, use DAX */
  355. #define EXT2_MOUNT_USRQUOTA 0x020000 /* user quota */
  356. #define EXT2_MOUNT_GRPQUOTA 0x040000 /* group quota */
  357. #define EXT2_MOUNT_RESERVATION 0x080000 /* Preallocation */
  358. #ifdef CONFIG_FS_DAX
  359. #define EXT2_MOUNT_DAX 0x100000 /* Direct Access */
  360. #else
  361. #define EXT2_MOUNT_DAX 0
  362. #endif
  363. #define clear_opt(o, opt) o &= ~EXT2_MOUNT_##opt
  364. #define set_opt(o, opt) o |= EXT2_MOUNT_##opt
  365. #define test_opt(sb, opt) (EXT2_SB(sb)->s_mount_opt & \
  366. EXT2_MOUNT_##opt)
  367. /*
  368. * Maximal mount counts between two filesystem checks
  369. */
  370. #define EXT2_DFL_MAX_MNT_COUNT 20 /* Allow 20 mounts */
  371. #define EXT2_DFL_CHECKINTERVAL 0 /* Don't use interval check */
  372. /*
  373. * Behaviour when detecting errors
  374. */
  375. #define EXT2_ERRORS_CONTINUE 1 /* Continue execution */
  376. #define EXT2_ERRORS_RO 2 /* Remount fs read-only */
  377. #define EXT2_ERRORS_PANIC 3 /* Panic */
  378. #define EXT2_ERRORS_DEFAULT EXT2_ERRORS_CONTINUE
  379. /*
  380. * Structure of the super block
  381. */
  382. struct ext2_super_block {
  383. __le32 s_inodes_count; /* Inodes count */
  384. __le32 s_blocks_count; /* Blocks count */
  385. __le32 s_r_blocks_count; /* Reserved blocks count */
  386. __le32 s_free_blocks_count; /* Free blocks count */
  387. __le32 s_free_inodes_count; /* Free inodes count */
  388. __le32 s_first_data_block; /* First Data Block */
  389. __le32 s_log_block_size; /* Block size */
  390. __le32 s_log_frag_size; /* Fragment size */
  391. __le32 s_blocks_per_group; /* # Blocks per group */
  392. __le32 s_frags_per_group; /* # Fragments per group */
  393. __le32 s_inodes_per_group; /* # Inodes per group */
  394. __le32 s_mtime; /* Mount time */
  395. __le32 s_wtime; /* Write time */
  396. __le16 s_mnt_count; /* Mount count */
  397. __le16 s_max_mnt_count; /* Maximal mount count */
  398. __le16 s_magic; /* Magic signature */
  399. __le16 s_state; /* File system state */
  400. __le16 s_errors; /* Behaviour when detecting errors */
  401. __le16 s_minor_rev_level; /* minor revision level */
  402. __le32 s_lastcheck; /* time of last check */
  403. __le32 s_checkinterval; /* max. time between checks */
  404. __le32 s_creator_os; /* OS */
  405. __le32 s_rev_level; /* Revision level */
  406. __le16 s_def_resuid; /* Default uid for reserved blocks */
  407. __le16 s_def_resgid; /* Default gid for reserved blocks */
  408. /*
  409. * These fields are for EXT2_DYNAMIC_REV superblocks only.
  410. *
  411. * Note: the difference between the compatible feature set and
  412. * the incompatible feature set is that if there is a bit set
  413. * in the incompatible feature set that the kernel doesn't
  414. * know about, it should refuse to mount the filesystem.
  415. *
  416. * e2fsck's requirements are more strict; if it doesn't know
  417. * about a feature in either the compatible or incompatible
  418. * feature set, it must abort and not try to meddle with
  419. * things it doesn't understand...
  420. */
  421. __le32 s_first_ino; /* First non-reserved inode */
  422. __le16 s_inode_size; /* size of inode structure */
  423. __le16 s_block_group_nr; /* block group # of this superblock */
  424. __le32 s_feature_compat; /* compatible feature set */
  425. __le32 s_feature_incompat; /* incompatible feature set */
  426. __le32 s_feature_ro_compat; /* readonly-compatible feature set */
  427. __u8 s_uuid[16]; /* 128-bit uuid for volume */
  428. char s_volume_name[16]; /* volume name */
  429. char s_last_mounted[64]; /* directory where last mounted */
  430. __le32 s_algorithm_usage_bitmap; /* For compression */
  431. /*
  432. * Performance hints. Directory preallocation should only
  433. * happen if the EXT2_COMPAT_PREALLOC flag is on.
  434. */
  435. __u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/
  436. __u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */
  437. __u16 s_padding1;
  438. /*
  439. * Journaling support valid if EXT3_FEATURE_COMPAT_HAS_JOURNAL set.
  440. */
  441. __u8 s_journal_uuid[16]; /* uuid of journal superblock */
  442. __u32 s_journal_inum; /* inode number of journal file */
  443. __u32 s_journal_dev; /* device number of journal file */
  444. __u32 s_last_orphan; /* start of list of inodes to delete */
  445. __u32 s_hash_seed[4]; /* HTREE hash seed */
  446. __u8 s_def_hash_version; /* Default hash version to use */
  447. __u8 s_reserved_char_pad;
  448. __u16 s_reserved_word_pad;
  449. __le32 s_default_mount_opts;
  450. __le32 s_first_meta_bg; /* First metablock block group */
  451. __u32 s_reserved[190]; /* Padding to the end of the block */
  452. };
  453. /*
  454. * Codes for operating systems
  455. */
  456. #define EXT2_OS_LINUX 0
  457. #define EXT2_OS_HURD 1
  458. #define EXT2_OS_MASIX 2
  459. #define EXT2_OS_FREEBSD 3
  460. #define EXT2_OS_LITES 4
  461. /*
  462. * Revision levels
  463. */
  464. #define EXT2_GOOD_OLD_REV 0 /* The good old (original) format */
  465. #define EXT2_DYNAMIC_REV 1 /* V2 format w/ dynamic inode sizes */
  466. #define EXT2_CURRENT_REV EXT2_GOOD_OLD_REV
  467. #define EXT2_MAX_SUPP_REV EXT2_DYNAMIC_REV
  468. #define EXT2_GOOD_OLD_INODE_SIZE 128
  469. /*
  470. * Feature set definitions
  471. */
  472. #define EXT2_HAS_COMPAT_FEATURE(sb,mask) \
  473. ( EXT2_SB(sb)->s_es->s_feature_compat & cpu_to_le32(mask) )
  474. #define EXT2_HAS_RO_COMPAT_FEATURE(sb,mask) \
  475. ( EXT2_SB(sb)->s_es->s_feature_ro_compat & cpu_to_le32(mask) )
  476. #define EXT2_HAS_INCOMPAT_FEATURE(sb,mask) \
  477. ( EXT2_SB(sb)->s_es->s_feature_incompat & cpu_to_le32(mask) )
  478. #define EXT2_SET_COMPAT_FEATURE(sb,mask) \
  479. EXT2_SB(sb)->s_es->s_feature_compat |= cpu_to_le32(mask)
  480. #define EXT2_SET_RO_COMPAT_FEATURE(sb,mask) \
  481. EXT2_SB(sb)->s_es->s_feature_ro_compat |= cpu_to_le32(mask)
  482. #define EXT2_SET_INCOMPAT_FEATURE(sb,mask) \
  483. EXT2_SB(sb)->s_es->s_feature_incompat |= cpu_to_le32(mask)
  484. #define EXT2_CLEAR_COMPAT_FEATURE(sb,mask) \
  485. EXT2_SB(sb)->s_es->s_feature_compat &= ~cpu_to_le32(mask)
  486. #define EXT2_CLEAR_RO_COMPAT_FEATURE(sb,mask) \
  487. EXT2_SB(sb)->s_es->s_feature_ro_compat &= ~cpu_to_le32(mask)
  488. #define EXT2_CLEAR_INCOMPAT_FEATURE(sb,mask) \
  489. EXT2_SB(sb)->s_es->s_feature_incompat &= ~cpu_to_le32(mask)
  490. #define EXT2_FEATURE_COMPAT_DIR_PREALLOC 0x0001
  491. #define EXT2_FEATURE_COMPAT_IMAGIC_INODES 0x0002
  492. #define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004
  493. #define EXT2_FEATURE_COMPAT_EXT_ATTR 0x0008
  494. #define EXT2_FEATURE_COMPAT_RESIZE_INO 0x0010
  495. #define EXT2_FEATURE_COMPAT_DIR_INDEX 0x0020
  496. #define EXT2_FEATURE_COMPAT_ANY 0xffffffff
  497. #define EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
  498. #define EXT2_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
  499. #define EXT2_FEATURE_RO_COMPAT_BTREE_DIR 0x0004
  500. #define EXT2_FEATURE_RO_COMPAT_ANY 0xffffffff
  501. #define EXT2_FEATURE_INCOMPAT_COMPRESSION 0x0001
  502. #define EXT2_FEATURE_INCOMPAT_FILETYPE 0x0002
  503. #define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004
  504. #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008
  505. #define EXT2_FEATURE_INCOMPAT_META_BG 0x0010
  506. #define EXT2_FEATURE_INCOMPAT_ANY 0xffffffff
  507. #define EXT2_FEATURE_COMPAT_SUPP EXT2_FEATURE_COMPAT_EXT_ATTR
  508. #define EXT2_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE| \
  509. EXT2_FEATURE_INCOMPAT_META_BG)
  510. #define EXT2_FEATURE_RO_COMPAT_SUPP (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
  511. EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
  512. EXT2_FEATURE_RO_COMPAT_BTREE_DIR)
  513. #define EXT2_FEATURE_RO_COMPAT_UNSUPPORTED ~EXT2_FEATURE_RO_COMPAT_SUPP
  514. #define EXT2_FEATURE_INCOMPAT_UNSUPPORTED ~EXT2_FEATURE_INCOMPAT_SUPP
  515. /*
  516. * Default values for user and/or group using reserved blocks
  517. */
  518. #define EXT2_DEF_RESUID 0
  519. #define EXT2_DEF_RESGID 0
  520. /*
  521. * Default mount options
  522. */
  523. #define EXT2_DEFM_DEBUG 0x0001
  524. #define EXT2_DEFM_BSDGROUPS 0x0002
  525. #define EXT2_DEFM_XATTR_USER 0x0004
  526. #define EXT2_DEFM_ACL 0x0008
  527. #define EXT2_DEFM_UID16 0x0010
  528. /* Not used by ext2, but reserved for use by ext3 */
  529. #define EXT3_DEFM_JMODE 0x0060
  530. #define EXT3_DEFM_JMODE_DATA 0x0020
  531. #define EXT3_DEFM_JMODE_ORDERED 0x0040
  532. #define EXT3_DEFM_JMODE_WBACK 0x0060
  533. /*
  534. * Structure of a directory entry
  535. */
  536. struct ext2_dir_entry {
  537. __le32 inode; /* Inode number */
  538. __le16 rec_len; /* Directory entry length */
  539. __le16 name_len; /* Name length */
  540. char name[]; /* File name, up to EXT2_NAME_LEN */
  541. };
  542. /*
  543. * The new version of the directory entry. Since EXT2 structures are
  544. * stored in intel byte order, and the name_len field could never be
  545. * bigger than 255 chars, it's safe to reclaim the extra byte for the
  546. * file_type field.
  547. */
  548. struct ext2_dir_entry_2 {
  549. __le32 inode; /* Inode number */
  550. __le16 rec_len; /* Directory entry length */
  551. __u8 name_len; /* Name length */
  552. __u8 file_type;
  553. char name[]; /* File name, up to EXT2_NAME_LEN */
  554. };
  555. /*
  556. * Ext2 directory file types. Only the low 3 bits are used. The
  557. * other bits are reserved for now.
  558. */
  559. enum {
  560. EXT2_FT_UNKNOWN = 0,
  561. EXT2_FT_REG_FILE = 1,
  562. EXT2_FT_DIR = 2,
  563. EXT2_FT_CHRDEV = 3,
  564. EXT2_FT_BLKDEV = 4,
  565. EXT2_FT_FIFO = 5,
  566. EXT2_FT_SOCK = 6,
  567. EXT2_FT_SYMLINK = 7,
  568. EXT2_FT_MAX
  569. };
  570. /*
  571. * EXT2_DIR_PAD defines the directory entries boundaries
  572. *
  573. * NOTE: It must be a multiple of 4
  574. */
  575. #define EXT2_DIR_PAD 4
  576. #define EXT2_DIR_ROUND (EXT2_DIR_PAD - 1)
  577. #define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \
  578. ~EXT2_DIR_ROUND)
  579. #define EXT2_MAX_REC_LEN ((1<<16)-1)
  580. static inline void verify_offsets(void)
  581. {
  582. #define A(x,y) BUILD_BUG_ON(x != offsetof(struct ext2_super_block, y));
  583. A(EXT2_SB_MAGIC_OFFSET, s_magic);
  584. A(EXT2_SB_BLOCKS_OFFSET, s_blocks_count);
  585. A(EXT2_SB_BSIZE_OFFSET, s_log_block_size);
  586. #undef A
  587. }
  588. /*
  589. * ext2 mount options
  590. */
  591. struct ext2_mount_options {
  592. unsigned long s_mount_opt;
  593. kuid_t s_resuid;
  594. kgid_t s_resgid;
  595. };
  596. /*
  597. * second extended file system inode data in memory
  598. */
  599. struct ext2_inode_info {
  600. __le32 i_data[15];
  601. __u32 i_flags;
  602. __u32 i_faddr;
  603. __u8 i_frag_no;
  604. __u8 i_frag_size;
  605. __u16 i_state;
  606. __u32 i_file_acl;
  607. __u32 i_dir_acl;
  608. __u32 i_dtime;
  609. /*
  610. * i_block_group is the number of the block group which contains
  611. * this file's inode. Constant across the lifetime of the inode,
  612. * it is used for making block allocation decisions - we try to
  613. * place a file's data blocks near its inode block, and new inodes
  614. * near to their parent directory's inode.
  615. */
  616. __u32 i_block_group;
  617. /* block reservation info */
  618. struct ext2_block_alloc_info *i_block_alloc_info;
  619. __u32 i_dir_start_lookup;
  620. #ifdef CONFIG_EXT2_FS_XATTR
  621. /*
  622. * Extended attributes can be read independently of the main file
  623. * data. Taking i_mutex even when reading would cause contention
  624. * between readers of EAs and writers of regular file data, so
  625. * instead we synchronize on xattr_sem when reading or changing
  626. * EAs.
  627. */
  628. struct rw_semaphore xattr_sem;
  629. #endif
  630. rwlock_t i_meta_lock;
  631. #ifdef CONFIG_FS_DAX
  632. struct rw_semaphore dax_sem;
  633. #endif
  634. /*
  635. * truncate_mutex is for serialising ext2_truncate() against
  636. * ext2_getblock(). It also protects the internals of the inode's
  637. * reservation data structures: ext2_reserve_window and
  638. * ext2_reserve_window_node.
  639. */
  640. struct mutex truncate_mutex;
  641. struct inode vfs_inode;
  642. struct list_head i_orphan; /* unlinked but open inodes */
  643. #ifdef CONFIG_QUOTA
  644. struct dquot *i_dquot[MAXQUOTAS];
  645. #endif
  646. };
  647. #ifdef CONFIG_FS_DAX
  648. #define dax_sem_down_write(ext2_inode) down_write(&(ext2_inode)->dax_sem)
  649. #define dax_sem_up_write(ext2_inode) up_write(&(ext2_inode)->dax_sem)
  650. #else
  651. #define dax_sem_down_write(ext2_inode)
  652. #define dax_sem_up_write(ext2_inode)
  653. #endif
  654. /*
  655. * Inode dynamic state flags
  656. */
  657. #define EXT2_STATE_NEW 0x00000001 /* inode is newly created */
  658. /*
  659. * Function prototypes
  660. */
  661. /*
  662. * Ok, these declarations are also in <linux/kernel.h> but none of the
  663. * ext2 source programs needs to include it so they are duplicated here.
  664. */
  665. static inline struct ext2_inode_info *EXT2_I(struct inode *inode)
  666. {
  667. return container_of(inode, struct ext2_inode_info, vfs_inode);
  668. }
  669. /* balloc.c */
  670. extern int ext2_bg_has_super(struct super_block *sb, int group);
  671. extern unsigned long ext2_bg_num_gdb(struct super_block *sb, int group);
  672. extern ext2_fsblk_t ext2_new_block(struct inode *, unsigned long, int *);
  673. extern ext2_fsblk_t ext2_new_blocks(struct inode *, unsigned long,
  674. unsigned long *, int *);
  675. extern int ext2_data_block_valid(struct ext2_sb_info *sbi, ext2_fsblk_t start_blk,
  676. unsigned int count);
  677. extern void ext2_free_blocks (struct inode *, unsigned long,
  678. unsigned long);
  679. extern unsigned long ext2_count_free_blocks (struct super_block *);
  680. extern unsigned long ext2_count_dirs (struct super_block *);
  681. extern struct ext2_group_desc * ext2_get_group_desc(struct super_block * sb,
  682. unsigned int block_group,
  683. struct buffer_head ** bh);
  684. extern void ext2_discard_reservation (struct inode *);
  685. extern int ext2_should_retry_alloc(struct super_block *sb, int *retries);
  686. extern void ext2_init_block_alloc_info(struct inode *);
  687. extern void ext2_rsv_window_add(struct super_block *sb, struct ext2_reserve_window_node *rsv);
  688. /* dir.c */
  689. extern int ext2_add_link (struct dentry *, struct inode *);
  690. extern ino_t ext2_inode_by_name(struct inode *, const struct qstr *);
  691. extern int ext2_make_empty(struct inode *, struct inode *);
  692. extern struct ext2_dir_entry_2 * ext2_find_entry (struct inode *,const struct qstr *, struct page **);
  693. extern int ext2_delete_entry (struct ext2_dir_entry_2 *, struct page *);
  694. extern int ext2_empty_dir (struct inode *);
  695. extern struct ext2_dir_entry_2 * ext2_dotdot (struct inode *, struct page **);
  696. extern void ext2_set_link(struct inode *, struct ext2_dir_entry_2 *, struct page *, struct inode *, int);
  697. /* ialloc.c */
  698. extern struct inode * ext2_new_inode (struct inode *, umode_t, const struct qstr *);
  699. extern void ext2_free_inode (struct inode *);
  700. extern unsigned long ext2_count_free_inodes (struct super_block *);
  701. extern unsigned long ext2_count_free (struct buffer_head *, unsigned);
  702. /* inode.c */
  703. extern struct inode *ext2_iget (struct super_block *, unsigned long);
  704. extern int ext2_write_inode (struct inode *, struct writeback_control *);
  705. extern void ext2_evict_inode(struct inode *);
  706. extern int ext2_get_block(struct inode *, sector_t, struct buffer_head *, int);
  707. extern int ext2_setattr (struct dentry *, struct iattr *);
  708. extern void ext2_set_inode_flags(struct inode *inode);
  709. extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
  710. u64 start, u64 len);
  711. /* ioctl.c */
  712. extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
  713. extern long ext2_compat_ioctl(struct file *, unsigned int, unsigned long);
  714. /* namei.c */
  715. struct dentry *ext2_get_parent(struct dentry *child);
  716. /* super.c */
  717. extern __printf(3, 4)
  718. void ext2_error(struct super_block *, const char *, const char *, ...);
  719. extern __printf(3, 4)
  720. void ext2_msg(struct super_block *, const char *, const char *, ...);
  721. extern void ext2_update_dynamic_rev (struct super_block *sb);
  722. extern void ext2_sync_super(struct super_block *sb, struct ext2_super_block *es,
  723. int wait);
  724. /*
  725. * Inodes and files operations
  726. */
  727. /* dir.c */
  728. extern const struct file_operations ext2_dir_operations;
  729. /* file.c */
  730. extern int ext2_fsync(struct file *file, loff_t start, loff_t end,
  731. int datasync);
  732. extern const struct inode_operations ext2_file_inode_operations;
  733. extern const struct file_operations ext2_file_operations;
  734. /* inode.c */
  735. extern void ext2_set_file_ops(struct inode *inode);
  736. extern const struct address_space_operations ext2_aops;
  737. extern const struct address_space_operations ext2_nobh_aops;
  738. extern const struct iomap_ops ext2_iomap_ops;
  739. /* namei.c */
  740. extern const struct inode_operations ext2_dir_inode_operations;
  741. extern const struct inode_operations ext2_special_inode_operations;
  742. /* symlink.c */
  743. extern const struct inode_operations ext2_fast_symlink_inode_operations;
  744. extern const struct inode_operations ext2_symlink_inode_operations;
  745. static inline ext2_fsblk_t
  746. ext2_group_first_block_no(struct super_block *sb, unsigned long group_no)
  747. {
  748. return group_no * (ext2_fsblk_t)EXT2_BLOCKS_PER_GROUP(sb) +
  749. le32_to_cpu(EXT2_SB(sb)->s_es->s_first_data_block);
  750. }
  751. #define ext2_set_bit __test_and_set_bit_le
  752. #define ext2_clear_bit __test_and_clear_bit_le
  753. #define ext2_test_bit test_bit_le
  754. #define ext2_find_first_zero_bit find_first_zero_bit_le
  755. #define ext2_find_next_zero_bit find_next_zero_bit_le