ocfs2_fs.h 45 KB

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