ocfs2_fs.h 47 KB

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