ocfs2_fs.h 50 KB

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