ocfs2_fs.h 40 KB

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