ocfs2_fs.h 22 KB

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