ocfs2_fs.h 50 KB

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