ocfs2_fs.h 51 KB

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