blob: 638d875eccc7d68df68d7a93a7395b9f520a2b31 [file] [log] [blame]
Thomas Gleixner921a3d42019-06-01 10:08:20 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Masahiro Yamadafa60ce22021-05-06 18:06:44 -07002/*
Mark Fashehccd979b2005-12-15 14:31:24 -08003 * ocfs2_fs.h
4 *
5 * On-disk structures for OCFS2.
6 *
7 * Copyright (C) 2002, 2004 Oracle. All rights reserved.
Mark Fashehccd979b2005-12-15 14:31:24 -08008 */
9
10#ifndef _OCFS2_FS_H
11#define _OCFS2_FS_H
12
Fabian Frederick62aa81d2017-07-06 15:36:10 -070013#include <linux/magic.h>
14
Mark Fashehccd979b2005-12-15 14:31:24 -080015/* 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
Mark Fashehccd979b2005-12-15 14:31:24 -080046/* 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"
Tao Ma5a7bc8e2008-08-18 17:38:46 +080051#define OCFS2_XATTR_BLOCK_SIGNATURE "XATTR01"
Mark Fasheh87d35a72008-12-10 17:36:25 -080052#define OCFS2_DIR_TRAILER_SIGNATURE "DIRTRL1"
Mark Fasheh9b7895e2008-11-12 16:27:44 -080053#define OCFS2_DX_ROOT_SIGNATURE "DXDIR01"
54#define OCFS2_DX_LEAF_SIGNATURE "DXLEAF1"
Tao Ma721f69c2009-08-18 11:17:49 +080055#define OCFS2_REFCOUNT_BLOCK_SIGNATURE "REFCNT1"
Mark Fashehccd979b2005-12-15 14:31:24 -080056
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
Joel Beckera9772182008-12-16 18:10:18 -080077#define OCFS2_FEATURE_COMPAT_SUPP (OCFS2_FEATURE_COMPAT_BACKUP_SB \
78 | OCFS2_FEATURE_COMPAT_JBD2_SB)
Mark Fashehdcd05382007-01-16 11:32:23 -080079#define OCFS2_FEATURE_INCOMPAT_SUPP (OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT \
Mark Fasheh15b1e362007-09-07 13:58:15 -070080 | OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC \
Joel Becker386a2ef2008-02-01 12:06:54 -080081 | OCFS2_FEATURE_INCOMPAT_INLINE_DATA \
Joel Beckerb61817e2008-02-01 15:08:23 -080082 | OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP \
Tiger Yang8154da32008-08-18 17:11:46 +080083 | OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK \
Joel Becker9d28cfb2008-10-16 17:53:29 -070084 | OCFS2_FEATURE_INCOMPAT_XATTR \
Mark Fasheh3a8df2b2008-11-24 17:14:09 -080085 | OCFS2_FEATURE_INCOMPAT_META_ECC \
Tao Ma64871b82009-08-18 11:48:02 +080086 | OCFS2_FEATURE_INCOMPAT_INDEXED_DIRS \
Tao Ma1a934c32010-03-18 15:54:22 +080087 | OCFS2_FEATURE_INCOMPAT_REFCOUNT_TREE \
Sunil Mushran98f486f22010-10-09 10:24:46 -070088 | OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG \
Mark Fasheh18d585f2015-03-12 16:25:46 -070089 | OCFS2_FEATURE_INCOMPAT_CLUSTERINFO \
90 | OCFS2_FEATURE_INCOMPAT_APPEND_DIO)
Jan Kara19ece542008-08-21 20:13:17 +020091#define OCFS2_FEATURE_RO_COMPAT_SUPP (OCFS2_FEATURE_RO_COMPAT_UNWRITTEN \
92 | OCFS2_FEATURE_RO_COMPAT_USRQUOTA \
Mark Fasheh18d585f2015-03-12 16:25:46 -070093 | OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)
Mark Fashehccd979b2005-12-15 14:31:24 -080094
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
Mark Fasheh89039012006-12-07 18:05:37 -0800102/*
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
Mark Fashehccd979b2005-12-15 14:31:24 -0800108
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800109/* Used to denote a non-clustered volume */
110#define OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT 0x0008
111
Mark Fasheh89039012006-12-07 18:05:37 -0800112/* Support for sparse allocation in b-trees */
113#define OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC 0x0010
114
Mark Fashehccd979b2005-12-15 14:31:24 -0800115/*
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700116 * 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
Mark Fasheh15b1e362007-09-07 13:58:15 -0700126/* Support for data packed into inode blocks */
127#define OCFS2_FEATURE_INCOMPAT_INLINE_DATA 0x0040
128
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700129/*
Joel Beckerb61817e2008-02-01 15:08:23 -0800130 * 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
Tiger Yang8154da32008-08-18 17:11:46 +0800140/* 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
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800146/* Support for indexed directores */
147#define OCFS2_FEATURE_INCOMPAT_INDEXED_DIRS 0x0400
148
Joel Beckerab552d52008-10-16 17:50:30 -0700149/* Metadata checksum and error correction */
150#define OCFS2_FEATURE_INCOMPAT_META_ECC 0x0800
151
Tao Ma721f69c2009-08-18 11:17:49 +0800152/* Refcount tree support */
153#define OCFS2_FEATURE_INCOMPAT_REFCOUNT_TREE 0x1000
154
Masahiro Yamadae1c05062015-07-07 10:14:59 +0900155/* Discontiguous block groups */
Joel Becker4cbe4242010-04-13 14:26:12 +0800156#define OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG 0x2000
157
Joel Beckerb61817e2008-02-01 15:08:23 -0800158/*
Sunil Mushran98f486f22010-10-09 10:24:46 -0700159 * 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/*
Mark Fasheh18d585f2015-03-12 16:25:46 -0700166 * Append Direct IO support
167 */
168#define OCFS2_FEATURE_INCOMPAT_APPEND_DIO 0x8000
169
170/*
Mark Fasheh50af94b2007-01-21 14:44:59 -0800171 * backup superblock flag is used to indicate that this volume
172 * has backup superblocks.
173 */
174#define OCFS2_FEATURE_COMPAT_BACKUP_SB 0x0001
175
Mark Fasheh328d5752007-06-18 10:48:04 -0700176/*
Joel Beckera9772182008-12-16 18:10:18 -0800177 * The filesystem will correctly handle journal feature bits.
178 */
179#define OCFS2_FEATURE_COMPAT_JBD2_SB 0x0002
180
181/*
Mark Fasheh328d5752007-06-18 10:48:04 -0700182 * Unwritten extents support.
183 */
184#define OCFS2_FEATURE_RO_COMPAT_UNWRITTEN 0x0001
185
Jan Kara1a224ad2008-08-20 15:43:36 +0200186/*
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
Joseph Qi160cc262015-02-16 16:00:15 -0800192
Mark Fasheh50af94b2007-01-21 14:44:59 -0800193/* 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/*
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700202 * Flags on ocfs2_super_block.s_tunefs_flags
203 */
204#define OCFS2_TUNEFS_INPROG_REMOVE_SLOT 0x0001 /* Removing slots */
205
206/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800207 * 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 */
Jan Kara1a224ad2008-08-20 15:43:36 +0200222#define OCFS2_QUOTA_FL (0x00001000) /* Quota file */
Joseph Qi06ee5c72015-02-16 15:59:54 -0800223#define OCFS2_DIO_ORPHANED_FL (0X00002000) /* On the orphan list especially
224 * for dio */
Mark Fashehccd979b2005-12-15 14:31:24 -0800225
Mark Fasheh15b1e362007-09-07 13:58:15 -0700226/*
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)
Tao Ma721f69c2009-08-18 11:17:49 +0800236#define OCFS2_HAS_REFCOUNT_FL (0x0010)
Mark Fasheh15b1e362007-09-07 13:58:15 -0700237
Herbert Poetzlca4d1472006-07-03 17:27:12 -0700238/* Inode attributes, keep in sync with EXT2 */
Tao Ma0000b862010-09-19 13:42:29 +0800239#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 */
Herbert Poetzlca4d1472006-07-03 17:27:12 -0700261
Tao Ma0000b862010-09-19 13:42:29 +0800262#define OCFS2_FL_VISIBLE FS_FL_USER_VISIBLE /* User visible flags */
263#define OCFS2_FL_MODIFIABLE FS_FL_USER_MODIFIABLE /* User modifiable flags */
Herbert Poetzlca4d1472006-07-03 17:27:12 -0700264
265/*
Mark Fashehe48edee2007-03-07 16:46:57 -0800266 * Extent record flags (e_node.leaf.flags)
267 */
Tao Ma721f69c2009-08-18 11:17:49 +0800268#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 */
Mark Fashehe48edee2007-03-07 16:46:57 -0800273
274/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800275 * 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 */
Junxiao Bi9277f832020-06-25 20:29:40 -0700291#define OCFS2_INVALID_SLOT ((u16)-1)
Mark Fashehccd979b2005-12-15 14:31:24 -0800292
293#define OCFS2_VOL_UUID_LEN 16
294#define OCFS2_MAX_VOL_LABEL_LEN 64
295
Sunil Mushran98f486f22010-10-09 10:24:46 -0700296/* The cluster stack fields */
Joel Beckerb61817e2008-02-01 15:08:23 -0800297#define OCFS2_STACK_LABEL_LEN 4
298#define OCFS2_CLUSTER_NAME_LEN 16
299
Sunil Mushran98f486f22010-10-09 10:24:46 -0700300/* Classic (historically speaking) cluster stack */
301#define OCFS2_CLASSIC_CLUSTER_STACK "o2cb"
302
Mark Fashehccd979b2005-12-15 14:31:24 -0800303/* Journal limits (in bytes) */
304#define OCFS2_MIN_JOURNAL_SIZE (4 * 1024 * 1024)
Mark Fashehccd979b2005-12-15 14:31:24 -0800305
Sunil Mushran2fbe8d12007-12-20 14:58:11 -0800306/*
Tiger Yangfdd77702008-08-18 17:08:55 +0800307 * 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
Sunil Mushran98f486f22010-10-09 10:24:46 -0700312/*
313 * Cluster info flags (ocfs2_cluster_info.ci_stackflags)
314 */
315#define OCFS2_CLUSTER_O2CB_GLOBAL_HEARTBEAT (0x01)
316
Mark Fashehccd979b2005-12-15 14:31:24 -0800317struct 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,
Junxiao Bi7569d3c2020-06-25 20:29:33 -0700327#define OCFS2_FIRST_ONLINE_SYSTEM_INODE GLOBAL_INODE_ALLOC_SYSTEM_INODE
Mark Fashehccd979b2005-12-15 14:31:24 -0800328 SLOT_MAP_SYSTEM_INODE,
Mark Fashehccd979b2005-12-15 14:31:24 -0800329 HEARTBEAT_SYSTEM_INODE,
330 GLOBAL_BITMAP_SYSTEM_INODE,
Jan Kara1a224ad2008-08-20 15:43:36 +0200331 USER_QUOTA_SYSTEM_INODE,
332 GROUP_QUOTA_SYSTEM_INODE,
333#define OCFS2_LAST_GLOBAL_SYSTEM_INODE GROUP_QUOTA_SYSTEM_INODE
Tao Mab4d693f2010-08-16 16:58:21 +0800334#define OCFS2_FIRST_LOCAL_SYSTEM_INODE ORPHAN_DIR_SYSTEM_INODE
Mark Fashehccd979b2005-12-15 14:31:24 -0800335 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,
Jan Kara1a224ad2008-08-20 15:43:36 +0200341 LOCAL_USER_QUOTA_SYSTEM_INODE,
342 LOCAL_GROUP_QUOTA_SYSTEM_INODE,
Tao Mab4d693f2010-08-16 16:58:21 +0800343#define OCFS2_LAST_LOCAL_SYSTEM_INODE LOCAL_GROUP_QUOTA_SYSTEM_INODE
Mark Fashehccd979b2005-12-15 14:31:24 -0800344 NUM_SYSTEM_INODES
345};
Tao Ma7d8f9872010-12-22 17:50:30 +0800346#define NUM_GLOBAL_SYSTEM_INODES OCFS2_FIRST_LOCAL_SYSTEM_INODE
Tao Mab4d693f2010-08-16 16:58:21 +0800347#define NUM_LOCAL_SYSTEM_INODES \
348 (NUM_SYSTEM_INODES - OCFS2_FIRST_LOCAL_SYSTEM_INODE)
Mark Fashehccd979b2005-12-15 14:31:24 -0800349
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 },
Jan Kara1a224ad2008-08-20 15:43:36 +0200360 [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 },
Mark Fashehccd979b2005-12-15 14:31:24 -0800362
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 },
Jan Kara1a224ad2008-08-20 15:43:36 +0200369 [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 },
Mark Fashehccd979b2005-12-15 14:31:24 -0800372};
373
374/* Parameter passed from mount.ocfs2 to module */
375#define OCFS2_HB_NONE "heartbeat=none"
376#define OCFS2_HB_LOCAL "heartbeat=local"
Sunil Mushran2c442712010-10-07 15:23:50 -0700377#define OCFS2_HB_GLOBAL "heartbeat=global"
Mark Fashehccd979b2005-12-15 14:31:24 -0800378
379/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800380 * 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)
Mark Fashehe7c17e42009-01-29 18:17:46 -0800390#define OCFS2_DIR_MIN_REC_LEN OCFS2_DIR_REC_LEN(1)
Mark Fashehccd979b2005-12-15 14:31:24 -0800391
392#define OCFS2_LINK_MAX 32000
Mark Fasheh198a1ca2008-11-20 17:54:57 -0800393#define OCFS2_DX_LINK_MAX ((1U << 31) - 1U)
394#define OCFS2_LINKS_HI_SHIFT 16
Mark Fashehe3a93c22009-02-17 15:29:35 -0800395#define OCFS2_DX_ENTRIES_MAX (0xffffffffU)
Mark Fashehccd979b2005-12-15 14:31:24 -0800396
Mark Fashehccd979b2005-12-15 14:31:24 -0800397
398/*
399 * Convenience casts
400 */
401#define OCFS2_RAW_SB(dinode) (&((dinode)->id2.i_super))
402
403/*
Joel Beckerab552d52008-10-16 17:50:30 -0700404 * 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.
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300411 This is a simple Hamming code dependent
Joel Beckerab552d52008-10-16 17:50:30 -0700412 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/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800420 * On disk extent record for OCFS2
421 * It describes a range of clusters on disk.
Mark Fashehe48edee2007-03-07 16:46:57 -0800422 *
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.
Mark Fashehccd979b2005-12-15 14:31:24 -0800425 */
426struct ocfs2_extent_rec {
427/*00*/ __le32 e_cpos; /* Offset into the file, in clusters */
Mark Fashehe48edee2007-03-07 16:46:57 -0800428 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 };
Mark Fashehccd979b2005-12-15 14:31:24 -0800437 __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
Mark Fashehdcd05382007-01-16 11:32:23 -0800462 header (a leaf)
463 NOTE: The high 8 bits cannot be
464 used - tree_depth is never that big.
465 */
Mark Fashehccd979b2005-12-15 14:31:24 -0800466 __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) */
Gustavo A. R. Silva95f34272020-04-01 21:03:58 -0700471/*10*/ struct ocfs2_extent_rec l_recs[]; /* Extent records */
Mark Fashehccd979b2005-12-15 14:31:24 -0800472};
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;
Gustavo A. R. Silva95f34272020-04-01 21:03:58 -0700485/*10*/ struct ocfs2_chain_rec cl_recs[]; /* Chain records */
Mark Fashehccd979b2005-12-15 14:31:24 -0800486};
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;
Gustavo A. R. Silva95f34272020-04-01 21:03:58 -0700497/*08*/ struct ocfs2_truncate_rec tl_recs[]; /* Truncate records */
Mark Fashehccd979b2005-12-15 14:31:24 -0800498};
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 */
Joel Beckerab552d52008-10-16 17:50:30 -0700506 struct ocfs2_block_check h_check; /* Error checking */
Mark Fashehccd979b2005-12-15 14:31:24 -0800507/*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 */
Joel Becker9cbc0122010-03-26 10:07:42 +0800513/*20*/ __le64 h_suballoc_loc; /* Suballocator block group this
514 eb belongs to. Only valid
515 if allocated from a
516 discontiguous block group */
Mark Fashehccd979b2005-12-15 14:31:24 -0800517 __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/*
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800525 * On disk slot map for OCFS2. This defines the contents of the "slot_map"
Joel Becker386a2ef2008-02-01 12:06:54 -0800526 * 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.
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800528 */
529struct ocfs2_slot_map {
530/*00*/ __le16 sm_slots[0];
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
Joel Becker386a2ef2008-02-01 12:06:54 -0800537struct ocfs2_extended_slot {
538/*00*/ __u8 es_valid;
539 __u8 es_reserved1[3];
540 __le32 es_node_num;
Guozhonghua8ba44222016-05-19 17:09:44 -0700541/*08*/
Joel Becker386a2ef2008-02-01 12:06:54 -0800542};
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*/ struct ocfs2_extended_slot se_slots[0];
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
Sunil Mushran98f486f22010-10-09 10:24:46 -0700558/*
559 * ci_stackflags is only valid if the incompat bit
560 * OCFS2_FEATURE_INCOMPAT_CLUSTERINFO is set.
561 */
Joel Beckerb61817e2008-02-01 15:08:23 -0800562struct ocfs2_cluster_info {
563/*00*/ __u8 ci_stack[OCFS2_STACK_LABEL_LEN];
Sunil Mushran98f486f22010-10-09 10:24:46 -0700564 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 };
Joel Beckerb61817e2008-02-01 15:08:23 -0800573/*08*/ __u8 ci_cluster[OCFS2_CLUSTER_NAME_LEN];
574/*18*/
575};
576
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800577/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800578 * 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 */
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700603 __le16 s_tunefs_flag;
Tiger Yangcf1d6c72008-08-18 17:11:00 +0800604 __le32 s_uuid_hash; /* hash value of uuid */
Mark Fashehccd979b2005-12-15 14:31:24 -0800605 __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 */
Sunil Mushran98f486f22010-10-09 10:24:46 -0700609/*A0*/ struct ocfs2_cluster_info s_cluster_info; /* Only valid if either
610 userspace or clusterinfo
611 INCOMPAT flag set. */
Tiger Yang8154da32008-08-18 17:11:46 +0800612/*B8*/ __le16 s_xattr_inline_size; /* extended attribute inline size
613 for this fs*/
614 __le16 s_reserved0;
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800615 __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 */
Joel Beckerb61817e2008-02-01 15:08:23 -0800618/*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 */
Mark Fashehccd979b2005-12-15 14:31:24 -0800628};
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;
Gustavo A. R. Silva95f34272020-04-01 21:03:58 -0700641/*10*/ __u8 la_bitmap[];
Mark Fashehccd979b2005-12-15 14:31:24 -0800642};
643
644/*
Mark Fasheh15b1e362007-09-07 13:58:15 -0700645 * 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;
Gustavo A. R. Silva95f34272020-04-01 21:03:58 -0700654 __u8 id_data[]; /* Start of user data */
Mark Fasheh15b1e362007-09-07 13:58:15 -0700655};
656
657/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800658 * 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 */
Mark Fasheh198a1ca2008-11-20 17:54:57 -0800667/*10*/ __le16 i_links_count_hi; /* High 16 bits of links count */
Tiger Yangfdd77702008-08-18 17:08:55 +0800668 __le16 i_xattr_inline_size;
Mark Fashehccd979b2005-12-15 14:31:24 -0800669 __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;
Tiger Yangfdd77702008-08-18 17:08:55 +0800687/*70*/ __le32 i_attr;
Tiger Yang50008632007-03-20 16:01:38 -0700688 __le16 i_orphaned_slot; /* Only valid when OCFS2_ORPHANED_FL
689 was set in i_flags */
Mark Fasheh15b1e362007-09-07 13:58:15 -0700690 __le16 i_dyn_features;
Tiger Yangfdd77702008-08-18 17:08:55 +0800691 __le64 i_xattr_loc;
Joel Beckerab552d52008-10-16 17:50:30 -0700692/*80*/ struct ocfs2_block_check i_check; /* Error checking */
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800693/*88*/ __le64 i_dx_root; /* Pointer to dir index root block */
Tao Ma721f69c2009-08-18 11:17:49 +0800694/*90*/ __le64 i_refcount_loc;
Joel Becker9cbc0122010-03-26 10:07:42 +0800695 __le64 i_suballoc_loc; /* Suballocator block group this
696 inode belongs to. Only valid
697 if allocated from a
698 discontiguous block group */
Joseph Qi06ee5c72015-02-16 15:59:54 -0800699/*A0*/ __le16 i_dio_orphaned_slot; /* only used for append dio write */
700 __le16 i_reserved1[3];
701 __le64 i_reserved2[2];
Mark Fashehccd979b2005-12-15 14:31:24 -0800702/*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. */
Sunil Mushranc69991a2008-07-14 17:31:09 -0700717 __le32 ij_recovery_generation; /* Incremented when the
718 journal is recovered
719 after an unclean
720 shutdown */
Mark Fashehccd979b2005-12-15 14:31:24 -0800721 } journal1;
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300722 } id1; /* Inode type dependent 1 */
Mark Fashehccd979b2005-12-15 14:31:24 -0800723/*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;
Mark Fasheh15b1e362007-09-07 13:58:15 -0700729 struct ocfs2_inline_data i_data;
Mark Fashehccd979b2005-12-15 14:31:24 -0800730 __u8 i_symlink[0];
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/*
Mark Fasheh87d35a72008-12-10 17:36:25 -0800750 * 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;
Guozhonghuaf3797d82018-06-07 17:04:51 -0700769/*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
Mark Fasheh87d35a72008-12-10 17:36:25 -0800772 blocks */
Guozhonghuaf3797d82018-06-07 17:04:51 -0700773 struct ocfs2_block_check db_check; /* Error checking */
Mark Fasheh87d35a72008-12-10 17:36:25 -0800774/*40*/
775};
776
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800777 /*
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 */
Gustavo A. R. Silva95f34272020-04-01 21:03:58 -0700799 struct ocfs2_dx_entry de_entries[]; /* Indexed dir entries
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800800 * in a packed array of
801 * length de_num_used */
802};
803
Mark Fasheh4ed8a6b2008-11-24 17:02:08 -0800804#define OCFS2_DX_FLAG_INLINE 0x01
805
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800806/*
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. */
Mark Fasheh4ed8a6b2008-11-24 17:02:08 -0800826 __u8 dr_flags; /* OCFS2_DX_FLAG_* flags */
827 __u8 dr_reserved0;
828 __le16 dr_reserved1;
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800829 __le64 dr_dir_blkno; /* Pointer to parent inode */
Mark Fashehe3a93c22009-02-17 15:29:35 -0800830 __le32 dr_num_entries; /* Total number of
831 * names stored in
832 * this directory.*/
833 __le32 dr_reserved2;
Mark Fashehe7c17e42009-01-29 18:17:46 -0800834 __le64 dr_free_blk; /* Pointer to head of free
835 * unindexed block list. */
Joel Becker9cbc0122010-03-26 10:07:42 +0800836 __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];
Mark Fasheh4ed8a6b2008-11-24 17:02:08 -0800842 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 };
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800851};
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
Mark Fasheh87d35a72008-12-10 17:36:25 -0800866/*
Joel Becker4cbe4242010-04-13 14:26:12 +0800867 * 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/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800874 * 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 __le32 bg_reserved1;
887 __le64 bg_next_group; /* Next group in my list, in
888 blocks */
889/*20*/ __le64 bg_parent_dinode; /* dinode which owns me, in
890 blocks */
891 __le64 bg_blkno; /* Offset on disk, in blocks */
Joel Beckerab552d52008-10-16 17:50:30 -0700892/*30*/ struct ocfs2_block_check bg_check; /* Error checking */
893 __le64 bg_reserved2;
Joel Becker4cbe4242010-04-13 14:26:12 +0800894/*40*/ union {
895 __u8 bg_bitmap[0];
896 struct {
897 /*
898 * Block groups may be discontiguous when
899 * OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG is set.
Masahiro Yamadae1c05062015-07-07 10:14:59 +0900900 * The extents of a discontiguous block group are
Joel Becker4cbe4242010-04-13 14:26:12 +0800901 * stored in bg_list. It is a flat list.
902 * l_tree_depth must always be zero. A
903 * discontiguous group is signified by a non-zero
904 * bg_list->l_next_free_rec. Only block groups
905 * can be discontiguous; Cluster groups cannot.
906 * We've never made a block group with more than
907 * 2048 blocks (256 bytes of bg_bitmap). This
908 * codifies that limit so that we can fit bg_list.
909 * bg_size of a discontiguous block group will
910 * be 256 to match bg_bitmap_filler.
911 */
912 __u8 bg_bitmap_filler[OCFS2_MAX_BG_BITMAP_SIZE];
913/*140*/ struct ocfs2_extent_list bg_list;
914 };
915 };
916/* Actual on-disk size is one block */
Mark Fashehccd979b2005-12-15 14:31:24 -0800917};
918
Tao Ma721f69c2009-08-18 11:17:49 +0800919struct ocfs2_refcount_rec {
920/*00*/ __le64 r_cpos; /* Physical offset, in clusters */
921 __le32 r_clusters; /* Clusters covered by this extent */
922 __le32 r_refcount; /* Reference count of this extent */
923/*10*/
924};
Tao Mae73a8192009-08-11 14:33:14 +0800925#define OCFS2_32BIT_POS_MASK (0xffffffffULL)
Tao Ma721f69c2009-08-18 11:17:49 +0800926
927#define OCFS2_REFCOUNT_LEAF_FL (0x00000001)
928#define OCFS2_REFCOUNT_TREE_FL (0x00000002)
929
930struct ocfs2_refcount_list {
931/*00*/ __le16 rl_count; /* Maximum number of entries possible
932 in rl_records */
933 __le16 rl_used; /* Current number of used records */
934 __le32 rl_reserved2;
935 __le64 rl_reserved1; /* Pad to sizeof(ocfs2_refcount_record) */
Gustavo A. R. Silva95f34272020-04-01 21:03:58 -0700936/*10*/ struct ocfs2_refcount_rec rl_recs[]; /* Refcount records */
Tao Ma721f69c2009-08-18 11:17:49 +0800937};
938
939
940struct ocfs2_refcount_block {
941/*00*/ __u8 rf_signature[8]; /* Signature for verification */
942 __le16 rf_suballoc_slot; /* Slot suballocator this block
943 belongs to */
944 __le16 rf_suballoc_bit; /* Bit offset in suballocator
945 block group */
946 __le32 rf_fs_generation; /* Must match superblock */
947/*10*/ __le64 rf_blkno; /* Offset on disk, in blocks */
948 __le64 rf_parent; /* Parent block, only valid if
949 OCFS2_REFCOUNT_LEAF_FL is set in
950 rf_flags */
951/*20*/ struct ocfs2_block_check rf_check; /* Error checking */
952 __le64 rf_last_eb_blk; /* Pointer to last extent block */
953/*30*/ __le32 rf_count; /* Number of inodes sharing this
954 refcount tree */
955 __le32 rf_flags; /* See the flags above */
956 __le32 rf_clusters; /* clusters covered by refcount tree. */
957 __le32 rf_cpos; /* cluster offset in refcount tree.*/
958/*40*/ __le32 rf_generation; /* generation number. all be the same
959 * for the same refcount tree. */
960 __le32 rf_reserved0;
Joel Becker9cbc0122010-03-26 10:07:42 +0800961 __le64 rf_suballoc_loc; /* Suballocator block group this
962 refcount block belongs to. Only
963 valid if allocated from a
964 discontiguous block group */
965/*50*/ __le64 rf_reserved1[6];
Tao Ma721f69c2009-08-18 11:17:49 +0800966/*80*/ union {
967 struct ocfs2_refcount_list rf_records; /* List of refcount
968 records */
969 struct ocfs2_extent_list rf_list; /* Extent record list,
970 only valid if
971 OCFS2_REFCOUNT_TREE_FL
972 is set in rf_flags */
973 };
974/* Actual on-disk size is one block */
975};
976
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800977/*
978 * On disk extended attribute structure for OCFS2.
979 */
980
981/*
982 * ocfs2_xattr_entry indicates one extend attribute.
983 *
984 * Note that it can be stored in inode, one block or one xattr bucket.
985 */
986struct ocfs2_xattr_entry {
987 __le32 xe_name_hash; /* hash value of xattr prefix+suffix. */
Tao Ma8573f792008-10-24 22:24:17 +0800988 __le16 xe_name_offset; /* byte offset from the 1st entry in the
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800989 local xattr storage(inode, xattr block or
990 xattr bucket). */
Lucas De Marchie9c54992011-04-26 23:28:26 -0700991 __u8 xe_name_len; /* xattr name len, doesn't include prefix. */
Tao Ma8573f792008-10-24 22:24:17 +0800992 __u8 xe_type; /* the low 7 bits indicate the name prefix
993 * type and the highest bit indicates whether
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800994 * the EA is stored in the local storage. */
995 __le64 xe_value_size; /* real xattr value length. */
996};
997
998/*
999 * On disk structure for xattr header.
1000 *
1001 * One ocfs2_xattr_header describes how many ocfs2_xattr_entry records in
1002 * the local xattr storage.
1003 */
1004struct ocfs2_xattr_header {
1005 __le16 xh_count; /* contains the count of how
1006 many records are in the
1007 local xattr storage. */
Tao Ma0c044f02008-08-18 17:38:50 +08001008 __le16 xh_free_start; /* current offset for storing
1009 xattr. */
1010 __le16 xh_name_value_len; /* total length of name/value
1011 length in this bucket. */
Tao Ma8573f792008-10-24 22:24:17 +08001012 __le16 xh_num_buckets; /* Number of xattr buckets
1013 in this extent record,
1014 only valid in the first
1015 bucket. */
Joel Beckerab552d52008-10-16 17:50:30 -07001016 struct ocfs2_block_check xh_check; /* Error checking
1017 (Note, this is only
1018 used for xattr
1019 buckets. A block uses
1020 xb_check and sets
1021 this field to zero.) */
Gustavo A. R. Silva95f34272020-04-01 21:03:58 -07001022 struct ocfs2_xattr_entry xh_entries[]; /* xattr entry list. */
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001023};
1024
1025/*
1026 * On disk structure for xattr value root.
1027 *
Tao Ma8573f792008-10-24 22:24:17 +08001028 * When an xattr's value is large enough, it is stored in an external
1029 * b-tree like file data. The xattr value root points to this structure.
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001030 */
1031struct ocfs2_xattr_value_root {
1032/*00*/ __le32 xr_clusters; /* clusters covered by xattr value. */
1033 __le32 xr_reserved0;
1034 __le64 xr_last_eb_blk; /* Pointer to last extent block */
1035/*10*/ struct ocfs2_extent_list xr_list; /* Extent record list */
1036};
1037
1038/*
1039 * On disk structure for xattr tree root.
1040 *
1041 * It is used when there are too many extended attributes for one file. These
1042 * attributes will be organized and stored in an indexed-btree.
1043 */
1044struct ocfs2_xattr_tree_root {
1045/*00*/ __le32 xt_clusters; /* clusters covered by xattr. */
1046 __le32 xt_reserved0;
1047 __le64 xt_last_eb_blk; /* Pointer to last extent block */
1048/*10*/ struct ocfs2_extent_list xt_list; /* Extent record list */
1049};
1050
Tiger Yangcf1d6c72008-08-18 17:11:00 +08001051#define OCFS2_XATTR_INDEXED 0x1
1052#define OCFS2_HASH_SHIFT 5
1053#define OCFS2_XATTR_ROUND 3
1054#define OCFS2_XATTR_SIZE(size) (((size) + OCFS2_XATTR_ROUND) & \
1055 ~(OCFS2_XATTR_ROUND))
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001056
Tao Ma0c044f02008-08-18 17:38:50 +08001057#define OCFS2_XATTR_BUCKET_SIZE 4096
1058#define OCFS2_XATTR_MAX_BLOCKS_PER_BUCKET (OCFS2_XATTR_BUCKET_SIZE \
1059 / OCFS2_MIN_BLOCKSIZE)
1060
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001061/*
1062 * On disk structure for xattr block.
1063 */
1064struct ocfs2_xattr_block {
1065/*00*/ __u8 xb_signature[8]; /* Signature for verification */
1066 __le16 xb_suballoc_slot; /* Slot suballocator this
1067 block belongs to. */
1068 __le16 xb_suballoc_bit; /* Bit offset in suballocator
1069 block group */
1070 __le32 xb_fs_generation; /* Must match super block */
1071/*10*/ __le64 xb_blkno; /* Offset on disk, in blocks */
Joel Beckerab552d52008-10-16 17:50:30 -07001072 struct ocfs2_block_check xb_check; /* Error checking */
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001073/*20*/ __le16 xb_flags; /* Indicates whether this block contains
1074 real xattr or a xattr tree. */
1075 __le16 xb_reserved0;
1076 __le32 xb_reserved1;
Joel Becker9cbc0122010-03-26 10:07:42 +08001077 __le64 xb_suballoc_loc; /* Suballocator block group this
1078 xattr block belongs to. Only
1079 valid if allocated from a
1080 discontiguous block group */
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001081/*30*/ union {
1082 struct ocfs2_xattr_header xb_header; /* xattr header if this
1083 block contains xattr */
1084 struct ocfs2_xattr_tree_root xb_root;/* xattr tree root if this
1085 block cotains xattr
1086 tree. */
1087 } xb_attrs;
1088};
1089
1090#define OCFS2_XATTR_ENTRY_LOCAL 0x80
1091#define OCFS2_XATTR_TYPE_MASK 0x7F
1092static inline void ocfs2_xattr_set_local(struct ocfs2_xattr_entry *xe,
1093 int local)
1094{
1095 if (local)
1096 xe->xe_type |= OCFS2_XATTR_ENTRY_LOCAL;
1097 else
1098 xe->xe_type &= ~OCFS2_XATTR_ENTRY_LOCAL;
1099}
1100
1101static inline int ocfs2_xattr_is_local(struct ocfs2_xattr_entry *xe)
1102{
1103 return xe->xe_type & OCFS2_XATTR_ENTRY_LOCAL;
1104}
1105
1106static inline void ocfs2_xattr_set_type(struct ocfs2_xattr_entry *xe, int type)
1107{
1108 xe->xe_type |= type & OCFS2_XATTR_TYPE_MASK;
1109}
1110
1111static inline int ocfs2_xattr_get_type(struct ocfs2_xattr_entry *xe)
1112{
1113 return xe->xe_type & OCFS2_XATTR_TYPE_MASK;
1114}
1115
Jan Kara9e33d692008-08-25 19:56:50 +02001116/*
1117 * On disk structures for global quota file
1118 */
1119
1120/* Magic numbers and known versions for global quota files */
1121#define OCFS2_GLOBAL_QMAGICS {\
1122 0x0cf52470, /* USRQUOTA */ \
1123 0x0cf52471 /* GRPQUOTA */ \
1124}
1125
1126#define OCFS2_GLOBAL_QVERSIONS {\
1127 0, \
1128 0, \
1129}
1130
1131
1132/* Each block of each quota file has a certain fixed number of bytes reserved
1133 * for OCFS2 internal use at its end. OCFS2 can use it for things like
1134 * checksums, etc. */
1135#define OCFS2_QBLK_RESERVED_SPACE 8
1136
1137/* Generic header of all quota files */
1138struct ocfs2_disk_dqheader {
1139 __le32 dqh_magic; /* Magic number identifying file */
1140 __le32 dqh_version; /* Quota format version */
1141};
1142
1143#define OCFS2_GLOBAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
1144
1145/* Information header of global quota file (immediately follows the generic
1146 * header) */
1147struct ocfs2_global_disk_dqinfo {
1148/*00*/ __le32 dqi_bgrace; /* Grace time for space softlimit excess */
1149 __le32 dqi_igrace; /* Grace time for inode softlimit excess */
1150 __le32 dqi_syncms; /* Time after which we sync local changes to
1151 * global quota file */
1152 __le32 dqi_blocks; /* Number of blocks in quota file */
1153/*10*/ __le32 dqi_free_blk; /* First free block in quota file */
1154 __le32 dqi_free_entry; /* First block with free dquot entry in quota
1155 * file */
1156};
1157
1158/* Structure with global user / group information. We reserve some space
1159 * for future use. */
1160struct ocfs2_global_disk_dqblk {
1161/*00*/ __le32 dqb_id; /* ID the structure belongs to */
1162 __le32 dqb_use_count; /* Number of nodes having reference to this structure */
1163 __le64 dqb_ihardlimit; /* absolute limit on allocated inodes */
1164/*10*/ __le64 dqb_isoftlimit; /* preferred inode limit */
1165 __le64 dqb_curinodes; /* current # allocated inodes */
1166/*20*/ __le64 dqb_bhardlimit; /* absolute limit on disk space */
1167 __le64 dqb_bsoftlimit; /* preferred limit on disk space */
1168/*30*/ __le64 dqb_curspace; /* current space occupied */
1169 __le64 dqb_btime; /* time limit for excessive disk use */
1170/*40*/ __le64 dqb_itime; /* time limit for excessive inode use */
1171 __le64 dqb_pad1;
1172/*50*/ __le64 dqb_pad2;
1173};
1174
1175/*
1176 * On-disk structures for local quota file
1177 */
1178
1179/* Magic numbers and known versions for local quota files */
1180#define OCFS2_LOCAL_QMAGICS {\
1181 0x0cf524c0, /* USRQUOTA */ \
1182 0x0cf524c1 /* GRPQUOTA */ \
1183}
1184
1185#define OCFS2_LOCAL_QVERSIONS {\
1186 0, \
1187 0, \
1188}
1189
1190/* Quota flags in dqinfo header */
1191#define OLQF_CLEAN 0x0001 /* Quota file is empty (this should be after\
1192 * quota has been cleanly turned off) */
1193
1194#define OCFS2_LOCAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
1195
1196/* Information header of local quota file (immediately follows the generic
1197 * header) */
1198struct ocfs2_local_disk_dqinfo {
1199 __le32 dqi_flags; /* Flags for quota file */
1200 __le32 dqi_chunks; /* Number of chunks of quota structures
1201 * with a bitmap */
1202 __le32 dqi_blocks; /* Number of blocks allocated for quota file */
1203};
1204
1205/* Header of one chunk of a quota file */
1206struct ocfs2_local_disk_chunk {
1207 __le32 dqc_free; /* Number of free entries in the bitmap */
Gustavo A. R. Silva95f34272020-04-01 21:03:58 -07001208 __u8 dqc_bitmap[]; /* Bitmap of entries in the corresponding
Jan Kara9e33d692008-08-25 19:56:50 +02001209 * chunk of quota file */
1210};
1211
1212/* One entry in local quota file */
1213struct ocfs2_local_disk_dqblk {
1214/*00*/ __le64 dqb_id; /* id this quota applies to */
1215 __le64 dqb_spacemod; /* Change in the amount of used space */
1216/*10*/ __le64 dqb_inodemod; /* Change in the amount of used inodes */
1217};
1218
Joel Beckerab552d52008-10-16 17:50:30 -07001219
1220/*
1221 * The quota trailer lives at the end of each quota block.
1222 */
1223
1224struct ocfs2_disk_dqtrailer {
1225/*00*/ struct ocfs2_block_check dq_check; /* Error checking */
1226/*08*/ /* Cannot be larger than OCFS2_QBLK_RESERVED_SPACE */
1227};
1228
1229static inline struct ocfs2_disk_dqtrailer *ocfs2_block_dqtrailer(int blocksize,
1230 void *buf)
1231{
1232 char *ptr = buf;
1233 ptr += blocksize - OCFS2_QBLK_RESERVED_SPACE;
1234
1235 return (struct ocfs2_disk_dqtrailer *)ptr;
1236}
1237
Mark Fashehccd979b2005-12-15 14:31:24 -08001238#ifdef __KERNEL__
1239static inline int ocfs2_fast_symlink_chars(struct super_block *sb)
1240{
1241 return sb->s_blocksize -
1242 offsetof(struct ocfs2_dinode, id2.i_symlink);
1243}
1244
Tiger Yangfdd77702008-08-18 17:08:55 +08001245static inline int ocfs2_max_inline_data_with_xattr(struct super_block *sb,
1246 struct ocfs2_dinode *di)
1247{
1248 unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
1249
1250 if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
1251 return sb->s_blocksize -
1252 offsetof(struct ocfs2_dinode, id2.i_data.id_data) -
1253 xattrsize;
1254 else
1255 return sb->s_blocksize -
1256 offsetof(struct ocfs2_dinode, id2.i_data.id_data);
1257}
1258
Mark Fashehccd979b2005-12-15 14:31:24 -08001259static inline int ocfs2_extent_recs_per_inode(struct super_block *sb)
1260{
1261 int size;
1262
1263 size = sb->s_blocksize -
1264 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1265
1266 return size / sizeof(struct ocfs2_extent_rec);
1267}
1268
Tiger Yangfdd77702008-08-18 17:08:55 +08001269static inline int ocfs2_extent_recs_per_inode_with_xattr(
1270 struct super_block *sb,
1271 struct ocfs2_dinode *di)
1272{
1273 int size;
1274 unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
1275
1276 if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
1277 size = sb->s_blocksize -
1278 offsetof(struct ocfs2_dinode, id2.i_list.l_recs) -
1279 xattrsize;
1280 else
1281 size = sb->s_blocksize -
1282 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1283
1284 return size / sizeof(struct ocfs2_extent_rec);
1285}
1286
Mark Fasheh9b7895e2008-11-12 16:27:44 -08001287static inline int ocfs2_extent_recs_per_dx_root(struct super_block *sb)
1288{
1289 int size;
1290
1291 size = sb->s_blocksize -
1292 offsetof(struct ocfs2_dx_root_block, dr_list.l_recs);
1293
1294 return size / sizeof(struct ocfs2_extent_rec);
1295}
1296
Mark Fashehccd979b2005-12-15 14:31:24 -08001297static inline int ocfs2_chain_recs_per_inode(struct super_block *sb)
1298{
1299 int size;
1300
1301 size = sb->s_blocksize -
1302 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
1303
1304 return size / sizeof(struct ocfs2_chain_rec);
1305}
1306
1307static inline u16 ocfs2_extent_recs_per_eb(struct super_block *sb)
1308{
1309 int size;
1310
1311 size = sb->s_blocksize -
1312 offsetof(struct ocfs2_extent_block, h_list.l_recs);
1313
1314 return size / sizeof(struct ocfs2_extent_rec);
1315}
1316
Joel Becker798db352010-04-13 14:26:32 +08001317static inline u16 ocfs2_extent_recs_per_gd(struct super_block *sb)
1318{
1319 int size;
1320
1321 size = sb->s_blocksize -
1322 offsetof(struct ocfs2_group_desc, bg_list.l_recs);
1323
1324 return size / sizeof(struct ocfs2_extent_rec);
1325}
1326
Mark Fasheh9b7895e2008-11-12 16:27:44 -08001327static inline int ocfs2_dx_entries_per_leaf(struct super_block *sb)
1328{
1329 int size;
1330
1331 size = sb->s_blocksize -
1332 offsetof(struct ocfs2_dx_leaf, dl_list.de_entries);
1333
1334 return size / sizeof(struct ocfs2_dx_entry);
1335}
1336
Mark Fasheh4ed8a6b2008-11-24 17:02:08 -08001337static inline int ocfs2_dx_entries_per_root(struct super_block *sb)
1338{
1339 int size;
1340
1341 size = sb->s_blocksize -
1342 offsetof(struct ocfs2_dx_root_block, dr_entries.de_entries);
1343
1344 return size / sizeof(struct ocfs2_dx_entry);
1345}
1346
Mark Fashehccd979b2005-12-15 14:31:24 -08001347static inline u16 ocfs2_local_alloc_size(struct super_block *sb)
1348{
1349 u16 size;
1350
1351 size = sb->s_blocksize -
1352 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
1353
1354 return size;
1355}
1356
Joel Becker4cbe4242010-04-13 14:26:12 +08001357static inline int ocfs2_group_bitmap_size(struct super_block *sb,
Tao Ma85718822010-04-13 14:38:06 +08001358 int suballocator,
1359 u32 feature_incompat)
Mark Fashehccd979b2005-12-15 14:31:24 -08001360{
Tao Ma85718822010-04-13 14:38:06 +08001361 int size = sb->s_blocksize -
1362 offsetof(struct ocfs2_group_desc, bg_bitmap);
Mark Fashehccd979b2005-12-15 14:31:24 -08001363
Tao Ma85718822010-04-13 14:38:06 +08001364 /*
1365 * The cluster allocator uses the entire block. Suballocators have
1366 * never used more than OCFS2_MAX_BG_BITMAP_SIZE. Unfortunately, older
1367 * code expects bg_size set to the maximum. Thus we must keep
1368 * bg_size as-is unless discontig_bg is enabled.
1369 */
1370 if (suballocator &&
1371 (feature_incompat & OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG))
Joel Becker4cbe4242010-04-13 14:26:12 +08001372 size = OCFS2_MAX_BG_BITMAP_SIZE;
Mark Fashehccd979b2005-12-15 14:31:24 -08001373
1374 return size;
1375}
1376
1377static inline int ocfs2_truncate_recs_per_inode(struct super_block *sb)
1378{
1379 int size;
1380
1381 size = sb->s_blocksize -
1382 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
1383
1384 return size / sizeof(struct ocfs2_truncate_rec);
1385}
Mark Fasheh50af94b2007-01-21 14:44:59 -08001386
1387static inline u64 ocfs2_backup_super_blkno(struct super_block *sb, int index)
1388{
1389 u64 offset = OCFS2_BACKUP_SB_START;
1390
1391 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
1392 offset <<= (2 * index);
Mark Fasheha8a75a22007-01-26 10:46:59 -08001393 offset >>= sb->s_blocksize_bits;
Mark Fasheh50af94b2007-01-21 14:44:59 -08001394 return offset;
1395 }
1396
1397 return 0;
1398
1399}
Tao Ma0c044f02008-08-18 17:38:50 +08001400
1401static inline u16 ocfs2_xattr_recs_per_xb(struct super_block *sb)
1402{
1403 int size;
1404
1405 size = sb->s_blocksize -
1406 offsetof(struct ocfs2_xattr_block,
1407 xb_attrs.xb_root.xt_list.l_recs);
1408
1409 return size / sizeof(struct ocfs2_extent_rec);
1410}
Tao Ma721f69c2009-08-18 11:17:49 +08001411
1412static inline u16 ocfs2_extent_recs_per_rb(struct super_block *sb)
1413{
1414 int size;
1415
1416 size = sb->s_blocksize -
1417 offsetof(struct ocfs2_refcount_block, rf_list.l_recs);
1418
1419 return size / sizeof(struct ocfs2_extent_rec);
1420}
1421
1422static inline u16 ocfs2_refcount_recs_per_rb(struct super_block *sb)
1423{
1424 int size;
1425
1426 size = sb->s_blocksize -
1427 offsetof(struct ocfs2_refcount_block, rf_records.rl_recs);
1428
1429 return size / sizeof(struct ocfs2_refcount_rec);
1430}
Tao Mae73a8192009-08-11 14:33:14 +08001431
1432static inline u32
1433ocfs2_get_ref_rec_low_cpos(const struct ocfs2_refcount_rec *rec)
1434{
1435 return le64_to_cpu(rec->r_cpos) & OCFS2_32BIT_POS_MASK;
1436}
Mark Fashehccd979b2005-12-15 14:31:24 -08001437#else
1438static inline int ocfs2_fast_symlink_chars(int blocksize)
1439{
1440 return blocksize - offsetof(struct ocfs2_dinode, id2.i_symlink);
1441}
1442
Tao Ma1097df32010-01-20 11:31:11 +08001443static inline int ocfs2_max_inline_data_with_xattr(int blocksize,
1444 struct ocfs2_dinode *di)
Mark Fasheh15b1e362007-09-07 13:58:15 -07001445{
Tao Ma1097df32010-01-20 11:31:11 +08001446 if (di && (di->i_dyn_features & OCFS2_INLINE_XATTR_FL))
1447 return blocksize -
1448 offsetof(struct ocfs2_dinode, id2.i_data.id_data) -
1449 di->i_xattr_inline_size;
1450 else
1451 return blocksize -
1452 offsetof(struct ocfs2_dinode, id2.i_data.id_data);
Mark Fasheh15b1e362007-09-07 13:58:15 -07001453}
1454
Mark Fashehccd979b2005-12-15 14:31:24 -08001455static inline int ocfs2_extent_recs_per_inode(int blocksize)
1456{
1457 int size;
1458
1459 size = blocksize -
1460 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1461
1462 return size / sizeof(struct ocfs2_extent_rec);
1463}
1464
1465static inline int ocfs2_chain_recs_per_inode(int blocksize)
1466{
1467 int size;
1468
1469 size = blocksize -
1470 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
1471
1472 return size / sizeof(struct ocfs2_chain_rec);
1473}
1474
1475static inline int ocfs2_extent_recs_per_eb(int blocksize)
1476{
1477 int size;
1478
1479 size = blocksize -
1480 offsetof(struct ocfs2_extent_block, h_list.l_recs);
1481
1482 return size / sizeof(struct ocfs2_extent_rec);
1483}
1484
Joel Becker798db352010-04-13 14:26:32 +08001485static inline int ocfs2_extent_recs_per_gd(int blocksize)
1486{
1487 int size;
1488
1489 size = blocksize -
1490 offsetof(struct ocfs2_group_desc, bg_list.l_recs);
1491
1492 return size / sizeof(struct ocfs2_extent_rec);
1493}
1494
Mark Fashehccd979b2005-12-15 14:31:24 -08001495static inline int ocfs2_local_alloc_size(int blocksize)
1496{
1497 int size;
1498
1499 size = blocksize -
1500 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
1501
1502 return size;
1503}
1504
Tao Ma85718822010-04-13 14:38:06 +08001505static inline int ocfs2_group_bitmap_size(int blocksize,
1506 int suballocator,
1507 uint32_t feature_incompat)
Mark Fashehccd979b2005-12-15 14:31:24 -08001508{
Tao Ma85718822010-04-13 14:38:06 +08001509 int size = sb->s_blocksize -
1510 offsetof(struct ocfs2_group_desc, bg_bitmap);
Mark Fashehccd979b2005-12-15 14:31:24 -08001511
Tao Ma85718822010-04-13 14:38:06 +08001512 /*
1513 * The cluster allocator uses the entire block. Suballocators have
1514 * never used more than OCFS2_MAX_BG_BITMAP_SIZE. Unfortunately, older
1515 * code expects bg_size set to the maximum. Thus we must keep
1516 * bg_size as-is unless discontig_bg is enabled.
1517 */
1518 if (suballocator &&
1519 (feature_incompat & OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG))
Joel Becker4cbe4242010-04-13 14:26:12 +08001520 size = OCFS2_MAX_BG_BITMAP_SIZE;
Mark Fashehccd979b2005-12-15 14:31:24 -08001521
1522 return size;
1523}
1524
1525static inline int ocfs2_truncate_recs_per_inode(int blocksize)
1526{
1527 int size;
1528
1529 size = blocksize -
1530 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
1531
1532 return size / sizeof(struct ocfs2_truncate_rec);
1533}
Mark Fasheh50af94b2007-01-21 14:44:59 -08001534
1535static inline uint64_t ocfs2_backup_super_blkno(int blocksize, int index)
1536{
1537 uint64_t offset = OCFS2_BACKUP_SB_START;
1538
1539 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
1540 offset <<= (2 * index);
1541 offset /= blocksize;
1542 return offset;
1543 }
1544
1545 return 0;
1546}
Tao Ma0c044f02008-08-18 17:38:50 +08001547
1548static inline int ocfs2_xattr_recs_per_xb(int blocksize)
1549{
1550 int size;
1551
1552 size = blocksize -
1553 offsetof(struct ocfs2_xattr_block,
1554 xb_attrs.xb_root.xt_list.l_recs);
1555
1556 return size / sizeof(struct ocfs2_extent_rec);
1557}
Mark Fashehccd979b2005-12-15 14:31:24 -08001558#endif /* __KERNEL__ */
1559
1560
1561static inline int ocfs2_system_inode_is_global(int type)
1562{
1563 return ((type >= 0) &&
1564 (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE));
1565}
1566
1567static inline int ocfs2_sprintf_system_inode_name(char *buf, int len,
1568 int type, int slot)
1569{
1570 int chars;
1571
1572 /*
1573 * Global system inodes can only have one copy. Everything
1574 * after OCFS2_LAST_GLOBAL_SYSTEM_INODE in the system inode
1575 * list has a copy per slot.
1576 */
1577 if (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE)
Joel Beckerfe9f3872008-06-12 22:39:18 -07001578 chars = snprintf(buf, len, "%s",
Mark Fashehccd979b2005-12-15 14:31:24 -08001579 ocfs2_system_inodes[type].si_name);
1580 else
1581 chars = snprintf(buf, len,
1582 ocfs2_system_inodes[type].si_name,
1583 slot);
1584
1585 return chars;
1586}
1587
1588static inline void ocfs2_set_de_type(struct ocfs2_dir_entry *de,
1589 umode_t mode)
1590{
Phillip Potter9dc21082019-05-13 17:15:53 -07001591 de->file_type = fs_umode_to_ftype(mode);
Mark Fashehccd979b2005-12-15 14:31:24 -08001592}
1593
Tao Maaf2bf0d2010-05-17 15:14:17 +08001594static inline int ocfs2_gd_is_discontig(struct ocfs2_group_desc *gd)
1595{
1596 if ((offsetof(struct ocfs2_group_desc, bg_bitmap) +
1597 le16_to_cpu(gd->bg_size)) !=
1598 offsetof(struct ocfs2_group_desc, bg_list))
1599 return 0;
1600 /*
1601 * Only valid to check l_next_free_rec if
1602 * bg_bitmap + bg_size == bg_list.
1603 */
1604 if (!gd->bg_list.l_next_free_rec)
1605 return 0;
1606 return 1;
1607}
Mark Fashehccd979b2005-12-15 14:31:24 -08001608#endif /* _OCFS2_FS_H */
1609