ocfs2_fs.h 47 KB

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