ocfs2_fs.h 34 KB

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