ocfs2_fs.h 20 KB

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