ocfs2_fs.h 38 KB

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