ocfs2_fs.h 44 KB

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