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