ocfs2_fs.h 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445
  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_DIR_MIN_REC_LEN OCFS2_DIR_REC_LEN(1)
  364. #define OCFS2_LINK_MAX 32000
  365. #define OCFS2_DX_LINK_MAX ((1U << 31) - 1U)
  366. #define OCFS2_LINKS_HI_SHIFT 16
  367. #define OCFS2_DX_ENTRIES_MAX (0xffffffffU)
  368. #define S_SHIFT 12
  369. static unsigned char ocfs2_type_by_mode[S_IFMT >> S_SHIFT] = {
  370. [S_IFREG >> S_SHIFT] = OCFS2_FT_REG_FILE,
  371. [S_IFDIR >> S_SHIFT] = OCFS2_FT_DIR,
  372. [S_IFCHR >> S_SHIFT] = OCFS2_FT_CHRDEV,
  373. [S_IFBLK >> S_SHIFT] = OCFS2_FT_BLKDEV,
  374. [S_IFIFO >> S_SHIFT] = OCFS2_FT_FIFO,
  375. [S_IFSOCK >> S_SHIFT] = OCFS2_FT_SOCK,
  376. [S_IFLNK >> S_SHIFT] = OCFS2_FT_SYMLINK,
  377. };
  378. /*
  379. * Convenience casts
  380. */
  381. #define OCFS2_RAW_SB(dinode) (&((dinode)->id2.i_super))
  382. /*
  383. * Block checking structure. This is used in metadata to validate the
  384. * contents. If OCFS2_FEATURE_INCOMPAT_META_ECC is not set, it is all
  385. * zeros.
  386. */
  387. struct ocfs2_block_check {
  388. /*00*/ __le32 bc_crc32e; /* 802.3 Ethernet II CRC32 */
  389. __le16 bc_ecc; /* Single-error-correction parity vector.
  390. This is a simple Hamming code dependant
  391. on the blocksize. OCFS2's maximum
  392. blocksize, 4K, requires 16 parity bits,
  393. so we fit in __le16. */
  394. __le16 bc_reserved1;
  395. /*08*/
  396. };
  397. /*
  398. * On disk extent record for OCFS2
  399. * It describes a range of clusters on disk.
  400. *
  401. * Length fields are divided into interior and leaf node versions.
  402. * This leaves room for a flags field (OCFS2_EXT_*) in the leaf nodes.
  403. */
  404. struct ocfs2_extent_rec {
  405. /*00*/ __le32 e_cpos; /* Offset into the file, in clusters */
  406. union {
  407. __le32 e_int_clusters; /* Clusters covered by all children */
  408. struct {
  409. __le16 e_leaf_clusters; /* Clusters covered by this
  410. extent */
  411. __u8 e_reserved1;
  412. __u8 e_flags; /* Extent flags */
  413. };
  414. };
  415. __le64 e_blkno; /* Physical disk offset, in blocks */
  416. /*10*/
  417. };
  418. struct ocfs2_chain_rec {
  419. __le32 c_free; /* Number of free bits in this chain. */
  420. __le32 c_total; /* Number of total bits in this chain */
  421. __le64 c_blkno; /* Physical disk offset (blocks) of 1st group */
  422. };
  423. struct ocfs2_truncate_rec {
  424. __le32 t_start; /* 1st cluster in this log */
  425. __le32 t_clusters; /* Number of total clusters covered */
  426. };
  427. /*
  428. * On disk extent list for OCFS2 (node in the tree). Note that this
  429. * is contained inside ocfs2_dinode or ocfs2_extent_block, so the
  430. * offsets are relative to ocfs2_dinode.id2.i_list or
  431. * ocfs2_extent_block.h_list, respectively.
  432. */
  433. struct ocfs2_extent_list {
  434. /*00*/ __le16 l_tree_depth; /* Extent tree depth from this
  435. point. 0 means data extents
  436. hang directly off this
  437. header (a leaf)
  438. NOTE: The high 8 bits cannot be
  439. used - tree_depth is never that big.
  440. */
  441. __le16 l_count; /* Number of extent records */
  442. __le16 l_next_free_rec; /* Next unused extent slot */
  443. __le16 l_reserved1;
  444. __le64 l_reserved2; /* Pad to
  445. sizeof(ocfs2_extent_rec) */
  446. /*10*/ struct ocfs2_extent_rec l_recs[0]; /* Extent records */
  447. };
  448. /*
  449. * On disk allocation chain list for OCFS2. Note that this is
  450. * contained inside ocfs2_dinode, so the offsets are relative to
  451. * ocfs2_dinode.id2.i_chain.
  452. */
  453. struct ocfs2_chain_list {
  454. /*00*/ __le16 cl_cpg; /* Clusters per Block Group */
  455. __le16 cl_bpc; /* Bits per cluster */
  456. __le16 cl_count; /* Total chains in this list */
  457. __le16 cl_next_free_rec; /* Next unused chain slot */
  458. __le64 cl_reserved1;
  459. /*10*/ struct ocfs2_chain_rec cl_recs[0]; /* Chain records */
  460. };
  461. /*
  462. * On disk deallocation log for OCFS2. Note that this is
  463. * contained inside ocfs2_dinode, so the offsets are relative to
  464. * ocfs2_dinode.id2.i_dealloc.
  465. */
  466. struct ocfs2_truncate_log {
  467. /*00*/ __le16 tl_count; /* Total records in this log */
  468. __le16 tl_used; /* Number of records in use */
  469. __le32 tl_reserved1;
  470. /*08*/ struct ocfs2_truncate_rec tl_recs[0]; /* Truncate records */
  471. };
  472. /*
  473. * On disk extent block (indirect block) for OCFS2
  474. */
  475. struct ocfs2_extent_block
  476. {
  477. /*00*/ __u8 h_signature[8]; /* Signature for verification */
  478. struct ocfs2_block_check h_check; /* Error checking */
  479. /*10*/ __le16 h_suballoc_slot; /* Slot suballocator this
  480. extent_header belongs to */
  481. __le16 h_suballoc_bit; /* Bit offset in suballocator
  482. block group */
  483. __le32 h_fs_generation; /* Must match super block */
  484. __le64 h_blkno; /* Offset on disk, in blocks */
  485. /*20*/ __le64 h_reserved3;
  486. __le64 h_next_leaf_blk; /* Offset on disk, in blocks,
  487. of next leaf header pointing
  488. to data */
  489. /*30*/ struct ocfs2_extent_list h_list; /* Extent record list */
  490. /* Actual on-disk size is one block */
  491. };
  492. /*
  493. * On disk slot map for OCFS2. This defines the contents of the "slot_map"
  494. * system file. A slot is valid if it contains a node number >= 0. The
  495. * value -1 (0xFFFF) is OCFS2_INVALID_SLOT. This marks a slot empty.
  496. */
  497. struct ocfs2_slot_map {
  498. /*00*/ __le16 sm_slots[0];
  499. /*
  500. * Actual on-disk size is one block. OCFS2_MAX_SLOTS is 255,
  501. * 255 * sizeof(__le16) == 512B, within the 512B block minimum blocksize.
  502. */
  503. };
  504. struct ocfs2_extended_slot {
  505. /*00*/ __u8 es_valid;
  506. __u8 es_reserved1[3];
  507. __le32 es_node_num;
  508. /*10*/
  509. };
  510. /*
  511. * The extended slot map, used when OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP
  512. * is set. It separates out the valid marker from the node number, and
  513. * has room to grow. Unlike the old slot map, this format is defined by
  514. * i_size.
  515. */
  516. struct ocfs2_slot_map_extended {
  517. /*00*/ struct ocfs2_extended_slot se_slots[0];
  518. /*
  519. * Actual size is i_size of the slot_map system file. It should
  520. * match s_max_slots * sizeof(struct ocfs2_extended_slot)
  521. */
  522. };
  523. struct ocfs2_cluster_info {
  524. /*00*/ __u8 ci_stack[OCFS2_STACK_LABEL_LEN];
  525. __le32 ci_reserved;
  526. /*08*/ __u8 ci_cluster[OCFS2_CLUSTER_NAME_LEN];
  527. /*18*/
  528. };
  529. /*
  530. * On disk superblock for OCFS2
  531. * Note that it is contained inside an ocfs2_dinode, so all offsets
  532. * are relative to the start of ocfs2_dinode.id2.
  533. */
  534. struct ocfs2_super_block {
  535. /*00*/ __le16 s_major_rev_level;
  536. __le16 s_minor_rev_level;
  537. __le16 s_mnt_count;
  538. __le16 s_max_mnt_count;
  539. __le16 s_state; /* File system state */
  540. __le16 s_errors; /* Behaviour when detecting errors */
  541. __le32 s_checkinterval; /* Max time between checks */
  542. /*10*/ __le64 s_lastcheck; /* Time of last check */
  543. __le32 s_creator_os; /* OS */
  544. __le32 s_feature_compat; /* Compatible feature set */
  545. /*20*/ __le32 s_feature_incompat; /* Incompatible feature set */
  546. __le32 s_feature_ro_compat; /* Readonly-compatible feature set */
  547. __le64 s_root_blkno; /* Offset, in blocks, of root directory
  548. dinode */
  549. /*30*/ __le64 s_system_dir_blkno; /* Offset, in blocks, of system
  550. directory dinode */
  551. __le32 s_blocksize_bits; /* Blocksize for this fs */
  552. __le32 s_clustersize_bits; /* Clustersize for this fs */
  553. /*40*/ __le16 s_max_slots; /* Max number of simultaneous mounts
  554. before tunefs required */
  555. __le16 s_tunefs_flag;
  556. __le32 s_uuid_hash; /* hash value of uuid */
  557. __le64 s_first_cluster_group; /* Block offset of 1st cluster
  558. * group header */
  559. /*50*/ __u8 s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */
  560. /*90*/ __u8 s_uuid[OCFS2_VOL_UUID_LEN]; /* 128-bit uuid */
  561. /*A0*/ struct ocfs2_cluster_info s_cluster_info; /* Selected userspace
  562. stack. Only valid
  563. with INCOMPAT flag. */
  564. /*B8*/ __le16 s_xattr_inline_size; /* extended attribute inline size
  565. for this fs*/
  566. __le16 s_reserved0;
  567. __le32 s_dx_seed[3]; /* seed[0-2] for dx dir hash.
  568. * s_uuid_hash serves as seed[3]. */
  569. /*C0*/ __le64 s_reserved2[15]; /* Fill out superblock */
  570. /*140*/
  571. /*
  572. * NOTE: As stated above, all offsets are relative to
  573. * ocfs2_dinode.id2, which is at 0xC0 in the inode.
  574. * 0xC0 + 0x140 = 0x200 or 512 bytes. A superblock must fit within
  575. * our smallest blocksize, which is 512 bytes. To ensure this,
  576. * we reserve the space in s_reserved2. Anything past s_reserved2
  577. * will not be available on the smallest blocksize.
  578. */
  579. };
  580. /*
  581. * Local allocation bitmap for OCFS2 slots
  582. * Note that it exists inside an ocfs2_dinode, so all offsets are
  583. * relative to the start of ocfs2_dinode.id2.
  584. */
  585. struct ocfs2_local_alloc
  586. {
  587. /*00*/ __le32 la_bm_off; /* Starting bit offset in main bitmap */
  588. __le16 la_size; /* Size of included bitmap, in bytes */
  589. __le16 la_reserved1;
  590. __le64 la_reserved2;
  591. /*10*/ __u8 la_bitmap[0];
  592. };
  593. /*
  594. * Data-in-inode header. This is only used if i_dyn_features has
  595. * OCFS2_INLINE_DATA_FL set.
  596. */
  597. struct ocfs2_inline_data
  598. {
  599. /*00*/ __le16 id_count; /* Number of bytes that can be used
  600. * for data, starting at id_data */
  601. __le16 id_reserved0;
  602. __le32 id_reserved1;
  603. __u8 id_data[0]; /* Start of user data */
  604. };
  605. /*
  606. * On disk inode for OCFS2
  607. */
  608. struct ocfs2_dinode {
  609. /*00*/ __u8 i_signature[8]; /* Signature for validation */
  610. __le32 i_generation; /* Generation number */
  611. __le16 i_suballoc_slot; /* Slot suballocator this inode
  612. belongs to */
  613. __le16 i_suballoc_bit; /* Bit offset in suballocator
  614. block group */
  615. /*10*/ __le16 i_links_count_hi; /* High 16 bits of links count */
  616. __le16 i_xattr_inline_size;
  617. __le32 i_clusters; /* Cluster count */
  618. __le32 i_uid; /* Owner UID */
  619. __le32 i_gid; /* Owning GID */
  620. /*20*/ __le64 i_size; /* Size in bytes */
  621. __le16 i_mode; /* File mode */
  622. __le16 i_links_count; /* Links count */
  623. __le32 i_flags; /* File flags */
  624. /*30*/ __le64 i_atime; /* Access time */
  625. __le64 i_ctime; /* Creation time */
  626. /*40*/ __le64 i_mtime; /* Modification time */
  627. __le64 i_dtime; /* Deletion time */
  628. /*50*/ __le64 i_blkno; /* Offset on disk, in blocks */
  629. __le64 i_last_eb_blk; /* Pointer to last extent
  630. block */
  631. /*60*/ __le32 i_fs_generation; /* Generation per fs-instance */
  632. __le32 i_atime_nsec;
  633. __le32 i_ctime_nsec;
  634. __le32 i_mtime_nsec;
  635. /*70*/ __le32 i_attr;
  636. __le16 i_orphaned_slot; /* Only valid when OCFS2_ORPHANED_FL
  637. was set in i_flags */
  638. __le16 i_dyn_features;
  639. __le64 i_xattr_loc;
  640. /*80*/ struct ocfs2_block_check i_check; /* Error checking */
  641. /*88*/ __le64 i_dx_root; /* Pointer to dir index root block */
  642. __le64 i_reserved2[5];
  643. /*B8*/ union {
  644. __le64 i_pad1; /* Generic way to refer to this
  645. 64bit union */
  646. struct {
  647. __le64 i_rdev; /* Device number */
  648. } dev1;
  649. struct { /* Info for bitmap system
  650. inodes */
  651. __le32 i_used; /* Bits (ie, clusters) used */
  652. __le32 i_total; /* Total bits (clusters)
  653. available */
  654. } bitmap1;
  655. struct { /* Info for journal system
  656. inodes */
  657. __le32 ij_flags; /* Mounted, version, etc. */
  658. __le32 ij_recovery_generation; /* Incremented when the
  659. journal is recovered
  660. after an unclean
  661. shutdown */
  662. } journal1;
  663. } id1; /* Inode type dependant 1 */
  664. /*C0*/ union {
  665. struct ocfs2_super_block i_super;
  666. struct ocfs2_local_alloc i_lab;
  667. struct ocfs2_chain_list i_chain;
  668. struct ocfs2_extent_list i_list;
  669. struct ocfs2_truncate_log i_dealloc;
  670. struct ocfs2_inline_data i_data;
  671. __u8 i_symlink[0];
  672. } id2;
  673. /* Actual on-disk size is one block */
  674. };
  675. /*
  676. * On-disk directory entry structure for OCFS2
  677. *
  678. * Packed as this structure could be accessed unaligned on 64-bit platforms
  679. */
  680. struct ocfs2_dir_entry {
  681. /*00*/ __le64 inode; /* Inode number */
  682. __le16 rec_len; /* Directory entry length */
  683. __u8 name_len; /* Name length */
  684. __u8 file_type;
  685. /*0C*/ char name[OCFS2_MAX_FILENAME_LEN]; /* File name */
  686. /* Actual on-disk length specified by rec_len */
  687. } __attribute__ ((packed));
  688. /*
  689. * Per-block record for the unindexed directory btree. This is carefully
  690. * crafted so that the rec_len and name_len records of an ocfs2_dir_entry are
  691. * mirrored. That way, the directory manipulation code needs a minimal amount
  692. * of update.
  693. *
  694. * NOTE: Keep this structure aligned to a multiple of 4 bytes.
  695. */
  696. struct ocfs2_dir_block_trailer {
  697. /*00*/ __le64 db_compat_inode; /* Always zero. Was inode */
  698. __le16 db_compat_rec_len; /* Backwards compatible with
  699. * ocfs2_dir_entry. */
  700. __u8 db_compat_name_len; /* Always zero. Was name_len */
  701. __u8 db_reserved0;
  702. __le16 db_reserved1;
  703. __le16 db_free_rec_len; /* Size of largest empty hole
  704. * in this block. (unused) */
  705. /*10*/ __u8 db_signature[8]; /* Signature for verification */
  706. __le64 db_reserved2;
  707. __le64 db_free_next; /* Next block in list (unused) */
  708. /*20*/ __le64 db_blkno; /* Offset on disk, in blocks */
  709. __le64 db_parent_dinode; /* dinode which owns me, in
  710. blocks */
  711. /*30*/ struct ocfs2_block_check db_check; /* Error checking */
  712. /*40*/
  713. };
  714. /*
  715. * A directory entry in the indexed tree. We don't store the full name here,
  716. * but instead provide a pointer to the full dirent in the unindexed tree.
  717. *
  718. * We also store name_len here so as to reduce the number of leaf blocks we
  719. * need to search in case of collisions.
  720. */
  721. struct ocfs2_dx_entry {
  722. __le32 dx_major_hash; /* Used to find logical
  723. * cluster in index */
  724. __le32 dx_minor_hash; /* Lower bits used to find
  725. * block in cluster */
  726. __le64 dx_dirent_blk; /* Physical block in unindexed
  727. * tree holding this dirent. */
  728. };
  729. struct ocfs2_dx_entry_list {
  730. __le32 de_reserved;
  731. __le16 de_count; /* Maximum number of entries
  732. * possible in de_entries */
  733. __le16 de_num_used; /* Current number of
  734. * de_entries entries */
  735. struct ocfs2_dx_entry de_entries[0]; /* Indexed dir entries
  736. * in a packed array of
  737. * length de_num_used */
  738. };
  739. #define OCFS2_DX_FLAG_INLINE 0x01
  740. /*
  741. * A directory indexing block. Each indexed directory has one of these,
  742. * pointed to by ocfs2_dinode.
  743. *
  744. * This block stores an indexed btree root, and a set of free space
  745. * start-of-list pointers.
  746. */
  747. struct ocfs2_dx_root_block {
  748. __u8 dr_signature[8]; /* Signature for verification */
  749. struct ocfs2_block_check dr_check; /* Error checking */
  750. __le16 dr_suballoc_slot; /* Slot suballocator this
  751. * block belongs to. */
  752. __le16 dr_suballoc_bit; /* Bit offset in suballocator
  753. * block group */
  754. __le32 dr_fs_generation; /* Must match super block */
  755. __le64 dr_blkno; /* Offset on disk, in blocks */
  756. __le64 dr_last_eb_blk; /* Pointer to last
  757. * extent block */
  758. __le32 dr_clusters; /* Clusters allocated
  759. * to the indexed tree. */
  760. __u8 dr_flags; /* OCFS2_DX_FLAG_* flags */
  761. __u8 dr_reserved0;
  762. __le16 dr_reserved1;
  763. __le64 dr_dir_blkno; /* Pointer to parent inode */
  764. __le32 dr_num_entries; /* Total number of
  765. * names stored in
  766. * this directory.*/
  767. __le32 dr_reserved2;
  768. __le64 dr_free_blk; /* Pointer to head of free
  769. * unindexed block list. */
  770. __le64 dr_reserved3[15];
  771. union {
  772. struct ocfs2_extent_list dr_list; /* Keep this aligned to 128
  773. * bits for maximum space
  774. * efficiency. */
  775. struct ocfs2_dx_entry_list dr_entries; /* In-root-block list of
  776. * entries. We grow out
  777. * to extents if this
  778. * gets too big. */
  779. };
  780. };
  781. /*
  782. * The header of a leaf block in the indexed tree.
  783. */
  784. struct ocfs2_dx_leaf {
  785. __u8 dl_signature[8];/* Signature for verification */
  786. struct ocfs2_block_check dl_check; /* Error checking */
  787. __le64 dl_blkno; /* Offset on disk, in blocks */
  788. __le32 dl_fs_generation;/* Must match super block */
  789. __le32 dl_reserved0;
  790. __le64 dl_reserved1;
  791. struct ocfs2_dx_entry_list dl_list;
  792. };
  793. /*
  794. * On disk allocator group structure for OCFS2
  795. */
  796. struct ocfs2_group_desc
  797. {
  798. /*00*/ __u8 bg_signature[8]; /* Signature for validation */
  799. __le16 bg_size; /* Size of included bitmap in
  800. bytes. */
  801. __le16 bg_bits; /* Bits represented by this
  802. group. */
  803. __le16 bg_free_bits_count; /* Free bits count */
  804. __le16 bg_chain; /* What chain I am in. */
  805. /*10*/ __le32 bg_generation;
  806. __le32 bg_reserved1;
  807. __le64 bg_next_group; /* Next group in my list, in
  808. blocks */
  809. /*20*/ __le64 bg_parent_dinode; /* dinode which owns me, in
  810. blocks */
  811. __le64 bg_blkno; /* Offset on disk, in blocks */
  812. /*30*/ struct ocfs2_block_check bg_check; /* Error checking */
  813. __le64 bg_reserved2;
  814. /*40*/ __u8 bg_bitmap[0];
  815. };
  816. /*
  817. * On disk extended attribute structure for OCFS2.
  818. */
  819. /*
  820. * ocfs2_xattr_entry indicates one extend attribute.
  821. *
  822. * Note that it can be stored in inode, one block or one xattr bucket.
  823. */
  824. struct ocfs2_xattr_entry {
  825. __le32 xe_name_hash; /* hash value of xattr prefix+suffix. */
  826. __le16 xe_name_offset; /* byte offset from the 1st entry in the
  827. local xattr storage(inode, xattr block or
  828. xattr bucket). */
  829. __u8 xe_name_len; /* xattr name len, does't include prefix. */
  830. __u8 xe_type; /* the low 7 bits indicate the name prefix
  831. * type and the highest bit indicates whether
  832. * the EA is stored in the local storage. */
  833. __le64 xe_value_size; /* real xattr value length. */
  834. };
  835. /*
  836. * On disk structure for xattr header.
  837. *
  838. * One ocfs2_xattr_header describes how many ocfs2_xattr_entry records in
  839. * the local xattr storage.
  840. */
  841. struct ocfs2_xattr_header {
  842. __le16 xh_count; /* contains the count of how
  843. many records are in the
  844. local xattr storage. */
  845. __le16 xh_free_start; /* current offset for storing
  846. xattr. */
  847. __le16 xh_name_value_len; /* total length of name/value
  848. length in this bucket. */
  849. __le16 xh_num_buckets; /* Number of xattr buckets
  850. in this extent record,
  851. only valid in the first
  852. bucket. */
  853. struct ocfs2_block_check xh_check; /* Error checking
  854. (Note, this is only
  855. used for xattr
  856. buckets. A block uses
  857. xb_check and sets
  858. this field to zero.) */
  859. struct ocfs2_xattr_entry xh_entries[0]; /* xattr entry list. */
  860. };
  861. /*
  862. * On disk structure for xattr value root.
  863. *
  864. * When an xattr's value is large enough, it is stored in an external
  865. * b-tree like file data. The xattr value root points to this structure.
  866. */
  867. struct ocfs2_xattr_value_root {
  868. /*00*/ __le32 xr_clusters; /* clusters covered by xattr value. */
  869. __le32 xr_reserved0;
  870. __le64 xr_last_eb_blk; /* Pointer to last extent block */
  871. /*10*/ struct ocfs2_extent_list xr_list; /* Extent record list */
  872. };
  873. /*
  874. * On disk structure for xattr tree root.
  875. *
  876. * It is used when there are too many extended attributes for one file. These
  877. * attributes will be organized and stored in an indexed-btree.
  878. */
  879. struct ocfs2_xattr_tree_root {
  880. /*00*/ __le32 xt_clusters; /* clusters covered by xattr. */
  881. __le32 xt_reserved0;
  882. __le64 xt_last_eb_blk; /* Pointer to last extent block */
  883. /*10*/ struct ocfs2_extent_list xt_list; /* Extent record list */
  884. };
  885. #define OCFS2_XATTR_INDEXED 0x1
  886. #define OCFS2_HASH_SHIFT 5
  887. #define OCFS2_XATTR_ROUND 3
  888. #define OCFS2_XATTR_SIZE(size) (((size) + OCFS2_XATTR_ROUND) & \
  889. ~(OCFS2_XATTR_ROUND))
  890. #define OCFS2_XATTR_BUCKET_SIZE 4096
  891. #define OCFS2_XATTR_MAX_BLOCKS_PER_BUCKET (OCFS2_XATTR_BUCKET_SIZE \
  892. / OCFS2_MIN_BLOCKSIZE)
  893. /*
  894. * On disk structure for xattr block.
  895. */
  896. struct ocfs2_xattr_block {
  897. /*00*/ __u8 xb_signature[8]; /* Signature for verification */
  898. __le16 xb_suballoc_slot; /* Slot suballocator this
  899. block belongs to. */
  900. __le16 xb_suballoc_bit; /* Bit offset in suballocator
  901. block group */
  902. __le32 xb_fs_generation; /* Must match super block */
  903. /*10*/ __le64 xb_blkno; /* Offset on disk, in blocks */
  904. struct ocfs2_block_check xb_check; /* Error checking */
  905. /*20*/ __le16 xb_flags; /* Indicates whether this block contains
  906. real xattr or a xattr tree. */
  907. __le16 xb_reserved0;
  908. __le32 xb_reserved1;
  909. __le64 xb_reserved2;
  910. /*30*/ union {
  911. struct ocfs2_xattr_header xb_header; /* xattr header if this
  912. block contains xattr */
  913. struct ocfs2_xattr_tree_root xb_root;/* xattr tree root if this
  914. block cotains xattr
  915. tree. */
  916. } xb_attrs;
  917. };
  918. #define OCFS2_XATTR_ENTRY_LOCAL 0x80
  919. #define OCFS2_XATTR_TYPE_MASK 0x7F
  920. static inline void ocfs2_xattr_set_local(struct ocfs2_xattr_entry *xe,
  921. int local)
  922. {
  923. if (local)
  924. xe->xe_type |= OCFS2_XATTR_ENTRY_LOCAL;
  925. else
  926. xe->xe_type &= ~OCFS2_XATTR_ENTRY_LOCAL;
  927. }
  928. static inline int ocfs2_xattr_is_local(struct ocfs2_xattr_entry *xe)
  929. {
  930. return xe->xe_type & OCFS2_XATTR_ENTRY_LOCAL;
  931. }
  932. static inline void ocfs2_xattr_set_type(struct ocfs2_xattr_entry *xe, int type)
  933. {
  934. xe->xe_type |= type & OCFS2_XATTR_TYPE_MASK;
  935. }
  936. static inline int ocfs2_xattr_get_type(struct ocfs2_xattr_entry *xe)
  937. {
  938. return xe->xe_type & OCFS2_XATTR_TYPE_MASK;
  939. }
  940. /*
  941. * On disk structures for global quota file
  942. */
  943. /* Magic numbers and known versions for global quota files */
  944. #define OCFS2_GLOBAL_QMAGICS {\
  945. 0x0cf52470, /* USRQUOTA */ \
  946. 0x0cf52471 /* GRPQUOTA */ \
  947. }
  948. #define OCFS2_GLOBAL_QVERSIONS {\
  949. 0, \
  950. 0, \
  951. }
  952. /* Each block of each quota file has a certain fixed number of bytes reserved
  953. * for OCFS2 internal use at its end. OCFS2 can use it for things like
  954. * checksums, etc. */
  955. #define OCFS2_QBLK_RESERVED_SPACE 8
  956. /* Generic header of all quota files */
  957. struct ocfs2_disk_dqheader {
  958. __le32 dqh_magic; /* Magic number identifying file */
  959. __le32 dqh_version; /* Quota format version */
  960. };
  961. #define OCFS2_GLOBAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
  962. /* Information header of global quota file (immediately follows the generic
  963. * header) */
  964. struct ocfs2_global_disk_dqinfo {
  965. /*00*/ __le32 dqi_bgrace; /* Grace time for space softlimit excess */
  966. __le32 dqi_igrace; /* Grace time for inode softlimit excess */
  967. __le32 dqi_syncms; /* Time after which we sync local changes to
  968. * global quota file */
  969. __le32 dqi_blocks; /* Number of blocks in quota file */
  970. /*10*/ __le32 dqi_free_blk; /* First free block in quota file */
  971. __le32 dqi_free_entry; /* First block with free dquot entry in quota
  972. * file */
  973. };
  974. /* Structure with global user / group information. We reserve some space
  975. * for future use. */
  976. struct ocfs2_global_disk_dqblk {
  977. /*00*/ __le32 dqb_id; /* ID the structure belongs to */
  978. __le32 dqb_use_count; /* Number of nodes having reference to this structure */
  979. __le64 dqb_ihardlimit; /* absolute limit on allocated inodes */
  980. /*10*/ __le64 dqb_isoftlimit; /* preferred inode limit */
  981. __le64 dqb_curinodes; /* current # allocated inodes */
  982. /*20*/ __le64 dqb_bhardlimit; /* absolute limit on disk space */
  983. __le64 dqb_bsoftlimit; /* preferred limit on disk space */
  984. /*30*/ __le64 dqb_curspace; /* current space occupied */
  985. __le64 dqb_btime; /* time limit for excessive disk use */
  986. /*40*/ __le64 dqb_itime; /* time limit for excessive inode use */
  987. __le64 dqb_pad1;
  988. /*50*/ __le64 dqb_pad2;
  989. };
  990. /*
  991. * On-disk structures for local quota file
  992. */
  993. /* Magic numbers and known versions for local quota files */
  994. #define OCFS2_LOCAL_QMAGICS {\
  995. 0x0cf524c0, /* USRQUOTA */ \
  996. 0x0cf524c1 /* GRPQUOTA */ \
  997. }
  998. #define OCFS2_LOCAL_QVERSIONS {\
  999. 0, \
  1000. 0, \
  1001. }
  1002. /* Quota flags in dqinfo header */
  1003. #define OLQF_CLEAN 0x0001 /* Quota file is empty (this should be after\
  1004. * quota has been cleanly turned off) */
  1005. #define OCFS2_LOCAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
  1006. /* Information header of local quota file (immediately follows the generic
  1007. * header) */
  1008. struct ocfs2_local_disk_dqinfo {
  1009. __le32 dqi_flags; /* Flags for quota file */
  1010. __le32 dqi_chunks; /* Number of chunks of quota structures
  1011. * with a bitmap */
  1012. __le32 dqi_blocks; /* Number of blocks allocated for quota file */
  1013. };
  1014. /* Header of one chunk of a quota file */
  1015. struct ocfs2_local_disk_chunk {
  1016. __le32 dqc_free; /* Number of free entries in the bitmap */
  1017. u8 dqc_bitmap[0]; /* Bitmap of entries in the corresponding
  1018. * chunk of quota file */
  1019. };
  1020. /* One entry in local quota file */
  1021. struct ocfs2_local_disk_dqblk {
  1022. /*00*/ __le64 dqb_id; /* id this quota applies to */
  1023. __le64 dqb_spacemod; /* Change in the amount of used space */
  1024. /*10*/ __le64 dqb_inodemod; /* Change in the amount of used inodes */
  1025. };
  1026. /*
  1027. * The quota trailer lives at the end of each quota block.
  1028. */
  1029. struct ocfs2_disk_dqtrailer {
  1030. /*00*/ struct ocfs2_block_check dq_check; /* Error checking */
  1031. /*08*/ /* Cannot be larger than OCFS2_QBLK_RESERVED_SPACE */
  1032. };
  1033. static inline struct ocfs2_disk_dqtrailer *ocfs2_block_dqtrailer(int blocksize,
  1034. void *buf)
  1035. {
  1036. char *ptr = buf;
  1037. ptr += blocksize - OCFS2_QBLK_RESERVED_SPACE;
  1038. return (struct ocfs2_disk_dqtrailer *)ptr;
  1039. }
  1040. #ifdef __KERNEL__
  1041. static inline int ocfs2_fast_symlink_chars(struct super_block *sb)
  1042. {
  1043. return sb->s_blocksize -
  1044. offsetof(struct ocfs2_dinode, id2.i_symlink);
  1045. }
  1046. static inline int ocfs2_max_inline_data_with_xattr(struct super_block *sb,
  1047. struct ocfs2_dinode *di)
  1048. {
  1049. unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
  1050. if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
  1051. return sb->s_blocksize -
  1052. offsetof(struct ocfs2_dinode, id2.i_data.id_data) -
  1053. xattrsize;
  1054. else
  1055. return sb->s_blocksize -
  1056. offsetof(struct ocfs2_dinode, id2.i_data.id_data);
  1057. }
  1058. static inline int ocfs2_extent_recs_per_inode(struct super_block *sb)
  1059. {
  1060. int size;
  1061. size = sb->s_blocksize -
  1062. offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
  1063. return size / sizeof(struct ocfs2_extent_rec);
  1064. }
  1065. static inline int ocfs2_extent_recs_per_inode_with_xattr(
  1066. struct super_block *sb,
  1067. struct ocfs2_dinode *di)
  1068. {
  1069. int size;
  1070. unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
  1071. if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
  1072. size = sb->s_blocksize -
  1073. offsetof(struct ocfs2_dinode, id2.i_list.l_recs) -
  1074. xattrsize;
  1075. else
  1076. size = sb->s_blocksize -
  1077. offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
  1078. return size / sizeof(struct ocfs2_extent_rec);
  1079. }
  1080. static inline int ocfs2_extent_recs_per_dx_root(struct super_block *sb)
  1081. {
  1082. int size;
  1083. size = sb->s_blocksize -
  1084. offsetof(struct ocfs2_dx_root_block, dr_list.l_recs);
  1085. return size / sizeof(struct ocfs2_extent_rec);
  1086. }
  1087. static inline int ocfs2_chain_recs_per_inode(struct super_block *sb)
  1088. {
  1089. int size;
  1090. size = sb->s_blocksize -
  1091. offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
  1092. return size / sizeof(struct ocfs2_chain_rec);
  1093. }
  1094. static inline u16 ocfs2_extent_recs_per_eb(struct super_block *sb)
  1095. {
  1096. int size;
  1097. size = sb->s_blocksize -
  1098. offsetof(struct ocfs2_extent_block, h_list.l_recs);
  1099. return size / sizeof(struct ocfs2_extent_rec);
  1100. }
  1101. static inline int ocfs2_dx_entries_per_leaf(struct super_block *sb)
  1102. {
  1103. int size;
  1104. size = sb->s_blocksize -
  1105. offsetof(struct ocfs2_dx_leaf, dl_list.de_entries);
  1106. return size / sizeof(struct ocfs2_dx_entry);
  1107. }
  1108. static inline int ocfs2_dx_entries_per_root(struct super_block *sb)
  1109. {
  1110. int size;
  1111. size = sb->s_blocksize -
  1112. offsetof(struct ocfs2_dx_root_block, dr_entries.de_entries);
  1113. return size / sizeof(struct ocfs2_dx_entry);
  1114. }
  1115. static inline u16 ocfs2_local_alloc_size(struct super_block *sb)
  1116. {
  1117. u16 size;
  1118. size = sb->s_blocksize -
  1119. offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
  1120. return size;
  1121. }
  1122. static inline int ocfs2_group_bitmap_size(struct super_block *sb)
  1123. {
  1124. int size;
  1125. size = sb->s_blocksize -
  1126. offsetof(struct ocfs2_group_desc, bg_bitmap);
  1127. return size;
  1128. }
  1129. static inline int ocfs2_truncate_recs_per_inode(struct super_block *sb)
  1130. {
  1131. int size;
  1132. size = sb->s_blocksize -
  1133. offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
  1134. return size / sizeof(struct ocfs2_truncate_rec);
  1135. }
  1136. static inline u64 ocfs2_backup_super_blkno(struct super_block *sb, int index)
  1137. {
  1138. u64 offset = OCFS2_BACKUP_SB_START;
  1139. if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
  1140. offset <<= (2 * index);
  1141. offset >>= sb->s_blocksize_bits;
  1142. return offset;
  1143. }
  1144. return 0;
  1145. }
  1146. static inline u16 ocfs2_xattr_recs_per_xb(struct super_block *sb)
  1147. {
  1148. int size;
  1149. size = sb->s_blocksize -
  1150. offsetof(struct ocfs2_xattr_block,
  1151. xb_attrs.xb_root.xt_list.l_recs);
  1152. return size / sizeof(struct ocfs2_extent_rec);
  1153. }
  1154. #else
  1155. static inline int ocfs2_fast_symlink_chars(int blocksize)
  1156. {
  1157. return blocksize - offsetof(struct ocfs2_dinode, id2.i_symlink);
  1158. }
  1159. static inline int ocfs2_max_inline_data(int blocksize)
  1160. {
  1161. return blocksize - offsetof(struct ocfs2_dinode, id2.i_data.id_data);
  1162. }
  1163. static inline int ocfs2_extent_recs_per_inode(int blocksize)
  1164. {
  1165. int size;
  1166. size = blocksize -
  1167. offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
  1168. return size / sizeof(struct ocfs2_extent_rec);
  1169. }
  1170. static inline int ocfs2_chain_recs_per_inode(int blocksize)
  1171. {
  1172. int size;
  1173. size = blocksize -
  1174. offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
  1175. return size / sizeof(struct ocfs2_chain_rec);
  1176. }
  1177. static inline int ocfs2_extent_recs_per_eb(int blocksize)
  1178. {
  1179. int size;
  1180. size = blocksize -
  1181. offsetof(struct ocfs2_extent_block, h_list.l_recs);
  1182. return size / sizeof(struct ocfs2_extent_rec);
  1183. }
  1184. static inline int ocfs2_local_alloc_size(int blocksize)
  1185. {
  1186. int size;
  1187. size = blocksize -
  1188. offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
  1189. return size;
  1190. }
  1191. static inline int ocfs2_group_bitmap_size(int blocksize)
  1192. {
  1193. int size;
  1194. size = blocksize -
  1195. offsetof(struct ocfs2_group_desc, bg_bitmap);
  1196. return size;
  1197. }
  1198. static inline int ocfs2_truncate_recs_per_inode(int blocksize)
  1199. {
  1200. int size;
  1201. size = blocksize -
  1202. offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
  1203. return size / sizeof(struct ocfs2_truncate_rec);
  1204. }
  1205. static inline uint64_t ocfs2_backup_super_blkno(int blocksize, int index)
  1206. {
  1207. uint64_t offset = OCFS2_BACKUP_SB_START;
  1208. if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
  1209. offset <<= (2 * index);
  1210. offset /= blocksize;
  1211. return offset;
  1212. }
  1213. return 0;
  1214. }
  1215. static inline int ocfs2_xattr_recs_per_xb(int blocksize)
  1216. {
  1217. int size;
  1218. size = blocksize -
  1219. offsetof(struct ocfs2_xattr_block,
  1220. xb_attrs.xb_root.xt_list.l_recs);
  1221. return size / sizeof(struct ocfs2_extent_rec);
  1222. }
  1223. #endif /* __KERNEL__ */
  1224. static inline int ocfs2_system_inode_is_global(int type)
  1225. {
  1226. return ((type >= 0) &&
  1227. (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE));
  1228. }
  1229. static inline int ocfs2_sprintf_system_inode_name(char *buf, int len,
  1230. int type, int slot)
  1231. {
  1232. int chars;
  1233. /*
  1234. * Global system inodes can only have one copy. Everything
  1235. * after OCFS2_LAST_GLOBAL_SYSTEM_INODE in the system inode
  1236. * list has a copy per slot.
  1237. */
  1238. if (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE)
  1239. chars = snprintf(buf, len, "%s",
  1240. ocfs2_system_inodes[type].si_name);
  1241. else
  1242. chars = snprintf(buf, len,
  1243. ocfs2_system_inodes[type].si_name,
  1244. slot);
  1245. return chars;
  1246. }
  1247. static inline void ocfs2_set_de_type(struct ocfs2_dir_entry *de,
  1248. umode_t mode)
  1249. {
  1250. de->file_type = ocfs2_type_by_mode[(mode & S_IFMT)>>S_SHIFT];
  1251. }
  1252. #endif /* _OCFS2_FS_H */