ocfs2_fs.h 34 KB

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