ocfs2_fs.h 20 KB

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