ocfs2_fs.h 51 KB

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