ocfs2_fs.h 44 KB

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