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