ocfs2_fs.h 50 KB

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