ocfs2_fs.h 43 KB

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