ocfs2_fs.h 21 KB

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