ext3_fs.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831
  1. /*
  2. * linux/include/linux/ext3_fs.h
  3. *
  4. * Copyright (C) 1992, 1993, 1994, 1995
  5. * Remy Card (card@masi.ibp.fr)
  6. * Laboratoire MASI - Institut Blaise Pascal
  7. * Universite Pierre et Marie Curie (Paris VI)
  8. *
  9. * from
  10. *
  11. * linux/include/linux/minix_fs.h
  12. *
  13. * Copyright (C) 1991, 1992 Linus Torvalds
  14. */
  15. #ifndef _LINUX_EXT3_FS_H
  16. #define _LINUX_EXT3_FS_H
  17. #include <linux/types.h>
  18. #include <linux/ext3_fs_i.h>
  19. #include <linux/ext3_fs_sb.h>
  20. struct statfs;
  21. /*
  22. * The second extended filesystem constants/structures
  23. */
  24. /*
  25. * Define EXT3FS_DEBUG to produce debug messages
  26. */
  27. #undef EXT3FS_DEBUG
  28. /*
  29. * Define EXT3_RESERVATION to reserve data blocks for expanding files
  30. */
  31. #define EXT3_DEFAULT_RESERVE_BLOCKS 8
  32. #define EXT3_MAX_RESERVE_BLOCKS 1024
  33. #define EXT3_RESERVE_WINDOW_NOT_ALLOCATED 0
  34. /*
  35. * Always enable hashed directories
  36. */
  37. #define CONFIG_EXT3_INDEX
  38. /*
  39. * Debug code
  40. */
  41. #ifdef EXT3FS_DEBUG
  42. #define ext3_debug(f, a...) \
  43. do { \
  44. printk (KERN_DEBUG "EXT3-fs DEBUG (%s, %d): %s:", \
  45. __FILE__, __LINE__, __FUNCTION__); \
  46. printk (KERN_DEBUG f, ## a); \
  47. } while (0)
  48. #else
  49. #define ext3_debug(f, a...) do {} while (0)
  50. #endif
  51. /*
  52. * Special inodes numbers
  53. */
  54. #define EXT3_BAD_INO 1 /* Bad blocks inode */
  55. #define EXT3_ROOT_INO 2 /* Root inode */
  56. #define EXT3_BOOT_LOADER_INO 5 /* Boot loader inode */
  57. #define EXT3_UNDEL_DIR_INO 6 /* Undelete directory inode */
  58. #define EXT3_RESIZE_INO 7 /* Reserved group descriptors inode */
  59. #define EXT3_JOURNAL_INO 8 /* Journal inode */
  60. /* First non-reserved inode for old ext3 filesystems */
  61. #define EXT3_GOOD_OLD_FIRST_INO 11
  62. /*
  63. * The second extended file system magic number
  64. */
  65. #define EXT3_SUPER_MAGIC 0xEF53
  66. /*
  67. * Maximal count of links to a file
  68. */
  69. #define EXT3_LINK_MAX 32000
  70. /*
  71. * Macro-instructions used to manage several block sizes
  72. */
  73. #define EXT3_MIN_BLOCK_SIZE 1024
  74. #define EXT3_MAX_BLOCK_SIZE 4096
  75. #define EXT3_MIN_BLOCK_LOG_SIZE 10
  76. #ifdef __KERNEL__
  77. # define EXT3_BLOCK_SIZE(s) ((s)->s_blocksize)
  78. #else
  79. # define EXT3_BLOCK_SIZE(s) (EXT3_MIN_BLOCK_SIZE << (s)->s_log_block_size)
  80. #endif
  81. #define EXT3_ADDR_PER_BLOCK(s) (EXT3_BLOCK_SIZE(s) / sizeof (__u32))
  82. #ifdef __KERNEL__
  83. # define EXT3_BLOCK_SIZE_BITS(s) ((s)->s_blocksize_bits)
  84. #else
  85. # define EXT3_BLOCK_SIZE_BITS(s) ((s)->s_log_block_size + 10)
  86. #endif
  87. #ifdef __KERNEL__
  88. #define EXT3_ADDR_PER_BLOCK_BITS(s) (EXT3_SB(s)->s_addr_per_block_bits)
  89. #define EXT3_INODE_SIZE(s) (EXT3_SB(s)->s_inode_size)
  90. #define EXT3_FIRST_INO(s) (EXT3_SB(s)->s_first_ino)
  91. #else
  92. #define EXT3_INODE_SIZE(s) (((s)->s_rev_level == EXT3_GOOD_OLD_REV) ? \
  93. EXT3_GOOD_OLD_INODE_SIZE : \
  94. (s)->s_inode_size)
  95. #define EXT3_FIRST_INO(s) (((s)->s_rev_level == EXT3_GOOD_OLD_REV) ? \
  96. EXT3_GOOD_OLD_FIRST_INO : \
  97. (s)->s_first_ino)
  98. #endif
  99. /*
  100. * Macro-instructions used to manage fragments
  101. */
  102. #define EXT3_MIN_FRAG_SIZE 1024
  103. #define EXT3_MAX_FRAG_SIZE 4096
  104. #define EXT3_MIN_FRAG_LOG_SIZE 10
  105. #ifdef __KERNEL__
  106. # define EXT3_FRAG_SIZE(s) (EXT3_SB(s)->s_frag_size)
  107. # define EXT3_FRAGS_PER_BLOCK(s) (EXT3_SB(s)->s_frags_per_block)
  108. #else
  109. # define EXT3_FRAG_SIZE(s) (EXT3_MIN_FRAG_SIZE << (s)->s_log_frag_size)
  110. # define EXT3_FRAGS_PER_BLOCK(s) (EXT3_BLOCK_SIZE(s) / EXT3_FRAG_SIZE(s))
  111. #endif
  112. /*
  113. * Structure of a blocks group descriptor
  114. */
  115. struct ext3_group_desc
  116. {
  117. __le32 bg_block_bitmap; /* Blocks bitmap block */
  118. __le32 bg_inode_bitmap; /* Inodes bitmap block */
  119. __le32 bg_inode_table; /* Inodes table block */
  120. __le16 bg_free_blocks_count; /* Free blocks count */
  121. __le16 bg_free_inodes_count; /* Free inodes count */
  122. __le16 bg_used_dirs_count; /* Directories count */
  123. __u16 bg_pad;
  124. __le32 bg_reserved[3];
  125. };
  126. /*
  127. * Macro-instructions used to manage group descriptors
  128. */
  129. #ifdef __KERNEL__
  130. # define EXT3_BLOCKS_PER_GROUP(s) (EXT3_SB(s)->s_blocks_per_group)
  131. # define EXT3_DESC_PER_BLOCK(s) (EXT3_SB(s)->s_desc_per_block)
  132. # define EXT3_INODES_PER_GROUP(s) (EXT3_SB(s)->s_inodes_per_group)
  133. # define EXT3_DESC_PER_BLOCK_BITS(s) (EXT3_SB(s)->s_desc_per_block_bits)
  134. #else
  135. # define EXT3_BLOCKS_PER_GROUP(s) ((s)->s_blocks_per_group)
  136. # define EXT3_DESC_PER_BLOCK(s) (EXT3_BLOCK_SIZE(s) / sizeof (struct ext3_group_desc))
  137. # define EXT3_INODES_PER_GROUP(s) ((s)->s_inodes_per_group)
  138. #endif
  139. /*
  140. * Constants relative to the data blocks
  141. */
  142. #define EXT3_NDIR_BLOCKS 12
  143. #define EXT3_IND_BLOCK EXT3_NDIR_BLOCKS
  144. #define EXT3_DIND_BLOCK (EXT3_IND_BLOCK + 1)
  145. #define EXT3_TIND_BLOCK (EXT3_DIND_BLOCK + 1)
  146. #define EXT3_N_BLOCKS (EXT3_TIND_BLOCK + 1)
  147. /*
  148. * Inode flags
  149. */
  150. #define EXT3_SECRM_FL 0x00000001 /* Secure deletion */
  151. #define EXT3_UNRM_FL 0x00000002 /* Undelete */
  152. #define EXT3_COMPR_FL 0x00000004 /* Compress file */
  153. #define EXT3_SYNC_FL 0x00000008 /* Synchronous updates */
  154. #define EXT3_IMMUTABLE_FL 0x00000010 /* Immutable file */
  155. #define EXT3_APPEND_FL 0x00000020 /* writes to file may only append */
  156. #define EXT3_NODUMP_FL 0x00000040 /* do not dump file */
  157. #define EXT3_NOATIME_FL 0x00000080 /* do not update atime */
  158. /* Reserved for compression usage... */
  159. #define EXT3_DIRTY_FL 0x00000100
  160. #define EXT3_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */
  161. #define EXT3_NOCOMPR_FL 0x00000400 /* Don't compress */
  162. #define EXT3_ECOMPR_FL 0x00000800 /* Compression error */
  163. /* End compression flags --- maybe not all used */
  164. #define EXT3_INDEX_FL 0x00001000 /* hash-indexed directory */
  165. #define EXT3_IMAGIC_FL 0x00002000 /* AFS directory */
  166. #define EXT3_JOURNAL_DATA_FL 0x00004000 /* file data should be journaled */
  167. #define EXT3_NOTAIL_FL 0x00008000 /* file tail should not be merged */
  168. #define EXT3_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */
  169. #define EXT3_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/
  170. #define EXT3_RESERVED_FL 0x80000000 /* reserved for ext3 lib */
  171. #define EXT3_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */
  172. #define EXT3_FL_USER_MODIFIABLE 0x000380FF /* User modifiable flags */
  173. /*
  174. * Inode dynamic state flags
  175. */
  176. #define EXT3_STATE_JDATA 0x00000001 /* journaled data exists */
  177. #define EXT3_STATE_NEW 0x00000002 /* inode is newly created */
  178. #define EXT3_STATE_XATTR 0x00000004 /* has in-inode xattrs */
  179. /* Used to pass group descriptor data when online resize is done */
  180. struct ext3_new_group_input {
  181. __u32 group; /* Group number for this data */
  182. __u32 block_bitmap; /* Absolute block number of block bitmap */
  183. __u32 inode_bitmap; /* Absolute block number of inode bitmap */
  184. __u32 inode_table; /* Absolute block number of inode table start */
  185. __u32 blocks_count; /* Total number of blocks in this group */
  186. __u16 reserved_blocks; /* Number of reserved blocks in this group */
  187. __u16 unused;
  188. };
  189. /* The struct ext3_new_group_input in kernel space, with free_blocks_count */
  190. struct ext3_new_group_data {
  191. __u32 group;
  192. __u32 block_bitmap;
  193. __u32 inode_bitmap;
  194. __u32 inode_table;
  195. __u32 blocks_count;
  196. __u16 reserved_blocks;
  197. __u16 unused;
  198. __u32 free_blocks_count;
  199. };
  200. /*
  201. * ioctl commands
  202. */
  203. #define EXT3_IOC_GETFLAGS _IOR('f', 1, long)
  204. #define EXT3_IOC_SETFLAGS _IOW('f', 2, long)
  205. #define EXT3_IOC_GETVERSION _IOR('f', 3, long)
  206. #define EXT3_IOC_SETVERSION _IOW('f', 4, long)
  207. #define EXT3_IOC_GROUP_EXTEND _IOW('f', 7, unsigned long)
  208. #define EXT3_IOC_GROUP_ADD _IOW('f', 8,struct ext3_new_group_input)
  209. #define EXT3_IOC_GETVERSION_OLD _IOR('v', 1, long)
  210. #define EXT3_IOC_SETVERSION_OLD _IOW('v', 2, long)
  211. #ifdef CONFIG_JBD_DEBUG
  212. #define EXT3_IOC_WAIT_FOR_READONLY _IOR('f', 99, long)
  213. #endif
  214. #define EXT3_IOC_GETRSVSZ _IOR('f', 5, long)
  215. #define EXT3_IOC_SETRSVSZ _IOW('f', 6, long)
  216. /*
  217. * Structure of an inode on the disk
  218. */
  219. struct ext3_inode {
  220. __le16 i_mode; /* File mode */
  221. __le16 i_uid; /* Low 16 bits of Owner Uid */
  222. __le32 i_size; /* Size in bytes */
  223. __le32 i_atime; /* Access time */
  224. __le32 i_ctime; /* Creation time */
  225. __le32 i_mtime; /* Modification time */
  226. __le32 i_dtime; /* Deletion Time */
  227. __le16 i_gid; /* Low 16 bits of Group Id */
  228. __le16 i_links_count; /* Links count */
  229. __le32 i_blocks; /* Blocks count */
  230. __le32 i_flags; /* File flags */
  231. union {
  232. struct {
  233. __u32 l_i_reserved1;
  234. } linux1;
  235. struct {
  236. __u32 h_i_translator;
  237. } hurd1;
  238. struct {
  239. __u32 m_i_reserved1;
  240. } masix1;
  241. } osd1; /* OS dependent 1 */
  242. __le32 i_block[EXT3_N_BLOCKS];/* Pointers to blocks */
  243. __le32 i_generation; /* File version (for NFS) */
  244. __le32 i_file_acl; /* File ACL */
  245. __le32 i_dir_acl; /* Directory ACL */
  246. __le32 i_faddr; /* Fragment address */
  247. union {
  248. struct {
  249. __u8 l_i_frag; /* Fragment number */
  250. __u8 l_i_fsize; /* Fragment size */
  251. __u16 i_pad1;
  252. __le16 l_i_uid_high; /* these 2 fields */
  253. __le16 l_i_gid_high; /* were reserved2[0] */
  254. __u32 l_i_reserved2;
  255. } linux2;
  256. struct {
  257. __u8 h_i_frag; /* Fragment number */
  258. __u8 h_i_fsize; /* Fragment size */
  259. __u16 h_i_mode_high;
  260. __u16 h_i_uid_high;
  261. __u16 h_i_gid_high;
  262. __u32 h_i_author;
  263. } hurd2;
  264. struct {
  265. __u8 m_i_frag; /* Fragment number */
  266. __u8 m_i_fsize; /* Fragment size */
  267. __u16 m_pad1;
  268. __u32 m_i_reserved2[2];
  269. } masix2;
  270. } osd2; /* OS dependent 2 */
  271. __le16 i_extra_isize;
  272. __le16 i_pad1;
  273. };
  274. #define i_size_high i_dir_acl
  275. #if defined(__KERNEL__) || defined(__linux__)
  276. #define i_reserved1 osd1.linux1.l_i_reserved1
  277. #define i_frag osd2.linux2.l_i_frag
  278. #define i_fsize osd2.linux2.l_i_fsize
  279. #define i_uid_low i_uid
  280. #define i_gid_low i_gid
  281. #define i_uid_high osd2.linux2.l_i_uid_high
  282. #define i_gid_high osd2.linux2.l_i_gid_high
  283. #define i_reserved2 osd2.linux2.l_i_reserved2
  284. #elif defined(__GNU__)
  285. #define i_translator osd1.hurd1.h_i_translator
  286. #define i_frag osd2.hurd2.h_i_frag;
  287. #define i_fsize osd2.hurd2.h_i_fsize;
  288. #define i_uid_high osd2.hurd2.h_i_uid_high
  289. #define i_gid_high osd2.hurd2.h_i_gid_high
  290. #define i_author osd2.hurd2.h_i_author
  291. #elif defined(__masix__)
  292. #define i_reserved1 osd1.masix1.m_i_reserved1
  293. #define i_frag osd2.masix2.m_i_frag
  294. #define i_fsize osd2.masix2.m_i_fsize
  295. #define i_reserved2 osd2.masix2.m_i_reserved2
  296. #endif /* defined(__KERNEL__) || defined(__linux__) */
  297. /*
  298. * File system states
  299. */
  300. #define EXT3_VALID_FS 0x0001 /* Unmounted cleanly */
  301. #define EXT3_ERROR_FS 0x0002 /* Errors detected */
  302. #define EXT3_ORPHAN_FS 0x0004 /* Orphans being recovered */
  303. /*
  304. * Mount flags
  305. */
  306. #define EXT3_MOUNT_CHECK 0x00001 /* Do mount-time checks */
  307. #define EXT3_MOUNT_OLDALLOC 0x00002 /* Don't use the new Orlov allocator */
  308. #define EXT3_MOUNT_GRPID 0x00004 /* Create files with directory's group */
  309. #define EXT3_MOUNT_DEBUG 0x00008 /* Some debugging messages */
  310. #define EXT3_MOUNT_ERRORS_CONT 0x00010 /* Continue on errors */
  311. #define EXT3_MOUNT_ERRORS_RO 0x00020 /* Remount fs ro on errors */
  312. #define EXT3_MOUNT_ERRORS_PANIC 0x00040 /* Panic on errors */
  313. #define EXT3_MOUNT_MINIX_DF 0x00080 /* Mimics the Minix statfs */
  314. #define EXT3_MOUNT_NOLOAD 0x00100 /* Don't use existing journal*/
  315. #define EXT3_MOUNT_ABORT 0x00200 /* Fatal error detected */
  316. #define EXT3_MOUNT_DATA_FLAGS 0x00C00 /* Mode for data writes: */
  317. #define EXT3_MOUNT_JOURNAL_DATA 0x00400 /* Write data to journal */
  318. #define EXT3_MOUNT_ORDERED_DATA 0x00800 /* Flush data before commit */
  319. #define EXT3_MOUNT_WRITEBACK_DATA 0x00C00 /* No data ordering */
  320. #define EXT3_MOUNT_UPDATE_JOURNAL 0x01000 /* Update the journal format */
  321. #define EXT3_MOUNT_NO_UID32 0x02000 /* Disable 32-bit UIDs */
  322. #define EXT3_MOUNT_XATTR_USER 0x04000 /* Extended user attributes */
  323. #define EXT3_MOUNT_POSIX_ACL 0x08000 /* POSIX Access Control Lists */
  324. #define EXT3_MOUNT_RESERVATION 0x10000 /* Preallocation */
  325. #define EXT3_MOUNT_BARRIER 0x20000 /* Use block barriers */
  326. #define EXT3_MOUNT_NOBH 0x40000 /* No bufferheads */
  327. #define EXT3_MOUNT_QUOTA 0x80000 /* Some quota option set */
  328. /* Compatibility, for having both ext2_fs.h and ext3_fs.h included at once */
  329. #ifndef _LINUX_EXT2_FS_H
  330. #define clear_opt(o, opt) o &= ~EXT3_MOUNT_##opt
  331. #define set_opt(o, opt) o |= EXT3_MOUNT_##opt
  332. #define test_opt(sb, opt) (EXT3_SB(sb)->s_mount_opt & \
  333. EXT3_MOUNT_##opt)
  334. #else
  335. #define EXT2_MOUNT_NOLOAD EXT3_MOUNT_NOLOAD
  336. #define EXT2_MOUNT_ABORT EXT3_MOUNT_ABORT
  337. #define EXT2_MOUNT_DATA_FLAGS EXT3_MOUNT_DATA_FLAGS
  338. #endif
  339. #define ext3_set_bit ext2_set_bit
  340. #define ext3_set_bit_atomic ext2_set_bit_atomic
  341. #define ext3_clear_bit ext2_clear_bit
  342. #define ext3_clear_bit_atomic ext2_clear_bit_atomic
  343. #define ext3_test_bit ext2_test_bit
  344. #define ext3_find_first_zero_bit ext2_find_first_zero_bit
  345. #define ext3_find_next_zero_bit ext2_find_next_zero_bit
  346. /*
  347. * Maximal mount counts between two filesystem checks
  348. */
  349. #define EXT3_DFL_MAX_MNT_COUNT 20 /* Allow 20 mounts */
  350. #define EXT3_DFL_CHECKINTERVAL 0 /* Don't use interval check */
  351. /*
  352. * Behaviour when detecting errors
  353. */
  354. #define EXT3_ERRORS_CONTINUE 1 /* Continue execution */
  355. #define EXT3_ERRORS_RO 2 /* Remount fs read-only */
  356. #define EXT3_ERRORS_PANIC 3 /* Panic */
  357. #define EXT3_ERRORS_DEFAULT EXT3_ERRORS_CONTINUE
  358. /*
  359. * Structure of the super block
  360. */
  361. struct ext3_super_block {
  362. /*00*/ __le32 s_inodes_count; /* Inodes count */
  363. __le32 s_blocks_count; /* Blocks count */
  364. __le32 s_r_blocks_count; /* Reserved blocks count */
  365. __le32 s_free_blocks_count; /* Free blocks count */
  366. /*10*/ __le32 s_free_inodes_count; /* Free inodes count */
  367. __le32 s_first_data_block; /* First Data Block */
  368. __le32 s_log_block_size; /* Block size */
  369. __le32 s_log_frag_size; /* Fragment size */
  370. /*20*/ __le32 s_blocks_per_group; /* # Blocks per group */
  371. __le32 s_frags_per_group; /* # Fragments per group */
  372. __le32 s_inodes_per_group; /* # Inodes per group */
  373. __le32 s_mtime; /* Mount time */
  374. /*30*/ __le32 s_wtime; /* Write time */
  375. __le16 s_mnt_count; /* Mount count */
  376. __le16 s_max_mnt_count; /* Maximal mount count */
  377. __le16 s_magic; /* Magic signature */
  378. __le16 s_state; /* File system state */
  379. __le16 s_errors; /* Behaviour when detecting errors */
  380. __le16 s_minor_rev_level; /* minor revision level */
  381. /*40*/ __le32 s_lastcheck; /* time of last check */
  382. __le32 s_checkinterval; /* max. time between checks */
  383. __le32 s_creator_os; /* OS */
  384. __le32 s_rev_level; /* Revision level */
  385. /*50*/ __le16 s_def_resuid; /* Default uid for reserved blocks */
  386. __le16 s_def_resgid; /* Default gid for reserved blocks */
  387. /*
  388. * These fields are for EXT3_DYNAMIC_REV superblocks only.
  389. *
  390. * Note: the difference between the compatible feature set and
  391. * the incompatible feature set is that if there is a bit set
  392. * in the incompatible feature set that the kernel doesn't
  393. * know about, it should refuse to mount the filesystem.
  394. *
  395. * e2fsck's requirements are more strict; if it doesn't know
  396. * about a feature in either the compatible or incompatible
  397. * feature set, it must abort and not try to meddle with
  398. * things it doesn't understand...
  399. */
  400. __le32 s_first_ino; /* First non-reserved inode */
  401. __le16 s_inode_size; /* size of inode structure */
  402. __le16 s_block_group_nr; /* block group # of this superblock */
  403. __le32 s_feature_compat; /* compatible feature set */
  404. /*60*/ __le32 s_feature_incompat; /* incompatible feature set */
  405. __le32 s_feature_ro_compat; /* readonly-compatible feature set */
  406. /*68*/ __u8 s_uuid[16]; /* 128-bit uuid for volume */
  407. /*78*/ char s_volume_name[16]; /* volume name */
  408. /*88*/ char s_last_mounted[64]; /* directory where last mounted */
  409. /*C8*/ __le32 s_algorithm_usage_bitmap; /* For compression */
  410. /*
  411. * Performance hints. Directory preallocation should only
  412. * happen if the EXT3_FEATURE_COMPAT_DIR_PREALLOC flag is on.
  413. */
  414. __u8 s_prealloc_blocks; /* Nr of blocks to try to preallocate*/
  415. __u8 s_prealloc_dir_blocks; /* Nr to preallocate for dirs */
  416. __u16 s_reserved_gdt_blocks; /* Per group desc for online growth */
  417. /*
  418. * Journaling support valid if EXT3_FEATURE_COMPAT_HAS_JOURNAL set.
  419. */
  420. /*D0*/ __u8 s_journal_uuid[16]; /* uuid of journal superblock */
  421. /*E0*/ __le32 s_journal_inum; /* inode number of journal file */
  422. __le32 s_journal_dev; /* device number of journal file */
  423. __le32 s_last_orphan; /* start of list of inodes to delete */
  424. __le32 s_hash_seed[4]; /* HTREE hash seed */
  425. __u8 s_def_hash_version; /* Default hash version to use */
  426. __u8 s_reserved_char_pad;
  427. __u16 s_reserved_word_pad;
  428. __le32 s_default_mount_opts;
  429. __le32 s_first_meta_bg; /* First metablock block group */
  430. __u32 s_reserved[190]; /* Padding to the end of the block */
  431. };
  432. #ifdef __KERNEL__
  433. static inline struct ext3_sb_info * EXT3_SB(struct super_block *sb)
  434. {
  435. return sb->s_fs_info;
  436. }
  437. static inline struct ext3_inode_info *EXT3_I(struct inode *inode)
  438. {
  439. return container_of(inode, struct ext3_inode_info, vfs_inode);
  440. }
  441. #else
  442. /* Assume that user mode programs are passing in an ext3fs superblock, not
  443. * a kernel struct super_block. This will allow us to call the feature-test
  444. * macros from user land. */
  445. #define EXT3_SB(sb) (sb)
  446. #endif
  447. #define NEXT_ORPHAN(inode) EXT3_I(inode)->i_dtime
  448. /*
  449. * Codes for operating systems
  450. */
  451. #define EXT3_OS_LINUX 0
  452. #define EXT3_OS_HURD 1
  453. #define EXT3_OS_MASIX 2
  454. #define EXT3_OS_FREEBSD 3
  455. #define EXT3_OS_LITES 4
  456. /*
  457. * Revision levels
  458. */
  459. #define EXT3_GOOD_OLD_REV 0 /* The good old (original) format */
  460. #define EXT3_DYNAMIC_REV 1 /* V2 format w/ dynamic inode sizes */
  461. #define EXT3_CURRENT_REV EXT3_GOOD_OLD_REV
  462. #define EXT3_MAX_SUPP_REV EXT3_DYNAMIC_REV
  463. #define EXT3_GOOD_OLD_INODE_SIZE 128
  464. /*
  465. * Feature set definitions
  466. */
  467. #define EXT3_HAS_COMPAT_FEATURE(sb,mask) \
  468. ( EXT3_SB(sb)->s_es->s_feature_compat & cpu_to_le32(mask) )
  469. #define EXT3_HAS_RO_COMPAT_FEATURE(sb,mask) \
  470. ( EXT3_SB(sb)->s_es->s_feature_ro_compat & cpu_to_le32(mask) )
  471. #define EXT3_HAS_INCOMPAT_FEATURE(sb,mask) \
  472. ( EXT3_SB(sb)->s_es->s_feature_incompat & cpu_to_le32(mask) )
  473. #define EXT3_SET_COMPAT_FEATURE(sb,mask) \
  474. EXT3_SB(sb)->s_es->s_feature_compat |= cpu_to_le32(mask)
  475. #define EXT3_SET_RO_COMPAT_FEATURE(sb,mask) \
  476. EXT3_SB(sb)->s_es->s_feature_ro_compat |= cpu_to_le32(mask)
  477. #define EXT3_SET_INCOMPAT_FEATURE(sb,mask) \
  478. EXT3_SB(sb)->s_es->s_feature_incompat |= cpu_to_le32(mask)
  479. #define EXT3_CLEAR_COMPAT_FEATURE(sb,mask) \
  480. EXT3_SB(sb)->s_es->s_feature_compat &= ~cpu_to_le32(mask)
  481. #define EXT3_CLEAR_RO_COMPAT_FEATURE(sb,mask) \
  482. EXT3_SB(sb)->s_es->s_feature_ro_compat &= ~cpu_to_le32(mask)
  483. #define EXT3_CLEAR_INCOMPAT_FEATURE(sb,mask) \
  484. EXT3_SB(sb)->s_es->s_feature_incompat &= ~cpu_to_le32(mask)
  485. #define EXT3_FEATURE_COMPAT_DIR_PREALLOC 0x0001
  486. #define EXT3_FEATURE_COMPAT_IMAGIC_INODES 0x0002
  487. #define EXT3_FEATURE_COMPAT_HAS_JOURNAL 0x0004
  488. #define EXT3_FEATURE_COMPAT_EXT_ATTR 0x0008
  489. #define EXT3_FEATURE_COMPAT_RESIZE_INODE 0x0010
  490. #define EXT3_FEATURE_COMPAT_DIR_INDEX 0x0020
  491. #define EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
  492. #define EXT3_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
  493. #define EXT3_FEATURE_RO_COMPAT_BTREE_DIR 0x0004
  494. #define EXT3_FEATURE_INCOMPAT_COMPRESSION 0x0001
  495. #define EXT3_FEATURE_INCOMPAT_FILETYPE 0x0002
  496. #define EXT3_FEATURE_INCOMPAT_RECOVER 0x0004 /* Needs recovery */
  497. #define EXT3_FEATURE_INCOMPAT_JOURNAL_DEV 0x0008 /* Journal device */
  498. #define EXT3_FEATURE_INCOMPAT_META_BG 0x0010
  499. #define EXT3_FEATURE_COMPAT_SUPP EXT2_FEATURE_COMPAT_EXT_ATTR
  500. #define EXT3_FEATURE_INCOMPAT_SUPP (EXT3_FEATURE_INCOMPAT_FILETYPE| \
  501. EXT3_FEATURE_INCOMPAT_RECOVER| \
  502. EXT3_FEATURE_INCOMPAT_META_BG)
  503. #define EXT3_FEATURE_RO_COMPAT_SUPP (EXT3_FEATURE_RO_COMPAT_SPARSE_SUPER| \
  504. EXT3_FEATURE_RO_COMPAT_LARGE_FILE| \
  505. EXT3_FEATURE_RO_COMPAT_BTREE_DIR)
  506. /*
  507. * Default values for user and/or group using reserved blocks
  508. */
  509. #define EXT3_DEF_RESUID 0
  510. #define EXT3_DEF_RESGID 0
  511. /*
  512. * Default mount options
  513. */
  514. #define EXT3_DEFM_DEBUG 0x0001
  515. #define EXT3_DEFM_BSDGROUPS 0x0002
  516. #define EXT3_DEFM_XATTR_USER 0x0004
  517. #define EXT3_DEFM_ACL 0x0008
  518. #define EXT3_DEFM_UID16 0x0010
  519. #define EXT3_DEFM_JMODE 0x0060
  520. #define EXT3_DEFM_JMODE_DATA 0x0020
  521. #define EXT3_DEFM_JMODE_ORDERED 0x0040
  522. #define EXT3_DEFM_JMODE_WBACK 0x0060
  523. /*
  524. * Structure of a directory entry
  525. */
  526. #define EXT3_NAME_LEN 255
  527. struct ext3_dir_entry {
  528. __le32 inode; /* Inode number */
  529. __le16 rec_len; /* Directory entry length */
  530. __le16 name_len; /* Name length */
  531. char name[EXT3_NAME_LEN]; /* File name */
  532. };
  533. /*
  534. * The new version of the directory entry. Since EXT3 structures are
  535. * stored in intel byte order, and the name_len field could never be
  536. * bigger than 255 chars, it's safe to reclaim the extra byte for the
  537. * file_type field.
  538. */
  539. struct ext3_dir_entry_2 {
  540. __le32 inode; /* Inode number */
  541. __le16 rec_len; /* Directory entry length */
  542. __u8 name_len; /* Name length */
  543. __u8 file_type;
  544. char name[EXT3_NAME_LEN]; /* File name */
  545. };
  546. /*
  547. * Ext3 directory file types. Only the low 3 bits are used. The
  548. * other bits are reserved for now.
  549. */
  550. #define EXT3_FT_UNKNOWN 0
  551. #define EXT3_FT_REG_FILE 1
  552. #define EXT3_FT_DIR 2
  553. #define EXT3_FT_CHRDEV 3
  554. #define EXT3_FT_BLKDEV 4
  555. #define EXT3_FT_FIFO 5
  556. #define EXT3_FT_SOCK 6
  557. #define EXT3_FT_SYMLINK 7
  558. #define EXT3_FT_MAX 8
  559. /*
  560. * EXT3_DIR_PAD defines the directory entries boundaries
  561. *
  562. * NOTE: It must be a multiple of 4
  563. */
  564. #define EXT3_DIR_PAD 4
  565. #define EXT3_DIR_ROUND (EXT3_DIR_PAD - 1)
  566. #define EXT3_DIR_REC_LEN(name_len) (((name_len) + 8 + EXT3_DIR_ROUND) & \
  567. ~EXT3_DIR_ROUND)
  568. /*
  569. * Hash Tree Directory indexing
  570. * (c) Daniel Phillips, 2001
  571. */
  572. #ifdef CONFIG_EXT3_INDEX
  573. #define is_dx(dir) (EXT3_HAS_COMPAT_FEATURE(dir->i_sb, \
  574. EXT3_FEATURE_COMPAT_DIR_INDEX) && \
  575. (EXT3_I(dir)->i_flags & EXT3_INDEX_FL))
  576. #define EXT3_DIR_LINK_MAX(dir) (!is_dx(dir) && (dir)->i_nlink >= EXT3_LINK_MAX)
  577. #define EXT3_DIR_LINK_EMPTY(dir) ((dir)->i_nlink == 2 || (dir)->i_nlink == 1)
  578. #else
  579. #define is_dx(dir) 0
  580. #define EXT3_DIR_LINK_MAX(dir) ((dir)->i_nlink >= EXT3_LINK_MAX)
  581. #define EXT3_DIR_LINK_EMPTY(dir) ((dir)->i_nlink == 2)
  582. #endif
  583. /* Legal values for the dx_root hash_version field: */
  584. #define DX_HASH_LEGACY 0
  585. #define DX_HASH_HALF_MD4 1
  586. #define DX_HASH_TEA 2
  587. /* hash info structure used by the directory hash */
  588. struct dx_hash_info
  589. {
  590. u32 hash;
  591. u32 minor_hash;
  592. int hash_version;
  593. u32 *seed;
  594. };
  595. #define EXT3_HTREE_EOF 0x7fffffff
  596. #ifdef __KERNEL__
  597. /*
  598. * Control parameters used by ext3_htree_next_block
  599. */
  600. #define HASH_NB_ALWAYS 1
  601. /*
  602. * Describe an inode's exact location on disk and in memory
  603. */
  604. struct ext3_iloc
  605. {
  606. struct buffer_head *bh;
  607. unsigned long offset;
  608. unsigned long block_group;
  609. };
  610. static inline struct ext3_inode *ext3_raw_inode(struct ext3_iloc *iloc)
  611. {
  612. return (struct ext3_inode *) (iloc->bh->b_data + iloc->offset);
  613. }
  614. /*
  615. * This structure is stuffed into the struct file's private_data field
  616. * for directories. It is where we put information so that we can do
  617. * readdir operations in hash tree order.
  618. */
  619. struct dir_private_info {
  620. struct rb_root root;
  621. struct rb_node *curr_node;
  622. struct fname *extra_fname;
  623. loff_t last_pos;
  624. __u32 curr_hash;
  625. __u32 curr_minor_hash;
  626. __u32 next_hash;
  627. };
  628. /*
  629. * Special error return code only used by dx_probe() and its callers.
  630. */
  631. #define ERR_BAD_DX_DIR -75000
  632. /*
  633. * Function prototypes
  634. */
  635. /*
  636. * Ok, these declarations are also in <linux/kernel.h> but none of the
  637. * ext3 source programs needs to include it so they are duplicated here.
  638. */
  639. # define NORET_TYPE /**/
  640. # define ATTRIB_NORET __attribute__((noreturn))
  641. # define NORET_AND noreturn,
  642. /* balloc.c */
  643. extern int ext3_bg_has_super(struct super_block *sb, int group);
  644. extern unsigned long ext3_bg_num_gdb(struct super_block *sb, int group);
  645. extern int ext3_new_block (handle_t *, struct inode *, unsigned long, int *);
  646. extern void ext3_free_blocks (handle_t *, struct inode *, unsigned long,
  647. unsigned long);
  648. extern void ext3_free_blocks_sb (handle_t *, struct super_block *,
  649. unsigned long, unsigned long, int *);
  650. extern unsigned long ext3_count_free_blocks (struct super_block *);
  651. extern void ext3_check_blocks_bitmap (struct super_block *);
  652. extern struct ext3_group_desc * ext3_get_group_desc(struct super_block * sb,
  653. unsigned int block_group,
  654. struct buffer_head ** bh);
  655. extern int ext3_should_retry_alloc(struct super_block *sb, int *retries);
  656. extern void ext3_init_block_alloc_info(struct inode *);
  657. extern void ext3_rsv_window_add(struct super_block *sb, struct ext3_reserve_window_node *rsv);
  658. /* dir.c */
  659. extern int ext3_check_dir_entry(const char *, struct inode *,
  660. struct ext3_dir_entry_2 *,
  661. struct buffer_head *, unsigned long);
  662. extern int ext3_htree_store_dirent(struct file *dir_file, __u32 hash,
  663. __u32 minor_hash,
  664. struct ext3_dir_entry_2 *dirent);
  665. extern void ext3_htree_free_dir_info(struct dir_private_info *p);
  666. /* fsync.c */
  667. extern int ext3_sync_file (struct file *, struct dentry *, int);
  668. /* hash.c */
  669. extern int ext3fs_dirhash(const char *name, int len, struct
  670. dx_hash_info *hinfo);
  671. /* ialloc.c */
  672. extern struct inode * ext3_new_inode (handle_t *, struct inode *, int);
  673. extern void ext3_free_inode (handle_t *, struct inode *);
  674. extern struct inode * ext3_orphan_get (struct super_block *, unsigned long);
  675. extern unsigned long ext3_count_free_inodes (struct super_block *);
  676. extern unsigned long ext3_count_dirs (struct super_block *);
  677. extern void ext3_check_inodes_bitmap (struct super_block *);
  678. extern unsigned long ext3_count_free (struct buffer_head *, unsigned);
  679. /* inode.c */
  680. extern int ext3_forget(handle_t *, int, struct inode *, struct buffer_head *, int);
  681. extern struct buffer_head * ext3_getblk (handle_t *, struct inode *, long, int, int *);
  682. extern struct buffer_head * ext3_bread (handle_t *, struct inode *, int, int, int *);
  683. extern void ext3_read_inode (struct inode *);
  684. extern int ext3_write_inode (struct inode *, int);
  685. extern int ext3_setattr (struct dentry *, struct iattr *);
  686. extern void ext3_delete_inode (struct inode *);
  687. extern int ext3_sync_inode (handle_t *, struct inode *);
  688. extern void ext3_discard_reservation (struct inode *);
  689. extern void ext3_dirty_inode(struct inode *);
  690. extern int ext3_change_inode_journal_flag(struct inode *, int);
  691. extern int ext3_get_inode_loc(struct inode *, struct ext3_iloc *);
  692. extern void ext3_truncate (struct inode *);
  693. extern void ext3_set_inode_flags(struct inode *);
  694. extern void ext3_set_aops(struct inode *inode);
  695. /* ioctl.c */
  696. extern int ext3_ioctl (struct inode *, struct file *, unsigned int,
  697. unsigned long);
  698. /* namei.c */
  699. extern int ext3_orphan_add(handle_t *, struct inode *);
  700. extern int ext3_orphan_del(handle_t *, struct inode *);
  701. extern int ext3_htree_fill_tree(struct file *dir_file, __u32 start_hash,
  702. __u32 start_minor_hash, __u32 *next_hash);
  703. /* resize.c */
  704. extern int ext3_group_add(struct super_block *sb,
  705. struct ext3_new_group_data *input);
  706. extern int ext3_group_extend(struct super_block *sb,
  707. struct ext3_super_block *es,
  708. unsigned long n_blocks_count);
  709. /* super.c */
  710. extern void ext3_error (struct super_block *, const char *, const char *, ...)
  711. __attribute__ ((format (printf, 3, 4)));
  712. extern void __ext3_std_error (struct super_block *, const char *, int);
  713. extern void ext3_abort (struct super_block *, const char *, const char *, ...)
  714. __attribute__ ((format (printf, 3, 4)));
  715. extern void ext3_warning (struct super_block *, const char *, const char *, ...)
  716. __attribute__ ((format (printf, 3, 4)));
  717. extern void ext3_update_dynamic_rev (struct super_block *sb);
  718. #define ext3_std_error(sb, errno) \
  719. do { \
  720. if ((errno)) \
  721. __ext3_std_error((sb), __FUNCTION__, (errno)); \
  722. } while (0)
  723. /*
  724. * Inodes and files operations
  725. */
  726. /* dir.c */
  727. extern struct file_operations ext3_dir_operations;
  728. /* file.c */
  729. extern struct inode_operations ext3_file_inode_operations;
  730. extern struct file_operations ext3_file_operations;
  731. /* namei.c */
  732. extern struct inode_operations ext3_dir_inode_operations;
  733. extern struct inode_operations ext3_special_inode_operations;
  734. /* symlink.c */
  735. extern struct inode_operations ext3_symlink_inode_operations;
  736. extern struct inode_operations ext3_fast_symlink_inode_operations;
  737. #endif /* __KERNEL__ */
  738. #endif /* _LINUX_EXT3_FS_H */