ocfs2_fs.h 34 KB

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