ext4_types.h 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045
  1. /*
  2. * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
  3. *
  4. *
  5. * HelenOS:
  6. * Copyright (c) 2012 Martin Sucha
  7. * Copyright (c) 2012 Frantisek Princ
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. *
  14. * - Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. * - Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in the
  18. * documentation and/or other materials provided with the distribution.
  19. * - The name of the author may not be used to endorse or promote products
  20. * derived from this software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  23. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  24. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  25. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  27. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  31. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. /** @addtogroup lwext4
  34. * @{
  35. */
  36. /**
  37. * @file ext4_types.h
  38. * @brief Ext4 data structure definitions.
  39. */
  40. #ifndef EXT4_TYPES_H_
  41. #define EXT4_TYPES_H_
  42. #ifdef __cplusplus
  43. extern "C" {
  44. #endif
  45. #include "ext4_config.h"
  46. #include "ext4_blockdev.h"
  47. #include "misc/tree.h"
  48. #include <stddef.h>
  49. #include <stdint.h>
  50. /*
  51. * Types of blocks.
  52. */
  53. typedef uint32_t ext4_lblk_t;
  54. typedef uint64_t ext4_fsblk_t;
  55. #define EXT4_CHECKSUM_CRC32C 1
  56. #define UUID_SIZE 16
  57. #pragma pack(push, 1)
  58. /*
  59. * Structure of the super block
  60. */
  61. struct ext4_sblock {
  62. uint32_t inodes_count; /* I-nodes count */
  63. uint32_t blocks_count_lo; /* Blocks count */
  64. uint32_t reserved_blocks_count_lo; /* Reserved blocks count */
  65. uint32_t free_blocks_count_lo; /* Free blocks count */
  66. uint32_t free_inodes_count; /* Free inodes count */
  67. uint32_t first_data_block; /* First Data Block */
  68. uint32_t log_block_size; /* Block size */
  69. uint32_t log_cluster_size; /* Obsoleted fragment size */
  70. uint32_t blocks_per_group; /* Number of blocks per group */
  71. uint32_t frags_per_group; /* Obsoleted fragments per group */
  72. uint32_t inodes_per_group; /* Number of inodes per group */
  73. uint32_t mount_time; /* Mount time */
  74. uint32_t write_time; /* Write time */
  75. uint16_t mount_count; /* Mount count */
  76. uint16_t max_mount_count; /* Maximal mount count */
  77. uint16_t magic; /* Magic signature */
  78. uint16_t state; /* File system state */
  79. uint16_t errors; /* Behavior when detecting errors */
  80. uint16_t minor_rev_level; /* Minor revision level */
  81. uint32_t last_check_time; /* Time of last check */
  82. uint32_t check_interval; /* Maximum time between checks */
  83. uint32_t creator_os; /* Creator OS */
  84. uint32_t rev_level; /* Revision level */
  85. uint16_t def_resuid; /* Default uid for reserved blocks */
  86. uint16_t def_resgid; /* Default gid for reserved blocks */
  87. /* Fields for EXT4_DYNAMIC_REV superblocks only. */
  88. uint32_t first_inode; /* First non-reserved inode */
  89. uint16_t inode_size; /* Size of inode structure */
  90. uint16_t block_group_index; /* Block group index of this superblock */
  91. uint32_t features_compatible; /* Compatible feature set */
  92. uint32_t features_incompatible; /* Incompatible feature set */
  93. uint32_t features_read_only; /* Readonly-compatible feature set */
  94. uint8_t uuid[UUID_SIZE]; /* 128-bit uuid for volume */
  95. char volume_name[16]; /* Volume name */
  96. char last_mounted[64]; /* Directory where last mounted */
  97. uint32_t algorithm_usage_bitmap; /* For compression */
  98. /*
  99. * Performance hints. Directory preallocation should only
  100. * happen if the EXT4_FEATURE_COMPAT_DIR_PREALLOC flag is on.
  101. */
  102. uint8_t s_prealloc_blocks; /* Number of blocks to try to preallocate */
  103. uint8_t s_prealloc_dir_blocks; /* Number to preallocate for dirs */
  104. uint16_t s_reserved_gdt_blocks; /* Per group desc for online growth */
  105. /*
  106. * Journaling support valid if EXT4_FEATURE_COMPAT_HAS_JOURNAL set.
  107. */
  108. uint8_t journal_uuid[UUID_SIZE]; /* UUID of journal superblock */
  109. uint32_t journal_inode_number; /* Inode number of journal file */
  110. uint32_t journal_dev; /* Device number of journal file */
  111. uint32_t last_orphan; /* Head of list of inodes to delete */
  112. uint32_t hash_seed[4]; /* HTREE hash seed */
  113. uint8_t default_hash_version; /* Default hash version to use */
  114. uint8_t journal_backup_type;
  115. uint16_t desc_size; /* Size of group descriptor */
  116. uint32_t default_mount_opts; /* Default mount options */
  117. uint32_t first_meta_bg; /* First metablock block group */
  118. uint32_t mkfs_time; /* When the filesystem was created */
  119. uint32_t journal_blocks[17]; /* Backup of the journal inode */
  120. /* 64bit support valid if EXT4_FEATURE_COMPAT_64BIT */
  121. uint32_t blocks_count_hi; /* Blocks count */
  122. uint32_t reserved_blocks_count_hi; /* Reserved blocks count */
  123. uint32_t free_blocks_count_hi; /* Free blocks count */
  124. uint16_t min_extra_isize; /* All inodes have at least # bytes */
  125. uint16_t want_extra_isize; /* New inodes should reserve # bytes */
  126. uint32_t flags; /* Miscellaneous flags */
  127. uint16_t raid_stride; /* RAID stride */
  128. uint16_t mmp_interval; /* # seconds to wait in MMP checking */
  129. uint64_t mmp_block; /* Block for multi-mount protection */
  130. uint32_t raid_stripe_width; /* Blocks on all data disks (N * stride) */
  131. uint8_t log_groups_per_flex; /* FLEX_BG group size */
  132. uint8_t checksum_type;
  133. uint16_t reserved_pad;
  134. uint64_t kbytes_written; /* Number of lifetime kilobytes written */
  135. uint32_t snapshot_inum; /* I-node number of active snapshot */
  136. uint32_t snapshot_id; /* Sequential ID of active snapshot */
  137. uint64_t
  138. snapshot_r_blocks_count; /* Reserved blocks for active snapshot's
  139. future use */
  140. uint32_t
  141. snapshot_list; /* I-node number of the head of the on-disk snapshot
  142. list */
  143. uint32_t error_count; /* Number of file system errors */
  144. uint32_t first_error_time; /* First time an error happened */
  145. uint32_t first_error_ino; /* I-node involved in first error */
  146. uint64_t first_error_block; /* Block involved of first error */
  147. uint8_t first_error_func[32]; /* Function where the error happened */
  148. uint32_t first_error_line; /* Line number where error happened */
  149. uint32_t last_error_time; /* Most recent time of an error */
  150. uint32_t last_error_ino; /* I-node involved in last error */
  151. uint32_t last_error_line; /* Line number where error happened */
  152. uint64_t last_error_block; /* Block involved of last error */
  153. uint8_t last_error_func[32]; /* Function where the error happened */
  154. uint8_t mount_opts[64];
  155. uint32_t usr_quota_inum; /* inode for tracking user quota */
  156. uint32_t grp_quota_inum; /* inode for tracking group quota */
  157. uint32_t overhead_clusters; /* overhead blocks/clusters in fs */
  158. uint32_t backup_bgs[2]; /* groups with sparse_super2 SBs */
  159. uint8_t encrypt_algos[4]; /* Encryption algorithms in use */
  160. uint8_t encrypt_pw_salt[16]; /* Salt used for string2key algorithm */
  161. uint32_t lpf_ino; /* Location of the lost+found inode */
  162. uint32_t padding[100]; /* Padding to the end of the block */
  163. uint32_t checksum; /* crc32c(superblock) */
  164. };
  165. #pragma pack(pop)
  166. #define EXT4_SUPERBLOCK_MAGIC 0xEF53
  167. #define EXT4_SUPERBLOCK_SIZE 1024
  168. #define EXT4_SUPERBLOCK_OFFSET 1024
  169. #define EXT4_SUPERBLOCK_OS_LINUX 0
  170. #define EXT4_SUPERBLOCK_OS_HURD 1
  171. /*
  172. * Misc. filesystem flags
  173. */
  174. #define EXT4_SUPERBLOCK_FLAGS_SIGNED_HASH 0x0001
  175. #define EXT4_SUPERBLOCK_FLAGS_UNSIGNED_HASH 0x0002
  176. #define EXT4_SUPERBLOCK_FLAGS_TEST_FILESYS 0x0004
  177. /*
  178. * Filesystem states
  179. */
  180. #define EXT4_SUPERBLOCK_STATE_VALID_FS 0x0001 /* Unmounted cleanly */
  181. #define EXT4_SUPERBLOCK_STATE_ERROR_FS 0x0002 /* Errors detected */
  182. #define EXT4_SUPERBLOCK_STATE_ORPHAN_FS 0x0004 /* Orphans being recovered */
  183. /*
  184. * Behaviour when errors detected
  185. */
  186. #define EXT4_SUPERBLOCK_ERRORS_CONTINUE 1 /* Continue execution */
  187. #define EXT4_SUPERBLOCK_ERRORS_RO 2 /* Remount fs read-only */
  188. #define EXT4_SUPERBLOCK_ERRORS_PANIC 3 /* Panic */
  189. #define EXT4_SUPERBLOCK_ERRORS_DEFAULT EXT4_ERRORS_CONTINUE
  190. /*
  191. * Compatible features
  192. */
  193. #define EXT4_FCOM_DIR_PREALLOC 0x0001
  194. #define EXT4_FCOM_IMAGIC_INODES 0x0002
  195. #define EXT4_FCOM_HAS_JOURNAL 0x0004
  196. #define EXT4_FCOM_EXT_ATTR 0x0008
  197. #define EXT4_FCOM_RESIZE_INODE 0x0010
  198. #define EXT4_FCOM_DIR_INDEX 0x0020
  199. /*
  200. * Read-only compatible features
  201. */
  202. #define EXT4_FRO_COM_SPARSE_SUPER 0x0001
  203. #define EXT4_FRO_COM_LARGE_FILE 0x0002
  204. #define EXT4_FRO_COM_BTREE_DIR 0x0004
  205. #define EXT4_FRO_COM_HUGE_FILE 0x0008
  206. #define EXT4_FRO_COM_GDT_CSUM 0x0010
  207. #define EXT4_FRO_COM_DIR_NLINK 0x0020
  208. #define EXT4_FRO_COM_EXTRA_ISIZE 0x0040
  209. #define EXT4_FRO_COM_QUOTA 0x0100
  210. #define EXT4_FRO_COM_BIGALLOC 0x0200
  211. #define EXT4_FRO_COM_METADATA_CSUM 0x0400
  212. /*
  213. * Incompatible features
  214. */
  215. #define EXT4_FINCOM_COMPRESSION 0x0001
  216. #define EXT4_FINCOM_FILETYPE 0x0002
  217. #define EXT4_FINCOM_RECOVER 0x0004 /* Needs recovery */
  218. #define EXT4_FINCOM_JOURNAL_DEV 0x0008 /* Journal device */
  219. #define EXT4_FINCOM_META_BG 0x0010
  220. #define EXT4_FINCOM_EXTENTS 0x0040 /* extents support */
  221. #define EXT4_FINCOM_64BIT 0x0080
  222. #define EXT4_FINCOM_MMP 0x0100
  223. #define EXT4_FINCOM_FLEX_BG 0x0200
  224. #define EXT4_FINCOM_EA_INODE 0x0400 /* EA in inode */
  225. #define EXT4_FINCOM_DIRDATA 0x1000 /* data in dirent */
  226. #define EXT4_FINCOM_BG_USE_META_CSUM 0x2000 /* use crc32c for bg */
  227. #define EXT4_FINCOM_LARGEDIR 0x4000 /* >2GB or 3-lvl htree */
  228. #define EXT4_FINCOM_INLINE_DATA 0x8000 /* data in inode */
  229. /*
  230. * EXT2 supported feature set
  231. */
  232. #define EXT2_SUPPORTED_FCOM 0x0000
  233. #define EXT2_SUPPORTED_FINCOM \
  234. (EXT4_FINCOM_FILETYPE | EXT4_FINCOM_META_BG)
  235. #define EXT2_SUPPORTED_FRO_COM \
  236. (EXT4_FRO_COM_SPARSE_SUPER | \
  237. EXT4_FRO_COM_LARGE_FILE)
  238. /*
  239. * EXT3 supported feature set
  240. */
  241. #define EXT3_SUPPORTED_FCOM (EXT4_FCOM_DIR_INDEX)
  242. #define EXT3_SUPPORTED_FINCOM \
  243. (EXT4_FINCOM_FILETYPE | EXT4_FINCOM_META_BG)
  244. #define EXT3_SUPPORTED_FRO_COM \
  245. (EXT4_FRO_COM_SPARSE_SUPER | EXT4_FRO_COM_LARGE_FILE)
  246. /*
  247. * EXT4 supported feature set
  248. */
  249. #define EXT4_SUPPORTED_FCOM (EXT4_FCOM_DIR_INDEX)
  250. #define EXT4_SUPPORTED_FINCOM \
  251. (EXT4_FINCOM_FILETYPE | EXT4_FINCOM_META_BG | \
  252. EXT4_FINCOM_EXTENTS | EXT4_FINCOM_FLEX_BG | \
  253. EXT4_FINCOM_64BIT)
  254. #define EXT4_SUPPORTED_FRO_COM \
  255. (EXT4_FRO_COM_SPARSE_SUPER | \
  256. EXT4_FRO_COM_METADATA_CSUM | \
  257. EXT4_FRO_COM_LARGE_FILE | EXT4_FRO_COM_GDT_CSUM | \
  258. EXT4_FRO_COM_DIR_NLINK | \
  259. EXT4_FRO_COM_EXTRA_ISIZE | EXT4_FRO_COM_HUGE_FILE)
  260. /*Ignored features:
  261. * RECOVER - journaling in lwext4 is not supported
  262. * (probably won't be ever...)
  263. * MMP - multi-mout protection (impossible scenario)
  264. * */
  265. #define EXT_FINCOM_IGNORED \
  266. EXT4_FINCOM_RECOVER | EXT4_FINCOM_MMP
  267. #if 0
  268. /*TODO: Features incompatible to implement*/
  269. #define EXT4_SUPPORTED_FINCOM
  270. (EXT4_FINCOM_INLINE_DATA)
  271. /*TODO: Features read only to implement*/
  272. #define EXT4_SUPPORTED_FRO_COM
  273. EXT4_FRO_COM_BIGALLOC |\
  274. EXT4_FRO_COM_QUOTA)
  275. #endif
  276. /* Inode table/bitmap not in use */
  277. #define EXT4_BLOCK_GROUP_INODE_UNINIT 0x0001
  278. /* Block bitmap not in use */
  279. #define EXT4_BLOCK_GROUP_BLOCK_UNINIT 0x0002
  280. /* On-disk itable initialized to zero */
  281. #define EXT4_BLOCK_GROUP_ITABLE_ZEROED 0x0004
  282. /*
  283. * Structure of a blocks group descriptor
  284. */
  285. struct ext4_bgroup {
  286. uint32_t block_bitmap_lo; /* Blocks bitmap block */
  287. uint32_t inode_bitmap_lo; /* Inodes bitmap block */
  288. uint32_t inode_table_first_block_lo; /* Inodes table block */
  289. uint16_t free_blocks_count_lo; /* Free blocks count */
  290. uint16_t free_inodes_count_lo; /* Free inodes count */
  291. uint16_t used_dirs_count_lo; /* Directories count */
  292. uint16_t flags; /* EXT4_BG_flags (INODE_UNINIT, etc) */
  293. uint32_t exclude_bitmap_lo; /* Exclude bitmap for snapshots */
  294. uint16_t block_bitmap_csum_lo; /* crc32c(s_uuid+grp_num+bbitmap) LE */
  295. uint16_t inode_bitmap_csum_lo; /* crc32c(s_uuid+grp_num+ibitmap) LE */
  296. uint16_t itable_unused_lo; /* Unused inodes count */
  297. uint16_t checksum; /* crc16(sb_uuid+group+desc) */
  298. uint32_t block_bitmap_hi; /* Blocks bitmap block MSB */
  299. uint32_t inode_bitmap_hi; /* I-nodes bitmap block MSB */
  300. uint32_t inode_table_first_block_hi; /* I-nodes table block MSB */
  301. uint16_t free_blocks_count_hi; /* Free blocks count MSB */
  302. uint16_t free_inodes_count_hi; /* Free i-nodes count MSB */
  303. uint16_t used_dirs_count_hi; /* Directories count MSB */
  304. uint16_t itable_unused_hi; /* Unused inodes count MSB */
  305. uint32_t exclude_bitmap_hi; /* Exclude bitmap block MSB */
  306. uint16_t block_bitmap_csum_hi; /* crc32c(s_uuid+grp_num+bbitmap) BE */
  307. uint16_t inode_bitmap_csum_hi; /* crc32c(s_uuid+grp_num+ibitmap) BE */
  308. uint32_t reserved; /* Padding */
  309. };
  310. #define EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE 32
  311. #define EXT4_MAX_BLOCK_GROUP_DESCRIPTOR_SIZE 64
  312. #define EXT4_MIN_BLOCK_SIZE 1024 /* 1 KiB */
  313. #define EXT4_MAX_BLOCK_SIZE 65536 /* 64 KiB */
  314. #define EXT4_REV0_INODE_SIZE 128
  315. #define EXT4_INODE_BLOCK_SIZE 512
  316. #define EXT4_INODE_DIRECT_BLOCK_COUNT 12
  317. #define EXT4_INODE_INDIRECT_BLOCK EXT4_INODE_DIRECT_BLOCK_COUNT
  318. #define EXT4_INODE_DOUBLE_INDIRECT_BLOCK (EXT4_INODE_INDIRECT_BLOCK + 1)
  319. #define EXT4_INODE_TRIPPLE_INDIRECT_BLOCK (EXT4_INODE_DOUBLE_INDIRECT_BLOCK + 1)
  320. #define EXT4_INODE_BLOCKS (EXT4_INODE_TRIPPLE_INDIRECT_BLOCK + 1)
  321. #define EXT4_INODE_INDIRECT_BLOCK_COUNT \
  322. (EXT4_INODE_BLOCKS - EXT4_INODE_DIRECT_BLOCK_COUNT)
  323. #pragma pack(push, 1)
  324. /*
  325. * Structure of an inode on the disk
  326. */
  327. struct ext4_inode {
  328. uint16_t mode; /* File mode */
  329. uint16_t uid; /* Low 16 bits of owner uid */
  330. uint32_t size_lo; /* Size in bytes */
  331. uint32_t access_time; /* Access time */
  332. uint32_t change_inode_time; /* I-node change time */
  333. uint32_t modification_time; /* Modification time */
  334. uint32_t deletion_time; /* Deletion time */
  335. uint16_t gid; /* Low 16 bits of group id */
  336. uint16_t links_count; /* Links count */
  337. uint32_t blocks_count_lo; /* Blocks count */
  338. uint32_t flags; /* File flags */
  339. uint32_t unused_osd1; /* OS dependent - not used in HelenOS */
  340. uint32_t blocks[EXT4_INODE_BLOCKS]; /* Pointers to blocks */
  341. uint32_t generation; /* File version (for NFS) */
  342. uint32_t file_acl_lo; /* File ACL */
  343. uint32_t size_hi;
  344. uint32_t obso_faddr; /* Obsoleted fragment address */
  345. union {
  346. struct {
  347. uint16_t blocks_high;
  348. uint16_t file_acl_high;
  349. uint16_t uid_high;
  350. uint16_t gid_high;
  351. uint16_t checksum_lo; /* crc32c(uuid+inum+inode) LE */
  352. uint16_t reserved2;
  353. } linux2;
  354. struct {
  355. uint16_t reserved1;
  356. uint16_t mode_high;
  357. uint16_t uid_high;
  358. uint16_t gid_high;
  359. uint32_t author;
  360. } hurd2;
  361. } osd2;
  362. uint16_t extra_isize;
  363. uint16_t checksum_hi; /* crc32c(uuid+inum+inode) BE */
  364. uint32_t ctime_extra; /* Extra change time (nsec << 2 | epoch) */
  365. uint32_t mtime_extra; /* Extra Modification time (nsec << 2 | epoch) */
  366. uint32_t atime_extra; /* Extra Access time (nsec << 2 | epoch) */
  367. uint32_t crtime; /* File creation time */
  368. uint32_t
  369. crtime_extra; /* Extra file creation time (nsec << 2 | epoch) */
  370. uint32_t version_hi; /* High 32 bits for 64-bit version */
  371. };
  372. #pragma pack(pop)
  373. #define EXT4_INODE_MODE_FIFO 0x1000
  374. #define EXT4_INODE_MODE_CHARDEV 0x2000
  375. #define EXT4_INODE_MODE_DIRECTORY 0x4000
  376. #define EXT4_INODE_MODE_BLOCKDEV 0x6000
  377. #define EXT4_INODE_MODE_FILE 0x8000
  378. #define EXT4_INODE_MODE_SOFTLINK 0xA000
  379. #define EXT4_INODE_MODE_SOCKET 0xC000
  380. #define EXT4_INODE_MODE_TYPE_MASK 0xF000
  381. /*
  382. * Inode flags
  383. */
  384. #define EXT4_INODE_FLAG_SECRM 0x00000001 /* Secure deletion */
  385. #define EXT4_INODE_FLAG_UNRM 0x00000002 /* Undelete */
  386. #define EXT4_INODE_FLAG_COMPR 0x00000004 /* Compress file */
  387. #define EXT4_INODE_FLAG_SYNC 0x00000008 /* Synchronous updates */
  388. #define EXT4_INODE_FLAG_IMMUTABLE 0x00000010 /* Immutable file */
  389. #define EXT4_INODE_FLAG_APPEND 0x00000020 /* writes to file may only append */
  390. #define EXT4_INODE_FLAG_NODUMP 0x00000040 /* do not dump file */
  391. #define EXT4_INODE_FLAG_NOATIME 0x00000080 /* do not update atime */
  392. /* Compression flags */
  393. #define EXT4_INODE_FLAG_DIRTY 0x00000100
  394. #define EXT4_INODE_FLAG_COMPRBLK \
  395. 0x00000200 /* One or more compressed clusters */
  396. #define EXT4_INODE_FLAG_NOCOMPR 0x00000400 /* Don't compress */
  397. #define EXT4_INODE_FLAG_ECOMPR 0x00000800 /* Compression error */
  398. #define EXT4_INODE_FLAG_INDEX 0x00001000 /* hash-indexed directory */
  399. #define EXT4_INODE_FLAG_IMAGIC 0x00002000 /* AFS directory */
  400. #define EXT4_INODE_FLAG_JOURNAL_DATA \
  401. 0x00004000 /* File data should be journaled */
  402. #define EXT4_INODE_FLAG_NOTAIL 0x00008000 /* File tail should not be merged */
  403. #define EXT4_INODE_FLAG_DIRSYNC \
  404. 0x00010000 /* Dirsync behaviour (directories only) */
  405. #define EXT4_INODE_FLAG_TOPDIR 0x00020000 /* Top of directory hierarchies */
  406. #define EXT4_INODE_FLAG_HUGE_FILE 0x00040000 /* Set to each huge file */
  407. #define EXT4_INODE_FLAG_EXTENTS 0x00080000 /* Inode uses extents */
  408. #define EXT4_INODE_FLAG_EA_INODE 0x00200000 /* Inode used for large EA */
  409. #define EXT4_INODE_FLAG_EOFBLOCKS 0x00400000 /* Blocks allocated beyond EOF */
  410. #define EXT4_INODE_FLAG_RESERVED 0x80000000 /* reserved for ext4 lib */
  411. #define EXT4_INODE_ROOT_INDEX 2
  412. #define EXT4_DIRECTORY_FILENAME_LEN 255
  413. /**@brief Directory entry types. */
  414. enum { EXT4_DE_UNKNOWN = 0,
  415. EXT4_DE_REG_FILE,
  416. EXT4_DE_DIR,
  417. EXT4_DE_CHRDEV,
  418. EXT4_DE_BLKDEV,
  419. EXT4_DE_FIFO,
  420. EXT4_DE_SOCK,
  421. EXT4_DE_SYMLINK };
  422. #define EXT4_DIRENTRY_DIR_CSUM 0xDE
  423. #pragma pack(push, 1)
  424. union ext4_dir_en_internal {
  425. uint8_t name_length_high; /* Higher 8 bits of name length */
  426. uint8_t inode_type; /* Type of referenced inode (in rev >= 0.5) */
  427. };
  428. /**
  429. * Linked list directory entry structure
  430. */
  431. struct ext4_dir_en {
  432. uint32_t inode; /* I-node for the entry */
  433. uint16_t entry_len; /* Distance to the next directory entry */
  434. uint8_t name_len; /* Lower 8 bits of name length */
  435. union ext4_dir_en_internal in;
  436. uint8_t name[EXT4_DIRECTORY_FILENAME_LEN]; /* Entry name */
  437. };
  438. /* Structures for indexed directory */
  439. struct ext4_dir_idx_climit {
  440. uint16_t limit;
  441. uint16_t count;
  442. };
  443. struct ext4_dir_idx_dot_en {
  444. uint32_t inode;
  445. uint16_t entry_length;
  446. uint8_t name_length;
  447. uint8_t inode_type;
  448. uint8_t name[4];
  449. };
  450. struct ext4_dir_idx_rinfo {
  451. uint32_t reserved_zero;
  452. uint8_t hash_version;
  453. uint8_t info_length;
  454. uint8_t indirect_levels;
  455. uint8_t unused_flags;
  456. };
  457. struct ext4_dir_idx_entry {
  458. uint32_t hash;
  459. uint32_t block;
  460. };
  461. struct ext4_dir_idx_root {
  462. struct ext4_dir_idx_dot_en dots[2];
  463. struct ext4_dir_idx_rinfo info;
  464. struct ext4_dir_idx_entry en[];
  465. };
  466. struct ext4_fake_dir_entry {
  467. uint32_t inode;
  468. uint16_t entry_length;
  469. uint8_t name_length;
  470. uint8_t inode_type;
  471. };
  472. struct ext4_dir_idx_node {
  473. struct ext4_fake_dir_entry fake;
  474. struct ext4_dir_idx_entry entries[];
  475. };
  476. /*
  477. * This goes at the end of each htree block.
  478. */
  479. struct ext4_dir_idx_tail {
  480. uint32_t reserved;
  481. uint32_t checksum; /* crc32c(uuid+inum+dirblock) */
  482. };
  483. /*
  484. * This is a bogus directory entry at the end of each leaf block that
  485. * records checksums.
  486. */
  487. struct ext4_dir_entry_tail {
  488. uint32_t reserved_zero1; /* Pretend to be unused */
  489. uint16_t rec_len; /* 12 */
  490. uint8_t reserved_zero2; /* Zero name length */
  491. uint8_t reserved_ft; /* 0xDE, fake file type */
  492. uint32_t checksum; /* crc32c(uuid+inum+dirblock) */
  493. };
  494. #pragma pack(pop)
  495. #define EXT4_DIRENT_TAIL(block, blocksize) \
  496. ((struct ext4_dir_entry_tail *)(((char *)(block)) + ((blocksize) - \
  497. sizeof(struct ext4_dir_entry_tail))))
  498. #define EXT4_ERR_BAD_DX_DIR (-25000)
  499. #define EXT4_LINK_MAX 65000
  500. #define EXT4_BAD_INO 1
  501. #define EXT4_ROOT_INO 2
  502. #define EXT4_BOOT_LOADER_INO 5
  503. #define EXT4_UNDEL_DIR_INO 6
  504. #define EXT4_RESIZE_INO 7
  505. #define EXT4_JOURNAL_INO 8
  506. #define EXT4_GOOD_OLD_FIRST_INO 11
  507. #define EXT4_EXT_UNWRITTEN_MASK (1L << 15)
  508. #define EXT4_EXT_MAX_LEN_WRITTEN (1L << 15)
  509. #define EXT4_EXT_MAX_LEN_UNWRITTEN \
  510. (EXT4_EXT_MAX_LEN_WRITTEN - 1)
  511. #define EXT4_EXT_GET_LEN(ex) to_le16((ex)->block_count)
  512. #define EXT4_EXT_GET_LEN_UNWRITTEN(ex) \
  513. (EXT4_EXT_GET_LEN(ex) &= ~(EXT4_EXT_UNWRITTEN_MASK))
  514. #define EXT4_EXT_SET_LEN(ex, count) \
  515. ((ex)->block_count = to_le16(count))
  516. #define EXT4_EXT_IS_UNWRITTEN(ex) \
  517. (EXT4_EXT_GET_LEN(ex) > EXT4_EXT_MAX_LEN_WRITTEN)
  518. #define EXT4_EXT_SET_UNWRITTEN(ex) \
  519. ((ex)->block_count |= to_le16(EXT4_EXT_UNWRITTEN_MASK))
  520. #define EXT4_EXT_SET_WRITTEN(ex) \
  521. ((ex)->block_count &= ~(to_le16(EXT4_EXT_UNWRITTEN_MASK)))
  522. #pragma pack(push, 1)
  523. /*
  524. * This is the extent tail on-disk structure.
  525. * All other extent structures are 12 bytes long. It turns out that
  526. * block_size % 12 >= 4 for at least all powers of 2 greater than 512, which
  527. * covers all valid ext4 block sizes. Therefore, this tail structure can be
  528. * crammed into the end of the block without having to rebalance the tree.
  529. */
  530. struct ext4_extent_tail
  531. {
  532. uint32_t et_checksum; /* crc32c(uuid+inum+extent_block) */
  533. };
  534. /*
  535. * This is the extent on-disk structure.
  536. * It's used at the bottom of the tree.
  537. */
  538. struct ext4_extent {
  539. uint32_t first_block; /* First logical block extent covers */
  540. uint16_t block_count; /* Number of blocks covered by extent */
  541. uint16_t start_hi; /* High 16 bits of physical block */
  542. uint32_t start_lo; /* Low 32 bits of physical block */
  543. };
  544. /*
  545. * This is index on-disk structure.
  546. * It's used at all the levels except the bottom.
  547. */
  548. struct ext4_extent_index {
  549. uint32_t first_block; /* Index covers logical blocks from 'block' */
  550. /**
  551. * Pointer to the physical block of the next
  552. * level. leaf or next index could be there
  553. * high 16 bits of physical block
  554. */
  555. uint32_t leaf_lo;
  556. uint16_t leaf_hi;
  557. uint16_t padding;
  558. };
  559. /*
  560. * Each block (leaves and indexes), even inode-stored has header.
  561. */
  562. struct ext4_extent_header {
  563. uint16_t magic;
  564. uint16_t entries_count; /* Number of valid entries */
  565. uint16_t max_entries_count; /* Capacity of store in entries */
  566. uint16_t depth; /* Has tree real underlying blocks? */
  567. uint32_t generation; /* generation of the tree */
  568. };
  569. #pragma pack(pop)
  570. #define EXT4_EXTENT_MAGIC 0xF30A
  571. #define EXT4_EXTENT_FIRST(header) \
  572. ((struct ext4_extent *)(((char *)(header)) + \
  573. sizeof(struct ext4_extent_header)))
  574. #define EXT4_EXTENT_FIRST_INDEX(header) \
  575. ((struct ext4_extent_index *)(((char *)(header)) + \
  576. sizeof(struct ext4_extent_header)))
  577. /*
  578. * EXT_INIT_MAX_LEN is the maximum number of blocks we can have in an
  579. * initialized extent. This is 2^15 and not (2^16 - 1), since we use the
  580. * MSB of ee_len field in the extent datastructure to signify if this
  581. * particular extent is an initialized extent or an uninitialized (i.e.
  582. * preallocated).
  583. * EXT_UNINIT_MAX_LEN is the maximum number of blocks we can have in an
  584. * uninitialized extent.
  585. * If ee_len is <= 0x8000, it is an initialized extent. Otherwise, it is an
  586. * uninitialized one. In other words, if MSB of ee_len is set, it is an
  587. * uninitialized extent with only one special scenario when ee_len = 0x8000.
  588. * In this case we can not have an uninitialized extent of zero length and
  589. * thus we make it as a special case of initialized extent with 0x8000 length.
  590. * This way we get better extent-to-group alignment for initialized extents.
  591. * Hence, the maximum number of blocks we can have in an *initialized*
  592. * extent is 2^15 (32768) and in an *uninitialized* extent is 2^15-1 (32767).
  593. */
  594. #define EXT_INIT_MAX_LEN (1L << 15)
  595. #define EXT_UNWRITTEN_MAX_LEN (EXT_INIT_MAX_LEN - 1)
  596. #define EXT_EXTENT_SIZE sizeof(struct ext4_extent)
  597. #define EXT_INDEX_SIZE sizeof(struct ext4_extent_idx)
  598. #define EXT_FIRST_EXTENT(__hdr__) \
  599. ((struct ext4_extent *)(((char *)(__hdr__)) + \
  600. sizeof(struct ext4_extent_header)))
  601. #define EXT_FIRST_INDEX(__hdr__) \
  602. ((struct ext4_extent_index *)(((char *)(__hdr__)) + \
  603. sizeof(struct ext4_extent_header)))
  604. #define EXT_HAS_FREE_INDEX(__path__) \
  605. ((__path__)->header->entries_count < (__path__)->header->max_entries_count)
  606. #define EXT_LAST_EXTENT(__hdr__) \
  607. (EXT_FIRST_EXTENT((__hdr__)) + (__hdr__)->entries_count - 1)
  608. #define EXT_LAST_INDEX(__hdr__) \
  609. (EXT_FIRST_INDEX((__hdr__)) + (__hdr__)->entries_count - 1)
  610. #define EXT_MAX_EXTENT(__hdr__) \
  611. (EXT_FIRST_EXTENT((__hdr__)) + (__hdr__)->max_entries_count - 1)
  612. #define EXT_MAX_INDEX(__hdr__) \
  613. (EXT_FIRST_INDEX((__hdr__)) + (__hdr__)->max_entries_count - 1)
  614. #define EXT4_EXTENT_TAIL_OFFSET(hdr) \
  615. (sizeof(struct ext4_extent_header) + \
  616. (sizeof(struct ext4_extent) * (hdr)->max_entries_count))
  617. /*
  618. * ext4_ext_next_allocated_block:
  619. * returns allocated block in subsequent extent or EXT_MAX_BLOCKS.
  620. * NOTE: it considers block number from index entry as
  621. * allocated block. Thus, index entries have to be consistent
  622. * with leaves.
  623. */
  624. #define EXT_MAX_BLOCKS (ext4_lblk_t) (-1)
  625. #define IN_RANGE(b, first, len) ((b) >= (first) && (b) <= (first) + (len) - 1)
  626. /******************************************************************************/
  627. /* EXT3 HTree directory indexing */
  628. #define EXT2_HTREE_LEGACY 0
  629. #define EXT2_HTREE_HALF_MD4 1
  630. #define EXT2_HTREE_TEA 2
  631. #define EXT2_HTREE_LEGACY_UNSIGNED 3
  632. #define EXT2_HTREE_HALF_MD4_UNSIGNED 4
  633. #define EXT2_HTREE_TEA_UNSIGNED 5
  634. #define EXT2_HTREE_EOF 0x7FFFFFFFUL
  635. /* Extended Attribute(EA) */
  636. /* Magic value in attribute blocks */
  637. #define EXT4_XATTR_MAGIC 0xEA020000
  638. /* Maximum number of references to one attribute block */
  639. #define EXT4_XATTR_REFCOUNT_MAX 1024
  640. /* Name indexes */
  641. #define EXT4_XATTR_INDEX_USER 1
  642. #define EXT4_XATTR_INDEX_POSIX_ACL_ACCESS 2
  643. #define EXT4_XATTR_INDEX_POSIX_ACL_DEFAULT 3
  644. #define EXT4_XATTR_INDEX_TRUSTED 4
  645. #define EXT4_XATTR_INDEX_LUSTRE 5
  646. #define EXT4_XATTR_INDEX_SECURITY 6
  647. #define EXT4_XATTR_INDEX_SYSTEM 7
  648. #define EXT4_XATTR_INDEX_RICHACL 8
  649. #define EXT4_XATTR_INDEX_ENCRYPTION 9
  650. #pragma pack(push, 1)
  651. struct ext4_xattr_header {
  652. uint32_t h_magic; /* magic number for identification */
  653. uint32_t h_refcount; /* reference count */
  654. uint32_t h_blocks; /* number of disk blocks used */
  655. uint32_t h_hash; /* hash value of all attributes */
  656. uint32_t h_checksum; /* crc32c(uuid+id+xattrblock) */
  657. /* id = inum if refcount=1, blknum otherwise */
  658. uint32_t h_reserved[3]; /* zero right now */
  659. };
  660. struct ext4_xattr_ibody_header {
  661. uint32_t h_magic; /* magic number for identification */
  662. };
  663. struct ext4_xattr_entry {
  664. uint8_t e_name_len; /* length of name */
  665. uint8_t e_name_index; /* attribute name index */
  666. uint16_t e_value_offs; /* offset in disk block of value */
  667. uint32_t e_value_block; /* disk block attribute is stored on (n/i) */
  668. uint32_t e_value_size; /* size of attribute value */
  669. uint32_t e_hash; /* hash value of name and value */
  670. };
  671. #pragma pack(pop)
  672. #define EXT4_GOOD_OLD_INODE_SIZE 128
  673. #define EXT4_XATTR_PAD_BITS 2
  674. #define EXT4_XATTR_PAD (1<<EXT4_XATTR_PAD_BITS)
  675. #define EXT4_XATTR_ROUND (EXT4_XATTR_PAD-1)
  676. #define EXT4_XATTR_LEN(name_len) \
  677. (((name_len) + EXT4_XATTR_ROUND + \
  678. sizeof(struct ext4_xattr_entry)) & ~EXT4_XATTR_ROUND)
  679. #define EXT4_XATTR_NEXT(entry) \
  680. ((struct ext4_xattr_entry *)( \
  681. (char *)(entry) + EXT4_XATTR_LEN((entry)->e_name_len)))
  682. #define EXT4_XATTR_SIZE(size) \
  683. (((size) + EXT4_XATTR_ROUND) & ~EXT4_XATTR_ROUND)
  684. #define EXT4_XATTR_NAME(entry) \
  685. ((char *)((entry) + 1))
  686. #define EXT4_XATTR_IHDR(raw_inode) \
  687. ((struct ext4_xattr_ibody_header *) \
  688. ((char *)raw_inode + \
  689. EXT4_GOOD_OLD_INODE_SIZE + \
  690. (raw_inode)->extra_isize))
  691. #define EXT4_XATTR_IFIRST(hdr) \
  692. ((struct ext4_xattr_entry *)((hdr)+1))
  693. #define EXT4_XATTR_BHDR(block) \
  694. ((struct ext4_xattr_header *)((block)->data))
  695. #define EXT4_XATTR_ENTRY(ptr) \
  696. ((struct ext4_xattr_entry *)(ptr))
  697. #define EXT4_XATTR_BFIRST(block) \
  698. EXT4_XATTR_ENTRY(EXT4_XATTR_BHDR(block)+1)
  699. #define EXT4_XATTR_IS_LAST_ENTRY(entry) \
  700. (*(uint32_t *)(entry) == 0)
  701. #define EXT4_ZERO_XATTR_VALUE ((void *)-1)
  702. /*****************************************************************************/
  703. /*
  704. * JBD stores integers in big endian.
  705. */
  706. #define JBD_MAGIC_NUMBER 0xc03b3998U /* The first 4 bytes of /dev/random! */
  707. /*
  708. * Descriptor block types:
  709. */
  710. #define JBD_DESCRIPTOR_BLOCK 1
  711. #define JBD_COMMIT_BLOCK 2
  712. #define JBD_SUPERBLOCK 3
  713. #define JBD_SUPERBLOCK_V2 4
  714. #define JBD_REVOKE_BLOCK 5
  715. #pragma pack(push, 1)
  716. /*
  717. * Standard header for all descriptor blocks:
  718. */
  719. struct jbd_bhdr {
  720. uint32_t magic;
  721. uint32_t blocktype;
  722. uint32_t sequence;
  723. };
  724. #pragma pack(pop)
  725. /*
  726. * Checksum types.
  727. */
  728. #define JBD_CRC32_CHKSUM 1
  729. #define JBD_MD5_CHKSUM 2
  730. #define JBD_SHA1_CHKSUM 3
  731. #define JBD_CRC32C_CHKSUM 4
  732. #define JBD_CRC32_CHKSUM_SIZE 4
  733. #define JBD_CHECKSUM_BYTES (32 / sizeof(uint32_t))
  734. #pragma pack(push, 1)
  735. /*
  736. * Commit block header for storing transactional checksums:
  737. *
  738. * NOTE: If FEATURE_COMPAT_CHECKSUM (checksum v1) is set, the h_chksum*
  739. * fields are used to store a checksum of the descriptor and data blocks.
  740. *
  741. * If FEATURE_INCOMPAT_CSUM_V2 (checksum v2) is set, then the h_chksum
  742. * field is used to store crc32c(uuid+commit_block). Each journal metadata
  743. * block gets its own checksum, and data block checksums are stored in
  744. * journal_block_tag (in the descriptor). The other h_chksum* fields are
  745. * not used.
  746. *
  747. * If FEATURE_INCOMPAT_CSUM_V3 is set, the descriptor block uses
  748. * journal_block_tag3_t to store a full 32-bit checksum. Everything else
  749. * is the same as v2.
  750. *
  751. * Checksum v1, v2, and v3 are mutually exclusive features.
  752. */
  753. struct jbd_commit_header {
  754. struct jbd_bhdr header;
  755. uint8_t chksum_type;
  756. uint8_t chksum_size;
  757. uint8_t padding[2];
  758. uint32_t chksum[JBD_CHECKSUM_BYTES];
  759. uint64_t commit_sec;
  760. uint32_t commit_nsec;
  761. };
  762. /*
  763. * The block tag: used to describe a single buffer in the journal
  764. */
  765. struct jbd_block_tag3 {
  766. uint32_t blocknr; /* The on-disk block number */
  767. uint32_t flags; /* See below */
  768. uint32_t blocknr_high; /* most-significant high 32bits. */
  769. uint32_t checksum; /* crc32c(uuid+seq+block) */
  770. };
  771. struct jbd_block_tag {
  772. uint32_t blocknr; /* The on-disk block number */
  773. uint16_t checksum; /* truncated crc32c(uuid+seq+block) */
  774. uint16_t flags; /* See below */
  775. uint32_t blocknr_high; /* most-significant high 32bits. */
  776. };
  777. #pragma pack(pop)
  778. /* Definitions for the journal tag flags word: */
  779. #define JBD_FLAG_ESCAPE 1 /* on-disk block is escaped */
  780. #define JBD_FLAG_SAME_UUID 2 /* block has same uuid as previous */
  781. #define JBD_FLAG_DELETED 4 /* block deleted by this transaction */
  782. #define JBD_FLAG_LAST_TAG 8 /* last tag in this descriptor block */
  783. #pragma pack(push, 1)
  784. /* Tail of descriptor block, for checksumming */
  785. struct jbd_block_tail {
  786. uint32_t checksum;
  787. };
  788. /*
  789. * The revoke descriptor: used on disk to describe a series of blocks to
  790. * be revoked from the log
  791. */
  792. struct jbd_revoke_header {
  793. struct jbd_bhdr header;
  794. uint32_t count; /* Count of bytes used in the block */
  795. };
  796. /* Tail of revoke block, for checksumming */
  797. struct jbd_revoke_tail {
  798. uint32_t checksum;
  799. };
  800. #pragma pack(pop)
  801. #define JBD_USERS_MAX 48
  802. #define JBD_USERS_SIZE (UUID_SIZE * JBD_USERS_MAX)
  803. #pragma pack(push, 1)
  804. /*
  805. * The journal superblock. All fields are in big-endian byte order.
  806. */
  807. struct jbd_sb {
  808. /* 0x0000 */
  809. struct jbd_bhdr header;
  810. /* 0x000C */
  811. /* Static information describing the journal */
  812. uint32_t blocksize; /* journal device blocksize */
  813. uint32_t maxlen; /* total blocks in journal file */
  814. uint32_t first; /* first block of log information */
  815. /* 0x0018 */
  816. /* Dynamic information describing the current state of the log */
  817. uint32_t sequence; /* first commit ID expected in log */
  818. uint32_t start; /* blocknr of start of log */
  819. /* 0x0020 */
  820. /* Error value, as set by journal_abort(). */
  821. int32_t error_val;
  822. /* 0x0024 */
  823. /* Remaining fields are only valid in a version-2 superblock */
  824. uint32_t feature_compat; /* compatible feature set */
  825. uint32_t feature_incompat; /* incompatible feature set */
  826. uint32_t feature_ro_compat; /* readonly-compatible feature set */
  827. /* 0x0030 */
  828. uint8_t uuid[UUID_SIZE]; /* 128-bit uuid for journal */
  829. /* 0x0040 */
  830. uint32_t nr_users; /* Nr of filesystems sharing log */
  831. uint32_t dynsuper; /* Blocknr of dynamic superblock copy*/
  832. /* 0x0048 */
  833. uint32_t max_transaction; /* Limit of journal blocks per trans.*/
  834. uint32_t max_trandata; /* Limit of data blocks per trans. */
  835. /* 0x0050 */
  836. uint8_t checksum_type; /* checksum type */
  837. uint8_t padding2[3];
  838. uint32_t padding[42];
  839. uint32_t checksum; /* crc32c(superblock) */
  840. /* 0x0100 */
  841. uint8_t users[JBD_USERS_SIZE]; /* ids of all fs'es sharing the log */
  842. /* 0x0400 */
  843. };
  844. #pragma pack(pop)
  845. #define JBD_SUPERBLOCK_SIZE sizeof(struct jbd_sb)
  846. #define JBD_HAS_COMPAT_FEATURE(jsb,mask) \
  847. ((jsb)->header.blocktype >= to_be32(2) && \
  848. ((jsb)->feature_compat & to_be32((mask))))
  849. #define JBD_HAS_RO_COMPAT_FEATURE(jsb,mask) \
  850. ((jsb)->header.blocktype >= to_be32(2) && \
  851. ((jsb)->feature_ro_compat & to_be32((mask))))
  852. #define JBD_HAS_INCOMPAT_FEATURE(jsb,mask) \
  853. ((jsb)->header.blocktype >= to_be32(2) && \
  854. ((jsb)->feature_incompat & to_be32((mask))))
  855. #define JBD_FEATURE_COMPAT_CHECKSUM 0x00000001
  856. #define JBD_FEATURE_INCOMPAT_REVOKE 0x00000001
  857. #define JBD_FEATURE_INCOMPAT_64BIT 0x00000002
  858. #define JBD_FEATURE_INCOMPAT_ASYNC_COMMIT 0x00000004
  859. #define JBD_FEATURE_INCOMPAT_CSUM_V2 0x00000008
  860. #define JBD_FEATURE_INCOMPAT_CSUM_V3 0x00000010
  861. /* Features known to this kernel version: */
  862. #define JBD_KNOWN_COMPAT_FEATURES 0
  863. #define JBD_KNOWN_ROCOMPAT_FEATURES 0
  864. #define JBD_KNOWN_INCOMPAT_FEATURES (JBD_FEATURE_INCOMPAT_REVOKE|\
  865. JBD_FEATURE_INCOMPAT_ASYNC_COMMIT|\
  866. JBD_FEATURE_INCOMPAT_64BIT|\
  867. JBD_FEATURE_INCOMPAT_CSUM_V2|\
  868. JBD_FEATURE_INCOMPAT_CSUM_V3)
  869. /*****************************************************************************/
  870. #define EXT4_CRC32_INIT (0xFFFFFFFFUL)
  871. /*****************************************************************************/
  872. #ifdef __cplusplus
  873. }
  874. #endif
  875. #endif /* EXT4_TYPES_H_ */
  876. /**
  877. * @}
  878. */