ocfs2_fs.h 40 KB

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