ocfs2_fs.h 47 KB

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