ocfs2_fs.h 46 KB

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