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 #include <linux/magic.h>
29 
30 /* Version */
31 #define OCFS2_MAJOR_REV_LEVEL		0
32 #define OCFS2_MINOR_REV_LEVEL          	90
33 
34 /*
35  * An OCFS2 volume starts this way:
36  * Sector 0: Valid ocfs1_vol_disk_hdr that cleanly fails to mount OCFS.
37  * Sector 1: Valid ocfs1_vol_label that cleanly fails to mount OCFS.
38  * Block OCFS2_SUPER_BLOCK_BLKNO: OCFS2 superblock.
39  *
40  * All other structures are found from the superblock information.
41  *
42  * OCFS2_SUPER_BLOCK_BLKNO is in blocks, not sectors.  eg, for a
43  * blocksize of 2K, it is 4096 bytes into disk.
44  */
45 #define OCFS2_SUPER_BLOCK_BLKNO		2
46 
47 /*
48  * Cluster size limits. The maximum is kept arbitrarily at 1 MB, and could
49  * grow if needed.
50  */
51 #define OCFS2_MIN_CLUSTERSIZE		4096
52 #define OCFS2_MAX_CLUSTERSIZE		1048576
53 
54 /*
55  * Blocks cannot be bigger than clusters, so the maximum blocksize is the
56  * minimum cluster size.
57  */
58 #define OCFS2_MIN_BLOCKSIZE		512
59 #define OCFS2_MAX_BLOCKSIZE		OCFS2_MIN_CLUSTERSIZE
60 
61 /* Object signatures */
62 #define OCFS2_SUPER_BLOCK_SIGNATURE	"OCFSV2"
63 #define OCFS2_INODE_SIGNATURE		"INODE01"
64 #define OCFS2_EXTENT_BLOCK_SIGNATURE	"EXBLK01"
65 #define OCFS2_GROUP_DESC_SIGNATURE      "GROUP01"
66 #define OCFS2_XATTR_BLOCK_SIGNATURE	"XATTR01"
67 #define OCFS2_DIR_TRAILER_SIGNATURE	"DIRTRL1"
68 #define OCFS2_DX_ROOT_SIGNATURE		"DXDIR01"
69 #define OCFS2_DX_LEAF_SIGNATURE		"DXLEAF1"
70 #define OCFS2_REFCOUNT_BLOCK_SIGNATURE	"REFCNT1"
71 
72 /* Compatibility flags */
73 #define OCFS2_HAS_COMPAT_FEATURE(sb,mask)			\
74 	( OCFS2_SB(sb)->s_feature_compat & (mask) )
75 #define OCFS2_HAS_RO_COMPAT_FEATURE(sb,mask)			\
76 	( OCFS2_SB(sb)->s_feature_ro_compat & (mask) )
77 #define OCFS2_HAS_INCOMPAT_FEATURE(sb,mask)			\
78 	( OCFS2_SB(sb)->s_feature_incompat & (mask) )
79 #define OCFS2_SET_COMPAT_FEATURE(sb,mask)			\
80 	OCFS2_SB(sb)->s_feature_compat |= (mask)
81 #define OCFS2_SET_RO_COMPAT_FEATURE(sb,mask)			\
82 	OCFS2_SB(sb)->s_feature_ro_compat |= (mask)
83 #define OCFS2_SET_INCOMPAT_FEATURE(sb,mask)			\
84 	OCFS2_SB(sb)->s_feature_incompat |= (mask)
85 #define OCFS2_CLEAR_COMPAT_FEATURE(sb,mask)			\
86 	OCFS2_SB(sb)->s_feature_compat &= ~(mask)
87 #define OCFS2_CLEAR_RO_COMPAT_FEATURE(sb,mask)			\
88 	OCFS2_SB(sb)->s_feature_ro_compat &= ~(mask)
89 #define OCFS2_CLEAR_INCOMPAT_FEATURE(sb,mask)			\
90 	OCFS2_SB(sb)->s_feature_incompat &= ~(mask)
91 
92 #define OCFS2_FEATURE_COMPAT_SUPP	(OCFS2_FEATURE_COMPAT_BACKUP_SB	\
93 					 | OCFS2_FEATURE_COMPAT_JBD2_SB)
94 #define OCFS2_FEATURE_INCOMPAT_SUPP	(OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT \
95 					 | OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC \
96 					 | OCFS2_FEATURE_INCOMPAT_INLINE_DATA \
97 					 | OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP \
98 					 | OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK \
99 					 | OCFS2_FEATURE_INCOMPAT_XATTR \
100 					 | OCFS2_FEATURE_INCOMPAT_META_ECC \
101 					 | OCFS2_FEATURE_INCOMPAT_INDEXED_DIRS \
102 					 | OCFS2_FEATURE_INCOMPAT_REFCOUNT_TREE \
103 					 | OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG	\
104 					 | OCFS2_FEATURE_INCOMPAT_CLUSTERINFO \
105 					 | OCFS2_FEATURE_INCOMPAT_APPEND_DIO)
106 #define OCFS2_FEATURE_RO_COMPAT_SUPP	(OCFS2_FEATURE_RO_COMPAT_UNWRITTEN \
107 					 | OCFS2_FEATURE_RO_COMPAT_USRQUOTA \
108 					 | OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)
109 
110 /*
111  * Heartbeat-only devices are missing journals and other files.  The
112  * filesystem driver can't load them, but the library can.  Never put
113  * this in OCFS2_FEATURE_INCOMPAT_SUPP, *ever*.
114  */
115 #define OCFS2_FEATURE_INCOMPAT_HEARTBEAT_DEV	0x0002
116 
117 /*
118  * tunefs sets this incompat flag before starting the resize and clears it
119  * at the end. This flag protects users from inadvertently mounting the fs
120  * after an aborted run without fsck-ing.
121  */
122 #define OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG    0x0004
123 
124 /* Used to denote a non-clustered volume */
125 #define OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT	0x0008
126 
127 /* Support for sparse allocation in b-trees */
128 #define OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC	0x0010
129 
130 /*
131  * Tunefs sets this incompat flag before starting an operation which
132  * would require cleanup on abort. This is done to protect users from
133  * inadvertently mounting the fs after an aborted run without
134  * fsck-ing.
135  *
136  * s_tunefs_flags on the super block describes precisely which
137  * operations were in progress.
138  */
139 #define OCFS2_FEATURE_INCOMPAT_TUNEFS_INPROG	0x0020
140 
141 /* Support for data packed into inode blocks */
142 #define OCFS2_FEATURE_INCOMPAT_INLINE_DATA	0x0040
143 
144 /*
145  * Support for alternate, userspace cluster stacks.  If set, the superblock
146  * field s_cluster_info contains a tag for the alternate stack in use as
147  * well as the name of the cluster being joined.
148  * mount.ocfs2 must pass in a matching stack name.
149  *
150  * If not set, the classic stack will be used.  This is compatbile with
151  * all older versions.
152  */
153 #define OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK	0x0080
154 
155 /* Support for the extended slot map */
156 #define OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP 0x100
157 
158 /* Support for extended attributes */
159 #define OCFS2_FEATURE_INCOMPAT_XATTR		0x0200
160 
161 /* Support for indexed directores */
162 #define OCFS2_FEATURE_INCOMPAT_INDEXED_DIRS	0x0400
163 
164 /* Metadata checksum and error correction */
165 #define OCFS2_FEATURE_INCOMPAT_META_ECC		0x0800
166 
167 /* Refcount tree support */
168 #define OCFS2_FEATURE_INCOMPAT_REFCOUNT_TREE	0x1000
169 
170 /* Discontiguous block groups */
171 #define OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG	0x2000
172 
173 /*
174  * Incompat bit to indicate useable clusterinfo with stackflags for all
175  * cluster stacks (userspace adnd o2cb). If this bit is set,
176  * INCOMPAT_USERSPACE_STACK becomes superfluous and thus should not be set.
177  */
178 #define OCFS2_FEATURE_INCOMPAT_CLUSTERINFO	0x4000
179 
180 /*
181  * Append Direct IO support
182  */
183 #define OCFS2_FEATURE_INCOMPAT_APPEND_DIO	0x8000
184 
185 /*
186  * backup superblock flag is used to indicate that this volume
187  * has backup superblocks.
188  */
189 #define OCFS2_FEATURE_COMPAT_BACKUP_SB		0x0001
190 
191 /*
192  * The filesystem will correctly handle journal feature bits.
193  */
194 #define OCFS2_FEATURE_COMPAT_JBD2_SB		0x0002
195 
196 /*
197  * Unwritten extents support.
198  */
199 #define OCFS2_FEATURE_RO_COMPAT_UNWRITTEN	0x0001
200 
201 /*
202  * Maintain quota information for this filesystem
203  */
204 #define OCFS2_FEATURE_RO_COMPAT_USRQUOTA	0x0002
205 #define OCFS2_FEATURE_RO_COMPAT_GRPQUOTA	0x0004
206 
207 
208 /* The byte offset of the first backup block will be 1G.
209  * The following will be 4G, 16G, 64G, 256G and 1T.
210  */
211 #define OCFS2_BACKUP_SB_START			1 << 30
212 
213 /* the max backup superblock nums */
214 #define OCFS2_MAX_BACKUP_SUPERBLOCKS	6
215 
216 /*
217  * Flags on ocfs2_super_block.s_tunefs_flags
218  */
219 #define OCFS2_TUNEFS_INPROG_REMOVE_SLOT		0x0001	/* Removing slots */
220 
221 /*
222  * Flags on ocfs2_dinode.i_flags
223  */
224 #define OCFS2_VALID_FL		(0x00000001)	/* Inode is valid */
225 #define OCFS2_UNUSED2_FL	(0x00000002)
226 #define OCFS2_ORPHANED_FL	(0x00000004)	/* On the orphan list */
227 #define OCFS2_UNUSED3_FL	(0x00000008)
228 /* System inode flags */
229 #define OCFS2_SYSTEM_FL		(0x00000010)	/* System inode */
230 #define OCFS2_SUPER_BLOCK_FL	(0x00000020)	/* Super block */
231 #define OCFS2_LOCAL_ALLOC_FL	(0x00000040)	/* Slot local alloc bitmap */
232 #define OCFS2_BITMAP_FL		(0x00000080)	/* Allocation bitmap */
233 #define OCFS2_JOURNAL_FL	(0x00000100)	/* Slot local journal */
234 #define OCFS2_HEARTBEAT_FL	(0x00000200)	/* Heartbeat area */
235 #define OCFS2_CHAIN_FL		(0x00000400)	/* Chain allocator */
236 #define OCFS2_DEALLOC_FL	(0x00000800)	/* Truncate log */
237 #define OCFS2_QUOTA_FL		(0x00001000)	/* Quota file */
238 #define OCFS2_DIO_ORPHANED_FL	(0X00002000)	/* On the orphan list especially
239 						 * for dio */
240 
241 /*
242  * Flags on ocfs2_dinode.i_dyn_features
243  *
244  * These can change much more often than i_flags. When adding flags,
245  * keep in mind that i_dyn_features is only 16 bits wide.
246  */
247 #define OCFS2_INLINE_DATA_FL	(0x0001)	/* Data stored in inode block */
248 #define OCFS2_HAS_XATTR_FL	(0x0002)
249 #define OCFS2_INLINE_XATTR_FL	(0x0004)
250 #define OCFS2_INDEXED_DIR_FL	(0x0008)
251 #define OCFS2_HAS_REFCOUNT_FL   (0x0010)
252 
253 /* Inode attributes, keep in sync with EXT2 */
254 #define OCFS2_SECRM_FL			FS_SECRM_FL	/* Secure deletion */
255 #define OCFS2_UNRM_FL			FS_UNRM_FL	/* Undelete */
256 #define OCFS2_COMPR_FL			FS_COMPR_FL	/* Compress file */
257 #define OCFS2_SYNC_FL			FS_SYNC_FL	/* Synchronous updates */
258 #define OCFS2_IMMUTABLE_FL		FS_IMMUTABLE_FL	/* Immutable file */
259 #define OCFS2_APPEND_FL			FS_APPEND_FL	/* writes to file may only append */
260 #define OCFS2_NODUMP_FL			FS_NODUMP_FL	/* do not dump file */
261 #define OCFS2_NOATIME_FL		FS_NOATIME_FL	/* do not update atime */
262 /* Reserved for compression usage... */
263 #define OCFS2_DIRTY_FL			FS_DIRTY_FL
264 #define OCFS2_COMPRBLK_FL		FS_COMPRBLK_FL	/* One or more compressed clusters */
265 #define OCFS2_NOCOMP_FL			FS_NOCOMP_FL	/* Don't compress */
266 #define OCFS2_ECOMPR_FL			FS_ECOMPR_FL	/* Compression error */
267 /* End compression flags --- maybe not all used */
268 #define OCFS2_BTREE_FL			FS_BTREE_FL	/* btree format dir */
269 #define OCFS2_INDEX_FL			FS_INDEX_FL	/* hash-indexed directory */
270 #define OCFS2_IMAGIC_FL			FS_IMAGIC_FL	/* AFS directory */
271 #define OCFS2_JOURNAL_DATA_FL		FS_JOURNAL_DATA_FL /* Reserved for ext3 */
272 #define OCFS2_NOTAIL_FL			FS_NOTAIL_FL	/* file tail should not be merged */
273 #define OCFS2_DIRSYNC_FL		FS_DIRSYNC_FL	/* dirsync behaviour (directories only) */
274 #define OCFS2_TOPDIR_FL			FS_TOPDIR_FL	/* Top of directory hierarchies*/
275 #define OCFS2_RESERVED_FL		FS_RESERVED_FL	/* reserved for ext2 lib */
276 
277 #define OCFS2_FL_VISIBLE		FS_FL_USER_VISIBLE	/* User visible flags */
278 #define OCFS2_FL_MODIFIABLE		FS_FL_USER_MODIFIABLE	/* User modifiable flags */
279 
280 /*
281  * Extent record flags (e_node.leaf.flags)
282  */
283 #define OCFS2_EXT_UNWRITTEN		(0x01)	/* Extent is allocated but
284 						 * unwritten */
285 #define OCFS2_EXT_REFCOUNTED		(0x02)  /* Extent is reference
286 						 * counted in an associated
287 						 * refcount tree */
288 
289 /*
290  * Journal Flags (ocfs2_dinode.id1.journal1.i_flags)
291  */
292 #define OCFS2_JOURNAL_DIRTY_FL	(0x00000001)	/* Journal needs recovery */
293 
294 /*
295  * superblock s_state flags
296  */
297 #define OCFS2_ERROR_FS		(0x00000001)	/* FS saw errors */
298 
299 /* Limit of space in ocfs2_dir_entry */
300 #define OCFS2_MAX_FILENAME_LEN		255
301 
302 /* Maximum slots on an ocfs2 file system */
303 #define OCFS2_MAX_SLOTS			255
304 
305 /* Slot map indicator for an empty slot */
306 #define OCFS2_INVALID_SLOT		((u16)-1)
307 
308 #define OCFS2_VOL_UUID_LEN		16
309 #define OCFS2_MAX_VOL_LABEL_LEN		64
310 
311 /* The cluster stack fields */
312 #define OCFS2_STACK_LABEL_LEN		4
313 #define OCFS2_CLUSTER_NAME_LEN		16
314 
315 /* Classic (historically speaking) cluster stack */
316 #define OCFS2_CLASSIC_CLUSTER_STACK	"o2cb"
317 
318 /* Journal limits (in bytes) */
319 #define OCFS2_MIN_JOURNAL_SIZE		(4 * 1024 * 1024)
320 
321 /*
322  * Inline extended attribute size (in bytes)
323  * The value chosen should be aligned to 16 byte boundaries.
324  */
325 #define OCFS2_MIN_XATTR_INLINE_SIZE     256
326 
327 /*
328  * Cluster info flags (ocfs2_cluster_info.ci_stackflags)
329  */
330 #define OCFS2_CLUSTER_O2CB_GLOBAL_HEARTBEAT	(0x01)
331 
332 struct ocfs2_system_inode_info {
333 	char	*si_name;
334 	int	si_iflags;
335 	int	si_mode;
336 };
337 
338 /* System file index */
339 enum {
340 	BAD_BLOCK_SYSTEM_INODE = 0,
341 	GLOBAL_INODE_ALLOC_SYSTEM_INODE,
342 #define OCFS2_FIRST_ONLINE_SYSTEM_INODE GLOBAL_INODE_ALLOC_SYSTEM_INODE
343 	SLOT_MAP_SYSTEM_INODE,
344 	HEARTBEAT_SYSTEM_INODE,
345 	GLOBAL_BITMAP_SYSTEM_INODE,
346 	USER_QUOTA_SYSTEM_INODE,
347 	GROUP_QUOTA_SYSTEM_INODE,
348 #define OCFS2_LAST_GLOBAL_SYSTEM_INODE GROUP_QUOTA_SYSTEM_INODE
349 #define OCFS2_FIRST_LOCAL_SYSTEM_INODE ORPHAN_DIR_SYSTEM_INODE
350 	ORPHAN_DIR_SYSTEM_INODE,
351 	EXTENT_ALLOC_SYSTEM_INODE,
352 	INODE_ALLOC_SYSTEM_INODE,
353 	JOURNAL_SYSTEM_INODE,
354 	LOCAL_ALLOC_SYSTEM_INODE,
355 	TRUNCATE_LOG_SYSTEM_INODE,
356 	LOCAL_USER_QUOTA_SYSTEM_INODE,
357 	LOCAL_GROUP_QUOTA_SYSTEM_INODE,
358 #define OCFS2_LAST_LOCAL_SYSTEM_INODE LOCAL_GROUP_QUOTA_SYSTEM_INODE
359 	NUM_SYSTEM_INODES
360 };
361 #define NUM_GLOBAL_SYSTEM_INODES OCFS2_FIRST_LOCAL_SYSTEM_INODE
362 #define NUM_LOCAL_SYSTEM_INODES	\
363 		(NUM_SYSTEM_INODES - OCFS2_FIRST_LOCAL_SYSTEM_INODE)
364 
365 static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = {
366 	/* Global system inodes (single copy) */
367 	/* The first two are only used from userspace mfks/tunefs */
368 	[BAD_BLOCK_SYSTEM_INODE]		= { "bad_blocks", 0, S_IFREG | 0644 },
369 	[GLOBAL_INODE_ALLOC_SYSTEM_INODE] 	= { "global_inode_alloc", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
370 
371 	/* These are used by the running filesystem */
372 	[SLOT_MAP_SYSTEM_INODE]			= { "slot_map", 0, S_IFREG | 0644 },
373 	[HEARTBEAT_SYSTEM_INODE]		= { "heartbeat", OCFS2_HEARTBEAT_FL, S_IFREG | 0644 },
374 	[GLOBAL_BITMAP_SYSTEM_INODE]		= { "global_bitmap", 0, S_IFREG | 0644 },
375 	[USER_QUOTA_SYSTEM_INODE]		= { "aquota.user", OCFS2_QUOTA_FL, S_IFREG | 0644 },
376 	[GROUP_QUOTA_SYSTEM_INODE]		= { "aquota.group", OCFS2_QUOTA_FL, S_IFREG | 0644 },
377 
378 	/* Slot-specific system inodes (one copy per slot) */
379 	[ORPHAN_DIR_SYSTEM_INODE]		= { "orphan_dir:%04d", 0, S_IFDIR | 0755 },
380 	[EXTENT_ALLOC_SYSTEM_INODE]		= { "extent_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
381 	[INODE_ALLOC_SYSTEM_INODE]		= { "inode_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
382 	[JOURNAL_SYSTEM_INODE]			= { "journal:%04d", OCFS2_JOURNAL_FL, S_IFREG | 0644 },
383 	[LOCAL_ALLOC_SYSTEM_INODE]		= { "local_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_LOCAL_ALLOC_FL, S_IFREG | 0644 },
384 	[TRUNCATE_LOG_SYSTEM_INODE]		= { "truncate_log:%04d", OCFS2_DEALLOC_FL, S_IFREG | 0644 },
385 	[LOCAL_USER_QUOTA_SYSTEM_INODE]		= { "aquota.user:%04d", OCFS2_QUOTA_FL, S_IFREG | 0644 },
386 	[LOCAL_GROUP_QUOTA_SYSTEM_INODE]	= { "aquota.group:%04d", OCFS2_QUOTA_FL, S_IFREG | 0644 },
387 };
388 
389 /* Parameter passed from mount.ocfs2 to module */
390 #define OCFS2_HB_NONE			"heartbeat=none"
391 #define OCFS2_HB_LOCAL			"heartbeat=local"
392 #define OCFS2_HB_GLOBAL			"heartbeat=global"
393 
394 /*
395  * OCFS2 directory file types.  Only the low 3 bits are used.  The
396  * other bits are reserved for now.
397  */
398 #define OCFS2_FT_UNKNOWN	0
399 #define OCFS2_FT_REG_FILE	1
400 #define OCFS2_FT_DIR		2
401 #define OCFS2_FT_CHRDEV		3
402 #define OCFS2_FT_BLKDEV		4
403 #define OCFS2_FT_FIFO		5
404 #define OCFS2_FT_SOCK		6
405 #define OCFS2_FT_SYMLINK	7
406 
407 #define OCFS2_FT_MAX		8
408 
409 /*
410  * OCFS2_DIR_PAD defines the directory entries boundaries
411  *
412  * NOTE: It must be a multiple of 4
413  */
414 #define OCFS2_DIR_PAD			4
415 #define OCFS2_DIR_ROUND			(OCFS2_DIR_PAD - 1)
416 #define OCFS2_DIR_MEMBER_LEN 		offsetof(struct ocfs2_dir_entry, name)
417 #define OCFS2_DIR_REC_LEN(name_len)	(((name_len) + OCFS2_DIR_MEMBER_LEN + \
418                                           OCFS2_DIR_ROUND) & \
419 					 ~OCFS2_DIR_ROUND)
420 #define OCFS2_DIR_MIN_REC_LEN	OCFS2_DIR_REC_LEN(1)
421 
422 #define OCFS2_LINK_MAX		32000
423 #define	OCFS2_DX_LINK_MAX	((1U << 31) - 1U)
424 #define	OCFS2_LINKS_HI_SHIFT	16
425 #define	OCFS2_DX_ENTRIES_MAX	(0xffffffffU)
426 
427 #define S_SHIFT			12
428 static unsigned char ocfs2_type_by_mode[S_IFMT >> S_SHIFT] = {
429 	[S_IFREG >> S_SHIFT]  = OCFS2_FT_REG_FILE,
430 	[S_IFDIR >> S_SHIFT]  = OCFS2_FT_DIR,
431 	[S_IFCHR >> S_SHIFT]  = OCFS2_FT_CHRDEV,
432 	[S_IFBLK >> S_SHIFT]  = OCFS2_FT_BLKDEV,
433 	[S_IFIFO >> S_SHIFT]  = OCFS2_FT_FIFO,
434 	[S_IFSOCK >> S_SHIFT] = OCFS2_FT_SOCK,
435 	[S_IFLNK >> S_SHIFT]  = OCFS2_FT_SYMLINK,
436 };
437 
438 
439 /*
440  * Convenience casts
441  */
442 #define OCFS2_RAW_SB(dinode)		(&((dinode)->id2.i_super))
443 
444 /*
445  * Block checking structure.  This is used in metadata to validate the
446  * contents.  If OCFS2_FEATURE_INCOMPAT_META_ECC is not set, it is all
447  * zeros.
448  */
449 struct ocfs2_block_check {
450 /*00*/	__le32 bc_crc32e;	/* 802.3 Ethernet II CRC32 */
451 	__le16 bc_ecc;		/* Single-error-correction parity vector.
452 				   This is a simple Hamming code dependent
453 				   on the blocksize.  OCFS2's maximum
454 				   blocksize, 4K, requires 16 parity bits,
455 				   so we fit in __le16. */
456 	__le16 bc_reserved1;
457 /*08*/
458 };
459 
460 /*
461  * On disk extent record for OCFS2
462  * It describes a range of clusters on disk.
463  *
464  * Length fields are divided into interior and leaf node versions.
465  * This leaves room for a flags field (OCFS2_EXT_*) in the leaf nodes.
466  */
467 struct ocfs2_extent_rec {
468 /*00*/	__le32 e_cpos;		/* Offset into the file, in clusters */
469 	union {
470 		__le32 e_int_clusters; /* Clusters covered by all children */
471 		struct {
472 			__le16 e_leaf_clusters; /* Clusters covered by this
473 						   extent */
474 			__u8 e_reserved1;
475 			__u8 e_flags; /* Extent flags */
476 		};
477 	};
478 	__le64 e_blkno;		/* Physical disk offset, in blocks */
479 /*10*/
480 };
481 
482 struct ocfs2_chain_rec {
483 	__le32 c_free;	/* Number of free bits in this chain. */
484 	__le32 c_total;	/* Number of total bits in this chain */
485 	__le64 c_blkno;	/* Physical disk offset (blocks) of 1st group */
486 };
487 
488 struct ocfs2_truncate_rec {
489 	__le32 t_start;		/* 1st cluster in this log */
490 	__le32 t_clusters;	/* Number of total clusters covered */
491 };
492 
493 /*
494  * On disk extent list for OCFS2 (node in the tree).  Note that this
495  * is contained inside ocfs2_dinode or ocfs2_extent_block, so the
496  * offsets are relative to ocfs2_dinode.id2.i_list or
497  * ocfs2_extent_block.h_list, respectively.
498  */
499 struct ocfs2_extent_list {
500 /*00*/	__le16 l_tree_depth;		/* Extent tree depth from this
501 					   point.  0 means data extents
502 					   hang directly off this
503 					   header (a leaf)
504 					   NOTE: The high 8 bits cannot be
505 					   used - tree_depth is never that big.
506 					*/
507 	__le16 l_count;			/* Number of extent records */
508 	__le16 l_next_free_rec;		/* Next unused extent slot */
509 	__le16 l_reserved1;
510 	__le64 l_reserved2;		/* Pad to
511 					   sizeof(ocfs2_extent_rec) */
512 /*10*/	struct ocfs2_extent_rec l_recs[0];	/* Extent records */
513 };
514 
515 /*
516  * On disk allocation chain list for OCFS2.  Note that this is
517  * contained inside ocfs2_dinode, so the offsets are relative to
518  * ocfs2_dinode.id2.i_chain.
519  */
520 struct ocfs2_chain_list {
521 /*00*/	__le16 cl_cpg;			/* Clusters per Block Group */
522 	__le16 cl_bpc;			/* Bits per cluster */
523 	__le16 cl_count;		/* Total chains in this list */
524 	__le16 cl_next_free_rec;	/* Next unused chain slot */
525 	__le64 cl_reserved1;
526 /*10*/	struct ocfs2_chain_rec cl_recs[0];	/* Chain records */
527 };
528 
529 /*
530  * On disk deallocation log for OCFS2.  Note that this is
531  * contained inside ocfs2_dinode, so the offsets are relative to
532  * ocfs2_dinode.id2.i_dealloc.
533  */
534 struct ocfs2_truncate_log {
535 /*00*/	__le16 tl_count;		/* Total records in this log */
536 	__le16 tl_used;			/* Number of records in use */
537 	__le32 tl_reserved1;
538 /*08*/	struct ocfs2_truncate_rec tl_recs[0];	/* Truncate records */
539 };
540 
541 /*
542  * On disk extent block (indirect block) for OCFS2
543  */
544 struct ocfs2_extent_block
545 {
546 /*00*/	__u8 h_signature[8];		/* Signature for verification */
547 	struct ocfs2_block_check h_check;	/* Error checking */
548 /*10*/	__le16 h_suballoc_slot;		/* Slot suballocator this
549 					   extent_header belongs to */
550 	__le16 h_suballoc_bit;		/* Bit offset in suballocator
551 					   block group */
552 	__le32 h_fs_generation;		/* Must match super block */
553 	__le64 h_blkno;			/* Offset on disk, in blocks */
554 /*20*/	__le64 h_suballoc_loc;		/* Suballocator block group this
555 					   eb belongs to.  Only valid
556 					   if allocated from a
557 					   discontiguous block group */
558 	__le64 h_next_leaf_blk;		/* Offset on disk, in blocks,
559 					   of next leaf header pointing
560 					   to data */
561 /*30*/	struct ocfs2_extent_list h_list;	/* Extent record list */
562 /* Actual on-disk size is one block */
563 };
564 
565 /*
566  * On disk slot map for OCFS2.  This defines the contents of the "slot_map"
567  * system file.  A slot is valid if it contains a node number >= 0.  The
568  * value -1 (0xFFFF) is OCFS2_INVALID_SLOT.  This marks a slot empty.
569  */
570 struct ocfs2_slot_map {
571 /*00*/	__le16 sm_slots[0];
572 /*
573  * Actual on-disk size is one block.  OCFS2_MAX_SLOTS is 255,
574  * 255 * sizeof(__le16) == 512B, within the 512B block minimum blocksize.
575  */
576 };
577 
578 struct ocfs2_extended_slot {
579 /*00*/	__u8	es_valid;
580 	__u8	es_reserved1[3];
581 	__le32	es_node_num;
582 /*08*/
583 };
584 
585 /*
586  * The extended slot map, used when OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP
587  * is set.  It separates out the valid marker from the node number, and
588  * has room to grow.  Unlike the old slot map, this format is defined by
589  * i_size.
590  */
591 struct ocfs2_slot_map_extended {
592 /*00*/	struct ocfs2_extended_slot se_slots[0];
593 /*
594  * Actual size is i_size of the slot_map system file.  It should
595  * match s_max_slots * sizeof(struct ocfs2_extended_slot)
596  */
597 };
598 
599 /*
600  * ci_stackflags is only valid if the incompat bit
601  * OCFS2_FEATURE_INCOMPAT_CLUSTERINFO is set.
602  */
603 struct ocfs2_cluster_info {
604 /*00*/	__u8   ci_stack[OCFS2_STACK_LABEL_LEN];
605 	union {
606 		__le32 ci_reserved;
607 		struct {
608 			__u8 ci_stackflags;
609 			__u8 ci_reserved1;
610 			__u8 ci_reserved2;
611 			__u8 ci_reserved3;
612 		};
613 	};
614 /*08*/	__u8   ci_cluster[OCFS2_CLUSTER_NAME_LEN];
615 /*18*/
616 };
617 
618 /*
619  * On disk superblock for OCFS2
620  * Note that it is contained inside an ocfs2_dinode, so all offsets
621  * are relative to the start of ocfs2_dinode.id2.
622  */
623 struct ocfs2_super_block {
624 /*00*/	__le16 s_major_rev_level;
625 	__le16 s_minor_rev_level;
626 	__le16 s_mnt_count;
627 	__le16 s_max_mnt_count;
628 	__le16 s_state;			/* File system state */
629 	__le16 s_errors;			/* Behaviour when detecting errors */
630 	__le32 s_checkinterval;		/* Max time between checks */
631 /*10*/	__le64 s_lastcheck;		/* Time of last check */
632 	__le32 s_creator_os;		/* OS */
633 	__le32 s_feature_compat;		/* Compatible feature set */
634 /*20*/	__le32 s_feature_incompat;	/* Incompatible feature set */
635 	__le32 s_feature_ro_compat;	/* Readonly-compatible feature set */
636 	__le64 s_root_blkno;		/* Offset, in blocks, of root directory
637 					   dinode */
638 /*30*/	__le64 s_system_dir_blkno;	/* Offset, in blocks, of system
639 					   directory dinode */
640 	__le32 s_blocksize_bits;		/* Blocksize for this fs */
641 	__le32 s_clustersize_bits;	/* Clustersize for this fs */
642 /*40*/	__le16 s_max_slots;		/* Max number of simultaneous mounts
643 					   before tunefs required */
644 	__le16 s_tunefs_flag;
645 	__le32 s_uuid_hash;		/* hash value of uuid */
646 	__le64 s_first_cluster_group;	/* Block offset of 1st cluster
647 					 * group header */
648 /*50*/	__u8  s_label[OCFS2_MAX_VOL_LABEL_LEN];	/* Label for mounting, etc. */
649 /*90*/	__u8  s_uuid[OCFS2_VOL_UUID_LEN];	/* 128-bit uuid */
650 /*A0*/  struct ocfs2_cluster_info s_cluster_info; /* Only valid if either
651 						     userspace or clusterinfo
652 						     INCOMPAT flag set. */
653 /*B8*/	__le16 s_xattr_inline_size;	/* extended attribute inline size
654 					   for this fs*/
655 	__le16 s_reserved0;
656 	__le32 s_dx_seed[3];		/* seed[0-2] for dx dir hash.
657 					 * s_uuid_hash serves as seed[3]. */
658 /*C0*/  __le64 s_reserved2[15];		/* Fill out superblock */
659 /*140*/
660 
661 	/*
662 	 * NOTE: As stated above, all offsets are relative to
663 	 * ocfs2_dinode.id2, which is at 0xC0 in the inode.
664 	 * 0xC0 + 0x140 = 0x200 or 512 bytes.  A superblock must fit within
665 	 * our smallest blocksize, which is 512 bytes.  To ensure this,
666 	 * we reserve the space in s_reserved2.  Anything past s_reserved2
667 	 * will not be available on the smallest blocksize.
668 	 */
669 };
670 
671 /*
672  * Local allocation bitmap for OCFS2 slots
673  * Note that it exists inside an ocfs2_dinode, so all offsets are
674  * relative to the start of ocfs2_dinode.id2.
675  */
676 struct ocfs2_local_alloc
677 {
678 /*00*/	__le32 la_bm_off;	/* Starting bit offset in main bitmap */
679 	__le16 la_size;		/* Size of included bitmap, in bytes */
680 	__le16 la_reserved1;
681 	__le64 la_reserved2;
682 /*10*/	__u8   la_bitmap[0];
683 };
684 
685 /*
686  * Data-in-inode header. This is only used if i_dyn_features has
687  * OCFS2_INLINE_DATA_FL set.
688  */
689 struct ocfs2_inline_data
690 {
691 /*00*/	__le16	id_count;	/* Number of bytes that can be used
692 				 * for data, starting at id_data */
693 	__le16	id_reserved0;
694 	__le32	id_reserved1;
695 	__u8	id_data[0];	/* Start of user data */
696 };
697 
698 /*
699  * On disk inode for OCFS2
700  */
701 struct ocfs2_dinode {
702 /*00*/	__u8 i_signature[8];		/* Signature for validation */
703 	__le32 i_generation;		/* Generation number */
704 	__le16 i_suballoc_slot;		/* Slot suballocator this inode
705 					   belongs to */
706 	__le16 i_suballoc_bit;		/* Bit offset in suballocator
707 					   block group */
708 /*10*/	__le16 i_links_count_hi;	/* High 16 bits of links count */
709 	__le16 i_xattr_inline_size;
710 	__le32 i_clusters;		/* Cluster count */
711 	__le32 i_uid;			/* Owner UID */
712 	__le32 i_gid;			/* Owning GID */
713 /*20*/	__le64 i_size;			/* Size in bytes */
714 	__le16 i_mode;			/* File mode */
715 	__le16 i_links_count;		/* Links count */
716 	__le32 i_flags;			/* File flags */
717 /*30*/	__le64 i_atime;			/* Access time */
718 	__le64 i_ctime;			/* Creation time */
719 /*40*/	__le64 i_mtime;			/* Modification time */
720 	__le64 i_dtime;			/* Deletion time */
721 /*50*/	__le64 i_blkno;			/* Offset on disk, in blocks */
722 	__le64 i_last_eb_blk;		/* Pointer to last extent
723 					   block */
724 /*60*/	__le32 i_fs_generation;		/* Generation per fs-instance */
725 	__le32 i_atime_nsec;
726 	__le32 i_ctime_nsec;
727 	__le32 i_mtime_nsec;
728 /*70*/	__le32 i_attr;
729 	__le16 i_orphaned_slot;		/* Only valid when OCFS2_ORPHANED_FL
730 					   was set in i_flags */
731 	__le16 i_dyn_features;
732 	__le64 i_xattr_loc;
733 /*80*/	struct ocfs2_block_check i_check;	/* Error checking */
734 /*88*/	__le64 i_dx_root;		/* Pointer to dir index root block */
735 /*90*/	__le64 i_refcount_loc;
736 	__le64 i_suballoc_loc;		/* Suballocator block group this
737 					   inode belongs to.  Only valid
738 					   if allocated from a
739 					   discontiguous block group */
740 /*A0*/	__le16 i_dio_orphaned_slot;	/* only used for append dio write */
741 	__le16 i_reserved1[3];
742 	__le64 i_reserved2[2];
743 /*B8*/	union {
744 		__le64 i_pad1;		/* Generic way to refer to this
745 					   64bit union */
746 		struct {
747 			__le64 i_rdev;	/* Device number */
748 		} dev1;
749 		struct {		/* Info for bitmap system
750 					   inodes */
751 			__le32 i_used;	/* Bits (ie, clusters) used  */
752 			__le32 i_total;	/* Total bits (clusters)
753 					   available */
754 		} bitmap1;
755 		struct {		/* Info for journal system
756 					   inodes */
757 			__le32 ij_flags;	/* Mounted, version, etc. */
758 			__le32 ij_recovery_generation; /* Incremented when the
759 							  journal is recovered
760 							  after an unclean
761 							  shutdown */
762 		} journal1;
763 	} id1;				/* Inode type dependent 1 */
764 /*C0*/	union {
765 		struct ocfs2_super_block	i_super;
766 		struct ocfs2_local_alloc	i_lab;
767 		struct ocfs2_chain_list		i_chain;
768 		struct ocfs2_extent_list	i_list;
769 		struct ocfs2_truncate_log	i_dealloc;
770 		struct ocfs2_inline_data	i_data;
771 		__u8               		i_symlink[0];
772 	} id2;
773 /* Actual on-disk size is one block */
774 };
775 
776 /*
777  * On-disk directory entry structure for OCFS2
778  *
779  * Packed as this structure could be accessed unaligned on 64-bit platforms
780  */
781 struct ocfs2_dir_entry {
782 /*00*/	__le64   inode;                  /* Inode number */
783 	__le16   rec_len;                /* Directory entry length */
784 	__u8    name_len;               /* Name length */
785 	__u8    file_type;
786 /*0C*/	char    name[OCFS2_MAX_FILENAME_LEN];   /* File name */
787 /* Actual on-disk length specified by rec_len */
788 } __attribute__ ((packed));
789 
790 /*
791  * Per-block record for the unindexed directory btree. This is carefully
792  * crafted so that the rec_len and name_len records of an ocfs2_dir_entry are
793  * mirrored. That way, the directory manipulation code needs a minimal amount
794  * of update.
795  *
796  * NOTE: Keep this structure aligned to a multiple of 4 bytes.
797  */
798 struct ocfs2_dir_block_trailer {
799 /*00*/	__le64		db_compat_inode;	/* Always zero. Was inode */
800 
801 	__le16		db_compat_rec_len;	/* Backwards compatible with
802 						 * ocfs2_dir_entry. */
803 	__u8		db_compat_name_len;	/* Always zero. Was name_len */
804 	__u8		db_reserved0;
805 	__le16		db_reserved1;
806 	__le16		db_free_rec_len;	/* Size of largest empty hole
807 						 * in this block. (unused) */
808 /*10*/	__u8		db_signature[8];	/* Signature for verification */
809 	__le64		db_reserved2;
810 /*20*/	__le64		db_free_next;		/* Next block in list (unused) */
811 	__le64		db_blkno;		/* Offset on disk, in blocks */
812 /*30*/	__le64		db_parent_dinode;	/* dinode which owns me, in
813 						   blocks */
814 	struct ocfs2_block_check db_check;	/* Error checking */
815 /*40*/
816 };
817 
818  /*
819  * A directory entry in the indexed tree. We don't store the full name here,
820  * but instead provide a pointer to the full dirent in the unindexed tree.
821  *
822  * We also store name_len here so as to reduce the number of leaf blocks we
823  * need to search in case of collisions.
824  */
825 struct ocfs2_dx_entry {
826 	__le32		dx_major_hash;	/* Used to find logical
827 					 * cluster in index */
828 	__le32		dx_minor_hash;	/* Lower bits used to find
829 					 * block in cluster */
830 	__le64		dx_dirent_blk;	/* Physical block in unindexed
831 					 * tree holding this dirent. */
832 };
833 
834 struct ocfs2_dx_entry_list {
835 	__le32		de_reserved;
836 	__le16		de_count;	/* Maximum number of entries
837 					 * possible in de_entries */
838 	__le16		de_num_used;	/* Current number of
839 					 * de_entries entries */
840 	struct	ocfs2_dx_entry		de_entries[0];	/* Indexed dir entries
841 							 * in a packed array of
842 							 * length de_num_used */
843 };
844 
845 #define OCFS2_DX_FLAG_INLINE	0x01
846 
847 /*
848  * A directory indexing block. Each indexed directory has one of these,
849  * pointed to by ocfs2_dinode.
850  *
851  * This block stores an indexed btree root, and a set of free space
852  * start-of-list pointers.
853  */
854 struct ocfs2_dx_root_block {
855 	__u8		dr_signature[8];	/* Signature for verification */
856 	struct ocfs2_block_check dr_check;	/* Error checking */
857 	__le16		dr_suballoc_slot;	/* Slot suballocator this
858 						 * block belongs to. */
859 	__le16		dr_suballoc_bit;	/* Bit offset in suballocator
860 						 * block group */
861 	__le32		dr_fs_generation;	/* Must match super block */
862 	__le64		dr_blkno;		/* Offset on disk, in blocks */
863 	__le64		dr_last_eb_blk;		/* Pointer to last
864 						 * extent block */
865 	__le32		dr_clusters;		/* Clusters allocated
866 						 * to the indexed tree. */
867 	__u8		dr_flags;		/* OCFS2_DX_FLAG_* flags */
868 	__u8		dr_reserved0;
869 	__le16		dr_reserved1;
870 	__le64		dr_dir_blkno;		/* Pointer to parent inode */
871 	__le32		dr_num_entries;		/* Total number of
872 						 * names stored in
873 						 * this directory.*/
874 	__le32		dr_reserved2;
875 	__le64		dr_free_blk;		/* Pointer to head of free
876 						 * unindexed block list. */
877 	__le64		dr_suballoc_loc;	/* Suballocator block group
878 						   this root belongs to.
879 						   Only valid if allocated
880 						   from a discontiguous
881 						   block group */
882 	__le64		dr_reserved3[14];
883 	union {
884 		struct ocfs2_extent_list dr_list; /* Keep this aligned to 128
885 						   * bits for maximum space
886 						   * efficiency. */
887 		struct ocfs2_dx_entry_list dr_entries; /* In-root-block list of
888 							* entries. We grow out
889 							* to extents if this
890 							* gets too big. */
891 	};
892 };
893 
894 /*
895  * The header of a leaf block in the indexed tree.
896  */
897 struct ocfs2_dx_leaf {
898 	__u8		dl_signature[8];/* Signature for verification */
899 	struct ocfs2_block_check dl_check;	/* Error checking */
900 	__le64		dl_blkno;	/* Offset on disk, in blocks */
901 	__le32		dl_fs_generation;/* Must match super block */
902 	__le32		dl_reserved0;
903 	__le64		dl_reserved1;
904 	struct ocfs2_dx_entry_list	dl_list;
905 };
906 
907 /*
908  * Largest bitmap for a block (suballocator) group in bytes.  This limit
909  * does not affect cluster groups (global allocator).  Cluster group
910  * bitmaps run to the end of the block.
911  */
912 #define OCFS2_MAX_BG_BITMAP_SIZE	256
913 
914 /*
915  * On disk allocator group structure for OCFS2
916  */
917 struct ocfs2_group_desc
918 {
919 /*00*/	__u8    bg_signature[8];        /* Signature for validation */
920 	__le16   bg_size;                /* Size of included bitmap in
921 					   bytes. */
922 	__le16   bg_bits;                /* Bits represented by this
923 					   group. */
924 	__le16	bg_free_bits_count;     /* Free bits count */
925 	__le16   bg_chain;               /* What chain I am in. */
926 /*10*/	__le32   bg_generation;
927 	__le32	bg_reserved1;
928 	__le64   bg_next_group;          /* Next group in my list, in
929 					   blocks */
930 /*20*/	__le64   bg_parent_dinode;       /* dinode which owns me, in
931 					   blocks */
932 	__le64   bg_blkno;               /* Offset on disk, in blocks */
933 /*30*/	struct ocfs2_block_check bg_check;	/* Error checking */
934 	__le64   bg_reserved2;
935 /*40*/	union {
936 		__u8    bg_bitmap[0];
937 		struct {
938 			/*
939 			 * Block groups may be discontiguous when
940 			 * OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG is set.
941 			 * The extents of a discontiguous block group are
942 			 * stored in bg_list.  It is a flat list.
943 			 * l_tree_depth must always be zero.  A
944 			 * discontiguous group is signified by a non-zero
945 			 * bg_list->l_next_free_rec.  Only block groups
946 			 * can be discontiguous; Cluster groups cannot.
947 			 * We've never made a block group with more than
948 			 * 2048 blocks (256 bytes of bg_bitmap).  This
949 			 * codifies that limit so that we can fit bg_list.
950 			 * bg_size of a discontiguous block group will
951 			 * be 256 to match bg_bitmap_filler.
952 			 */
953 			__u8 bg_bitmap_filler[OCFS2_MAX_BG_BITMAP_SIZE];
954 /*140*/			struct ocfs2_extent_list bg_list;
955 		};
956 	};
957 /* Actual on-disk size is one block */
958 };
959 
960 struct ocfs2_refcount_rec {
961 /*00*/	__le64 r_cpos;		/* Physical offset, in clusters */
962 	__le32 r_clusters;	/* Clusters covered by this extent */
963 	__le32 r_refcount;	/* Reference count of this extent */
964 /*10*/
965 };
966 #define OCFS2_32BIT_POS_MASK		(0xffffffffULL)
967 
968 #define OCFS2_REFCOUNT_LEAF_FL          (0x00000001)
969 #define OCFS2_REFCOUNT_TREE_FL          (0x00000002)
970 
971 struct ocfs2_refcount_list {
972 /*00*/	__le16 rl_count;	/* Maximum number of entries possible
973 				   in rl_records */
974 	__le16 rl_used;		/* Current number of used records */
975 	__le32 rl_reserved2;
976 	__le64 rl_reserved1;	/* Pad to sizeof(ocfs2_refcount_record) */
977 /*10*/	struct ocfs2_refcount_rec rl_recs[0];	/* Refcount records */
978 };
979 
980 
981 struct ocfs2_refcount_block {
982 /*00*/	__u8 rf_signature[8];		/* Signature for verification */
983 	__le16 rf_suballoc_slot;	/* Slot suballocator this block
984 					   belongs to */
985 	__le16 rf_suballoc_bit;		/* Bit offset in suballocator
986 					   block group */
987 	__le32 rf_fs_generation;	/* Must match superblock */
988 /*10*/	__le64 rf_blkno;		/* Offset on disk, in blocks */
989 	__le64 rf_parent;		/* Parent block, only valid if
990 					   OCFS2_REFCOUNT_LEAF_FL is set in
991 					   rf_flags */
992 /*20*/	struct ocfs2_block_check rf_check;	/* Error checking */
993 	__le64 rf_last_eb_blk;		/* Pointer to last extent block */
994 /*30*/	__le32 rf_count;		/* Number of inodes sharing this
995 					   refcount tree */
996 	__le32 rf_flags;		/* See the flags above */
997 	__le32 rf_clusters;		/* clusters covered by refcount tree. */
998 	__le32 rf_cpos;			/* cluster offset in refcount tree.*/
999 /*40*/	__le32 rf_generation;		/* generation number. all be the same
1000 					 * for the same refcount tree. */
1001 	__le32 rf_reserved0;
1002 	__le64 rf_suballoc_loc;		/* Suballocator block group this
1003 					   refcount block belongs to. Only
1004 					   valid if allocated from a
1005 					   discontiguous block group */
1006 /*50*/	__le64 rf_reserved1[6];
1007 /*80*/	union {
1008 		struct ocfs2_refcount_list rf_records;  /* List of refcount
1009 							  records */
1010 		struct ocfs2_extent_list rf_list;	/* Extent record list,
1011 							only valid if
1012 							OCFS2_REFCOUNT_TREE_FL
1013 							is set in rf_flags */
1014 	};
1015 /* Actual on-disk size is one block */
1016 };
1017 
1018 /*
1019  * On disk extended attribute structure for OCFS2.
1020  */
1021 
1022 /*
1023  * ocfs2_xattr_entry indicates one extend attribute.
1024  *
1025  * Note that it can be stored in inode, one block or one xattr bucket.
1026  */
1027 struct ocfs2_xattr_entry {
1028 	__le32	xe_name_hash;    /* hash value of xattr prefix+suffix. */
1029 	__le16	xe_name_offset;  /* byte offset from the 1st entry in the
1030 				    local xattr storage(inode, xattr block or
1031 				    xattr bucket). */
1032 	__u8	xe_name_len;	 /* xattr name len, doesn't include prefix. */
1033 	__u8	xe_type;         /* the low 7 bits indicate the name prefix
1034 				  * type and the highest bit indicates whether
1035 				  * the EA is stored in the local storage. */
1036 	__le64	xe_value_size;	 /* real xattr value length. */
1037 };
1038 
1039 /*
1040  * On disk structure for xattr header.
1041  *
1042  * One ocfs2_xattr_header describes how many ocfs2_xattr_entry records in
1043  * the local xattr storage.
1044  */
1045 struct ocfs2_xattr_header {
1046 	__le16	xh_count;                       /* contains the count of how
1047 						   many records are in the
1048 						   local xattr storage. */
1049 	__le16	xh_free_start;                  /* current offset for storing
1050 						   xattr. */
1051 	__le16	xh_name_value_len;              /* total length of name/value
1052 						   length in this bucket. */
1053 	__le16	xh_num_buckets;                 /* Number of xattr buckets
1054 						   in this extent record,
1055 						   only valid in the first
1056 						   bucket. */
1057 	struct ocfs2_block_check xh_check;	/* Error checking
1058 						   (Note, this is only
1059 						    used for xattr
1060 						    buckets.  A block uses
1061 						    xb_check and sets
1062 						    this field to zero.) */
1063 	struct ocfs2_xattr_entry xh_entries[0]; /* xattr entry list. */
1064 };
1065 
1066 /*
1067  * On disk structure for xattr value root.
1068  *
1069  * When an xattr's value is large enough, it is stored in an external
1070  * b-tree like file data.  The xattr value root points to this structure.
1071  */
1072 struct ocfs2_xattr_value_root {
1073 /*00*/	__le32	xr_clusters;              /* clusters covered by xattr value. */
1074 	__le32	xr_reserved0;
1075 	__le64	xr_last_eb_blk;           /* Pointer to last extent block */
1076 /*10*/	struct ocfs2_extent_list xr_list; /* Extent record list */
1077 };
1078 
1079 /*
1080  * On disk structure for xattr tree root.
1081  *
1082  * It is used when there are too many extended attributes for one file. These
1083  * attributes will be organized and stored in an indexed-btree.
1084  */
1085 struct ocfs2_xattr_tree_root {
1086 /*00*/	__le32	xt_clusters;              /* clusters covered by xattr. */
1087 	__le32	xt_reserved0;
1088 	__le64	xt_last_eb_blk;           /* Pointer to last extent block */
1089 /*10*/	struct ocfs2_extent_list xt_list; /* Extent record list */
1090 };
1091 
1092 #define OCFS2_XATTR_INDEXED	0x1
1093 #define OCFS2_HASH_SHIFT	5
1094 #define OCFS2_XATTR_ROUND	3
1095 #define OCFS2_XATTR_SIZE(size)	(((size) + OCFS2_XATTR_ROUND) & \
1096 				~(OCFS2_XATTR_ROUND))
1097 
1098 #define OCFS2_XATTR_BUCKET_SIZE			4096
1099 #define OCFS2_XATTR_MAX_BLOCKS_PER_BUCKET 	(OCFS2_XATTR_BUCKET_SIZE \
1100 						 / OCFS2_MIN_BLOCKSIZE)
1101 
1102 /*
1103  * On disk structure for xattr block.
1104  */
1105 struct ocfs2_xattr_block {
1106 /*00*/	__u8	xb_signature[8];     /* Signature for verification */
1107 	__le16	xb_suballoc_slot;    /* Slot suballocator this
1108 					block belongs to. */
1109 	__le16	xb_suballoc_bit;     /* Bit offset in suballocator
1110 					block group */
1111 	__le32	xb_fs_generation;    /* Must match super block */
1112 /*10*/	__le64	xb_blkno;            /* Offset on disk, in blocks */
1113 	struct ocfs2_block_check xb_check;	/* Error checking */
1114 /*20*/	__le16	xb_flags;            /* Indicates whether this block contains
1115 					real xattr or a xattr tree. */
1116 	__le16	xb_reserved0;
1117 	__le32  xb_reserved1;
1118 	__le64	xb_suballoc_loc;	/* Suballocator block group this
1119 					   xattr block belongs to. Only
1120 					   valid if allocated from a
1121 					   discontiguous block group */
1122 /*30*/	union {
1123 		struct ocfs2_xattr_header xb_header; /* xattr header if this
1124 							block contains xattr */
1125 		struct ocfs2_xattr_tree_root xb_root;/* xattr tree root if this
1126 							block cotains xattr
1127 							tree. */
1128 	} xb_attrs;
1129 };
1130 
1131 #define OCFS2_XATTR_ENTRY_LOCAL		0x80
1132 #define OCFS2_XATTR_TYPE_MASK		0x7F
ocfs2_xattr_set_local(struct ocfs2_xattr_entry * xe,int local)1133 static inline void ocfs2_xattr_set_local(struct ocfs2_xattr_entry *xe,
1134 					 int local)
1135 {
1136 	if (local)
1137 		xe->xe_type |= OCFS2_XATTR_ENTRY_LOCAL;
1138 	else
1139 		xe->xe_type &= ~OCFS2_XATTR_ENTRY_LOCAL;
1140 }
1141 
ocfs2_xattr_is_local(struct ocfs2_xattr_entry * xe)1142 static inline int ocfs2_xattr_is_local(struct ocfs2_xattr_entry *xe)
1143 {
1144 	return xe->xe_type & OCFS2_XATTR_ENTRY_LOCAL;
1145 }
1146 
ocfs2_xattr_set_type(struct ocfs2_xattr_entry * xe,int type)1147 static inline void ocfs2_xattr_set_type(struct ocfs2_xattr_entry *xe, int type)
1148 {
1149 	xe->xe_type |= type & OCFS2_XATTR_TYPE_MASK;
1150 }
1151 
ocfs2_xattr_get_type(struct ocfs2_xattr_entry * xe)1152 static inline int ocfs2_xattr_get_type(struct ocfs2_xattr_entry *xe)
1153 {
1154 	return xe->xe_type & OCFS2_XATTR_TYPE_MASK;
1155 }
1156 
1157 /*
1158  *  On disk structures for global quota file
1159  */
1160 
1161 /* Magic numbers and known versions for global quota files */
1162 #define OCFS2_GLOBAL_QMAGICS {\
1163 	0x0cf52470, /* USRQUOTA */ \
1164 	0x0cf52471  /* GRPQUOTA */ \
1165 }
1166 
1167 #define OCFS2_GLOBAL_QVERSIONS {\
1168 	0, \
1169 	0, \
1170 }
1171 
1172 
1173 /* Each block of each quota file has a certain fixed number of bytes reserved
1174  * for OCFS2 internal use at its end. OCFS2 can use it for things like
1175  * checksums, etc. */
1176 #define OCFS2_QBLK_RESERVED_SPACE 8
1177 
1178 /* Generic header of all quota files */
1179 struct ocfs2_disk_dqheader {
1180 	__le32 dqh_magic;	/* Magic number identifying file */
1181 	__le32 dqh_version;	/* Quota format version */
1182 };
1183 
1184 #define OCFS2_GLOBAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
1185 
1186 /* Information header of global quota file (immediately follows the generic
1187  * header) */
1188 struct ocfs2_global_disk_dqinfo {
1189 /*00*/	__le32 dqi_bgrace;	/* Grace time for space softlimit excess */
1190 	__le32 dqi_igrace;	/* Grace time for inode softlimit excess */
1191 	__le32 dqi_syncms;	/* Time after which we sync local changes to
1192 				 * global quota file */
1193 	__le32 dqi_blocks;	/* Number of blocks in quota file */
1194 /*10*/	__le32 dqi_free_blk;	/* First free block in quota file */
1195 	__le32 dqi_free_entry;	/* First block with free dquot entry in quota
1196 				 * file */
1197 };
1198 
1199 /* Structure with global user / group information. We reserve some space
1200  * for future use. */
1201 struct ocfs2_global_disk_dqblk {
1202 /*00*/	__le32 dqb_id;          /* ID the structure belongs to */
1203 	__le32 dqb_use_count;   /* Number of nodes having reference to this structure */
1204 	__le64 dqb_ihardlimit;  /* absolute limit on allocated inodes */
1205 /*10*/	__le64 dqb_isoftlimit;  /* preferred inode limit */
1206 	__le64 dqb_curinodes;   /* current # allocated inodes */
1207 /*20*/	__le64 dqb_bhardlimit;  /* absolute limit on disk space */
1208 	__le64 dqb_bsoftlimit;  /* preferred limit on disk space */
1209 /*30*/	__le64 dqb_curspace;    /* current space occupied */
1210 	__le64 dqb_btime;       /* time limit for excessive disk use */
1211 /*40*/	__le64 dqb_itime;       /* time limit for excessive inode use */
1212 	__le64 dqb_pad1;
1213 /*50*/	__le64 dqb_pad2;
1214 };
1215 
1216 /*
1217  *  On-disk structures for local quota file
1218  */
1219 
1220 /* Magic numbers and known versions for local quota files */
1221 #define OCFS2_LOCAL_QMAGICS {\
1222 	0x0cf524c0, /* USRQUOTA */ \
1223 	0x0cf524c1  /* GRPQUOTA */ \
1224 }
1225 
1226 #define OCFS2_LOCAL_QVERSIONS {\
1227 	0, \
1228 	0, \
1229 }
1230 
1231 /* Quota flags in dqinfo header */
1232 #define OLQF_CLEAN	0x0001	/* Quota file is empty (this should be after\
1233 				 * quota has been cleanly turned off) */
1234 
1235 #define OCFS2_LOCAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
1236 
1237 /* Information header of local quota file (immediately follows the generic
1238  * header) */
1239 struct ocfs2_local_disk_dqinfo {
1240 	__le32 dqi_flags;	/* Flags for quota file */
1241 	__le32 dqi_chunks;	/* Number of chunks of quota structures
1242 				 * with a bitmap */
1243 	__le32 dqi_blocks;	/* Number of blocks allocated for quota file */
1244 };
1245 
1246 /* Header of one chunk of a quota file */
1247 struct ocfs2_local_disk_chunk {
1248 	__le32 dqc_free;	/* Number of free entries in the bitmap */
1249 	__u8 dqc_bitmap[0];	/* Bitmap of entries in the corresponding
1250 				 * chunk of quota file */
1251 };
1252 
1253 /* One entry in local quota file */
1254 struct ocfs2_local_disk_dqblk {
1255 /*00*/	__le64 dqb_id;		/* id this quota applies to */
1256 	__le64 dqb_spacemod;	/* Change in the amount of used space */
1257 /*10*/	__le64 dqb_inodemod;	/* Change in the amount of used inodes */
1258 };
1259 
1260 
1261 /*
1262  * The quota trailer lives at the end of each quota block.
1263  */
1264 
1265 struct ocfs2_disk_dqtrailer {
1266 /*00*/	struct ocfs2_block_check dq_check;	/* Error checking */
1267 /*08*/	/* Cannot be larger than OCFS2_QBLK_RESERVED_SPACE */
1268 };
1269 
ocfs2_block_dqtrailer(int blocksize,void * buf)1270 static inline struct ocfs2_disk_dqtrailer *ocfs2_block_dqtrailer(int blocksize,
1271 								 void *buf)
1272 {
1273 	char *ptr = buf;
1274 	ptr += blocksize - OCFS2_QBLK_RESERVED_SPACE;
1275 
1276 	return (struct ocfs2_disk_dqtrailer *)ptr;
1277 }
1278 
1279 #ifdef __KERNEL__
ocfs2_fast_symlink_chars(struct super_block * sb)1280 static inline int ocfs2_fast_symlink_chars(struct super_block *sb)
1281 {
1282 	return  sb->s_blocksize -
1283 		 offsetof(struct ocfs2_dinode, id2.i_symlink);
1284 }
1285 
ocfs2_max_inline_data_with_xattr(struct super_block * sb,struct ocfs2_dinode * di)1286 static inline int ocfs2_max_inline_data_with_xattr(struct super_block *sb,
1287 						   struct ocfs2_dinode *di)
1288 {
1289 	unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
1290 
1291 	if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
1292 		return sb->s_blocksize -
1293 			offsetof(struct ocfs2_dinode, id2.i_data.id_data) -
1294 			xattrsize;
1295 	else
1296 		return sb->s_blocksize -
1297 			offsetof(struct ocfs2_dinode, id2.i_data.id_data);
1298 }
1299 
ocfs2_extent_recs_per_inode(struct super_block * sb)1300 static inline int ocfs2_extent_recs_per_inode(struct super_block *sb)
1301 {
1302 	int size;
1303 
1304 	size = sb->s_blocksize -
1305 		offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1306 
1307 	return size / sizeof(struct ocfs2_extent_rec);
1308 }
1309 
ocfs2_extent_recs_per_inode_with_xattr(struct super_block * sb,struct ocfs2_dinode * di)1310 static inline int ocfs2_extent_recs_per_inode_with_xattr(
1311 						struct super_block *sb,
1312 						struct ocfs2_dinode *di)
1313 {
1314 	int size;
1315 	unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
1316 
1317 	if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
1318 		size = sb->s_blocksize -
1319 			offsetof(struct ocfs2_dinode, id2.i_list.l_recs) -
1320 			xattrsize;
1321 	else
1322 		size = sb->s_blocksize -
1323 			offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1324 
1325 	return size / sizeof(struct ocfs2_extent_rec);
1326 }
1327 
ocfs2_extent_recs_per_dx_root(struct super_block * sb)1328 static inline int ocfs2_extent_recs_per_dx_root(struct super_block *sb)
1329 {
1330 	int size;
1331 
1332 	size = sb->s_blocksize -
1333 		offsetof(struct ocfs2_dx_root_block, dr_list.l_recs);
1334 
1335 	return size / sizeof(struct ocfs2_extent_rec);
1336 }
1337 
ocfs2_chain_recs_per_inode(struct super_block * sb)1338 static inline int ocfs2_chain_recs_per_inode(struct super_block *sb)
1339 {
1340 	int size;
1341 
1342 	size = sb->s_blocksize -
1343 		offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
1344 
1345 	return size / sizeof(struct ocfs2_chain_rec);
1346 }
1347 
ocfs2_extent_recs_per_eb(struct super_block * sb)1348 static inline u16 ocfs2_extent_recs_per_eb(struct super_block *sb)
1349 {
1350 	int size;
1351 
1352 	size = sb->s_blocksize -
1353 		offsetof(struct ocfs2_extent_block, h_list.l_recs);
1354 
1355 	return size / sizeof(struct ocfs2_extent_rec);
1356 }
1357 
ocfs2_extent_recs_per_gd(struct super_block * sb)1358 static inline u16 ocfs2_extent_recs_per_gd(struct super_block *sb)
1359 {
1360 	int size;
1361 
1362 	size = sb->s_blocksize -
1363 		offsetof(struct ocfs2_group_desc, bg_list.l_recs);
1364 
1365 	return size / sizeof(struct ocfs2_extent_rec);
1366 }
1367 
ocfs2_dx_entries_per_leaf(struct super_block * sb)1368 static inline int ocfs2_dx_entries_per_leaf(struct super_block *sb)
1369 {
1370 	int size;
1371 
1372 	size = sb->s_blocksize -
1373 		offsetof(struct ocfs2_dx_leaf, dl_list.de_entries);
1374 
1375 	return size / sizeof(struct ocfs2_dx_entry);
1376 }
1377 
ocfs2_dx_entries_per_root(struct super_block * sb)1378 static inline int ocfs2_dx_entries_per_root(struct super_block *sb)
1379 {
1380 	int size;
1381 
1382 	size = sb->s_blocksize -
1383 		offsetof(struct ocfs2_dx_root_block, dr_entries.de_entries);
1384 
1385 	return size / sizeof(struct ocfs2_dx_entry);
1386 }
1387 
ocfs2_local_alloc_size(struct super_block * sb)1388 static inline u16 ocfs2_local_alloc_size(struct super_block *sb)
1389 {
1390 	u16 size;
1391 
1392 	size = sb->s_blocksize -
1393 		offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
1394 
1395 	return size;
1396 }
1397 
ocfs2_group_bitmap_size(struct super_block * sb,int suballocator,u32 feature_incompat)1398 static inline int ocfs2_group_bitmap_size(struct super_block *sb,
1399 					  int suballocator,
1400 					  u32 feature_incompat)
1401 {
1402 	int size = sb->s_blocksize -
1403 		offsetof(struct ocfs2_group_desc, bg_bitmap);
1404 
1405 	/*
1406 	 * The cluster allocator uses the entire block.  Suballocators have
1407 	 * never used more than OCFS2_MAX_BG_BITMAP_SIZE.  Unfortunately, older
1408 	 * code expects bg_size set to the maximum.  Thus we must keep
1409 	 * bg_size as-is unless discontig_bg is enabled.
1410 	 */
1411 	if (suballocator &&
1412 	    (feature_incompat & OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG))
1413 		size = OCFS2_MAX_BG_BITMAP_SIZE;
1414 
1415 	return size;
1416 }
1417 
ocfs2_truncate_recs_per_inode(struct super_block * sb)1418 static inline int ocfs2_truncate_recs_per_inode(struct super_block *sb)
1419 {
1420 	int size;
1421 
1422 	size = sb->s_blocksize -
1423 		offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
1424 
1425 	return size / sizeof(struct ocfs2_truncate_rec);
1426 }
1427 
ocfs2_backup_super_blkno(struct super_block * sb,int index)1428 static inline u64 ocfs2_backup_super_blkno(struct super_block *sb, int index)
1429 {
1430 	u64 offset = OCFS2_BACKUP_SB_START;
1431 
1432 	if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
1433 		offset <<= (2 * index);
1434 		offset >>= sb->s_blocksize_bits;
1435 		return offset;
1436 	}
1437 
1438 	return 0;
1439 
1440 }
1441 
ocfs2_xattr_recs_per_xb(struct super_block * sb)1442 static inline u16 ocfs2_xattr_recs_per_xb(struct super_block *sb)
1443 {
1444 	int size;
1445 
1446 	size = sb->s_blocksize -
1447 		offsetof(struct ocfs2_xattr_block,
1448 			 xb_attrs.xb_root.xt_list.l_recs);
1449 
1450 	return size / sizeof(struct ocfs2_extent_rec);
1451 }
1452 
ocfs2_extent_recs_per_rb(struct super_block * sb)1453 static inline u16 ocfs2_extent_recs_per_rb(struct super_block *sb)
1454 {
1455 	int size;
1456 
1457 	size = sb->s_blocksize -
1458 		offsetof(struct ocfs2_refcount_block, rf_list.l_recs);
1459 
1460 	return size / sizeof(struct ocfs2_extent_rec);
1461 }
1462 
ocfs2_refcount_recs_per_rb(struct super_block * sb)1463 static inline u16 ocfs2_refcount_recs_per_rb(struct super_block *sb)
1464 {
1465 	int size;
1466 
1467 	size = sb->s_blocksize -
1468 		offsetof(struct ocfs2_refcount_block, rf_records.rl_recs);
1469 
1470 	return size / sizeof(struct ocfs2_refcount_rec);
1471 }
1472 
1473 static inline u32
ocfs2_get_ref_rec_low_cpos(const struct ocfs2_refcount_rec * rec)1474 ocfs2_get_ref_rec_low_cpos(const struct ocfs2_refcount_rec *rec)
1475 {
1476 	return le64_to_cpu(rec->r_cpos) & OCFS2_32BIT_POS_MASK;
1477 }
1478 #else
ocfs2_fast_symlink_chars(int blocksize)1479 static inline int ocfs2_fast_symlink_chars(int blocksize)
1480 {
1481 	return blocksize - offsetof(struct ocfs2_dinode, id2.i_symlink);
1482 }
1483 
ocfs2_max_inline_data_with_xattr(int blocksize,struct ocfs2_dinode * di)1484 static inline int ocfs2_max_inline_data_with_xattr(int blocksize,
1485 						   struct ocfs2_dinode *di)
1486 {
1487 	if (di && (di->i_dyn_features & OCFS2_INLINE_XATTR_FL))
1488 		return blocksize -
1489 			offsetof(struct ocfs2_dinode, id2.i_data.id_data) -
1490 			di->i_xattr_inline_size;
1491 	else
1492 		return blocksize -
1493 			offsetof(struct ocfs2_dinode, id2.i_data.id_data);
1494 }
1495 
ocfs2_extent_recs_per_inode(int blocksize)1496 static inline int ocfs2_extent_recs_per_inode(int blocksize)
1497 {
1498 	int size;
1499 
1500 	size = blocksize -
1501 		offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1502 
1503 	return size / sizeof(struct ocfs2_extent_rec);
1504 }
1505 
ocfs2_chain_recs_per_inode(int blocksize)1506 static inline int ocfs2_chain_recs_per_inode(int blocksize)
1507 {
1508 	int size;
1509 
1510 	size = blocksize -
1511 		offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
1512 
1513 	return size / sizeof(struct ocfs2_chain_rec);
1514 }
1515 
ocfs2_extent_recs_per_eb(int blocksize)1516 static inline int ocfs2_extent_recs_per_eb(int blocksize)
1517 {
1518 	int size;
1519 
1520 	size = blocksize -
1521 		offsetof(struct ocfs2_extent_block, h_list.l_recs);
1522 
1523 	return size / sizeof(struct ocfs2_extent_rec);
1524 }
1525 
ocfs2_extent_recs_per_gd(int blocksize)1526 static inline int ocfs2_extent_recs_per_gd(int blocksize)
1527 {
1528 	int size;
1529 
1530 	size = blocksize -
1531 		offsetof(struct ocfs2_group_desc, bg_list.l_recs);
1532 
1533 	return size / sizeof(struct ocfs2_extent_rec);
1534 }
1535 
ocfs2_local_alloc_size(int blocksize)1536 static inline int ocfs2_local_alloc_size(int blocksize)
1537 {
1538 	int size;
1539 
1540 	size = blocksize -
1541 		offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
1542 
1543 	return size;
1544 }
1545 
ocfs2_group_bitmap_size(int blocksize,int suballocator,uint32_t feature_incompat)1546 static inline int ocfs2_group_bitmap_size(int blocksize,
1547 					  int suballocator,
1548 					  uint32_t feature_incompat)
1549 {
1550 	int size = sb->s_blocksize -
1551 		offsetof(struct ocfs2_group_desc, bg_bitmap);
1552 
1553 	/*
1554 	 * The cluster allocator uses the entire block.  Suballocators have
1555 	 * never used more than OCFS2_MAX_BG_BITMAP_SIZE.  Unfortunately, older
1556 	 * code expects bg_size set to the maximum.  Thus we must keep
1557 	 * bg_size as-is unless discontig_bg is enabled.
1558 	 */
1559 	if (suballocator &&
1560 	    (feature_incompat & OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG))
1561 		size = OCFS2_MAX_BG_BITMAP_SIZE;
1562 
1563 	return size;
1564 }
1565 
ocfs2_truncate_recs_per_inode(int blocksize)1566 static inline int ocfs2_truncate_recs_per_inode(int blocksize)
1567 {
1568 	int size;
1569 
1570 	size = blocksize -
1571 		offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
1572 
1573 	return size / sizeof(struct ocfs2_truncate_rec);
1574 }
1575 
ocfs2_backup_super_blkno(int blocksize,int index)1576 static inline uint64_t ocfs2_backup_super_blkno(int blocksize, int index)
1577 {
1578 	uint64_t offset = OCFS2_BACKUP_SB_START;
1579 
1580 	if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
1581 		offset <<= (2 * index);
1582 		offset /= blocksize;
1583 		return offset;
1584 	}
1585 
1586 	return 0;
1587 }
1588 
ocfs2_xattr_recs_per_xb(int blocksize)1589 static inline int ocfs2_xattr_recs_per_xb(int blocksize)
1590 {
1591 	int size;
1592 
1593 	size = blocksize -
1594 		offsetof(struct ocfs2_xattr_block,
1595 			 xb_attrs.xb_root.xt_list.l_recs);
1596 
1597 	return size / sizeof(struct ocfs2_extent_rec);
1598 }
1599 #endif  /* __KERNEL__ */
1600 
1601 
ocfs2_system_inode_is_global(int type)1602 static inline int ocfs2_system_inode_is_global(int type)
1603 {
1604 	return ((type >= 0) &&
1605 		(type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE));
1606 }
1607 
ocfs2_sprintf_system_inode_name(char * buf,int len,int type,int slot)1608 static inline int ocfs2_sprintf_system_inode_name(char *buf, int len,
1609 						  int type, int slot)
1610 {
1611 	int chars;
1612 
1613         /*
1614          * Global system inodes can only have one copy.  Everything
1615          * after OCFS2_LAST_GLOBAL_SYSTEM_INODE in the system inode
1616          * list has a copy per slot.
1617          */
1618 	if (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE)
1619 		chars = snprintf(buf, len, "%s",
1620 				 ocfs2_system_inodes[type].si_name);
1621 	else
1622 		chars = snprintf(buf, len,
1623 				 ocfs2_system_inodes[type].si_name,
1624 				 slot);
1625 
1626 	return chars;
1627 }
1628 
ocfs2_set_de_type(struct ocfs2_dir_entry * de,umode_t mode)1629 static inline void ocfs2_set_de_type(struct ocfs2_dir_entry *de,
1630 				    umode_t mode)
1631 {
1632 	de->file_type = ocfs2_type_by_mode[(mode & S_IFMT)>>S_SHIFT];
1633 }
1634 
ocfs2_gd_is_discontig(struct ocfs2_group_desc * gd)1635 static inline int ocfs2_gd_is_discontig(struct ocfs2_group_desc *gd)
1636 {
1637 	if ((offsetof(struct ocfs2_group_desc, bg_bitmap) +
1638 	     le16_to_cpu(gd->bg_size)) !=
1639 	    offsetof(struct ocfs2_group_desc, bg_list))
1640 		return 0;
1641 	/*
1642 	 * Only valid to check l_next_free_rec if
1643 	 * bg_bitmap + bg_size == bg_list.
1644 	 */
1645 	if (!gd->bg_list.l_next_free_rec)
1646 		return 0;
1647 	return 1;
1648 }
1649 #endif  /* _OCFS2_FS_H */
1650 
1651