ocfs2_fs.h 28 KB

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