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