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