ocfs2_fs.h 51 KB

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