ocfs2_fs.h 44 KB

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