ocfs2_fs.h 25 KB

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