ocfs2_fs.h 51 KB

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