ocfs2_fs.h 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /* -*- mode: c; c-basic-offset: 8; -*-
  3. * vim: noexpandtab sw=8 ts=8 sts=0:
  4. *
  5. * ocfs2_fs.h
  6. *
  7. * On-disk structures for OCFS2.
  8. *
  9. * Copyright (C) 2002, 2004 Oracle. All rights reserved.
  10. */
  11. #ifndef _OCFS2_FS_H
  12. #define _OCFS2_FS_H
  13. #include <linux/magic.h>
  14. /* Version */
  15. #define OCFS2_MAJOR_REV_LEVEL 0
  16. #define OCFS2_MINOR_REV_LEVEL 90
  17. /*
  18. * An OCFS2 volume starts this way:
  19. * Sector 0: Valid ocfs1_vol_disk_hdr that cleanly fails to mount OCFS.
  20. * Sector 1: Valid ocfs1_vol_label that cleanly fails to mount OCFS.
  21. * Block OCFS2_SUPER_BLOCK_BLKNO: OCFS2 superblock.
  22. *
  23. * All other structures are found from the superblock information.
  24. *
  25. * OCFS2_SUPER_BLOCK_BLKNO is in blocks, not sectors. eg, for a
  26. * blocksize of 2K, it is 4096 bytes into disk.
  27. */
  28. #define OCFS2_SUPER_BLOCK_BLKNO 2
  29. /*
  30. * Cluster size limits. The maximum is kept arbitrarily at 1 MB, and could
  31. * grow if needed.
  32. */
  33. #define OCFS2_MIN_CLUSTERSIZE 4096
  34. #define OCFS2_MAX_CLUSTERSIZE 1048576
  35. /*
  36. * Blocks cannot be bigger than clusters, so the maximum blocksize is the
  37. * minimum cluster size.
  38. */
  39. #define OCFS2_MIN_BLOCKSIZE 512
  40. #define OCFS2_MAX_BLOCKSIZE OCFS2_MIN_CLUSTERSIZE
  41. /* Object signatures */
  42. #define OCFS2_SUPER_BLOCK_SIGNATURE "OCFSV2"
  43. #define OCFS2_INODE_SIGNATURE "INODE01"
  44. #define OCFS2_EXTENT_BLOCK_SIGNATURE "EXBLK01"
  45. #define OCFS2_GROUP_DESC_SIGNATURE "GROUP01"
  46. #define OCFS2_XATTR_BLOCK_SIGNATURE "XATTR01"
  47. #define OCFS2_DIR_TRAILER_SIGNATURE "DIRTRL1"
  48. #define OCFS2_DX_ROOT_SIGNATURE "DXDIR01"
  49. #define OCFS2_DX_LEAF_SIGNATURE "DXLEAF1"
  50. #define OCFS2_REFCOUNT_BLOCK_SIGNATURE "REFCNT1"
  51. /* Compatibility flags */
  52. #define OCFS2_HAS_COMPAT_FEATURE(sb,mask) \
  53. ( OCFS2_SB(sb)->s_feature_compat & (mask) )
  54. #define OCFS2_HAS_RO_COMPAT_FEATURE(sb,mask) \
  55. ( OCFS2_SB(sb)->s_feature_ro_compat & (mask) )
  56. #define OCFS2_HAS_INCOMPAT_FEATURE(sb,mask) \
  57. ( OCFS2_SB(sb)->s_feature_incompat & (mask) )
  58. #define OCFS2_SET_COMPAT_FEATURE(sb,mask) \
  59. OCFS2_SB(sb)->s_feature_compat |= (mask)
  60. #define OCFS2_SET_RO_COMPAT_FEATURE(sb,mask) \
  61. OCFS2_SB(sb)->s_feature_ro_compat |= (mask)
  62. #define OCFS2_SET_INCOMPAT_FEATURE(sb,mask) \
  63. OCFS2_SB(sb)->s_feature_incompat |= (mask)
  64. #define OCFS2_CLEAR_COMPAT_FEATURE(sb,mask) \
  65. OCFS2_SB(sb)->s_feature_compat &= ~(mask)
  66. #define OCFS2_CLEAR_RO_COMPAT_FEATURE(sb,mask) \
  67. OCFS2_SB(sb)->s_feature_ro_compat &= ~(mask)
  68. #define OCFS2_CLEAR_INCOMPAT_FEATURE(sb,mask) \
  69. OCFS2_SB(sb)->s_feature_incompat &= ~(mask)
  70. #define OCFS2_FEATURE_COMPAT_SUPP (OCFS2_FEATURE_COMPAT_BACKUP_SB \
  71. | OCFS2_FEATURE_COMPAT_JBD2_SB)
  72. #define OCFS2_FEATURE_INCOMPAT_SUPP (OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT \
  73. | OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC \
  74. | OCFS2_FEATURE_INCOMPAT_INLINE_DATA \
  75. | OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP \
  76. | OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK \
  77. | OCFS2_FEATURE_INCOMPAT_XATTR \
  78. | OCFS2_FEATURE_INCOMPAT_META_ECC \
  79. | OCFS2_FEATURE_INCOMPAT_INDEXED_DIRS \
  80. | OCFS2_FEATURE_INCOMPAT_REFCOUNT_TREE \
  81. | OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG \
  82. | OCFS2_FEATURE_INCOMPAT_CLUSTERINFO \
  83. | OCFS2_FEATURE_INCOMPAT_APPEND_DIO)
  84. #define OCFS2_FEATURE_RO_COMPAT_SUPP (OCFS2_FEATURE_RO_COMPAT_UNWRITTEN \
  85. | OCFS2_FEATURE_RO_COMPAT_USRQUOTA \
  86. | OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)
  87. /*
  88. * Heartbeat-only devices are missing journals and other files. The
  89. * filesystem driver can't load them, but the library can. Never put
  90. * this in OCFS2_FEATURE_INCOMPAT_SUPP, *ever*.
  91. */
  92. #define OCFS2_FEATURE_INCOMPAT_HEARTBEAT_DEV 0x0002
  93. /*
  94. * tunefs sets this incompat flag before starting the resize and clears it
  95. * at the end. This flag protects users from inadvertently mounting the fs
  96. * after an aborted run without fsck-ing.
  97. */
  98. #define OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG 0x0004
  99. /* Used to denote a non-clustered volume */
  100. #define OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT 0x0008
  101. /* Support for sparse allocation in b-trees */
  102. #define OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC 0x0010
  103. /*
  104. * Tunefs sets this incompat flag before starting an operation which
  105. * would require cleanup on abort. This is done to protect users from
  106. * inadvertently mounting the fs after an aborted run without
  107. * fsck-ing.
  108. *
  109. * s_tunefs_flags on the super block describes precisely which
  110. * operations were in progress.
  111. */
  112. #define OCFS2_FEATURE_INCOMPAT_TUNEFS_INPROG 0x0020
  113. /* Support for data packed into inode blocks */
  114. #define OCFS2_FEATURE_INCOMPAT_INLINE_DATA 0x0040
  115. /*
  116. * Support for alternate, userspace cluster stacks. If set, the superblock
  117. * field s_cluster_info contains a tag for the alternate stack in use as
  118. * well as the name of the cluster being joined.
  119. * mount.ocfs2 must pass in a matching stack name.
  120. *
  121. * If not set, the classic stack will be used. This is compatbile with
  122. * all older versions.
  123. */
  124. #define OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK 0x0080
  125. /* Support for the extended slot map */
  126. #define OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP 0x100
  127. /* Support for extended attributes */
  128. #define OCFS2_FEATURE_INCOMPAT_XATTR 0x0200
  129. /* Support for indexed directores */
  130. #define OCFS2_FEATURE_INCOMPAT_INDEXED_DIRS 0x0400
  131. /* Metadata checksum and error correction */
  132. #define OCFS2_FEATURE_INCOMPAT_META_ECC 0x0800
  133. /* Refcount tree support */
  134. #define OCFS2_FEATURE_INCOMPAT_REFCOUNT_TREE 0x1000
  135. /* Discontiguous block groups */
  136. #define OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG 0x2000
  137. /*
  138. * Incompat bit to indicate useable clusterinfo with stackflags for all
  139. * cluster stacks (userspace adnd o2cb). If this bit is set,
  140. * INCOMPAT_USERSPACE_STACK becomes superfluous and thus should not be set.
  141. */
  142. #define OCFS2_FEATURE_INCOMPAT_CLUSTERINFO 0x4000
  143. /*
  144. * Append Direct IO support
  145. */
  146. #define OCFS2_FEATURE_INCOMPAT_APPEND_DIO 0x8000
  147. /*
  148. * backup superblock flag is used to indicate that this volume
  149. * has backup superblocks.
  150. */
  151. #define OCFS2_FEATURE_COMPAT_BACKUP_SB 0x0001
  152. /*
  153. * The filesystem will correctly handle journal feature bits.
  154. */
  155. #define OCFS2_FEATURE_COMPAT_JBD2_SB 0x0002
  156. /*
  157. * Unwritten extents support.
  158. */
  159. #define OCFS2_FEATURE_RO_COMPAT_UNWRITTEN 0x0001
  160. /*
  161. * Maintain quota information for this filesystem
  162. */
  163. #define OCFS2_FEATURE_RO_COMPAT_USRQUOTA 0x0002
  164. #define OCFS2_FEATURE_RO_COMPAT_GRPQUOTA 0x0004
  165. /* The byte offset of the first backup block will be 1G.
  166. * The following will be 4G, 16G, 64G, 256G and 1T.
  167. */
  168. #define OCFS2_BACKUP_SB_START 1 << 30
  169. /* the max backup superblock nums */
  170. #define OCFS2_MAX_BACKUP_SUPERBLOCKS 6
  171. /*
  172. * Flags on ocfs2_super_block.s_tunefs_flags
  173. */
  174. #define OCFS2_TUNEFS_INPROG_REMOVE_SLOT 0x0001 /* Removing slots */
  175. /*
  176. * Flags on ocfs2_dinode.i_flags
  177. */
  178. #define OCFS2_VALID_FL (0x00000001) /* Inode is valid */
  179. #define OCFS2_UNUSED2_FL (0x00000002)
  180. #define OCFS2_ORPHANED_FL (0x00000004) /* On the orphan list */
  181. #define OCFS2_UNUSED3_FL (0x00000008)
  182. /* System inode flags */
  183. #define OCFS2_SYSTEM_FL (0x00000010) /* System inode */
  184. #define OCFS2_SUPER_BLOCK_FL (0x00000020) /* Super block */
  185. #define OCFS2_LOCAL_ALLOC_FL (0x00000040) /* Slot local alloc bitmap */
  186. #define OCFS2_BITMAP_FL (0x00000080) /* Allocation bitmap */
  187. #define OCFS2_JOURNAL_FL (0x00000100) /* Slot local journal */
  188. #define OCFS2_HEARTBEAT_FL (0x00000200) /* Heartbeat area */
  189. #define OCFS2_CHAIN_FL (0x00000400) /* Chain allocator */
  190. #define OCFS2_DEALLOC_FL (0x00000800) /* Truncate log */
  191. #define OCFS2_QUOTA_FL (0x00001000) /* Quota file */
  192. #define OCFS2_DIO_ORPHANED_FL (0X00002000) /* On the orphan list especially
  193. * for dio */
  194. /*
  195. * Flags on ocfs2_dinode.i_dyn_features
  196. *
  197. * These can change much more often than i_flags. When adding flags,
  198. * keep in mind that i_dyn_features is only 16 bits wide.
  199. */
  200. #define OCFS2_INLINE_DATA_FL (0x0001) /* Data stored in inode block */
  201. #define OCFS2_HAS_XATTR_FL (0x0002)
  202. #define OCFS2_INLINE_XATTR_FL (0x0004)
  203. #define OCFS2_INDEXED_DIR_FL (0x0008)
  204. #define OCFS2_HAS_REFCOUNT_FL (0x0010)
  205. /* Inode attributes, keep in sync with EXT2 */
  206. #define OCFS2_SECRM_FL FS_SECRM_FL /* Secure deletion */
  207. #define OCFS2_UNRM_FL FS_UNRM_FL /* Undelete */
  208. #define OCFS2_COMPR_FL FS_COMPR_FL /* Compress file */
  209. #define OCFS2_SYNC_FL FS_SYNC_FL /* Synchronous updates */
  210. #define OCFS2_IMMUTABLE_FL FS_IMMUTABLE_FL /* Immutable file */
  211. #define OCFS2_APPEND_FL FS_APPEND_FL /* writes to file may only append */
  212. #define OCFS2_NODUMP_FL FS_NODUMP_FL /* do not dump file */
  213. #define OCFS2_NOATIME_FL FS_NOATIME_FL /* do not update atime */
  214. /* Reserved for compression usage... */
  215. #define OCFS2_DIRTY_FL FS_DIRTY_FL
  216. #define OCFS2_COMPRBLK_FL FS_COMPRBLK_FL /* One or more compressed clusters */
  217. #define OCFS2_NOCOMP_FL FS_NOCOMP_FL /* Don't compress */
  218. #define OCFS2_ECOMPR_FL FS_ECOMPR_FL /* Compression error */
  219. /* End compression flags --- maybe not all used */
  220. #define OCFS2_BTREE_FL FS_BTREE_FL /* btree format dir */
  221. #define OCFS2_INDEX_FL FS_INDEX_FL /* hash-indexed directory */
  222. #define OCFS2_IMAGIC_FL FS_IMAGIC_FL /* AFS directory */
  223. #define OCFS2_JOURNAL_DATA_FL FS_JOURNAL_DATA_FL /* Reserved for ext3 */
  224. #define OCFS2_NOTAIL_FL FS_NOTAIL_FL /* file tail should not be merged */
  225. #define OCFS2_DIRSYNC_FL FS_DIRSYNC_FL /* dirsync behaviour (directories only) */
  226. #define OCFS2_TOPDIR_FL FS_TOPDIR_FL /* Top of directory hierarchies*/
  227. #define OCFS2_RESERVED_FL FS_RESERVED_FL /* reserved for ext2 lib */
  228. #define OCFS2_FL_VISIBLE FS_FL_USER_VISIBLE /* User visible flags */
  229. #define OCFS2_FL_MODIFIABLE FS_FL_USER_MODIFIABLE /* User modifiable flags */
  230. /*
  231. * Extent record flags (e_node.leaf.flags)
  232. */
  233. #define OCFS2_EXT_UNWRITTEN (0x01) /* Extent is allocated but
  234. * unwritten */
  235. #define OCFS2_EXT_REFCOUNTED (0x02) /* Extent is reference
  236. * counted in an associated
  237. * refcount tree */
  238. /*
  239. * Journal Flags (ocfs2_dinode.id1.journal1.i_flags)
  240. */
  241. #define OCFS2_JOURNAL_DIRTY_FL (0x00000001) /* Journal needs recovery */
  242. /*
  243. * superblock s_state flags
  244. */
  245. #define OCFS2_ERROR_FS (0x00000001) /* FS saw errors */
  246. /* Limit of space in ocfs2_dir_entry */
  247. #define OCFS2_MAX_FILENAME_LEN 255
  248. /* Maximum slots on an ocfs2 file system */
  249. #define OCFS2_MAX_SLOTS 255
  250. /* Slot map indicator for an empty slot */
  251. #define OCFS2_INVALID_SLOT ((u16)-1)
  252. #define OCFS2_VOL_UUID_LEN 16
  253. #define OCFS2_MAX_VOL_LABEL_LEN 64
  254. /* The cluster stack fields */
  255. #define OCFS2_STACK_LABEL_LEN 4
  256. #define OCFS2_CLUSTER_NAME_LEN 16
  257. /* Classic (historically speaking) cluster stack */
  258. #define OCFS2_CLASSIC_CLUSTER_STACK "o2cb"
  259. /* Journal limits (in bytes) */
  260. #define OCFS2_MIN_JOURNAL_SIZE (4 * 1024 * 1024)
  261. /*
  262. * Inline extended attribute size (in bytes)
  263. * The value chosen should be aligned to 16 byte boundaries.
  264. */
  265. #define OCFS2_MIN_XATTR_INLINE_SIZE 256
  266. /*
  267. * Cluster info flags (ocfs2_cluster_info.ci_stackflags)
  268. */
  269. #define OCFS2_CLUSTER_O2CB_GLOBAL_HEARTBEAT (0x01)
  270. struct ocfs2_system_inode_info {
  271. char *si_name;
  272. int si_iflags;
  273. int si_mode;
  274. };
  275. /* System file index */
  276. enum {
  277. BAD_BLOCK_SYSTEM_INODE = 0,
  278. GLOBAL_INODE_ALLOC_SYSTEM_INODE,
  279. #define OCFS2_FIRST_ONLINE_SYSTEM_INODE GLOBAL_INODE_ALLOC_SYSTEM_INODE
  280. SLOT_MAP_SYSTEM_INODE,
  281. HEARTBEAT_SYSTEM_INODE,
  282. GLOBAL_BITMAP_SYSTEM_INODE,
  283. USER_QUOTA_SYSTEM_INODE,
  284. GROUP_QUOTA_SYSTEM_INODE,
  285. #define OCFS2_LAST_GLOBAL_SYSTEM_INODE GROUP_QUOTA_SYSTEM_INODE
  286. #define OCFS2_FIRST_LOCAL_SYSTEM_INODE ORPHAN_DIR_SYSTEM_INODE
  287. ORPHAN_DIR_SYSTEM_INODE,
  288. EXTENT_ALLOC_SYSTEM_INODE,
  289. INODE_ALLOC_SYSTEM_INODE,
  290. JOURNAL_SYSTEM_INODE,
  291. LOCAL_ALLOC_SYSTEM_INODE,
  292. TRUNCATE_LOG_SYSTEM_INODE,
  293. LOCAL_USER_QUOTA_SYSTEM_INODE,
  294. LOCAL_GROUP_QUOTA_SYSTEM_INODE,
  295. #define OCFS2_LAST_LOCAL_SYSTEM_INODE LOCAL_GROUP_QUOTA_SYSTEM_INODE
  296. NUM_SYSTEM_INODES
  297. };
  298. #define NUM_GLOBAL_SYSTEM_INODES OCFS2_FIRST_LOCAL_SYSTEM_INODE
  299. #define NUM_LOCAL_SYSTEM_INODES \
  300. (NUM_SYSTEM_INODES - OCFS2_FIRST_LOCAL_SYSTEM_INODE)
  301. static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = {
  302. /* Global system inodes (single copy) */
  303. /* The first two are only used from userspace mfks/tunefs */
  304. [BAD_BLOCK_SYSTEM_INODE] = { "bad_blocks", 0, S_IFREG | 0644 },
  305. [GLOBAL_INODE_ALLOC_SYSTEM_INODE] = { "global_inode_alloc", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
  306. /* These are used by the running filesystem */
  307. [SLOT_MAP_SYSTEM_INODE] = { "slot_map", 0, S_IFREG | 0644 },
  308. [HEARTBEAT_SYSTEM_INODE] = { "heartbeat", OCFS2_HEARTBEAT_FL, S_IFREG | 0644 },
  309. [GLOBAL_BITMAP_SYSTEM_INODE] = { "global_bitmap", 0, S_IFREG | 0644 },
  310. [USER_QUOTA_SYSTEM_INODE] = { "aquota.user", OCFS2_QUOTA_FL, S_IFREG | 0644 },
  311. [GROUP_QUOTA_SYSTEM_INODE] = { "aquota.group", OCFS2_QUOTA_FL, S_IFREG | 0644 },
  312. /* Slot-specific system inodes (one copy per slot) */
  313. [ORPHAN_DIR_SYSTEM_INODE] = { "orphan_dir:%04d", 0, S_IFDIR | 0755 },
  314. [EXTENT_ALLOC_SYSTEM_INODE] = { "extent_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
  315. [INODE_ALLOC_SYSTEM_INODE] = { "inode_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
  316. [JOURNAL_SYSTEM_INODE] = { "journal:%04d", OCFS2_JOURNAL_FL, S_IFREG | 0644 },
  317. [LOCAL_ALLOC_SYSTEM_INODE] = { "local_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_LOCAL_ALLOC_FL, S_IFREG | 0644 },
  318. [TRUNCATE_LOG_SYSTEM_INODE] = { "truncate_log:%04d", OCFS2_DEALLOC_FL, S_IFREG | 0644 },
  319. [LOCAL_USER_QUOTA_SYSTEM_INODE] = { "aquota.user:%04d", OCFS2_QUOTA_FL, S_IFREG | 0644 },
  320. [LOCAL_GROUP_QUOTA_SYSTEM_INODE] = { "aquota.group:%04d", OCFS2_QUOTA_FL, S_IFREG | 0644 },
  321. };
  322. /* Parameter passed from mount.ocfs2 to module */
  323. #define OCFS2_HB_NONE "heartbeat=none"
  324. #define OCFS2_HB_LOCAL "heartbeat=local"
  325. #define OCFS2_HB_GLOBAL "heartbeat=global"
  326. /*
  327. * OCFS2_DIR_PAD defines the directory entries boundaries
  328. *
  329. * NOTE: It must be a multiple of 4
  330. */
  331. #define OCFS2_DIR_PAD 4
  332. #define OCFS2_DIR_ROUND (OCFS2_DIR_PAD - 1)
  333. #define OCFS2_DIR_MEMBER_LEN offsetof(struct ocfs2_dir_entry, name)
  334. #define OCFS2_DIR_REC_LEN(name_len) (((name_len) + OCFS2_DIR_MEMBER_LEN + \
  335. OCFS2_DIR_ROUND) & \
  336. ~OCFS2_DIR_ROUND)
  337. #define OCFS2_DIR_MIN_REC_LEN OCFS2_DIR_REC_LEN(1)
  338. #define OCFS2_LINK_MAX 32000
  339. #define OCFS2_DX_LINK_MAX ((1U << 31) - 1U)
  340. #define OCFS2_LINKS_HI_SHIFT 16
  341. #define OCFS2_DX_ENTRIES_MAX (0xffffffffU)
  342. /*
  343. * Convenience casts
  344. */
  345. #define OCFS2_RAW_SB(dinode) (&((dinode)->id2.i_super))
  346. /*
  347. * Block checking structure. This is used in metadata to validate the
  348. * contents. If OCFS2_FEATURE_INCOMPAT_META_ECC is not set, it is all
  349. * zeros.
  350. */
  351. struct ocfs2_block_check {
  352. /*00*/ __le32 bc_crc32e; /* 802.3 Ethernet II CRC32 */
  353. __le16 bc_ecc; /* Single-error-correction parity vector.
  354. This is a simple Hamming code dependent
  355. on the blocksize. OCFS2's maximum
  356. blocksize, 4K, requires 16 parity bits,
  357. so we fit in __le16. */
  358. __le16 bc_reserved1;
  359. /*08*/
  360. };
  361. /*
  362. * On disk extent record for OCFS2
  363. * It describes a range of clusters on disk.
  364. *
  365. * Length fields are divided into interior and leaf node versions.
  366. * This leaves room for a flags field (OCFS2_EXT_*) in the leaf nodes.
  367. */
  368. struct ocfs2_extent_rec {
  369. /*00*/ __le32 e_cpos; /* Offset into the file, in clusters */
  370. union {
  371. __le32 e_int_clusters; /* Clusters covered by all children */
  372. struct {
  373. __le16 e_leaf_clusters; /* Clusters covered by this
  374. extent */
  375. __u8 e_reserved1;
  376. __u8 e_flags; /* Extent flags */
  377. };
  378. };
  379. __le64 e_blkno; /* Physical disk offset, in blocks */
  380. /*10*/
  381. };
  382. struct ocfs2_chain_rec {
  383. __le32 c_free; /* Number of free bits in this chain. */
  384. __le32 c_total; /* Number of total bits in this chain */
  385. __le64 c_blkno; /* Physical disk offset (blocks) of 1st group */
  386. };
  387. struct ocfs2_truncate_rec {
  388. __le32 t_start; /* 1st cluster in this log */
  389. __le32 t_clusters; /* Number of total clusters covered */
  390. };
  391. /*
  392. * On disk extent list for OCFS2 (node in the tree). Note that this
  393. * is contained inside ocfs2_dinode or ocfs2_extent_block, so the
  394. * offsets are relative to ocfs2_dinode.id2.i_list or
  395. * ocfs2_extent_block.h_list, respectively.
  396. */
  397. struct ocfs2_extent_list {
  398. /*00*/ __le16 l_tree_depth; /* Extent tree depth from this
  399. point. 0 means data extents
  400. hang directly off this
  401. header (a leaf)
  402. NOTE: The high 8 bits cannot be
  403. used - tree_depth is never that big.
  404. */
  405. __le16 l_count; /* Number of extent records */
  406. __le16 l_next_free_rec; /* Next unused extent slot */
  407. __le16 l_reserved1;
  408. __le64 l_reserved2; /* Pad to
  409. sizeof(ocfs2_extent_rec) */
  410. /*10*/ struct ocfs2_extent_rec l_recs[]; /* Extent records */
  411. };
  412. /*
  413. * On disk allocation chain list for OCFS2. Note that this is
  414. * contained inside ocfs2_dinode, so the offsets are relative to
  415. * ocfs2_dinode.id2.i_chain.
  416. */
  417. struct ocfs2_chain_list {
  418. /*00*/ __le16 cl_cpg; /* Clusters per Block Group */
  419. __le16 cl_bpc; /* Bits per cluster */
  420. __le16 cl_count; /* Total chains in this list */
  421. __le16 cl_next_free_rec; /* Next unused chain slot */
  422. __le64 cl_reserved1;
  423. /*10*/ struct ocfs2_chain_rec cl_recs[]; /* Chain records */
  424. };
  425. /*
  426. * On disk deallocation log for OCFS2. Note that this is
  427. * contained inside ocfs2_dinode, so the offsets are relative to
  428. * ocfs2_dinode.id2.i_dealloc.
  429. */
  430. struct ocfs2_truncate_log {
  431. /*00*/ __le16 tl_count; /* Total records in this log */
  432. __le16 tl_used; /* Number of records in use */
  433. __le32 tl_reserved1;
  434. /*08*/ struct ocfs2_truncate_rec tl_recs[]; /* Truncate records */
  435. };
  436. /*
  437. * On disk extent block (indirect block) for OCFS2
  438. */
  439. struct ocfs2_extent_block
  440. {
  441. /*00*/ __u8 h_signature[8]; /* Signature for verification */
  442. struct ocfs2_block_check h_check; /* Error checking */
  443. /*10*/ __le16 h_suballoc_slot; /* Slot suballocator this
  444. extent_header belongs to */
  445. __le16 h_suballoc_bit; /* Bit offset in suballocator
  446. block group */
  447. __le32 h_fs_generation; /* Must match super block */
  448. __le64 h_blkno; /* Offset on disk, in blocks */
  449. /*20*/ __le64 h_suballoc_loc; /* Suballocator block group this
  450. eb belongs to. Only valid
  451. if allocated from a
  452. discontiguous block group */
  453. __le64 h_next_leaf_blk; /* Offset on disk, in blocks,
  454. of next leaf header pointing
  455. to data */
  456. /*30*/ struct ocfs2_extent_list h_list; /* Extent record list */
  457. /* Actual on-disk size is one block */
  458. };
  459. /*
  460. * On disk slot map for OCFS2. This defines the contents of the "slot_map"
  461. * system file. A slot is valid if it contains a node number >= 0. The
  462. * value -1 (0xFFFF) is OCFS2_INVALID_SLOT. This marks a slot empty.
  463. */
  464. struct ocfs2_slot_map {
  465. /*00*/ __le16 sm_slots[0];
  466. /*
  467. * Actual on-disk size is one block. OCFS2_MAX_SLOTS is 255,
  468. * 255 * sizeof(__le16) == 512B, within the 512B block minimum blocksize.
  469. */
  470. };
  471. struct ocfs2_extended_slot {
  472. /*00*/ __u8 es_valid;
  473. __u8 es_reserved1[3];
  474. __le32 es_node_num;
  475. /*08*/
  476. };
  477. /*
  478. * The extended slot map, used when OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP
  479. * is set. It separates out the valid marker from the node number, and
  480. * has room to grow. Unlike the old slot map, this format is defined by
  481. * i_size.
  482. */
  483. struct ocfs2_slot_map_extended {
  484. /*00*/ struct ocfs2_extended_slot se_slots[0];
  485. /*
  486. * Actual size is i_size of the slot_map system file. It should
  487. * match s_max_slots * sizeof(struct ocfs2_extended_slot)
  488. */
  489. };
  490. /*
  491. * ci_stackflags is only valid if the incompat bit
  492. * OCFS2_FEATURE_INCOMPAT_CLUSTERINFO is set.
  493. */
  494. struct ocfs2_cluster_info {
  495. /*00*/ __u8 ci_stack[OCFS2_STACK_LABEL_LEN];
  496. union {
  497. __le32 ci_reserved;
  498. struct {
  499. __u8 ci_stackflags;
  500. __u8 ci_reserved1;
  501. __u8 ci_reserved2;
  502. __u8 ci_reserved3;
  503. };
  504. };
  505. /*08*/ __u8 ci_cluster[OCFS2_CLUSTER_NAME_LEN];
  506. /*18*/
  507. };
  508. /*
  509. * On disk superblock for OCFS2
  510. * Note that it is contained inside an ocfs2_dinode, so all offsets
  511. * are relative to the start of ocfs2_dinode.id2.
  512. */
  513. struct ocfs2_super_block {
  514. /*00*/ __le16 s_major_rev_level;
  515. __le16 s_minor_rev_level;
  516. __le16 s_mnt_count;
  517. __le16 s_max_mnt_count;
  518. __le16 s_state; /* File system state */
  519. __le16 s_errors; /* Behaviour when detecting errors */
  520. __le32 s_checkinterval; /* Max time between checks */
  521. /*10*/ __le64 s_lastcheck; /* Time of last check */
  522. __le32 s_creator_os; /* OS */
  523. __le32 s_feature_compat; /* Compatible feature set */
  524. /*20*/ __le32 s_feature_incompat; /* Incompatible feature set */
  525. __le32 s_feature_ro_compat; /* Readonly-compatible feature set */
  526. __le64 s_root_blkno; /* Offset, in blocks, of root directory
  527. dinode */
  528. /*30*/ __le64 s_system_dir_blkno; /* Offset, in blocks, of system
  529. directory dinode */
  530. __le32 s_blocksize_bits; /* Blocksize for this fs */
  531. __le32 s_clustersize_bits; /* Clustersize for this fs */
  532. /*40*/ __le16 s_max_slots; /* Max number of simultaneous mounts
  533. before tunefs required */
  534. __le16 s_tunefs_flag;
  535. __le32 s_uuid_hash; /* hash value of uuid */
  536. __le64 s_first_cluster_group; /* Block offset of 1st cluster
  537. * group header */
  538. /*50*/ __u8 s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */
  539. /*90*/ __u8 s_uuid[OCFS2_VOL_UUID_LEN]; /* 128-bit uuid */
  540. /*A0*/ struct ocfs2_cluster_info s_cluster_info; /* Only valid if either
  541. userspace or clusterinfo
  542. INCOMPAT flag set. */
  543. /*B8*/ __le16 s_xattr_inline_size; /* extended attribute inline size
  544. for this fs*/
  545. __le16 s_reserved0;
  546. __le32 s_dx_seed[3]; /* seed[0-2] for dx dir hash.
  547. * s_uuid_hash serves as seed[3]. */
  548. /*C0*/ __le64 s_reserved2[15]; /* Fill out superblock */
  549. /*140*/
  550. /*
  551. * NOTE: As stated above, all offsets are relative to
  552. * ocfs2_dinode.id2, which is at 0xC0 in the inode.
  553. * 0xC0 + 0x140 = 0x200 or 512 bytes. A superblock must fit within
  554. * our smallest blocksize, which is 512 bytes. To ensure this,
  555. * we reserve the space in s_reserved2. Anything past s_reserved2
  556. * will not be available on the smallest blocksize.
  557. */
  558. };
  559. /*
  560. * Local allocation bitmap for OCFS2 slots
  561. * Note that it exists inside an ocfs2_dinode, so all offsets are
  562. * relative to the start of ocfs2_dinode.id2.
  563. */
  564. struct ocfs2_local_alloc
  565. {
  566. /*00*/ __le32 la_bm_off; /* Starting bit offset in main bitmap */
  567. __le16 la_size; /* Size of included bitmap, in bytes */
  568. __le16 la_reserved1;
  569. __le64 la_reserved2;
  570. /*10*/ __u8 la_bitmap[];
  571. };
  572. /*
  573. * Data-in-inode header. This is only used if i_dyn_features has
  574. * OCFS2_INLINE_DATA_FL set.
  575. */
  576. struct ocfs2_inline_data
  577. {
  578. /*00*/ __le16 id_count; /* Number of bytes that can be used
  579. * for data, starting at id_data */
  580. __le16 id_reserved0;
  581. __le32 id_reserved1;
  582. __u8 id_data[]; /* Start of user data */
  583. };
  584. /*
  585. * On disk inode for OCFS2
  586. */
  587. struct ocfs2_dinode {
  588. /*00*/ __u8 i_signature[8]; /* Signature for validation */
  589. __le32 i_generation; /* Generation number */
  590. __le16 i_suballoc_slot; /* Slot suballocator this inode
  591. belongs to */
  592. __le16 i_suballoc_bit; /* Bit offset in suballocator
  593. block group */
  594. /*10*/ __le16 i_links_count_hi; /* High 16 bits of links count */
  595. __le16 i_xattr_inline_size;
  596. __le32 i_clusters; /* Cluster count */
  597. __le32 i_uid; /* Owner UID */
  598. __le32 i_gid; /* Owning GID */
  599. /*20*/ __le64 i_size; /* Size in bytes */
  600. __le16 i_mode; /* File mode */
  601. __le16 i_links_count; /* Links count */
  602. __le32 i_flags; /* File flags */
  603. /*30*/ __le64 i_atime; /* Access time */
  604. __le64 i_ctime; /* Creation time */
  605. /*40*/ __le64 i_mtime; /* Modification time */
  606. __le64 i_dtime; /* Deletion time */
  607. /*50*/ __le64 i_blkno; /* Offset on disk, in blocks */
  608. __le64 i_last_eb_blk; /* Pointer to last extent
  609. block */
  610. /*60*/ __le32 i_fs_generation; /* Generation per fs-instance */
  611. __le32 i_atime_nsec;
  612. __le32 i_ctime_nsec;
  613. __le32 i_mtime_nsec;
  614. /*70*/ __le32 i_attr;
  615. __le16 i_orphaned_slot; /* Only valid when OCFS2_ORPHANED_FL
  616. was set in i_flags */
  617. __le16 i_dyn_features;
  618. __le64 i_xattr_loc;
  619. /*80*/ struct ocfs2_block_check i_check; /* Error checking */
  620. /*88*/ __le64 i_dx_root; /* Pointer to dir index root block */
  621. /*90*/ __le64 i_refcount_loc;
  622. __le64 i_suballoc_loc; /* Suballocator block group this
  623. inode belongs to. Only valid
  624. if allocated from a
  625. discontiguous block group */
  626. /*A0*/ __le16 i_dio_orphaned_slot; /* only used for append dio write */
  627. __le16 i_reserved1[3];
  628. __le64 i_reserved2[2];
  629. /*B8*/ union {
  630. __le64 i_pad1; /* Generic way to refer to this
  631. 64bit union */
  632. struct {
  633. __le64 i_rdev; /* Device number */
  634. } dev1;
  635. struct { /* Info for bitmap system
  636. inodes */
  637. __le32 i_used; /* Bits (ie, clusters) used */
  638. __le32 i_total; /* Total bits (clusters)
  639. available */
  640. } bitmap1;
  641. struct { /* Info for journal system
  642. inodes */
  643. __le32 ij_flags; /* Mounted, version, etc. */
  644. __le32 ij_recovery_generation; /* Incremented when the
  645. journal is recovered
  646. after an unclean
  647. shutdown */
  648. } journal1;
  649. } id1; /* Inode type dependent 1 */
  650. /*C0*/ union {
  651. struct ocfs2_super_block i_super;
  652. struct ocfs2_local_alloc i_lab;
  653. struct ocfs2_chain_list i_chain;
  654. struct ocfs2_extent_list i_list;
  655. struct ocfs2_truncate_log i_dealloc;
  656. struct ocfs2_inline_data i_data;
  657. __u8 i_symlink[0];
  658. } id2;
  659. /* Actual on-disk size is one block */
  660. };
  661. /*
  662. * On-disk directory entry structure for OCFS2
  663. *
  664. * Packed as this structure could be accessed unaligned on 64-bit platforms
  665. */
  666. struct ocfs2_dir_entry {
  667. /*00*/ __le64 inode; /* Inode number */
  668. __le16 rec_len; /* Directory entry length */
  669. __u8 name_len; /* Name length */
  670. __u8 file_type;
  671. /*0C*/ char name[OCFS2_MAX_FILENAME_LEN]; /* File name */
  672. /* Actual on-disk length specified by rec_len */
  673. } __attribute__ ((packed));
  674. /*
  675. * Per-block record for the unindexed directory btree. This is carefully
  676. * crafted so that the rec_len and name_len records of an ocfs2_dir_entry are
  677. * mirrored. That way, the directory manipulation code needs a minimal amount
  678. * of update.
  679. *
  680. * NOTE: Keep this structure aligned to a multiple of 4 bytes.
  681. */
  682. struct ocfs2_dir_block_trailer {
  683. /*00*/ __le64 db_compat_inode; /* Always zero. Was inode */
  684. __le16 db_compat_rec_len; /* Backwards compatible with
  685. * ocfs2_dir_entry. */
  686. __u8 db_compat_name_len; /* Always zero. Was name_len */
  687. __u8 db_reserved0;
  688. __le16 db_reserved1;
  689. __le16 db_free_rec_len; /* Size of largest empty hole
  690. * in this block. (unused) */
  691. /*10*/ __u8 db_signature[8]; /* Signature for verification */
  692. __le64 db_reserved2;
  693. /*20*/ __le64 db_free_next; /* Next block in list (unused) */
  694. __le64 db_blkno; /* Offset on disk, in blocks */
  695. /*30*/ __le64 db_parent_dinode; /* dinode which owns me, in
  696. blocks */
  697. struct ocfs2_block_check db_check; /* Error checking */
  698. /*40*/
  699. };
  700. /*
  701. * A directory entry in the indexed tree. We don't store the full name here,
  702. * but instead provide a pointer to the full dirent in the unindexed tree.
  703. *
  704. * We also store name_len here so as to reduce the number of leaf blocks we
  705. * need to search in case of collisions.
  706. */
  707. struct ocfs2_dx_entry {
  708. __le32 dx_major_hash; /* Used to find logical
  709. * cluster in index */
  710. __le32 dx_minor_hash; /* Lower bits used to find
  711. * block in cluster */
  712. __le64 dx_dirent_blk; /* Physical block in unindexed
  713. * tree holding this dirent. */
  714. };
  715. struct ocfs2_dx_entry_list {
  716. __le32 de_reserved;
  717. __le16 de_count; /* Maximum number of entries
  718. * possible in de_entries */
  719. __le16 de_num_used; /* Current number of
  720. * de_entries entries */
  721. struct ocfs2_dx_entry de_entries[]; /* Indexed dir entries
  722. * in a packed array of
  723. * length de_num_used */
  724. };
  725. #define OCFS2_DX_FLAG_INLINE 0x01
  726. /*
  727. * A directory indexing block. Each indexed directory has one of these,
  728. * pointed to by ocfs2_dinode.
  729. *
  730. * This block stores an indexed btree root, and a set of free space
  731. * start-of-list pointers.
  732. */
  733. struct ocfs2_dx_root_block {
  734. __u8 dr_signature[8]; /* Signature for verification */
  735. struct ocfs2_block_check dr_check; /* Error checking */
  736. __le16 dr_suballoc_slot; /* Slot suballocator this
  737. * block belongs to. */
  738. __le16 dr_suballoc_bit; /* Bit offset in suballocator
  739. * block group */
  740. __le32 dr_fs_generation; /* Must match super block */
  741. __le64 dr_blkno; /* Offset on disk, in blocks */
  742. __le64 dr_last_eb_blk; /* Pointer to last
  743. * extent block */
  744. __le32 dr_clusters; /* Clusters allocated
  745. * to the indexed tree. */
  746. __u8 dr_flags; /* OCFS2_DX_FLAG_* flags */
  747. __u8 dr_reserved0;
  748. __le16 dr_reserved1;
  749. __le64 dr_dir_blkno; /* Pointer to parent inode */
  750. __le32 dr_num_entries; /* Total number of
  751. * names stored in
  752. * this directory.*/
  753. __le32 dr_reserved2;
  754. __le64 dr_free_blk; /* Pointer to head of free
  755. * unindexed block list. */
  756. __le64 dr_suballoc_loc; /* Suballocator block group
  757. this root belongs to.
  758. Only valid if allocated
  759. from a discontiguous
  760. block group */
  761. __le64 dr_reserved3[14];
  762. union {
  763. struct ocfs2_extent_list dr_list; /* Keep this aligned to 128
  764. * bits for maximum space
  765. * efficiency. */
  766. struct ocfs2_dx_entry_list dr_entries; /* In-root-block list of
  767. * entries. We grow out
  768. * to extents if this
  769. * gets too big. */
  770. };
  771. };
  772. /*
  773. * The header of a leaf block in the indexed tree.
  774. */
  775. struct ocfs2_dx_leaf {
  776. __u8 dl_signature[8];/* Signature for verification */
  777. struct ocfs2_block_check dl_check; /* Error checking */
  778. __le64 dl_blkno; /* Offset on disk, in blocks */
  779. __le32 dl_fs_generation;/* Must match super block */
  780. __le32 dl_reserved0;
  781. __le64 dl_reserved1;
  782. struct ocfs2_dx_entry_list dl_list;
  783. };
  784. /*
  785. * Largest bitmap for a block (suballocator) group in bytes. This limit
  786. * does not affect cluster groups (global allocator). Cluster group
  787. * bitmaps run to the end of the block.
  788. */
  789. #define OCFS2_MAX_BG_BITMAP_SIZE 256
  790. /*
  791. * On disk allocator group structure for OCFS2
  792. */
  793. struct ocfs2_group_desc
  794. {
  795. /*00*/ __u8 bg_signature[8]; /* Signature for validation */
  796. __le16 bg_size; /* Size of included bitmap in
  797. bytes. */
  798. __le16 bg_bits; /* Bits represented by this
  799. group. */
  800. __le16 bg_free_bits_count; /* Free bits count */
  801. __le16 bg_chain; /* What chain I am in. */
  802. /*10*/ __le32 bg_generation;
  803. __le32 bg_reserved1;
  804. __le64 bg_next_group; /* Next group in my list, in
  805. blocks */
  806. /*20*/ __le64 bg_parent_dinode; /* dinode which owns me, in
  807. blocks */
  808. __le64 bg_blkno; /* Offset on disk, in blocks */
  809. /*30*/ struct ocfs2_block_check bg_check; /* Error checking */
  810. __le64 bg_reserved2;
  811. /*40*/ union {
  812. __u8 bg_bitmap[0];
  813. struct {
  814. /*
  815. * Block groups may be discontiguous when
  816. * OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG is set.
  817. * The extents of a discontiguous block group are
  818. * stored in bg_list. It is a flat list.
  819. * l_tree_depth must always be zero. A
  820. * discontiguous group is signified by a non-zero
  821. * bg_list->l_next_free_rec. Only block groups
  822. * can be discontiguous; Cluster groups cannot.
  823. * We've never made a block group with more than
  824. * 2048 blocks (256 bytes of bg_bitmap). This
  825. * codifies that limit so that we can fit bg_list.
  826. * bg_size of a discontiguous block group will
  827. * be 256 to match bg_bitmap_filler.
  828. */
  829. __u8 bg_bitmap_filler[OCFS2_MAX_BG_BITMAP_SIZE];
  830. /*140*/ struct ocfs2_extent_list bg_list;
  831. };
  832. };
  833. /* Actual on-disk size is one block */
  834. };
  835. struct ocfs2_refcount_rec {
  836. /*00*/ __le64 r_cpos; /* Physical offset, in clusters */
  837. __le32 r_clusters; /* Clusters covered by this extent */
  838. __le32 r_refcount; /* Reference count of this extent */
  839. /*10*/
  840. };
  841. #define OCFS2_32BIT_POS_MASK (0xffffffffULL)
  842. #define OCFS2_REFCOUNT_LEAF_FL (0x00000001)
  843. #define OCFS2_REFCOUNT_TREE_FL (0x00000002)
  844. struct ocfs2_refcount_list {
  845. /*00*/ __le16 rl_count; /* Maximum number of entries possible
  846. in rl_records */
  847. __le16 rl_used; /* Current number of used records */
  848. __le32 rl_reserved2;
  849. __le64 rl_reserved1; /* Pad to sizeof(ocfs2_refcount_record) */
  850. /*10*/ struct ocfs2_refcount_rec rl_recs[]; /* Refcount records */
  851. };
  852. struct ocfs2_refcount_block {
  853. /*00*/ __u8 rf_signature[8]; /* Signature for verification */
  854. __le16 rf_suballoc_slot; /* Slot suballocator this block
  855. belongs to */
  856. __le16 rf_suballoc_bit; /* Bit offset in suballocator
  857. block group */
  858. __le32 rf_fs_generation; /* Must match superblock */
  859. /*10*/ __le64 rf_blkno; /* Offset on disk, in blocks */
  860. __le64 rf_parent; /* Parent block, only valid if
  861. OCFS2_REFCOUNT_LEAF_FL is set in
  862. rf_flags */
  863. /*20*/ struct ocfs2_block_check rf_check; /* Error checking */
  864. __le64 rf_last_eb_blk; /* Pointer to last extent block */
  865. /*30*/ __le32 rf_count; /* Number of inodes sharing this
  866. refcount tree */
  867. __le32 rf_flags; /* See the flags above */
  868. __le32 rf_clusters; /* clusters covered by refcount tree. */
  869. __le32 rf_cpos; /* cluster offset in refcount tree.*/
  870. /*40*/ __le32 rf_generation; /* generation number. all be the same
  871. * for the same refcount tree. */
  872. __le32 rf_reserved0;
  873. __le64 rf_suballoc_loc; /* Suballocator block group this
  874. refcount block belongs to. Only
  875. valid if allocated from a
  876. discontiguous block group */
  877. /*50*/ __le64 rf_reserved1[6];
  878. /*80*/ union {
  879. struct ocfs2_refcount_list rf_records; /* List of refcount
  880. records */
  881. struct ocfs2_extent_list rf_list; /* Extent record list,
  882. only valid if
  883. OCFS2_REFCOUNT_TREE_FL
  884. is set in rf_flags */
  885. };
  886. /* Actual on-disk size is one block */
  887. };
  888. /*
  889. * On disk extended attribute structure for OCFS2.
  890. */
  891. /*
  892. * ocfs2_xattr_entry indicates one extend attribute.
  893. *
  894. * Note that it can be stored in inode, one block or one xattr bucket.
  895. */
  896. struct ocfs2_xattr_entry {
  897. __le32 xe_name_hash; /* hash value of xattr prefix+suffix. */
  898. __le16 xe_name_offset; /* byte offset from the 1st entry in the
  899. local xattr storage(inode, xattr block or
  900. xattr bucket). */
  901. __u8 xe_name_len; /* xattr name len, doesn't include prefix. */
  902. __u8 xe_type; /* the low 7 bits indicate the name prefix
  903. * type and the highest bit indicates whether
  904. * the EA is stored in the local storage. */
  905. __le64 xe_value_size; /* real xattr value length. */
  906. };
  907. /*
  908. * On disk structure for xattr header.
  909. *
  910. * One ocfs2_xattr_header describes how many ocfs2_xattr_entry records in
  911. * the local xattr storage.
  912. */
  913. struct ocfs2_xattr_header {
  914. __le16 xh_count; /* contains the count of how
  915. many records are in the
  916. local xattr storage. */
  917. __le16 xh_free_start; /* current offset for storing
  918. xattr. */
  919. __le16 xh_name_value_len; /* total length of name/value
  920. length in this bucket. */
  921. __le16 xh_num_buckets; /* Number of xattr buckets
  922. in this extent record,
  923. only valid in the first
  924. bucket. */
  925. struct ocfs2_block_check xh_check; /* Error checking
  926. (Note, this is only
  927. used for xattr
  928. buckets. A block uses
  929. xb_check and sets
  930. this field to zero.) */
  931. struct ocfs2_xattr_entry xh_entries[]; /* xattr entry list. */
  932. };
  933. /*
  934. * On disk structure for xattr value root.
  935. *
  936. * When an xattr's value is large enough, it is stored in an external
  937. * b-tree like file data. The xattr value root points to this structure.
  938. */
  939. struct ocfs2_xattr_value_root {
  940. /*00*/ __le32 xr_clusters; /* clusters covered by xattr value. */
  941. __le32 xr_reserved0;
  942. __le64 xr_last_eb_blk; /* Pointer to last extent block */
  943. /*10*/ struct ocfs2_extent_list xr_list; /* Extent record list */
  944. };
  945. /*
  946. * On disk structure for xattr tree root.
  947. *
  948. * It is used when there are too many extended attributes for one file. These
  949. * attributes will be organized and stored in an indexed-btree.
  950. */
  951. struct ocfs2_xattr_tree_root {
  952. /*00*/ __le32 xt_clusters; /* clusters covered by xattr. */
  953. __le32 xt_reserved0;
  954. __le64 xt_last_eb_blk; /* Pointer to last extent block */
  955. /*10*/ struct ocfs2_extent_list xt_list; /* Extent record list */
  956. };
  957. #define OCFS2_XATTR_INDEXED 0x1
  958. #define OCFS2_HASH_SHIFT 5
  959. #define OCFS2_XATTR_ROUND 3
  960. #define OCFS2_XATTR_SIZE(size) (((size) + OCFS2_XATTR_ROUND) & \
  961. ~(OCFS2_XATTR_ROUND))
  962. #define OCFS2_XATTR_BUCKET_SIZE 4096
  963. #define OCFS2_XATTR_MAX_BLOCKS_PER_BUCKET (OCFS2_XATTR_BUCKET_SIZE \
  964. / OCFS2_MIN_BLOCKSIZE)
  965. /*
  966. * On disk structure for xattr block.
  967. */
  968. struct ocfs2_xattr_block {
  969. /*00*/ __u8 xb_signature[8]; /* Signature for verification */
  970. __le16 xb_suballoc_slot; /* Slot suballocator this
  971. block belongs to. */
  972. __le16 xb_suballoc_bit; /* Bit offset in suballocator
  973. block group */
  974. __le32 xb_fs_generation; /* Must match super block */
  975. /*10*/ __le64 xb_blkno; /* Offset on disk, in blocks */
  976. struct ocfs2_block_check xb_check; /* Error checking */
  977. /*20*/ __le16 xb_flags; /* Indicates whether this block contains
  978. real xattr or a xattr tree. */
  979. __le16 xb_reserved0;
  980. __le32 xb_reserved1;
  981. __le64 xb_suballoc_loc; /* Suballocator block group this
  982. xattr block belongs to. Only
  983. valid if allocated from a
  984. discontiguous block group */
  985. /*30*/ union {
  986. struct ocfs2_xattr_header xb_header; /* xattr header if this
  987. block contains xattr */
  988. struct ocfs2_xattr_tree_root xb_root;/* xattr tree root if this
  989. block cotains xattr
  990. tree. */
  991. } xb_attrs;
  992. };
  993. #define OCFS2_XATTR_ENTRY_LOCAL 0x80
  994. #define OCFS2_XATTR_TYPE_MASK 0x7F
  995. static inline void ocfs2_xattr_set_local(struct ocfs2_xattr_entry *xe,
  996. int local)
  997. {
  998. if (local)
  999. xe->xe_type |= OCFS2_XATTR_ENTRY_LOCAL;
  1000. else
  1001. xe->xe_type &= ~OCFS2_XATTR_ENTRY_LOCAL;
  1002. }
  1003. static inline int ocfs2_xattr_is_local(struct ocfs2_xattr_entry *xe)
  1004. {
  1005. return xe->xe_type & OCFS2_XATTR_ENTRY_LOCAL;
  1006. }
  1007. static inline void ocfs2_xattr_set_type(struct ocfs2_xattr_entry *xe, int type)
  1008. {
  1009. xe->xe_type |= type & OCFS2_XATTR_TYPE_MASK;
  1010. }
  1011. static inline int ocfs2_xattr_get_type(struct ocfs2_xattr_entry *xe)
  1012. {
  1013. return xe->xe_type & OCFS2_XATTR_TYPE_MASK;
  1014. }
  1015. /*
  1016. * On disk structures for global quota file
  1017. */
  1018. /* Magic numbers and known versions for global quota files */
  1019. #define OCFS2_GLOBAL_QMAGICS {\
  1020. 0x0cf52470, /* USRQUOTA */ \
  1021. 0x0cf52471 /* GRPQUOTA */ \
  1022. }
  1023. #define OCFS2_GLOBAL_QVERSIONS {\
  1024. 0, \
  1025. 0, \
  1026. }
  1027. /* Each block of each quota file has a certain fixed number of bytes reserved
  1028. * for OCFS2 internal use at its end. OCFS2 can use it for things like
  1029. * checksums, etc. */
  1030. #define OCFS2_QBLK_RESERVED_SPACE 8
  1031. /* Generic header of all quota files */
  1032. struct ocfs2_disk_dqheader {
  1033. __le32 dqh_magic; /* Magic number identifying file */
  1034. __le32 dqh_version; /* Quota format version */
  1035. };
  1036. #define OCFS2_GLOBAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
  1037. /* Information header of global quota file (immediately follows the generic
  1038. * header) */
  1039. struct ocfs2_global_disk_dqinfo {
  1040. /*00*/ __le32 dqi_bgrace; /* Grace time for space softlimit excess */
  1041. __le32 dqi_igrace; /* Grace time for inode softlimit excess */
  1042. __le32 dqi_syncms; /* Time after which we sync local changes to
  1043. * global quota file */
  1044. __le32 dqi_blocks; /* Number of blocks in quota file */
  1045. /*10*/ __le32 dqi_free_blk; /* First free block in quota file */
  1046. __le32 dqi_free_entry; /* First block with free dquot entry in quota
  1047. * file */
  1048. };
  1049. /* Structure with global user / group information. We reserve some space
  1050. * for future use. */
  1051. struct ocfs2_global_disk_dqblk {
  1052. /*00*/ __le32 dqb_id; /* ID the structure belongs to */
  1053. __le32 dqb_use_count; /* Number of nodes having reference to this structure */
  1054. __le64 dqb_ihardlimit; /* absolute limit on allocated inodes */
  1055. /*10*/ __le64 dqb_isoftlimit; /* preferred inode limit */
  1056. __le64 dqb_curinodes; /* current # allocated inodes */
  1057. /*20*/ __le64 dqb_bhardlimit; /* absolute limit on disk space */
  1058. __le64 dqb_bsoftlimit; /* preferred limit on disk space */
  1059. /*30*/ __le64 dqb_curspace; /* current space occupied */
  1060. __le64 dqb_btime; /* time limit for excessive disk use */
  1061. /*40*/ __le64 dqb_itime; /* time limit for excessive inode use */
  1062. __le64 dqb_pad1;
  1063. /*50*/ __le64 dqb_pad2;
  1064. };
  1065. /*
  1066. * On-disk structures for local quota file
  1067. */
  1068. /* Magic numbers and known versions for local quota files */
  1069. #define OCFS2_LOCAL_QMAGICS {\
  1070. 0x0cf524c0, /* USRQUOTA */ \
  1071. 0x0cf524c1 /* GRPQUOTA */ \
  1072. }
  1073. #define OCFS2_LOCAL_QVERSIONS {\
  1074. 0, \
  1075. 0, \
  1076. }
  1077. /* Quota flags in dqinfo header */
  1078. #define OLQF_CLEAN 0x0001 /* Quota file is empty (this should be after\
  1079. * quota has been cleanly turned off) */
  1080. #define OCFS2_LOCAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
  1081. /* Information header of local quota file (immediately follows the generic
  1082. * header) */
  1083. struct ocfs2_local_disk_dqinfo {
  1084. __le32 dqi_flags; /* Flags for quota file */
  1085. __le32 dqi_chunks; /* Number of chunks of quota structures
  1086. * with a bitmap */
  1087. __le32 dqi_blocks; /* Number of blocks allocated for quota file */
  1088. };
  1089. /* Header of one chunk of a quota file */
  1090. struct ocfs2_local_disk_chunk {
  1091. __le32 dqc_free; /* Number of free entries in the bitmap */
  1092. __u8 dqc_bitmap[]; /* Bitmap of entries in the corresponding
  1093. * chunk of quota file */
  1094. };
  1095. /* One entry in local quota file */
  1096. struct ocfs2_local_disk_dqblk {
  1097. /*00*/ __le64 dqb_id; /* id this quota applies to */
  1098. __le64 dqb_spacemod; /* Change in the amount of used space */
  1099. /*10*/ __le64 dqb_inodemod; /* Change in the amount of used inodes */
  1100. };
  1101. /*
  1102. * The quota trailer lives at the end of each quota block.
  1103. */
  1104. struct ocfs2_disk_dqtrailer {
  1105. /*00*/ struct ocfs2_block_check dq_check; /* Error checking */
  1106. /*08*/ /* Cannot be larger than OCFS2_QBLK_RESERVED_SPACE */
  1107. };
  1108. static inline struct ocfs2_disk_dqtrailer *ocfs2_block_dqtrailer(int blocksize,
  1109. void *buf)
  1110. {
  1111. char *ptr = buf;
  1112. ptr += blocksize - OCFS2_QBLK_RESERVED_SPACE;
  1113. return (struct ocfs2_disk_dqtrailer *)ptr;
  1114. }
  1115. #ifdef __KERNEL__
  1116. static inline int ocfs2_fast_symlink_chars(struct super_block *sb)
  1117. {
  1118. return sb->s_blocksize -
  1119. offsetof(struct ocfs2_dinode, id2.i_symlink);
  1120. }
  1121. static inline int ocfs2_max_inline_data_with_xattr(struct super_block *sb,
  1122. struct ocfs2_dinode *di)
  1123. {
  1124. unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
  1125. if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
  1126. return sb->s_blocksize -
  1127. offsetof(struct ocfs2_dinode, id2.i_data.id_data) -
  1128. xattrsize;
  1129. else
  1130. return sb->s_blocksize -
  1131. offsetof(struct ocfs2_dinode, id2.i_data.id_data);
  1132. }
  1133. static inline int ocfs2_extent_recs_per_inode(struct super_block *sb)
  1134. {
  1135. int size;
  1136. size = sb->s_blocksize -
  1137. offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
  1138. return size / sizeof(struct ocfs2_extent_rec);
  1139. }
  1140. static inline int ocfs2_extent_recs_per_inode_with_xattr(
  1141. struct super_block *sb,
  1142. struct ocfs2_dinode *di)
  1143. {
  1144. int size;
  1145. unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
  1146. if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
  1147. size = sb->s_blocksize -
  1148. offsetof(struct ocfs2_dinode, id2.i_list.l_recs) -
  1149. xattrsize;
  1150. else
  1151. size = sb->s_blocksize -
  1152. offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
  1153. return size / sizeof(struct ocfs2_extent_rec);
  1154. }
  1155. static inline int ocfs2_extent_recs_per_dx_root(struct super_block *sb)
  1156. {
  1157. int size;
  1158. size = sb->s_blocksize -
  1159. offsetof(struct ocfs2_dx_root_block, dr_list.l_recs);
  1160. return size / sizeof(struct ocfs2_extent_rec);
  1161. }
  1162. static inline int ocfs2_chain_recs_per_inode(struct super_block *sb)
  1163. {
  1164. int size;
  1165. size = sb->s_blocksize -
  1166. offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
  1167. return size / sizeof(struct ocfs2_chain_rec);
  1168. }
  1169. static inline u16 ocfs2_extent_recs_per_eb(struct super_block *sb)
  1170. {
  1171. int size;
  1172. size = sb->s_blocksize -
  1173. offsetof(struct ocfs2_extent_block, h_list.l_recs);
  1174. return size / sizeof(struct ocfs2_extent_rec);
  1175. }
  1176. static inline u16 ocfs2_extent_recs_per_gd(struct super_block *sb)
  1177. {
  1178. int size;
  1179. size = sb->s_blocksize -
  1180. offsetof(struct ocfs2_group_desc, bg_list.l_recs);
  1181. return size / sizeof(struct ocfs2_extent_rec);
  1182. }
  1183. static inline int ocfs2_dx_entries_per_leaf(struct super_block *sb)
  1184. {
  1185. int size;
  1186. size = sb->s_blocksize -
  1187. offsetof(struct ocfs2_dx_leaf, dl_list.de_entries);
  1188. return size / sizeof(struct ocfs2_dx_entry);
  1189. }
  1190. static inline int ocfs2_dx_entries_per_root(struct super_block *sb)
  1191. {
  1192. int size;
  1193. size = sb->s_blocksize -
  1194. offsetof(struct ocfs2_dx_root_block, dr_entries.de_entries);
  1195. return size / sizeof(struct ocfs2_dx_entry);
  1196. }
  1197. static inline u16 ocfs2_local_alloc_size(struct super_block *sb)
  1198. {
  1199. u16 size;
  1200. size = sb->s_blocksize -
  1201. offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
  1202. return size;
  1203. }
  1204. static inline int ocfs2_group_bitmap_size(struct super_block *sb,
  1205. int suballocator,
  1206. u32 feature_incompat)
  1207. {
  1208. int size = sb->s_blocksize -
  1209. offsetof(struct ocfs2_group_desc, bg_bitmap);
  1210. /*
  1211. * The cluster allocator uses the entire block. Suballocators have
  1212. * never used more than OCFS2_MAX_BG_BITMAP_SIZE. Unfortunately, older
  1213. * code expects bg_size set to the maximum. Thus we must keep
  1214. * bg_size as-is unless discontig_bg is enabled.
  1215. */
  1216. if (suballocator &&
  1217. (feature_incompat & OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG))
  1218. size = OCFS2_MAX_BG_BITMAP_SIZE;
  1219. return size;
  1220. }
  1221. static inline int ocfs2_truncate_recs_per_inode(struct super_block *sb)
  1222. {
  1223. int size;
  1224. size = sb->s_blocksize -
  1225. offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
  1226. return size / sizeof(struct ocfs2_truncate_rec);
  1227. }
  1228. static inline u64 ocfs2_backup_super_blkno(struct super_block *sb, int index)
  1229. {
  1230. u64 offset = OCFS2_BACKUP_SB_START;
  1231. if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
  1232. offset <<= (2 * index);
  1233. offset >>= sb->s_blocksize_bits;
  1234. return offset;
  1235. }
  1236. return 0;
  1237. }
  1238. static inline u16 ocfs2_xattr_recs_per_xb(struct super_block *sb)
  1239. {
  1240. int size;
  1241. size = sb->s_blocksize -
  1242. offsetof(struct ocfs2_xattr_block,
  1243. xb_attrs.xb_root.xt_list.l_recs);
  1244. return size / sizeof(struct ocfs2_extent_rec);
  1245. }
  1246. static inline u16 ocfs2_extent_recs_per_rb(struct super_block *sb)
  1247. {
  1248. int size;
  1249. size = sb->s_blocksize -
  1250. offsetof(struct ocfs2_refcount_block, rf_list.l_recs);
  1251. return size / sizeof(struct ocfs2_extent_rec);
  1252. }
  1253. static inline u16 ocfs2_refcount_recs_per_rb(struct super_block *sb)
  1254. {
  1255. int size;
  1256. size = sb->s_blocksize -
  1257. offsetof(struct ocfs2_refcount_block, rf_records.rl_recs);
  1258. return size / sizeof(struct ocfs2_refcount_rec);
  1259. }
  1260. static inline u32
  1261. ocfs2_get_ref_rec_low_cpos(const struct ocfs2_refcount_rec *rec)
  1262. {
  1263. return le64_to_cpu(rec->r_cpos) & OCFS2_32BIT_POS_MASK;
  1264. }
  1265. #else
  1266. static inline int ocfs2_fast_symlink_chars(int blocksize)
  1267. {
  1268. return blocksize - offsetof(struct ocfs2_dinode, id2.i_symlink);
  1269. }
  1270. static inline int ocfs2_max_inline_data_with_xattr(int blocksize,
  1271. struct ocfs2_dinode *di)
  1272. {
  1273. if (di && (di->i_dyn_features & OCFS2_INLINE_XATTR_FL))
  1274. return blocksize -
  1275. offsetof(struct ocfs2_dinode, id2.i_data.id_data) -
  1276. di->i_xattr_inline_size;
  1277. else
  1278. return blocksize -
  1279. offsetof(struct ocfs2_dinode, id2.i_data.id_data);
  1280. }
  1281. static inline int ocfs2_extent_recs_per_inode(int blocksize)
  1282. {
  1283. int size;
  1284. size = blocksize -
  1285. offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
  1286. return size / sizeof(struct ocfs2_extent_rec);
  1287. }
  1288. static inline int ocfs2_chain_recs_per_inode(int blocksize)
  1289. {
  1290. int size;
  1291. size = blocksize -
  1292. offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
  1293. return size / sizeof(struct ocfs2_chain_rec);
  1294. }
  1295. static inline int ocfs2_extent_recs_per_eb(int blocksize)
  1296. {
  1297. int size;
  1298. size = blocksize -
  1299. offsetof(struct ocfs2_extent_block, h_list.l_recs);
  1300. return size / sizeof(struct ocfs2_extent_rec);
  1301. }
  1302. static inline int ocfs2_extent_recs_per_gd(int blocksize)
  1303. {
  1304. int size;
  1305. size = blocksize -
  1306. offsetof(struct ocfs2_group_desc, bg_list.l_recs);
  1307. return size / sizeof(struct ocfs2_extent_rec);
  1308. }
  1309. static inline int ocfs2_local_alloc_size(int blocksize)
  1310. {
  1311. int size;
  1312. size = blocksize -
  1313. offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
  1314. return size;
  1315. }
  1316. static inline int ocfs2_group_bitmap_size(int blocksize,
  1317. int suballocator,
  1318. uint32_t feature_incompat)
  1319. {
  1320. int size = sb->s_blocksize -
  1321. offsetof(struct ocfs2_group_desc, bg_bitmap);
  1322. /*
  1323. * The cluster allocator uses the entire block. Suballocators have
  1324. * never used more than OCFS2_MAX_BG_BITMAP_SIZE. Unfortunately, older
  1325. * code expects bg_size set to the maximum. Thus we must keep
  1326. * bg_size as-is unless discontig_bg is enabled.
  1327. */
  1328. if (suballocator &&
  1329. (feature_incompat & OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG))
  1330. size = OCFS2_MAX_BG_BITMAP_SIZE;
  1331. return size;
  1332. }
  1333. static inline int ocfs2_truncate_recs_per_inode(int blocksize)
  1334. {
  1335. int size;
  1336. size = blocksize -
  1337. offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
  1338. return size / sizeof(struct ocfs2_truncate_rec);
  1339. }
  1340. static inline uint64_t ocfs2_backup_super_blkno(int blocksize, int index)
  1341. {
  1342. uint64_t offset = OCFS2_BACKUP_SB_START;
  1343. if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
  1344. offset <<= (2 * index);
  1345. offset /= blocksize;
  1346. return offset;
  1347. }
  1348. return 0;
  1349. }
  1350. static inline int ocfs2_xattr_recs_per_xb(int blocksize)
  1351. {
  1352. int size;
  1353. size = blocksize -
  1354. offsetof(struct ocfs2_xattr_block,
  1355. xb_attrs.xb_root.xt_list.l_recs);
  1356. return size / sizeof(struct ocfs2_extent_rec);
  1357. }
  1358. #endif /* __KERNEL__ */
  1359. static inline int ocfs2_system_inode_is_global(int type)
  1360. {
  1361. return ((type >= 0) &&
  1362. (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE));
  1363. }
  1364. static inline int ocfs2_sprintf_system_inode_name(char *buf, int len,
  1365. int type, int slot)
  1366. {
  1367. int chars;
  1368. /*
  1369. * Global system inodes can only have one copy. Everything
  1370. * after OCFS2_LAST_GLOBAL_SYSTEM_INODE in the system inode
  1371. * list has a copy per slot.
  1372. */
  1373. if (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE)
  1374. chars = snprintf(buf, len, "%s",
  1375. ocfs2_system_inodes[type].si_name);
  1376. else
  1377. chars = snprintf(buf, len,
  1378. ocfs2_system_inodes[type].si_name,
  1379. slot);
  1380. return chars;
  1381. }
  1382. static inline void ocfs2_set_de_type(struct ocfs2_dir_entry *de,
  1383. umode_t mode)
  1384. {
  1385. de->file_type = fs_umode_to_ftype(mode);
  1386. }
  1387. static inline int ocfs2_gd_is_discontig(struct ocfs2_group_desc *gd)
  1388. {
  1389. if ((offsetof(struct ocfs2_group_desc, bg_bitmap) +
  1390. le16_to_cpu(gd->bg_size)) !=
  1391. offsetof(struct ocfs2_group_desc, bg_list))
  1392. return 0;
  1393. /*
  1394. * Only valid to check l_next_free_rec if
  1395. * bg_bitmap + bg_size == bg_list.
  1396. */
  1397. if (!gd->bg_list.l_next_free_rec)
  1398. return 0;
  1399. return 1;
  1400. }
  1401. #endif /* _OCFS2_FS_H */