ext2.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831
  1. /*
  2. * Copyright (C) 1992, 1993, 1994, 1995
  3. * Remy Card (card@masi.ibp.fr)
  4. * Laboratoire MASI - Institut Blaise Pascal
  5. * Universite Pierre et Marie Curie (Paris VI)
  6. *
  7. * from
  8. *
  9. * linux/include/linux/minix_fs.h
  10. *
  11. * Copyright (C) 1991, 1992 Linus Torvalds
  12. */
  13. #include <linux/fs.h>
  14. #include <linux/ext2_fs.h>
  15. #include <linux/blockgroup_lock.h>
  16. #include <linux/percpu_counter.h>
  17. #include <linux/rbtree.h>
  18. /* XXX Here for now... not interested in restructing headers JUST now */
  19. /* data type for block offset of block group */
  20. typedef int ext2_grpblk_t;
  21. /* data type for filesystem-wide blocks number */
  22. typedef unsigned long ext2_fsblk_t;
  23. #define E2FSBLK "%lu"
  24. struct ext2_reserve_window {
  25. ext2_fsblk_t _rsv_start; /* First byte reserved */
  26. ext2_fsblk_t _rsv_end; /* Last byte reserved or 0 */
  27. };
  28. struct ext2_reserve_window_node {
  29. struct rb_node rsv_node;
  30. __u32 rsv_goal_size;
  31. __u32 rsv_alloc_hit;
  32. struct ext2_reserve_window rsv_window;
  33. };
  34. struct ext2_block_alloc_info {
  35. /* information about reservation window */
  36. struct ext2_reserve_window_node rsv_window_node;
  37. /*
  38. * was i_next_alloc_block in ext2_inode_info
  39. * is the logical (file-relative) number of the
  40. * most-recently-allocated block in this file.
  41. * We use this for detecting linearly ascending allocation requests.
  42. */
  43. __u32 last_alloc_logical_block;
  44. /*
  45. * Was i_next_alloc_goal in ext2_inode_info
  46. * is the *physical* companion to i_next_alloc_block.
  47. * it the the physical block number of the block which was most-recentl
  48. * allocated to this file. This give us the goal (target) for the next
  49. * allocation when we detect linearly ascending requests.
  50. */
  51. ext2_fsblk_t last_alloc_physical_block;
  52. };
  53. #define rsv_start rsv_window._rsv_start
  54. #define rsv_end rsv_window._rsv_end
  55. /*
  56. * second extended-fs super-block data in memory
  57. */
  58. struct ext2_sb_info {
  59. unsigned long s_frag_size; /* Size of a fragment in bytes */
  60. unsigned long s_frags_per_block;/* Number of fragments per block */
  61. unsigned long s_inodes_per_block;/* Number of inodes per block */
  62. unsigned long s_frags_per_group;/* Number of fragments in a group */
  63. unsigned long s_blocks_per_group;/* Number of blocks in a group */
  64. unsigned long s_inodes_per_group;/* Number of inodes in a group */
  65. unsigned long s_itb_per_group; /* Number of inode table blocks per group */
  66. unsigned long s_gdb_count; /* Number of group descriptor blocks */
  67. unsigned long s_desc_per_block; /* Number of group descriptors per block */
  68. unsigned long s_groups_count; /* Number of groups in the fs */
  69. unsigned long s_overhead_last; /* Last calculated overhead */
  70. unsigned long s_blocks_last; /* Last seen block count */
  71. struct buffer_head * s_sbh; /* Buffer containing the super block */
  72. struct ext2_super_block * s_es; /* Pointer to the super block in the buffer */
  73. struct buffer_head ** s_group_desc;
  74. unsigned long s_mount_opt;
  75. unsigned long s_sb_block;
  76. kuid_t s_resuid;
  77. kgid_t s_resgid;
  78. unsigned short s_mount_state;
  79. unsigned short s_pad;
  80. int s_addr_per_block_bits;
  81. int s_desc_per_block_bits;
  82. int s_inode_size;
  83. int s_first_ino;
  84. spinlock_t s_next_gen_lock;
  85. u32 s_next_generation;
  86. unsigned long s_dir_count;
  87. u8 *s_debts;
  88. struct percpu_counter s_freeblocks_counter;
  89. struct percpu_counter s_freeinodes_counter;
  90. struct percpu_counter s_dirs_counter;
  91. struct blockgroup_lock *s_blockgroup_lock;
  92. /* root of the per fs reservation window tree */
  93. spinlock_t s_rsv_window_lock;
  94. struct rb_root s_rsv_window_root;
  95. struct ext2_reserve_window_node s_rsv_window_head;
  96. /*
  97. * s_lock protects against concurrent modifications of s_mount_state,
  98. * s_blocks_last, s_overhead_last and the content of superblock's
  99. * buffer pointed to by sbi->s_es.
  100. *
  101. * Note: It is used in ext2_show_options() to provide a consistent view
  102. * of the mount options.
  103. */
  104. spinlock_t s_lock;
  105. };
  106. static inline spinlock_t *
  107. sb_bgl_lock(struct ext2_sb_info *sbi, unsigned int block_group)
  108. {
  109. return bgl_lock_ptr(sbi->s_blockgroup_lock, block_group);
  110. }
  111. /*
  112. * Define EXT2FS_DEBUG to produce debug messages
  113. */
  114. #undef EXT2FS_DEBUG
  115. /*
  116. * Define EXT2_RESERVATION to reserve data blocks for expanding files
  117. */
  118. #define EXT2_DEFAULT_RESERVE_BLOCKS 8
  119. /*max window size: 1024(direct blocks) + 3([t,d]indirect blocks) */
  120. #define EXT2_MAX_RESERVE_BLOCKS 1027
  121. #define EXT2_RESERVE_WINDOW_NOT_ALLOCATED 0
  122. /*
  123. * The second extended file system version
  124. */
  125. #define EXT2FS_DATE "95/08/09"
  126. #define EXT2FS_VERSION "0.5b"
  127. /*
  128. * Debug code
  129. */
  130. #ifdef EXT2FS_DEBUG
  131. # define ext2_debug(f, a...) { \
  132. printk ("EXT2-fs DEBUG (%s, %d): %s:", \
  133. __FILE__, __LINE__, __func__); \
  134. printk (f, ## a); \
  135. }
  136. #else
  137. # define ext2_debug(f, a...) /**/
  138. #endif
  139. /*
  140. * Special inode numbers
  141. */
  142. #define EXT2_BAD_INO 1 /* Bad blocks inode */
  143. #define EXT2_ROOT_INO 2 /* Root inode */
  144. #define EXT2_BOOT_LOADER_INO 5 /* Boot loader inode */
  145. #define EXT2_UNDEL_DIR_INO 6 /* Undelete directory inode */
  146. /* First non-reserved inode for old ext2 filesystems */
  147. #define EXT2_GOOD_OLD_FIRST_INO 11
  148. static inline struct ext2_sb_info *EXT2_SB(struct super_block *sb)
  149. {
  150. return sb->s_fs_info;
  151. }
  152. /*
  153. * Macro-instructions used to manage several block sizes
  154. */
  155. #define EXT2_MIN_BLOCK_SIZE 1024
  156. #define EXT2_MAX_BLOCK_SIZE 4096
  157. #define EXT2_MIN_BLOCK_LOG_SIZE 10
  158. #define EXT2_BLOCK_SIZE(s) ((s)->s_blocksize)
  159. #define EXT2_ADDR_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s) / sizeof (__u32))
  160. #define EXT2_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)
  161. #define EXT2_ADDR_PER_BLOCK_BITS(s) (EXT2_SB(s)->s_addr_per_block_bits)
  162. #define EXT2_INODE_SIZE(s) (EXT2_SB(s)->s_inode_size)
  163. #define EXT2_FIRST_INO(s) (EXT2_SB(s)->s_first_ino)
  164. /*
  165. * Macro-instructions used to manage fragments
  166. */
  167. #define EXT2_MIN_FRAG_SIZE 1024
  168. #define EXT2_MAX_FRAG_SIZE 4096
  169. #define EXT2_MIN_FRAG_LOG_SIZE 10
  170. #define EXT2_FRAG_SIZE(s) (EXT2_SB(s)->s_frag_size)
  171. #define EXT2_FRAGS_PER_BLOCK(s) (EXT2_SB(s)->s_frags_per_block)
  172. /*
  173. * Structure of a blocks group descriptor
  174. */
  175. struct ext2_group_desc
  176. {
  177. __le32 bg_block_bitmap; /* Blocks bitmap block */
  178. __le32 bg_inode_bitmap; /* Inodes bitmap block */
  179. __le32 bg_inode_table; /* Inodes table block */
  180. __le16 bg_free_blocks_count; /* Free blocks count */
  181. __le16 bg_free_inodes_count; /* Free inodes count */
  182. __le16 bg_used_dirs_count; /* Directories count */
  183. __le16 bg_pad;
  184. __le32 bg_reserved[3];
  185. };
  186. /*
  187. * Macro-instructions used to manage group descriptors
  188. */
  189. #define EXT2_BLOCKS_PER_GROUP(s) (EXT2_SB(s)->s_blocks_per_group)
  190. #define EXT2_DESC_PER_BLOCK(s) (EXT2_SB(s)->s_desc_per_block)
  191. #define EXT2_INODES_PER_GROUP(s) (EXT2_SB(s)->s_inodes_per_group)
  192. #define EXT2_DESC_PER_BLOCK_BITS(s) (EXT2_SB(s)->s_desc_per_block_bits)
  193. /*
  194. * Constants relative to the data blocks
  195. */
  196. #define EXT2_NDIR_BLOCKS 12
  197. #define EXT2_IND_BLOCK EXT2_NDIR_BLOCKS
  198. #define EXT2_DIND_BLOCK (EXT2_IND_BLOCK + 1)
  199. #define EXT2_TIND_BLOCK (EXT2_DIND_BLOCK + 1)
  200. #define EXT2_N_BLOCKS (EXT2_TIND_BLOCK + 1)
  201. /*
  202. * Inode flags (GETFLAGS/SETFLAGS)
  203. */
  204. #define EXT2_SECRM_FL FS_SECRM_FL /* Secure deletion */
  205. #define EXT2_UNRM_FL FS_UNRM_FL /* Undelete */
  206. #define EXT2_COMPR_FL FS_COMPR_FL /* Compress file */
  207. #define EXT2_SYNC_FL FS_SYNC_FL /* Synchronous updates */
  208. #define EXT2_IMMUTABLE_FL FS_IMMUTABLE_FL /* Immutable file */
  209. #define EXT2_APPEND_FL FS_APPEND_FL /* writes to file may only append */
  210. #define EXT2_NODUMP_FL FS_NODUMP_FL /* do not dump file */
  211. #define EXT2_NOATIME_FL FS_NOATIME_FL /* do not update atime */
  212. /* Reserved for compression usage... */
  213. #define EXT2_DIRTY_FL FS_DIRTY_FL
  214. #define EXT2_COMPRBLK_FL FS_COMPRBLK_FL /* One or more compressed clusters */
  215. #define EXT2_NOCOMP_FL FS_NOCOMP_FL /* Don't compress */
  216. #define EXT2_ECOMPR_FL FS_ECOMPR_FL /* Compression error */
  217. /* End compression flags --- maybe not all used */
  218. #define EXT2_BTREE_FL FS_BTREE_FL /* btree format dir */
  219. #define EXT2_INDEX_FL FS_INDEX_FL /* hash-indexed directory */
  220. #define EXT2_IMAGIC_FL FS_IMAGIC_FL /* AFS directory */
  221. #define EXT2_JOURNAL_DATA_FL FS_JOURNAL_DATA_FL /* Reserved for ext3 */
  222. #define EXT2_NOTAIL_FL FS_NOTAIL_FL /* file tail should not be merged */
  223. #define EXT2_DIRSYNC_FL FS_DIRSYNC_FL /* dirsync behaviour (directories only) */
  224. #define EXT2_TOPDIR_FL FS_TOPDIR_FL /* Top of directory hierarchies*/
  225. #define EXT2_RESERVED_FL FS_RESERVED_FL /* reserved for ext2 lib */
  226. #define EXT2_FL_USER_VISIBLE FS_FL_USER_VISIBLE /* User visible flags */
  227. #define EXT2_FL_USER_MODIFIABLE FS_FL_USER_MODIFIABLE /* User modifiable flags */
  228. /* Flags that should be inherited by new inodes from their parent. */
  229. #define EXT2_FL_INHERITED (EXT2_SECRM_FL | EXT2_UNRM_FL | EXT2_COMPR_FL |\
  230. EXT2_SYNC_FL | EXT2_NODUMP_FL |\
  231. EXT2_NOATIME_FL | EXT2_COMPRBLK_FL |\
  232. EXT2_NOCOMP_FL | EXT2_JOURNAL_DATA_FL |\
  233. EXT2_NOTAIL_FL | EXT2_DIRSYNC_FL)
  234. /* Flags that are appropriate for regular files (all but dir-specific ones). */
  235. #define EXT2_REG_FLMASK (~(EXT2_DIRSYNC_FL | EXT2_TOPDIR_FL))
  236. /* Flags that are appropriate for non-directories/regular files. */
  237. #define EXT2_OTHER_FLMASK (EXT2_NODUMP_FL | EXT2_NOATIME_FL)
  238. /* Mask out flags that are inappropriate for the given type of inode. */
  239. static inline __u32 ext2_mask_flags(umode_t mode, __u32 flags)
  240. {
  241. if (S_ISDIR(mode))
  242. return flags;
  243. else if (S_ISREG(mode))
  244. return flags & EXT2_REG_FLMASK;
  245. else
  246. return flags & EXT2_OTHER_FLMASK;
  247. }
  248. /*
  249. * ioctl commands
  250. */
  251. #define EXT2_IOC_GETFLAGS FS_IOC_GETFLAGS
  252. #define EXT2_IOC_SETFLAGS FS_IOC_SETFLAGS
  253. #define EXT2_IOC_GETVERSION FS_IOC_GETVERSION
  254. #define EXT2_IOC_SETVERSION FS_IOC_SETVERSION
  255. #define EXT2_IOC_GETRSVSZ _IOR('f', 5, long)
  256. #define EXT2_IOC_SETRSVSZ _IOW('f', 6, long)
  257. /*
  258. * ioctl commands in 32 bit emulation
  259. */
  260. #define EXT2_IOC32_GETFLAGS FS_IOC32_GETFLAGS
  261. #define EXT2_IOC32_SETFLAGS FS_IOC32_SETFLAGS
  262. #define EXT2_IOC32_GETVERSION FS_IOC32_GETVERSION
  263. #define EXT2_IOC32_SETVERSION FS_IOC32_SETVERSION
  264. /*
  265. * Structure of an inode on the disk
  266. */
  267. struct ext2_inode {
  268. __le16 i_mode; /* File mode */
  269. __le16 i_uid; /* Low 16 bits of Owner Uid */
  270. __le32 i_size; /* Size in bytes */
  271. __le32 i_atime; /* Access time */
  272. __le32 i_ctime; /* Creation time */
  273. __le32 i_mtime; /* Modification time */
  274. __le32 i_dtime; /* Deletion Time */
  275. __le16 i_gid; /* Low 16 bits of Group Id */
  276. __le16 i_links_count; /* Links count */
  277. __le32 i_blocks; /* Blocks count */
  278. __le32 i_flags; /* File flags */
  279. union {
  280. struct {
  281. __le32 l_i_reserved1;
  282. } linux1;
  283. struct {
  284. __le32 h_i_translator;
  285. } hurd1;
  286. struct {
  287. __le32 m_i_reserved1;
  288. } masix1;
  289. } osd1; /* OS dependent 1 */
  290. __le32 i_block[EXT2_N_BLOCKS];/* Pointers to blocks */
  291. __le32 i_generation; /* File version (for NFS) */
  292. __le32 i_file_acl; /* File ACL */
  293. __le32 i_dir_acl; /* Directory ACL */
  294. __le32 i_faddr; /* Fragment address */
  295. union {
  296. struct {
  297. __u8 l_i_frag; /* Fragment number */
  298. __u8 l_i_fsize; /* Fragment size */
  299. __u16 i_pad1;
  300. __le16 l_i_uid_high; /* these 2 fields */
  301. __le16 l_i_gid_high; /* were reserved2[0] */
  302. __u32 l_i_reserved2;
  303. } linux2;
  304. struct {
  305. __u8 h_i_frag; /* Fragment number */
  306. __u8 h_i_fsize; /* Fragment size */
  307. __le16 h_i_mode_high;
  308. __le16 h_i_uid_high;
  309. __le16 h_i_gid_high;
  310. __le32 h_i_author;
  311. } hurd2;
  312. struct {
  313. __u8 m_i_frag; /* Fragment number */
  314. __u8 m_i_fsize; /* Fragment size */
  315. __u16 m_pad1;
  316. __u32 m_i_reserved2[2];
  317. } masix2;
  318. } osd2; /* OS dependent 2 */
  319. };
  320. #define i_size_high i_dir_acl
  321. #define i_reserved1 osd1.linux1.l_i_reserved1
  322. #define i_frag osd2.linux2.l_i_frag
  323. #define i_fsize osd2.linux2.l_i_fsize
  324. #define i_uid_low i_uid
  325. #define i_gid_low i_gid
  326. #define i_uid_high osd2.linux2.l_i_uid_high
  327. #define i_gid_high osd2.linux2.l_i_gid_high
  328. #define i_reserved2 osd2.linux2.l_i_reserved2
  329. /*
  330. * File system states
  331. */
  332. #define EXT2_VALID_FS 0x0001 /* Unmounted cleanly */
  333. #define EXT2_ERROR_FS 0x0002 /* Errors detected */
  334. /*
  335. * Mount flags
  336. */
  337. #define EXT2_MOUNT_CHECK 0x000001 /* Do mount-time checks */
  338. #define EXT2_MOUNT_OLDALLOC 0x000002 /* Don't use the new Orlov allocator */
  339. #define EXT2_MOUNT_GRPID 0x000004 /* Create files with directory's group */
  340. #define EXT2_MOUNT_DEBUG 0x000008 /* Some debugging messages */
  341. #define EXT2_MOUNT_ERRORS_CONT 0x000010 /* Continue on errors */
  342. #define EXT2_MOUNT_ERRORS_RO 0x000020 /* Remount fs ro on errors */
  343. #define EXT2_MOUNT_ERRORS_PANIC 0x000040 /* Panic on errors */
  344. #define EXT2_MOUNT_MINIX_DF 0x000080 /* Mimics the Minix statfs */
  345. #define EXT2_MOUNT_NOBH 0x000100 /* No buffer_heads */
  346. #define EXT2_MOUNT_NO_UID32 0x000200 /* Disable 32-bit UIDs */
  347. #define EXT2_MOUNT_XATTR_USER 0x004000 /* Extended user attributes */
  348. #define EXT2_MOUNT_POSIX_ACL 0x008000 /* POSIX Access Control Lists */
  349. #define EXT2_MOUNT_XIP 0x010000 /* Obsolete, use DAX */
  350. #define EXT2_MOUNT_USRQUOTA 0x020000 /* user quota */
  351. #define EXT2_MOUNT_GRPQUOTA 0x040000 /* group quota */
  352. #define EXT2_MOUNT_RESERVATION 0x080000 /* Preallocation */
  353. #ifdef CONFIG_FS_DAX
  354. #define EXT2_MOUNT_DAX 0x100000 /* Direct Access */
  355. #else
  356. #define EXT2_MOUNT_DAX 0
  357. #endif
  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 directory file types. Only the low 3 bits are used. The
  552. * other bits are reserved for now.
  553. */
  554. enum {
  555. EXT2_FT_UNKNOWN = 0,
  556. EXT2_FT_REG_FILE = 1,
  557. EXT2_FT_DIR = 2,
  558. EXT2_FT_CHRDEV = 3,
  559. EXT2_FT_BLKDEV = 4,
  560. EXT2_FT_FIFO = 5,
  561. EXT2_FT_SOCK = 6,
  562. EXT2_FT_SYMLINK = 7,
  563. EXT2_FT_MAX
  564. };
  565. /*
  566. * EXT2_DIR_PAD defines the directory entries boundaries
  567. *
  568. * NOTE: It must be a multiple of 4
  569. */
  570. #define EXT2_DIR_PAD 4
  571. #define EXT2_DIR_ROUND (EXT2_DIR_PAD - 1)
  572. #define EXT2_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT2_DIR_ROUND) & \
  573. ~EXT2_DIR_ROUND)
  574. #define EXT2_MAX_REC_LEN ((1<<16)-1)
  575. static inline void verify_offsets(void)
  576. {
  577. #define A(x,y) BUILD_BUG_ON(x != offsetof(struct ext2_super_block, y));
  578. A(EXT2_SB_MAGIC_OFFSET, s_magic);
  579. A(EXT2_SB_BLOCKS_OFFSET, s_blocks_count);
  580. A(EXT2_SB_BSIZE_OFFSET, s_log_block_size);
  581. #undef A
  582. }
  583. /*
  584. * ext2 mount options
  585. */
  586. struct ext2_mount_options {
  587. unsigned long s_mount_opt;
  588. kuid_t s_resuid;
  589. kgid_t s_resgid;
  590. };
  591. /*
  592. * second extended file system inode data in memory
  593. */
  594. struct ext2_inode_info {
  595. __le32 i_data[15];
  596. __u32 i_flags;
  597. __u32 i_faddr;
  598. __u8 i_frag_no;
  599. __u8 i_frag_size;
  600. __u16 i_state;
  601. __u32 i_file_acl;
  602. __u32 i_dir_acl;
  603. __u32 i_dtime;
  604. /*
  605. * i_block_group is the number of the block group which contains
  606. * this file's inode. Constant across the lifetime of the inode,
  607. * it is used for making block allocation decisions - we try to
  608. * place a file's data blocks near its inode block, and new inodes
  609. * near to their parent directory's inode.
  610. */
  611. __u32 i_block_group;
  612. /* block reservation info */
  613. struct ext2_block_alloc_info *i_block_alloc_info;
  614. __u32 i_dir_start_lookup;
  615. #ifdef CONFIG_EXT2_FS_XATTR
  616. /*
  617. * Extended attributes can be read independently of the main file
  618. * data. Taking i_mutex even when reading would cause contention
  619. * between readers of EAs and writers of regular file data, so
  620. * instead we synchronize on xattr_sem when reading or changing
  621. * EAs.
  622. */
  623. struct rw_semaphore xattr_sem;
  624. #endif
  625. rwlock_t i_meta_lock;
  626. #ifdef CONFIG_FS_DAX
  627. struct rw_semaphore dax_sem;
  628. #endif
  629. /*
  630. * truncate_mutex is for serialising ext2_truncate() against
  631. * ext2_getblock(). It also protects the internals of the inode's
  632. * reservation data structures: ext2_reserve_window and
  633. * ext2_reserve_window_node.
  634. */
  635. struct mutex truncate_mutex;
  636. struct inode vfs_inode;
  637. struct list_head i_orphan; /* unlinked but open inodes */
  638. #ifdef CONFIG_QUOTA
  639. struct dquot *i_dquot[MAXQUOTAS];
  640. #endif
  641. };
  642. #ifdef CONFIG_FS_DAX
  643. #define dax_sem_down_write(ext2_inode) down_write(&(ext2_inode)->dax_sem)
  644. #define dax_sem_up_write(ext2_inode) up_write(&(ext2_inode)->dax_sem)
  645. #else
  646. #define dax_sem_down_write(ext2_inode)
  647. #define dax_sem_up_write(ext2_inode)
  648. #endif
  649. /*
  650. * Inode dynamic state flags
  651. */
  652. #define EXT2_STATE_NEW 0x00000001 /* inode is newly created */
  653. /*
  654. * Function prototypes
  655. */
  656. /*
  657. * Ok, these declarations are also in <linux/kernel.h> but none of the
  658. * ext2 source programs needs to include it so they are duplicated here.
  659. */
  660. static inline struct ext2_inode_info *EXT2_I(struct inode *inode)
  661. {
  662. return container_of(inode, struct ext2_inode_info, vfs_inode);
  663. }
  664. /* balloc.c */
  665. extern int ext2_bg_has_super(struct super_block *sb, int group);
  666. extern unsigned long ext2_bg_num_gdb(struct super_block *sb, int group);
  667. extern ext2_fsblk_t ext2_new_block(struct inode *, unsigned long, int *);
  668. extern ext2_fsblk_t ext2_new_blocks(struct inode *, unsigned long,
  669. unsigned long *, int *);
  670. extern void ext2_free_blocks (struct inode *, unsigned long,
  671. unsigned long);
  672. extern unsigned long ext2_count_free_blocks (struct super_block *);
  673. extern unsigned long ext2_count_dirs (struct super_block *);
  674. extern void ext2_check_blocks_bitmap (struct super_block *);
  675. extern struct ext2_group_desc * ext2_get_group_desc(struct super_block * sb,
  676. unsigned int block_group,
  677. struct buffer_head ** bh);
  678. extern void ext2_discard_reservation (struct inode *);
  679. extern int ext2_should_retry_alloc(struct super_block *sb, int *retries);
  680. extern void ext2_init_block_alloc_info(struct inode *);
  681. extern void ext2_rsv_window_add(struct super_block *sb, struct ext2_reserve_window_node *rsv);
  682. /* dir.c */
  683. extern int ext2_add_link (struct dentry *, struct inode *);
  684. extern ino_t ext2_inode_by_name(struct inode *, struct qstr *);
  685. extern int ext2_make_empty(struct inode *, struct inode *);
  686. extern struct ext2_dir_entry_2 * ext2_find_entry (struct inode *,struct qstr *, struct page **);
  687. extern int ext2_delete_entry (struct ext2_dir_entry_2 *, struct page *);
  688. extern int ext2_empty_dir (struct inode *);
  689. extern struct ext2_dir_entry_2 * ext2_dotdot (struct inode *, struct page **);
  690. extern void ext2_set_link(struct inode *, struct ext2_dir_entry_2 *, struct page *, struct inode *, int);
  691. /* ialloc.c */
  692. extern struct inode * ext2_new_inode (struct inode *, umode_t, const struct qstr *);
  693. extern void ext2_free_inode (struct inode *);
  694. extern unsigned long ext2_count_free_inodes (struct super_block *);
  695. extern void ext2_check_inodes_bitmap (struct super_block *);
  696. extern unsigned long ext2_count_free (struct buffer_head *, unsigned);
  697. /* inode.c */
  698. extern struct inode *ext2_iget (struct super_block *, unsigned long);
  699. extern int ext2_write_inode (struct inode *, struct writeback_control *);
  700. extern void ext2_evict_inode(struct inode *);
  701. extern int ext2_get_block(struct inode *, sector_t, struct buffer_head *, int);
  702. extern int ext2_setattr (struct dentry *, struct iattr *);
  703. extern void ext2_set_inode_flags(struct inode *inode);
  704. extern void ext2_get_inode_flags(struct ext2_inode_info *);
  705. extern int ext2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
  706. u64 start, u64 len);
  707. /* ioctl.c */
  708. extern long ext2_ioctl(struct file *, unsigned int, unsigned long);
  709. extern long ext2_compat_ioctl(struct file *, unsigned int, unsigned long);
  710. /* namei.c */
  711. struct dentry *ext2_get_parent(struct dentry *child);
  712. /* super.c */
  713. extern __printf(3, 4)
  714. void ext2_error(struct super_block *, const char *, const char *, ...);
  715. extern __printf(3, 4)
  716. void ext2_msg(struct super_block *, const char *, const char *, ...);
  717. extern void ext2_update_dynamic_rev (struct super_block *sb);
  718. extern void ext2_write_super (struct super_block *);
  719. /*
  720. * Inodes and files operations
  721. */
  722. /* dir.c */
  723. extern const struct file_operations ext2_dir_operations;
  724. /* file.c */
  725. extern int ext2_fsync(struct file *file, loff_t start, loff_t end,
  726. int datasync);
  727. extern const struct inode_operations ext2_file_inode_operations;
  728. extern const struct file_operations ext2_file_operations;
  729. /* inode.c */
  730. extern const struct address_space_operations ext2_aops;
  731. extern const struct address_space_operations ext2_nobh_aops;
  732. /* namei.c */
  733. extern const struct inode_operations ext2_dir_inode_operations;
  734. extern const struct inode_operations ext2_special_inode_operations;
  735. /* symlink.c */
  736. extern const struct inode_operations ext2_fast_symlink_inode_operations;
  737. extern const struct inode_operations ext2_symlink_inode_operations;
  738. static inline ext2_fsblk_t
  739. ext2_group_first_block_no(struct super_block *sb, unsigned long group_no)
  740. {
  741. return group_no * (ext2_fsblk_t)EXT2_BLOCKS_PER_GROUP(sb) +
  742. le32_to_cpu(EXT2_SB(sb)->s_es->s_first_data_block);
  743. }
  744. #define ext2_set_bit __test_and_set_bit_le
  745. #define ext2_clear_bit __test_and_clear_bit_le
  746. #define ext2_test_bit test_bit_le
  747. #define ext2_find_first_zero_bit find_first_zero_bit_le
  748. #define ext2_find_next_zero_bit find_next_zero_bit_le