ext2.h 28 KB

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