blob: b01d0dddfcc1752ef502391182f75459c2d38b44 [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 \
103 | OCFS2_FEATURE_INCOMPAT_REFCOUNT_TREE)
Jan Kara19ece542008-08-21 20:13:17 +0200104#define OCFS2_FEATURE_RO_COMPAT_SUPP (OCFS2_FEATURE_RO_COMPAT_UNWRITTEN \
105 | OCFS2_FEATURE_RO_COMPAT_USRQUOTA \
106 | OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)
Mark Fashehccd979b2005-12-15 14:31:24 -0800107
108/*
109 * Heartbeat-only devices are missing journals and other files. The
110 * filesystem driver can't load them, but the library can. Never put
111 * this in OCFS2_FEATURE_INCOMPAT_SUPP, *ever*.
112 */
113#define OCFS2_FEATURE_INCOMPAT_HEARTBEAT_DEV 0x0002
114
Mark Fasheh89039012006-12-07 18:05:37 -0800115/*
116 * tunefs sets this incompat flag before starting the resize and clears it
117 * at the end. This flag protects users from inadvertently mounting the fs
118 * after an aborted run without fsck-ing.
119 */
120#define OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG 0x0004
Mark Fashehccd979b2005-12-15 14:31:24 -0800121
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800122/* Used to denote a non-clustered volume */
123#define OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT 0x0008
124
Mark Fasheh89039012006-12-07 18:05:37 -0800125/* Support for sparse allocation in b-trees */
126#define OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC 0x0010
127
Mark Fashehccd979b2005-12-15 14:31:24 -0800128/*
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700129 * Tunefs sets this incompat flag before starting an operation which
130 * would require cleanup on abort. This is done to protect users from
131 * inadvertently mounting the fs after an aborted run without
132 * fsck-ing.
133 *
134 * s_tunefs_flags on the super block describes precisely which
135 * operations were in progress.
136 */
137#define OCFS2_FEATURE_INCOMPAT_TUNEFS_INPROG 0x0020
138
Mark Fasheh15b1e362007-09-07 13:58:15 -0700139/* Support for data packed into inode blocks */
140#define OCFS2_FEATURE_INCOMPAT_INLINE_DATA 0x0040
141
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700142/*
Joel Beckerb61817e2008-02-01 15:08:23 -0800143 * Support for alternate, userspace cluster stacks. If set, the superblock
144 * field s_cluster_info contains a tag for the alternate stack in use as
145 * well as the name of the cluster being joined.
146 * mount.ocfs2 must pass in a matching stack name.
147 *
148 * If not set, the classic stack will be used. This is compatbile with
149 * all older versions.
150 */
151#define OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK 0x0080
152
Tiger Yang8154da32008-08-18 17:11:46 +0800153/* Support for the extended slot map */
154#define OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP 0x100
155
156/* Support for extended attributes */
157#define OCFS2_FEATURE_INCOMPAT_XATTR 0x0200
158
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800159/* Support for indexed directores */
160#define OCFS2_FEATURE_INCOMPAT_INDEXED_DIRS 0x0400
161
Joel Beckerab552d52008-10-16 17:50:30 -0700162/* Metadata checksum and error correction */
163#define OCFS2_FEATURE_INCOMPAT_META_ECC 0x0800
164
Tao Ma721f69c2009-08-18 11:17:49 +0800165/* Refcount tree support */
166#define OCFS2_FEATURE_INCOMPAT_REFCOUNT_TREE 0x1000
167
Joel Becker4cbe4242010-04-13 14:26:12 +0800168/* Discontigous block groups */
169#define OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG 0x2000
170
Joel Beckerb61817e2008-02-01 15:08:23 -0800171/*
Mark Fasheh50af94b2007-01-21 14:44:59 -0800172 * backup superblock flag is used to indicate that this volume
173 * has backup superblocks.
174 */
175#define OCFS2_FEATURE_COMPAT_BACKUP_SB 0x0001
176
Mark Fasheh328d5752007-06-18 10:48:04 -0700177/*
Joel Beckera9772182008-12-16 18:10:18 -0800178 * The filesystem will correctly handle journal feature bits.
179 */
180#define OCFS2_FEATURE_COMPAT_JBD2_SB 0x0002
181
182/*
Mark Fasheh328d5752007-06-18 10:48:04 -0700183 * Unwritten extents support.
184 */
185#define OCFS2_FEATURE_RO_COMPAT_UNWRITTEN 0x0001
186
Jan Kara1a224ad2008-08-20 15:43:36 +0200187/*
188 * Maintain quota information for this filesystem
189 */
190#define OCFS2_FEATURE_RO_COMPAT_USRQUOTA 0x0002
191#define OCFS2_FEATURE_RO_COMPAT_GRPQUOTA 0x0004
192
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 */
Mark Fashehccd979b2005-12-15 14:31:24 -0800223
Mark Fasheh15b1e362007-09-07 13:58:15 -0700224/*
225 * Flags on ocfs2_dinode.i_dyn_features
226 *
227 * These can change much more often than i_flags. When adding flags,
228 * keep in mind that i_dyn_features is only 16 bits wide.
229 */
230#define OCFS2_INLINE_DATA_FL (0x0001) /* Data stored in inode block */
231#define OCFS2_HAS_XATTR_FL (0x0002)
232#define OCFS2_INLINE_XATTR_FL (0x0004)
233#define OCFS2_INDEXED_DIR_FL (0x0008)
Tao Ma721f69c2009-08-18 11:17:49 +0800234#define OCFS2_HAS_REFCOUNT_FL (0x0010)
Mark Fasheh15b1e362007-09-07 13:58:15 -0700235
Herbert Poetzlca4d1472006-07-03 17:27:12 -0700236/* Inode attributes, keep in sync with EXT2 */
237#define OCFS2_SECRM_FL (0x00000001) /* Secure deletion */
238#define OCFS2_UNRM_FL (0x00000002) /* Undelete */
239#define OCFS2_COMPR_FL (0x00000004) /* Compress file */
240#define OCFS2_SYNC_FL (0x00000008) /* Synchronous updates */
241#define OCFS2_IMMUTABLE_FL (0x00000010) /* Immutable file */
242#define OCFS2_APPEND_FL (0x00000020) /* writes to file may only append */
243#define OCFS2_NODUMP_FL (0x00000040) /* do not dump file */
244#define OCFS2_NOATIME_FL (0x00000080) /* do not update atime */
245#define OCFS2_DIRSYNC_FL (0x00010000) /* dirsync behaviour (directories only) */
246
247#define OCFS2_FL_VISIBLE (0x000100FF) /* User visible flags */
248#define OCFS2_FL_MODIFIABLE (0x000100FF) /* User modifiable flags */
249
250/*
Mark Fashehe48edee2007-03-07 16:46:57 -0800251 * Extent record flags (e_node.leaf.flags)
252 */
Tao Ma721f69c2009-08-18 11:17:49 +0800253#define OCFS2_EXT_UNWRITTEN (0x01) /* Extent is allocated but
254 * unwritten */
255#define OCFS2_EXT_REFCOUNTED (0x02) /* Extent is reference
256 * counted in an associated
257 * refcount tree */
Mark Fashehe48edee2007-03-07 16:46:57 -0800258
259/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800260 * Journal Flags (ocfs2_dinode.id1.journal1.i_flags)
261 */
262#define OCFS2_JOURNAL_DIRTY_FL (0x00000001) /* Journal needs recovery */
263
264/*
265 * superblock s_state flags
266 */
267#define OCFS2_ERROR_FS (0x00000001) /* FS saw errors */
268
269/* Limit of space in ocfs2_dir_entry */
270#define OCFS2_MAX_FILENAME_LEN 255
271
272/* Maximum slots on an ocfs2 file system */
273#define OCFS2_MAX_SLOTS 255
274
275/* Slot map indicator for an empty slot */
276#define OCFS2_INVALID_SLOT -1
277
278#define OCFS2_VOL_UUID_LEN 16
279#define OCFS2_MAX_VOL_LABEL_LEN 64
280
Joel Beckerb61817e2008-02-01 15:08:23 -0800281/* The alternate, userspace stack fields */
282#define OCFS2_STACK_LABEL_LEN 4
283#define OCFS2_CLUSTER_NAME_LEN 16
284
Mark Fashehccd979b2005-12-15 14:31:24 -0800285/* Journal limits (in bytes) */
286#define OCFS2_MIN_JOURNAL_SIZE (4 * 1024 * 1024)
Mark Fashehccd979b2005-12-15 14:31:24 -0800287
Sunil Mushran2fbe8d12007-12-20 14:58:11 -0800288/*
Tiger Yangfdd77702008-08-18 17:08:55 +0800289 * Inline extended attribute size (in bytes)
290 * The value chosen should be aligned to 16 byte boundaries.
291 */
292#define OCFS2_MIN_XATTR_INLINE_SIZE 256
293
Mark Fashehccd979b2005-12-15 14:31:24 -0800294struct ocfs2_system_inode_info {
295 char *si_name;
296 int si_iflags;
297 int si_mode;
298};
299
300/* System file index */
301enum {
302 BAD_BLOCK_SYSTEM_INODE = 0,
303 GLOBAL_INODE_ALLOC_SYSTEM_INODE,
304 SLOT_MAP_SYSTEM_INODE,
305#define OCFS2_FIRST_ONLINE_SYSTEM_INODE SLOT_MAP_SYSTEM_INODE
306 HEARTBEAT_SYSTEM_INODE,
307 GLOBAL_BITMAP_SYSTEM_INODE,
Jan Kara1a224ad2008-08-20 15:43:36 +0200308 USER_QUOTA_SYSTEM_INODE,
309 GROUP_QUOTA_SYSTEM_INODE,
310#define OCFS2_LAST_GLOBAL_SYSTEM_INODE GROUP_QUOTA_SYSTEM_INODE
Mark Fashehccd979b2005-12-15 14:31:24 -0800311 ORPHAN_DIR_SYSTEM_INODE,
312 EXTENT_ALLOC_SYSTEM_INODE,
313 INODE_ALLOC_SYSTEM_INODE,
314 JOURNAL_SYSTEM_INODE,
315 LOCAL_ALLOC_SYSTEM_INODE,
316 TRUNCATE_LOG_SYSTEM_INODE,
Jan Kara1a224ad2008-08-20 15:43:36 +0200317 LOCAL_USER_QUOTA_SYSTEM_INODE,
318 LOCAL_GROUP_QUOTA_SYSTEM_INODE,
Mark Fashehccd979b2005-12-15 14:31:24 -0800319 NUM_SYSTEM_INODES
320};
321
322static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = {
323 /* Global system inodes (single copy) */
324 /* The first two are only used from userspace mfks/tunefs */
325 [BAD_BLOCK_SYSTEM_INODE] = { "bad_blocks", 0, S_IFREG | 0644 },
326 [GLOBAL_INODE_ALLOC_SYSTEM_INODE] = { "global_inode_alloc", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
327
328 /* These are used by the running filesystem */
329 [SLOT_MAP_SYSTEM_INODE] = { "slot_map", 0, S_IFREG | 0644 },
330 [HEARTBEAT_SYSTEM_INODE] = { "heartbeat", OCFS2_HEARTBEAT_FL, S_IFREG | 0644 },
331 [GLOBAL_BITMAP_SYSTEM_INODE] = { "global_bitmap", 0, S_IFREG | 0644 },
Jan Kara1a224ad2008-08-20 15:43:36 +0200332 [USER_QUOTA_SYSTEM_INODE] = { "aquota.user", OCFS2_QUOTA_FL, S_IFREG | 0644 },
333 [GROUP_QUOTA_SYSTEM_INODE] = { "aquota.group", OCFS2_QUOTA_FL, S_IFREG | 0644 },
Mark Fashehccd979b2005-12-15 14:31:24 -0800334
335 /* Slot-specific system inodes (one copy per slot) */
336 [ORPHAN_DIR_SYSTEM_INODE] = { "orphan_dir:%04d", 0, S_IFDIR | 0755 },
337 [EXTENT_ALLOC_SYSTEM_INODE] = { "extent_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
338 [INODE_ALLOC_SYSTEM_INODE] = { "inode_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
339 [JOURNAL_SYSTEM_INODE] = { "journal:%04d", OCFS2_JOURNAL_FL, S_IFREG | 0644 },
340 [LOCAL_ALLOC_SYSTEM_INODE] = { "local_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_LOCAL_ALLOC_FL, S_IFREG | 0644 },
Jan Kara1a224ad2008-08-20 15:43:36 +0200341 [TRUNCATE_LOG_SYSTEM_INODE] = { "truncate_log:%04d", OCFS2_DEALLOC_FL, S_IFREG | 0644 },
342 [LOCAL_USER_QUOTA_SYSTEM_INODE] = { "aquota.user:%04d", OCFS2_QUOTA_FL, S_IFREG | 0644 },
343 [LOCAL_GROUP_QUOTA_SYSTEM_INODE] = { "aquota.group:%04d", OCFS2_QUOTA_FL, S_IFREG | 0644 },
Mark Fashehccd979b2005-12-15 14:31:24 -0800344};
345
346/* Parameter passed from mount.ocfs2 to module */
347#define OCFS2_HB_NONE "heartbeat=none"
348#define OCFS2_HB_LOCAL "heartbeat=local"
349
350/*
351 * OCFS2 directory file types. Only the low 3 bits are used. The
352 * other bits are reserved for now.
353 */
354#define OCFS2_FT_UNKNOWN 0
355#define OCFS2_FT_REG_FILE 1
356#define OCFS2_FT_DIR 2
357#define OCFS2_FT_CHRDEV 3
358#define OCFS2_FT_BLKDEV 4
359#define OCFS2_FT_FIFO 5
360#define OCFS2_FT_SOCK 6
361#define OCFS2_FT_SYMLINK 7
362
363#define OCFS2_FT_MAX 8
364
365/*
366 * OCFS2_DIR_PAD defines the directory entries boundaries
367 *
368 * NOTE: It must be a multiple of 4
369 */
370#define OCFS2_DIR_PAD 4
371#define OCFS2_DIR_ROUND (OCFS2_DIR_PAD - 1)
372#define OCFS2_DIR_MEMBER_LEN offsetof(struct ocfs2_dir_entry, name)
373#define OCFS2_DIR_REC_LEN(name_len) (((name_len) + OCFS2_DIR_MEMBER_LEN + \
374 OCFS2_DIR_ROUND) & \
375 ~OCFS2_DIR_ROUND)
Mark Fashehe7c17e42009-01-29 18:17:46 -0800376#define OCFS2_DIR_MIN_REC_LEN OCFS2_DIR_REC_LEN(1)
Mark Fashehccd979b2005-12-15 14:31:24 -0800377
378#define OCFS2_LINK_MAX 32000
Mark Fasheh198a1ca2008-11-20 17:54:57 -0800379#define OCFS2_DX_LINK_MAX ((1U << 31) - 1U)
380#define OCFS2_LINKS_HI_SHIFT 16
Mark Fashehe3a93c22009-02-17 15:29:35 -0800381#define OCFS2_DX_ENTRIES_MAX (0xffffffffU)
Mark Fashehccd979b2005-12-15 14:31:24 -0800382
383#define S_SHIFT 12
384static unsigned char ocfs2_type_by_mode[S_IFMT >> S_SHIFT] = {
385 [S_IFREG >> S_SHIFT] = OCFS2_FT_REG_FILE,
386 [S_IFDIR >> S_SHIFT] = OCFS2_FT_DIR,
387 [S_IFCHR >> S_SHIFT] = OCFS2_FT_CHRDEV,
388 [S_IFBLK >> S_SHIFT] = OCFS2_FT_BLKDEV,
389 [S_IFIFO >> S_SHIFT] = OCFS2_FT_FIFO,
390 [S_IFSOCK >> S_SHIFT] = OCFS2_FT_SOCK,
391 [S_IFLNK >> S_SHIFT] = OCFS2_FT_SYMLINK,
392};
393
394
395/*
396 * Convenience casts
397 */
398#define OCFS2_RAW_SB(dinode) (&((dinode)->id2.i_super))
399
400/*
Joel Beckerab552d52008-10-16 17:50:30 -0700401 * Block checking structure. This is used in metadata to validate the
402 * contents. If OCFS2_FEATURE_INCOMPAT_META_ECC is not set, it is all
403 * zeros.
404 */
405struct ocfs2_block_check {
406/*00*/ __le32 bc_crc32e; /* 802.3 Ethernet II CRC32 */
407 __le16 bc_ecc; /* Single-error-correction parity vector.
408 This is a simple Hamming code dependant
409 on the blocksize. OCFS2's maximum
410 blocksize, 4K, requires 16 parity bits,
411 so we fit in __le16. */
412 __le16 bc_reserved1;
413/*08*/
414};
415
416/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800417 * On disk extent record for OCFS2
418 * It describes a range of clusters on disk.
Mark Fashehe48edee2007-03-07 16:46:57 -0800419 *
420 * Length fields are divided into interior and leaf node versions.
421 * This leaves room for a flags field (OCFS2_EXT_*) in the leaf nodes.
Mark Fashehccd979b2005-12-15 14:31:24 -0800422 */
423struct ocfs2_extent_rec {
424/*00*/ __le32 e_cpos; /* Offset into the file, in clusters */
Mark Fashehe48edee2007-03-07 16:46:57 -0800425 union {
426 __le32 e_int_clusters; /* Clusters covered by all children */
427 struct {
428 __le16 e_leaf_clusters; /* Clusters covered by this
429 extent */
430 __u8 e_reserved1;
431 __u8 e_flags; /* Extent flags */
432 };
433 };
Mark Fashehccd979b2005-12-15 14:31:24 -0800434 __le64 e_blkno; /* Physical disk offset, in blocks */
435/*10*/
436};
437
438struct ocfs2_chain_rec {
439 __le32 c_free; /* Number of free bits in this chain. */
440 __le32 c_total; /* Number of total bits in this chain */
441 __le64 c_blkno; /* Physical disk offset (blocks) of 1st group */
442};
443
444struct ocfs2_truncate_rec {
445 __le32 t_start; /* 1st cluster in this log */
446 __le32 t_clusters; /* Number of total clusters covered */
447};
448
449/*
450 * On disk extent list for OCFS2 (node in the tree). Note that this
451 * is contained inside ocfs2_dinode or ocfs2_extent_block, so the
452 * offsets are relative to ocfs2_dinode.id2.i_list or
453 * ocfs2_extent_block.h_list, respectively.
454 */
455struct ocfs2_extent_list {
456/*00*/ __le16 l_tree_depth; /* Extent tree depth from this
457 point. 0 means data extents
458 hang directly off this
Mark Fashehdcd05382007-01-16 11:32:23 -0800459 header (a leaf)
460 NOTE: The high 8 bits cannot be
461 used - tree_depth is never that big.
462 */
Mark Fashehccd979b2005-12-15 14:31:24 -0800463 __le16 l_count; /* Number of extent records */
464 __le16 l_next_free_rec; /* Next unused extent slot */
465 __le16 l_reserved1;
466 __le64 l_reserved2; /* Pad to
467 sizeof(ocfs2_extent_rec) */
468/*10*/ struct ocfs2_extent_rec l_recs[0]; /* Extent records */
469};
470
471/*
472 * On disk allocation chain list for OCFS2. Note that this is
473 * contained inside ocfs2_dinode, so the offsets are relative to
474 * ocfs2_dinode.id2.i_chain.
475 */
476struct ocfs2_chain_list {
477/*00*/ __le16 cl_cpg; /* Clusters per Block Group */
478 __le16 cl_bpc; /* Bits per cluster */
479 __le16 cl_count; /* Total chains in this list */
480 __le16 cl_next_free_rec; /* Next unused chain slot */
481 __le64 cl_reserved1;
482/*10*/ struct ocfs2_chain_rec cl_recs[0]; /* Chain records */
483};
484
485/*
486 * On disk deallocation log for OCFS2. Note that this is
487 * contained inside ocfs2_dinode, so the offsets are relative to
488 * ocfs2_dinode.id2.i_dealloc.
489 */
490struct ocfs2_truncate_log {
491/*00*/ __le16 tl_count; /* Total records in this log */
492 __le16 tl_used; /* Number of records in use */
493 __le32 tl_reserved1;
494/*08*/ struct ocfs2_truncate_rec tl_recs[0]; /* Truncate records */
495};
496
497/*
498 * On disk extent block (indirect block) for OCFS2
499 */
500struct ocfs2_extent_block
501{
502/*00*/ __u8 h_signature[8]; /* Signature for verification */
Joel Beckerab552d52008-10-16 17:50:30 -0700503 struct ocfs2_block_check h_check; /* Error checking */
Mark Fashehccd979b2005-12-15 14:31:24 -0800504/*10*/ __le16 h_suballoc_slot; /* Slot suballocator this
505 extent_header belongs to */
506 __le16 h_suballoc_bit; /* Bit offset in suballocator
507 block group */
508 __le32 h_fs_generation; /* Must match super block */
509 __le64 h_blkno; /* Offset on disk, in blocks */
Joel Becker9cbc0122010-03-26 10:07:42 +0800510/*20*/ __le64 h_suballoc_loc; /* Suballocator block group this
511 eb belongs to. Only valid
512 if allocated from a
513 discontiguous block group */
Mark Fashehccd979b2005-12-15 14:31:24 -0800514 __le64 h_next_leaf_blk; /* Offset on disk, in blocks,
515 of next leaf header pointing
516 to data */
517/*30*/ struct ocfs2_extent_list h_list; /* Extent record list */
518/* Actual on-disk size is one block */
519};
520
521/*
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800522 * On disk slot map for OCFS2. This defines the contents of the "slot_map"
Joel Becker386a2ef2008-02-01 12:06:54 -0800523 * system file. A slot is valid if it contains a node number >= 0. The
524 * value -1 (0xFFFF) is OCFS2_INVALID_SLOT. This marks a slot empty.
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800525 */
526struct ocfs2_slot_map {
527/*00*/ __le16 sm_slots[0];
528/*
529 * Actual on-disk size is one block. OCFS2_MAX_SLOTS is 255,
530 * 255 * sizeof(__le16) == 512B, within the 512B block minimum blocksize.
531 */
532};
533
Joel Becker386a2ef2008-02-01 12:06:54 -0800534struct ocfs2_extended_slot {
535/*00*/ __u8 es_valid;
536 __u8 es_reserved1[3];
537 __le32 es_node_num;
538/*10*/
539};
540
541/*
542 * The extended slot map, used when OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP
543 * is set. It separates out the valid marker from the node number, and
544 * has room to grow. Unlike the old slot map, this format is defined by
545 * i_size.
546 */
547struct ocfs2_slot_map_extended {
548/*00*/ struct ocfs2_extended_slot se_slots[0];
549/*
550 * Actual size is i_size of the slot_map system file. It should
551 * match s_max_slots * sizeof(struct ocfs2_extended_slot)
552 */
553};
554
Joel Beckerb61817e2008-02-01 15:08:23 -0800555struct ocfs2_cluster_info {
556/*00*/ __u8 ci_stack[OCFS2_STACK_LABEL_LEN];
557 __le32 ci_reserved;
558/*08*/ __u8 ci_cluster[OCFS2_CLUSTER_NAME_LEN];
559/*18*/
560};
561
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800562/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800563 * On disk superblock for OCFS2
564 * Note that it is contained inside an ocfs2_dinode, so all offsets
565 * are relative to the start of ocfs2_dinode.id2.
566 */
567struct ocfs2_super_block {
568/*00*/ __le16 s_major_rev_level;
569 __le16 s_minor_rev_level;
570 __le16 s_mnt_count;
571 __le16 s_max_mnt_count;
572 __le16 s_state; /* File system state */
573 __le16 s_errors; /* Behaviour when detecting errors */
574 __le32 s_checkinterval; /* Max time between checks */
575/*10*/ __le64 s_lastcheck; /* Time of last check */
576 __le32 s_creator_os; /* OS */
577 __le32 s_feature_compat; /* Compatible feature set */
578/*20*/ __le32 s_feature_incompat; /* Incompatible feature set */
579 __le32 s_feature_ro_compat; /* Readonly-compatible feature set */
580 __le64 s_root_blkno; /* Offset, in blocks, of root directory
581 dinode */
582/*30*/ __le64 s_system_dir_blkno; /* Offset, in blocks, of system
583 directory dinode */
584 __le32 s_blocksize_bits; /* Blocksize for this fs */
585 __le32 s_clustersize_bits; /* Clustersize for this fs */
586/*40*/ __le16 s_max_slots; /* Max number of simultaneous mounts
587 before tunefs required */
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700588 __le16 s_tunefs_flag;
Tiger Yangcf1d6c72008-08-18 17:11:00 +0800589 __le32 s_uuid_hash; /* hash value of uuid */
Mark Fashehccd979b2005-12-15 14:31:24 -0800590 __le64 s_first_cluster_group; /* Block offset of 1st cluster
591 * group header */
592/*50*/ __u8 s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */
593/*90*/ __u8 s_uuid[OCFS2_VOL_UUID_LEN]; /* 128-bit uuid */
Joel Beckerb61817e2008-02-01 15:08:23 -0800594/*A0*/ struct ocfs2_cluster_info s_cluster_info; /* Selected userspace
595 stack. Only valid
596 with INCOMPAT flag. */
Tiger Yang8154da32008-08-18 17:11:46 +0800597/*B8*/ __le16 s_xattr_inline_size; /* extended attribute inline size
598 for this fs*/
599 __le16 s_reserved0;
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800600 __le32 s_dx_seed[3]; /* seed[0-2] for dx dir hash.
601 * s_uuid_hash serves as seed[3]. */
602/*C0*/ __le64 s_reserved2[15]; /* Fill out superblock */
Joel Beckerb61817e2008-02-01 15:08:23 -0800603/*140*/
604
605 /*
606 * NOTE: As stated above, all offsets are relative to
607 * ocfs2_dinode.id2, which is at 0xC0 in the inode.
608 * 0xC0 + 0x140 = 0x200 or 512 bytes. A superblock must fit within
609 * our smallest blocksize, which is 512 bytes. To ensure this,
610 * we reserve the space in s_reserved2. Anything past s_reserved2
611 * will not be available on the smallest blocksize.
612 */
Mark Fashehccd979b2005-12-15 14:31:24 -0800613};
614
615/*
616 * Local allocation bitmap for OCFS2 slots
617 * Note that it exists inside an ocfs2_dinode, so all offsets are
618 * relative to the start of ocfs2_dinode.id2.
619 */
620struct ocfs2_local_alloc
621{
622/*00*/ __le32 la_bm_off; /* Starting bit offset in main bitmap */
623 __le16 la_size; /* Size of included bitmap, in bytes */
624 __le16 la_reserved1;
625 __le64 la_reserved2;
626/*10*/ __u8 la_bitmap[0];
627};
628
629/*
Mark Fasheh15b1e362007-09-07 13:58:15 -0700630 * Data-in-inode header. This is only used if i_dyn_features has
631 * OCFS2_INLINE_DATA_FL set.
632 */
633struct ocfs2_inline_data
634{
635/*00*/ __le16 id_count; /* Number of bytes that can be used
636 * for data, starting at id_data */
637 __le16 id_reserved0;
638 __le32 id_reserved1;
639 __u8 id_data[0]; /* Start of user data */
640};
641
642/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800643 * On disk inode for OCFS2
644 */
645struct ocfs2_dinode {
646/*00*/ __u8 i_signature[8]; /* Signature for validation */
647 __le32 i_generation; /* Generation number */
648 __le16 i_suballoc_slot; /* Slot suballocator this inode
649 belongs to */
650 __le16 i_suballoc_bit; /* Bit offset in suballocator
651 block group */
Mark Fasheh198a1ca2008-11-20 17:54:57 -0800652/*10*/ __le16 i_links_count_hi; /* High 16 bits of links count */
Tiger Yangfdd77702008-08-18 17:08:55 +0800653 __le16 i_xattr_inline_size;
Mark Fashehccd979b2005-12-15 14:31:24 -0800654 __le32 i_clusters; /* Cluster count */
655 __le32 i_uid; /* Owner UID */
656 __le32 i_gid; /* Owning GID */
657/*20*/ __le64 i_size; /* Size in bytes */
658 __le16 i_mode; /* File mode */
659 __le16 i_links_count; /* Links count */
660 __le32 i_flags; /* File flags */
661/*30*/ __le64 i_atime; /* Access time */
662 __le64 i_ctime; /* Creation time */
663/*40*/ __le64 i_mtime; /* Modification time */
664 __le64 i_dtime; /* Deletion time */
665/*50*/ __le64 i_blkno; /* Offset on disk, in blocks */
666 __le64 i_last_eb_blk; /* Pointer to last extent
667 block */
668/*60*/ __le32 i_fs_generation; /* Generation per fs-instance */
669 __le32 i_atime_nsec;
670 __le32 i_ctime_nsec;
671 __le32 i_mtime_nsec;
Tiger Yangfdd77702008-08-18 17:08:55 +0800672/*70*/ __le32 i_attr;
Tiger Yang50008632007-03-20 16:01:38 -0700673 __le16 i_orphaned_slot; /* Only valid when OCFS2_ORPHANED_FL
674 was set in i_flags */
Mark Fasheh15b1e362007-09-07 13:58:15 -0700675 __le16 i_dyn_features;
Tiger Yangfdd77702008-08-18 17:08:55 +0800676 __le64 i_xattr_loc;
Joel Beckerab552d52008-10-16 17:50:30 -0700677/*80*/ struct ocfs2_block_check i_check; /* Error checking */
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800678/*88*/ __le64 i_dx_root; /* Pointer to dir index root block */
Tao Ma721f69c2009-08-18 11:17:49 +0800679/*90*/ __le64 i_refcount_loc;
Joel Becker9cbc0122010-03-26 10:07:42 +0800680 __le64 i_suballoc_loc; /* Suballocator block group this
681 inode belongs to. Only valid
682 if allocated from a
683 discontiguous block group */
684/*A0*/ __le64 i_reserved2[3];
Mark Fashehccd979b2005-12-15 14:31:24 -0800685/*B8*/ union {
686 __le64 i_pad1; /* Generic way to refer to this
687 64bit union */
688 struct {
689 __le64 i_rdev; /* Device number */
690 } dev1;
691 struct { /* Info for bitmap system
692 inodes */
693 __le32 i_used; /* Bits (ie, clusters) used */
694 __le32 i_total; /* Total bits (clusters)
695 available */
696 } bitmap1;
697 struct { /* Info for journal system
698 inodes */
699 __le32 ij_flags; /* Mounted, version, etc. */
Sunil Mushranc69991a2008-07-14 17:31:09 -0700700 __le32 ij_recovery_generation; /* Incremented when the
701 journal is recovered
702 after an unclean
703 shutdown */
Mark Fashehccd979b2005-12-15 14:31:24 -0800704 } journal1;
705 } id1; /* Inode type dependant 1 */
706/*C0*/ union {
707 struct ocfs2_super_block i_super;
708 struct ocfs2_local_alloc i_lab;
709 struct ocfs2_chain_list i_chain;
710 struct ocfs2_extent_list i_list;
711 struct ocfs2_truncate_log i_dealloc;
Mark Fasheh15b1e362007-09-07 13:58:15 -0700712 struct ocfs2_inline_data i_data;
Mark Fashehccd979b2005-12-15 14:31:24 -0800713 __u8 i_symlink[0];
714 } id2;
715/* Actual on-disk size is one block */
716};
717
718/*
719 * On-disk directory entry structure for OCFS2
720 *
721 * Packed as this structure could be accessed unaligned on 64-bit platforms
722 */
723struct ocfs2_dir_entry {
724/*00*/ __le64 inode; /* Inode number */
725 __le16 rec_len; /* Directory entry length */
726 __u8 name_len; /* Name length */
727 __u8 file_type;
728/*0C*/ char name[OCFS2_MAX_FILENAME_LEN]; /* File name */
729/* Actual on-disk length specified by rec_len */
730} __attribute__ ((packed));
731
732/*
Mark Fasheh87d35a72008-12-10 17:36:25 -0800733 * Per-block record for the unindexed directory btree. This is carefully
734 * crafted so that the rec_len and name_len records of an ocfs2_dir_entry are
735 * mirrored. That way, the directory manipulation code needs a minimal amount
736 * of update.
737 *
738 * NOTE: Keep this structure aligned to a multiple of 4 bytes.
739 */
740struct ocfs2_dir_block_trailer {
741/*00*/ __le64 db_compat_inode; /* Always zero. Was inode */
742
743 __le16 db_compat_rec_len; /* Backwards compatible with
744 * ocfs2_dir_entry. */
745 __u8 db_compat_name_len; /* Always zero. Was name_len */
746 __u8 db_reserved0;
747 __le16 db_reserved1;
748 __le16 db_free_rec_len; /* Size of largest empty hole
749 * in this block. (unused) */
750/*10*/ __u8 db_signature[8]; /* Signature for verification */
751 __le64 db_reserved2;
752 __le64 db_free_next; /* Next block in list (unused) */
753/*20*/ __le64 db_blkno; /* Offset on disk, in blocks */
754 __le64 db_parent_dinode; /* dinode which owns me, in
755 blocks */
Joel Beckerc175a512008-12-10 17:58:22 -0800756/*30*/ struct ocfs2_block_check db_check; /* Error checking */
Mark Fasheh87d35a72008-12-10 17:36:25 -0800757/*40*/
758};
759
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800760 /*
761 * A directory entry in the indexed tree. We don't store the full name here,
762 * but instead provide a pointer to the full dirent in the unindexed tree.
763 *
764 * We also store name_len here so as to reduce the number of leaf blocks we
765 * need to search in case of collisions.
766 */
767struct ocfs2_dx_entry {
768 __le32 dx_major_hash; /* Used to find logical
769 * cluster in index */
770 __le32 dx_minor_hash; /* Lower bits used to find
771 * block in cluster */
772 __le64 dx_dirent_blk; /* Physical block in unindexed
773 * tree holding this dirent. */
774};
775
776struct ocfs2_dx_entry_list {
777 __le32 de_reserved;
778 __le16 de_count; /* Maximum number of entries
779 * possible in de_entries */
780 __le16 de_num_used; /* Current number of
781 * de_entries entries */
782 struct ocfs2_dx_entry de_entries[0]; /* Indexed dir entries
783 * in a packed array of
784 * length de_num_used */
785};
786
Mark Fasheh4ed8a6b2008-11-24 17:02:08 -0800787#define OCFS2_DX_FLAG_INLINE 0x01
788
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800789/*
790 * A directory indexing block. Each indexed directory has one of these,
791 * pointed to by ocfs2_dinode.
792 *
793 * This block stores an indexed btree root, and a set of free space
794 * start-of-list pointers.
795 */
796struct ocfs2_dx_root_block {
797 __u8 dr_signature[8]; /* Signature for verification */
798 struct ocfs2_block_check dr_check; /* Error checking */
799 __le16 dr_suballoc_slot; /* Slot suballocator this
800 * block belongs to. */
801 __le16 dr_suballoc_bit; /* Bit offset in suballocator
802 * block group */
803 __le32 dr_fs_generation; /* Must match super block */
804 __le64 dr_blkno; /* Offset on disk, in blocks */
805 __le64 dr_last_eb_blk; /* Pointer to last
806 * extent block */
807 __le32 dr_clusters; /* Clusters allocated
808 * to the indexed tree. */
Mark Fasheh4ed8a6b2008-11-24 17:02:08 -0800809 __u8 dr_flags; /* OCFS2_DX_FLAG_* flags */
810 __u8 dr_reserved0;
811 __le16 dr_reserved1;
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800812 __le64 dr_dir_blkno; /* Pointer to parent inode */
Mark Fashehe3a93c22009-02-17 15:29:35 -0800813 __le32 dr_num_entries; /* Total number of
814 * names stored in
815 * this directory.*/
816 __le32 dr_reserved2;
Mark Fashehe7c17e42009-01-29 18:17:46 -0800817 __le64 dr_free_blk; /* Pointer to head of free
818 * unindexed block list. */
Joel Becker9cbc0122010-03-26 10:07:42 +0800819 __le64 dr_suballoc_loc; /* Suballocator block group
820 this root belongs to.
821 Only valid if allocated
822 from a discontiguous
823 block group */
824 __le64 dr_reserved3[14];
Mark Fasheh4ed8a6b2008-11-24 17:02:08 -0800825 union {
826 struct ocfs2_extent_list dr_list; /* Keep this aligned to 128
827 * bits for maximum space
828 * efficiency. */
829 struct ocfs2_dx_entry_list dr_entries; /* In-root-block list of
830 * entries. We grow out
831 * to extents if this
832 * gets too big. */
833 };
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800834};
835
836/*
837 * The header of a leaf block in the indexed tree.
838 */
839struct ocfs2_dx_leaf {
840 __u8 dl_signature[8];/* Signature for verification */
841 struct ocfs2_block_check dl_check; /* Error checking */
842 __le64 dl_blkno; /* Offset on disk, in blocks */
843 __le32 dl_fs_generation;/* Must match super block */
844 __le32 dl_reserved0;
845 __le64 dl_reserved1;
846 struct ocfs2_dx_entry_list dl_list;
847};
848
Mark Fasheh87d35a72008-12-10 17:36:25 -0800849/*
Joel Becker4cbe4242010-04-13 14:26:12 +0800850 * Largest bitmap for a block (suballocator) group in bytes. This limit
851 * does not affect cluster groups (global allocator). Cluster group
852 * bitmaps run to the end of the block.
853 */
854#define OCFS2_MAX_BG_BITMAP_SIZE 256
855
856/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800857 * On disk allocator group structure for OCFS2
858 */
859struct ocfs2_group_desc
860{
861/*00*/ __u8 bg_signature[8]; /* Signature for validation */
862 __le16 bg_size; /* Size of included bitmap in
863 bytes. */
864 __le16 bg_bits; /* Bits represented by this
865 group. */
866 __le16 bg_free_bits_count; /* Free bits count */
867 __le16 bg_chain; /* What chain I am in. */
868/*10*/ __le32 bg_generation;
869 __le32 bg_reserved1;
870 __le64 bg_next_group; /* Next group in my list, in
871 blocks */
872/*20*/ __le64 bg_parent_dinode; /* dinode which owns me, in
873 blocks */
874 __le64 bg_blkno; /* Offset on disk, in blocks */
Joel Beckerab552d52008-10-16 17:50:30 -0700875/*30*/ struct ocfs2_block_check bg_check; /* Error checking */
876 __le64 bg_reserved2;
Joel Becker4cbe4242010-04-13 14:26:12 +0800877/*40*/ union {
878 __u8 bg_bitmap[0];
879 struct {
880 /*
881 * Block groups may be discontiguous when
882 * OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG is set.
883 * The extents of a discontigous block group are
884 * stored in bg_list. It is a flat list.
885 * l_tree_depth must always be zero. A
886 * discontiguous group is signified by a non-zero
887 * bg_list->l_next_free_rec. Only block groups
888 * can be discontiguous; Cluster groups cannot.
889 * We've never made a block group with more than
890 * 2048 blocks (256 bytes of bg_bitmap). This
891 * codifies that limit so that we can fit bg_list.
892 * bg_size of a discontiguous block group will
893 * be 256 to match bg_bitmap_filler.
894 */
895 __u8 bg_bitmap_filler[OCFS2_MAX_BG_BITMAP_SIZE];
896/*140*/ struct ocfs2_extent_list bg_list;
897 };
898 };
899/* Actual on-disk size is one block */
Mark Fashehccd979b2005-12-15 14:31:24 -0800900};
901
Tao Ma721f69c2009-08-18 11:17:49 +0800902struct ocfs2_refcount_rec {
903/*00*/ __le64 r_cpos; /* Physical offset, in clusters */
904 __le32 r_clusters; /* Clusters covered by this extent */
905 __le32 r_refcount; /* Reference count of this extent */
906/*10*/
907};
Tao Mae73a8192009-08-11 14:33:14 +0800908#define OCFS2_32BIT_POS_MASK (0xffffffffULL)
Tao Ma721f69c2009-08-18 11:17:49 +0800909
910#define OCFS2_REFCOUNT_LEAF_FL (0x00000001)
911#define OCFS2_REFCOUNT_TREE_FL (0x00000002)
912
913struct ocfs2_refcount_list {
914/*00*/ __le16 rl_count; /* Maximum number of entries possible
915 in rl_records */
916 __le16 rl_used; /* Current number of used records */
917 __le32 rl_reserved2;
918 __le64 rl_reserved1; /* Pad to sizeof(ocfs2_refcount_record) */
919/*10*/ struct ocfs2_refcount_rec rl_recs[0]; /* Refcount records */
920};
921
922
923struct ocfs2_refcount_block {
924/*00*/ __u8 rf_signature[8]; /* Signature for verification */
925 __le16 rf_suballoc_slot; /* Slot suballocator this block
926 belongs to */
927 __le16 rf_suballoc_bit; /* Bit offset in suballocator
928 block group */
929 __le32 rf_fs_generation; /* Must match superblock */
930/*10*/ __le64 rf_blkno; /* Offset on disk, in blocks */
931 __le64 rf_parent; /* Parent block, only valid if
932 OCFS2_REFCOUNT_LEAF_FL is set in
933 rf_flags */
934/*20*/ struct ocfs2_block_check rf_check; /* Error checking */
935 __le64 rf_last_eb_blk; /* Pointer to last extent block */
936/*30*/ __le32 rf_count; /* Number of inodes sharing this
937 refcount tree */
938 __le32 rf_flags; /* See the flags above */
939 __le32 rf_clusters; /* clusters covered by refcount tree. */
940 __le32 rf_cpos; /* cluster offset in refcount tree.*/
941/*40*/ __le32 rf_generation; /* generation number. all be the same
942 * for the same refcount tree. */
943 __le32 rf_reserved0;
Joel Becker9cbc0122010-03-26 10:07:42 +0800944 __le64 rf_suballoc_loc; /* Suballocator block group this
945 refcount block belongs to. Only
946 valid if allocated from a
947 discontiguous block group */
948/*50*/ __le64 rf_reserved1[6];
Tao Ma721f69c2009-08-18 11:17:49 +0800949/*80*/ union {
950 struct ocfs2_refcount_list rf_records; /* List of refcount
951 records */
952 struct ocfs2_extent_list rf_list; /* Extent record list,
953 only valid if
954 OCFS2_REFCOUNT_TREE_FL
955 is set in rf_flags */
956 };
957/* Actual on-disk size is one block */
958};
959
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800960/*
961 * On disk extended attribute structure for OCFS2.
962 */
963
964/*
965 * ocfs2_xattr_entry indicates one extend attribute.
966 *
967 * Note that it can be stored in inode, one block or one xattr bucket.
968 */
969struct ocfs2_xattr_entry {
970 __le32 xe_name_hash; /* hash value of xattr prefix+suffix. */
Tao Ma8573f792008-10-24 22:24:17 +0800971 __le16 xe_name_offset; /* byte offset from the 1st entry in the
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800972 local xattr storage(inode, xattr block or
973 xattr bucket). */
974 __u8 xe_name_len; /* xattr name len, does't include prefix. */
Tao Ma8573f792008-10-24 22:24:17 +0800975 __u8 xe_type; /* the low 7 bits indicate the name prefix
976 * type and the highest bit indicates whether
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800977 * the EA is stored in the local storage. */
978 __le64 xe_value_size; /* real xattr value length. */
979};
980
981/*
982 * On disk structure for xattr header.
983 *
984 * One ocfs2_xattr_header describes how many ocfs2_xattr_entry records in
985 * the local xattr storage.
986 */
987struct ocfs2_xattr_header {
988 __le16 xh_count; /* contains the count of how
989 many records are in the
990 local xattr storage. */
Tao Ma0c044f02008-08-18 17:38:50 +0800991 __le16 xh_free_start; /* current offset for storing
992 xattr. */
993 __le16 xh_name_value_len; /* total length of name/value
994 length in this bucket. */
Tao Ma8573f792008-10-24 22:24:17 +0800995 __le16 xh_num_buckets; /* Number of xattr buckets
996 in this extent record,
997 only valid in the first
998 bucket. */
Joel Beckerab552d52008-10-16 17:50:30 -0700999 struct ocfs2_block_check xh_check; /* Error checking
1000 (Note, this is only
1001 used for xattr
1002 buckets. A block uses
1003 xb_check and sets
1004 this field to zero.) */
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001005 struct ocfs2_xattr_entry xh_entries[0]; /* xattr entry list. */
1006};
1007
1008/*
1009 * On disk structure for xattr value root.
1010 *
Tao Ma8573f792008-10-24 22:24:17 +08001011 * When an xattr's value is large enough, it is stored in an external
1012 * b-tree like file data. The xattr value root points to this structure.
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001013 */
1014struct ocfs2_xattr_value_root {
1015/*00*/ __le32 xr_clusters; /* clusters covered by xattr value. */
1016 __le32 xr_reserved0;
1017 __le64 xr_last_eb_blk; /* Pointer to last extent block */
1018/*10*/ struct ocfs2_extent_list xr_list; /* Extent record list */
1019};
1020
1021/*
1022 * On disk structure for xattr tree root.
1023 *
1024 * It is used when there are too many extended attributes for one file. These
1025 * attributes will be organized and stored in an indexed-btree.
1026 */
1027struct ocfs2_xattr_tree_root {
1028/*00*/ __le32 xt_clusters; /* clusters covered by xattr. */
1029 __le32 xt_reserved0;
1030 __le64 xt_last_eb_blk; /* Pointer to last extent block */
1031/*10*/ struct ocfs2_extent_list xt_list; /* Extent record list */
1032};
1033
Tiger Yangcf1d6c72008-08-18 17:11:00 +08001034#define OCFS2_XATTR_INDEXED 0x1
1035#define OCFS2_HASH_SHIFT 5
1036#define OCFS2_XATTR_ROUND 3
1037#define OCFS2_XATTR_SIZE(size) (((size) + OCFS2_XATTR_ROUND) & \
1038 ~(OCFS2_XATTR_ROUND))
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001039
Tao Ma0c044f02008-08-18 17:38:50 +08001040#define OCFS2_XATTR_BUCKET_SIZE 4096
1041#define OCFS2_XATTR_MAX_BLOCKS_PER_BUCKET (OCFS2_XATTR_BUCKET_SIZE \
1042 / OCFS2_MIN_BLOCKSIZE)
1043
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001044/*
1045 * On disk structure for xattr block.
1046 */
1047struct ocfs2_xattr_block {
1048/*00*/ __u8 xb_signature[8]; /* Signature for verification */
1049 __le16 xb_suballoc_slot; /* Slot suballocator this
1050 block belongs to. */
1051 __le16 xb_suballoc_bit; /* Bit offset in suballocator
1052 block group */
1053 __le32 xb_fs_generation; /* Must match super block */
1054/*10*/ __le64 xb_blkno; /* Offset on disk, in blocks */
Joel Beckerab552d52008-10-16 17:50:30 -07001055 struct ocfs2_block_check xb_check; /* Error checking */
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001056/*20*/ __le16 xb_flags; /* Indicates whether this block contains
1057 real xattr or a xattr tree. */
1058 __le16 xb_reserved0;
1059 __le32 xb_reserved1;
Joel Becker9cbc0122010-03-26 10:07:42 +08001060 __le64 xb_suballoc_loc; /* Suballocator block group this
1061 xattr block belongs to. Only
1062 valid if allocated from a
1063 discontiguous block group */
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001064/*30*/ union {
1065 struct ocfs2_xattr_header xb_header; /* xattr header if this
1066 block contains xattr */
1067 struct ocfs2_xattr_tree_root xb_root;/* xattr tree root if this
1068 block cotains xattr
1069 tree. */
1070 } xb_attrs;
1071};
1072
1073#define OCFS2_XATTR_ENTRY_LOCAL 0x80
1074#define OCFS2_XATTR_TYPE_MASK 0x7F
1075static inline void ocfs2_xattr_set_local(struct ocfs2_xattr_entry *xe,
1076 int local)
1077{
1078 if (local)
1079 xe->xe_type |= OCFS2_XATTR_ENTRY_LOCAL;
1080 else
1081 xe->xe_type &= ~OCFS2_XATTR_ENTRY_LOCAL;
1082}
1083
1084static inline int ocfs2_xattr_is_local(struct ocfs2_xattr_entry *xe)
1085{
1086 return xe->xe_type & OCFS2_XATTR_ENTRY_LOCAL;
1087}
1088
1089static inline void ocfs2_xattr_set_type(struct ocfs2_xattr_entry *xe, int type)
1090{
1091 xe->xe_type |= type & OCFS2_XATTR_TYPE_MASK;
1092}
1093
1094static inline int ocfs2_xattr_get_type(struct ocfs2_xattr_entry *xe)
1095{
1096 return xe->xe_type & OCFS2_XATTR_TYPE_MASK;
1097}
1098
Jan Kara9e33d692008-08-25 19:56:50 +02001099/*
1100 * On disk structures for global quota file
1101 */
1102
1103/* Magic numbers and known versions for global quota files */
1104#define OCFS2_GLOBAL_QMAGICS {\
1105 0x0cf52470, /* USRQUOTA */ \
1106 0x0cf52471 /* GRPQUOTA */ \
1107}
1108
1109#define OCFS2_GLOBAL_QVERSIONS {\
1110 0, \
1111 0, \
1112}
1113
1114
1115/* Each block of each quota file has a certain fixed number of bytes reserved
1116 * for OCFS2 internal use at its end. OCFS2 can use it for things like
1117 * checksums, etc. */
1118#define OCFS2_QBLK_RESERVED_SPACE 8
1119
1120/* Generic header of all quota files */
1121struct ocfs2_disk_dqheader {
1122 __le32 dqh_magic; /* Magic number identifying file */
1123 __le32 dqh_version; /* Quota format version */
1124};
1125
1126#define OCFS2_GLOBAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
1127
1128/* Information header of global quota file (immediately follows the generic
1129 * header) */
1130struct ocfs2_global_disk_dqinfo {
1131/*00*/ __le32 dqi_bgrace; /* Grace time for space softlimit excess */
1132 __le32 dqi_igrace; /* Grace time for inode softlimit excess */
1133 __le32 dqi_syncms; /* Time after which we sync local changes to
1134 * global quota file */
1135 __le32 dqi_blocks; /* Number of blocks in quota file */
1136/*10*/ __le32 dqi_free_blk; /* First free block in quota file */
1137 __le32 dqi_free_entry; /* First block with free dquot entry in quota
1138 * file */
1139};
1140
1141/* Structure with global user / group information. We reserve some space
1142 * for future use. */
1143struct ocfs2_global_disk_dqblk {
1144/*00*/ __le32 dqb_id; /* ID the structure belongs to */
1145 __le32 dqb_use_count; /* Number of nodes having reference to this structure */
1146 __le64 dqb_ihardlimit; /* absolute limit on allocated inodes */
1147/*10*/ __le64 dqb_isoftlimit; /* preferred inode limit */
1148 __le64 dqb_curinodes; /* current # allocated inodes */
1149/*20*/ __le64 dqb_bhardlimit; /* absolute limit on disk space */
1150 __le64 dqb_bsoftlimit; /* preferred limit on disk space */
1151/*30*/ __le64 dqb_curspace; /* current space occupied */
1152 __le64 dqb_btime; /* time limit for excessive disk use */
1153/*40*/ __le64 dqb_itime; /* time limit for excessive inode use */
1154 __le64 dqb_pad1;
1155/*50*/ __le64 dqb_pad2;
1156};
1157
1158/*
1159 * On-disk structures for local quota file
1160 */
1161
1162/* Magic numbers and known versions for local quota files */
1163#define OCFS2_LOCAL_QMAGICS {\
1164 0x0cf524c0, /* USRQUOTA */ \
1165 0x0cf524c1 /* GRPQUOTA */ \
1166}
1167
1168#define OCFS2_LOCAL_QVERSIONS {\
1169 0, \
1170 0, \
1171}
1172
1173/* Quota flags in dqinfo header */
1174#define OLQF_CLEAN 0x0001 /* Quota file is empty (this should be after\
1175 * quota has been cleanly turned off) */
1176
1177#define OCFS2_LOCAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
1178
1179/* Information header of local quota file (immediately follows the generic
1180 * header) */
1181struct ocfs2_local_disk_dqinfo {
1182 __le32 dqi_flags; /* Flags for quota file */
1183 __le32 dqi_chunks; /* Number of chunks of quota structures
1184 * with a bitmap */
1185 __le32 dqi_blocks; /* Number of blocks allocated for quota file */
1186};
1187
1188/* Header of one chunk of a quota file */
1189struct ocfs2_local_disk_chunk {
1190 __le32 dqc_free; /* Number of free entries in the bitmap */
Coly Li93654542009-12-06 22:38:53 +08001191 __u8 dqc_bitmap[0]; /* Bitmap of entries in the corresponding
Jan Kara9e33d692008-08-25 19:56:50 +02001192 * chunk of quota file */
1193};
1194
1195/* One entry in local quota file */
1196struct ocfs2_local_disk_dqblk {
1197/*00*/ __le64 dqb_id; /* id this quota applies to */
1198 __le64 dqb_spacemod; /* Change in the amount of used space */
1199/*10*/ __le64 dqb_inodemod; /* Change in the amount of used inodes */
1200};
1201
Joel Beckerab552d52008-10-16 17:50:30 -07001202
1203/*
1204 * The quota trailer lives at the end of each quota block.
1205 */
1206
1207struct ocfs2_disk_dqtrailer {
1208/*00*/ struct ocfs2_block_check dq_check; /* Error checking */
1209/*08*/ /* Cannot be larger than OCFS2_QBLK_RESERVED_SPACE */
1210};
1211
1212static inline struct ocfs2_disk_dqtrailer *ocfs2_block_dqtrailer(int blocksize,
1213 void *buf)
1214{
1215 char *ptr = buf;
1216 ptr += blocksize - OCFS2_QBLK_RESERVED_SPACE;
1217
1218 return (struct ocfs2_disk_dqtrailer *)ptr;
1219}
1220
Mark Fashehccd979b2005-12-15 14:31:24 -08001221#ifdef __KERNEL__
1222static inline int ocfs2_fast_symlink_chars(struct super_block *sb)
1223{
1224 return sb->s_blocksize -
1225 offsetof(struct ocfs2_dinode, id2.i_symlink);
1226}
1227
Tiger Yangfdd77702008-08-18 17:08:55 +08001228static inline int ocfs2_max_inline_data_with_xattr(struct super_block *sb,
1229 struct ocfs2_dinode *di)
1230{
1231 unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
1232
1233 if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
1234 return sb->s_blocksize -
1235 offsetof(struct ocfs2_dinode, id2.i_data.id_data) -
1236 xattrsize;
1237 else
1238 return sb->s_blocksize -
1239 offsetof(struct ocfs2_dinode, id2.i_data.id_data);
1240}
1241
Mark Fashehccd979b2005-12-15 14:31:24 -08001242static inline int ocfs2_extent_recs_per_inode(struct super_block *sb)
1243{
1244 int size;
1245
1246 size = sb->s_blocksize -
1247 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1248
1249 return size / sizeof(struct ocfs2_extent_rec);
1250}
1251
Tiger Yangfdd77702008-08-18 17:08:55 +08001252static inline int ocfs2_extent_recs_per_inode_with_xattr(
1253 struct super_block *sb,
1254 struct ocfs2_dinode *di)
1255{
1256 int size;
1257 unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
1258
1259 if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
1260 size = sb->s_blocksize -
1261 offsetof(struct ocfs2_dinode, id2.i_list.l_recs) -
1262 xattrsize;
1263 else
1264 size = sb->s_blocksize -
1265 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1266
1267 return size / sizeof(struct ocfs2_extent_rec);
1268}
1269
Mark Fasheh9b7895e2008-11-12 16:27:44 -08001270static inline int ocfs2_extent_recs_per_dx_root(struct super_block *sb)
1271{
1272 int size;
1273
1274 size = sb->s_blocksize -
1275 offsetof(struct ocfs2_dx_root_block, dr_list.l_recs);
1276
1277 return size / sizeof(struct ocfs2_extent_rec);
1278}
1279
Mark Fashehccd979b2005-12-15 14:31:24 -08001280static inline int ocfs2_chain_recs_per_inode(struct super_block *sb)
1281{
1282 int size;
1283
1284 size = sb->s_blocksize -
1285 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
1286
1287 return size / sizeof(struct ocfs2_chain_rec);
1288}
1289
1290static inline u16 ocfs2_extent_recs_per_eb(struct super_block *sb)
1291{
1292 int size;
1293
1294 size = sb->s_blocksize -
1295 offsetof(struct ocfs2_extent_block, h_list.l_recs);
1296
1297 return size / sizeof(struct ocfs2_extent_rec);
1298}
1299
Joel Becker798db352010-04-13 14:26:32 +08001300static inline u16 ocfs2_extent_recs_per_gd(struct super_block *sb)
1301{
1302 int size;
1303
1304 size = sb->s_blocksize -
1305 offsetof(struct ocfs2_group_desc, bg_list.l_recs);
1306
1307 return size / sizeof(struct ocfs2_extent_rec);
1308}
1309
Mark Fasheh9b7895e2008-11-12 16:27:44 -08001310static inline int ocfs2_dx_entries_per_leaf(struct super_block *sb)
1311{
1312 int size;
1313
1314 size = sb->s_blocksize -
1315 offsetof(struct ocfs2_dx_leaf, dl_list.de_entries);
1316
1317 return size / sizeof(struct ocfs2_dx_entry);
1318}
1319
Mark Fasheh4ed8a6b2008-11-24 17:02:08 -08001320static inline int ocfs2_dx_entries_per_root(struct super_block *sb)
1321{
1322 int size;
1323
1324 size = sb->s_blocksize -
1325 offsetof(struct ocfs2_dx_root_block, dr_entries.de_entries);
1326
1327 return size / sizeof(struct ocfs2_dx_entry);
1328}
1329
Mark Fashehccd979b2005-12-15 14:31:24 -08001330static inline u16 ocfs2_local_alloc_size(struct super_block *sb)
1331{
1332 u16 size;
1333
1334 size = sb->s_blocksize -
1335 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
1336
1337 return size;
1338}
1339
Joel Becker4cbe4242010-04-13 14:26:12 +08001340static inline int ocfs2_group_bitmap_size(struct super_block *sb,
Tao Ma85718822010-04-13 14:38:06 +08001341 int suballocator,
1342 u32 feature_incompat)
Mark Fashehccd979b2005-12-15 14:31:24 -08001343{
Tao Ma85718822010-04-13 14:38:06 +08001344 int size = sb->s_blocksize -
1345 offsetof(struct ocfs2_group_desc, bg_bitmap);
Mark Fashehccd979b2005-12-15 14:31:24 -08001346
Tao Ma85718822010-04-13 14:38:06 +08001347 /*
1348 * The cluster allocator uses the entire block. Suballocators have
1349 * never used more than OCFS2_MAX_BG_BITMAP_SIZE. Unfortunately, older
1350 * code expects bg_size set to the maximum. Thus we must keep
1351 * bg_size as-is unless discontig_bg is enabled.
1352 */
1353 if (suballocator &&
1354 (feature_incompat & OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG))
Joel Becker4cbe4242010-04-13 14:26:12 +08001355 size = OCFS2_MAX_BG_BITMAP_SIZE;
Mark Fashehccd979b2005-12-15 14:31:24 -08001356
1357 return size;
1358}
1359
1360static inline int ocfs2_truncate_recs_per_inode(struct super_block *sb)
1361{
1362 int size;
1363
1364 size = sb->s_blocksize -
1365 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
1366
1367 return size / sizeof(struct ocfs2_truncate_rec);
1368}
Mark Fasheh50af94b2007-01-21 14:44:59 -08001369
1370static inline u64 ocfs2_backup_super_blkno(struct super_block *sb, int index)
1371{
1372 u64 offset = OCFS2_BACKUP_SB_START;
1373
1374 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
1375 offset <<= (2 * index);
Mark Fasheha8a75a22007-01-26 10:46:59 -08001376 offset >>= sb->s_blocksize_bits;
Mark Fasheh50af94b2007-01-21 14:44:59 -08001377 return offset;
1378 }
1379
1380 return 0;
1381
1382}
Tao Ma0c044f02008-08-18 17:38:50 +08001383
1384static inline u16 ocfs2_xattr_recs_per_xb(struct super_block *sb)
1385{
1386 int size;
1387
1388 size = sb->s_blocksize -
1389 offsetof(struct ocfs2_xattr_block,
1390 xb_attrs.xb_root.xt_list.l_recs);
1391
1392 return size / sizeof(struct ocfs2_extent_rec);
1393}
Tao Ma721f69c2009-08-18 11:17:49 +08001394
1395static inline u16 ocfs2_extent_recs_per_rb(struct super_block *sb)
1396{
1397 int size;
1398
1399 size = sb->s_blocksize -
1400 offsetof(struct ocfs2_refcount_block, rf_list.l_recs);
1401
1402 return size / sizeof(struct ocfs2_extent_rec);
1403}
1404
1405static inline u16 ocfs2_refcount_recs_per_rb(struct super_block *sb)
1406{
1407 int size;
1408
1409 size = sb->s_blocksize -
1410 offsetof(struct ocfs2_refcount_block, rf_records.rl_recs);
1411
1412 return size / sizeof(struct ocfs2_refcount_rec);
1413}
Tao Mae73a8192009-08-11 14:33:14 +08001414
1415static inline u32
1416ocfs2_get_ref_rec_low_cpos(const struct ocfs2_refcount_rec *rec)
1417{
1418 return le64_to_cpu(rec->r_cpos) & OCFS2_32BIT_POS_MASK;
1419}
Mark Fashehccd979b2005-12-15 14:31:24 -08001420#else
1421static inline int ocfs2_fast_symlink_chars(int blocksize)
1422{
1423 return blocksize - offsetof(struct ocfs2_dinode, id2.i_symlink);
1424}
1425
Tao Ma1097df32010-01-20 11:31:11 +08001426static inline int ocfs2_max_inline_data_with_xattr(int blocksize,
1427 struct ocfs2_dinode *di)
Mark Fasheh15b1e362007-09-07 13:58:15 -07001428{
Tao Ma1097df32010-01-20 11:31:11 +08001429 if (di && (di->i_dyn_features & OCFS2_INLINE_XATTR_FL))
1430 return blocksize -
1431 offsetof(struct ocfs2_dinode, id2.i_data.id_data) -
1432 di->i_xattr_inline_size;
1433 else
1434 return blocksize -
1435 offsetof(struct ocfs2_dinode, id2.i_data.id_data);
Mark Fasheh15b1e362007-09-07 13:58:15 -07001436}
1437
Mark Fashehccd979b2005-12-15 14:31:24 -08001438static inline int ocfs2_extent_recs_per_inode(int blocksize)
1439{
1440 int size;
1441
1442 size = blocksize -
1443 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1444
1445 return size / sizeof(struct ocfs2_extent_rec);
1446}
1447
1448static inline int ocfs2_chain_recs_per_inode(int blocksize)
1449{
1450 int size;
1451
1452 size = blocksize -
1453 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
1454
1455 return size / sizeof(struct ocfs2_chain_rec);
1456}
1457
1458static inline int ocfs2_extent_recs_per_eb(int blocksize)
1459{
1460 int size;
1461
1462 size = blocksize -
1463 offsetof(struct ocfs2_extent_block, h_list.l_recs);
1464
1465 return size / sizeof(struct ocfs2_extent_rec);
1466}
1467
Joel Becker798db352010-04-13 14:26:32 +08001468static inline int ocfs2_extent_recs_per_gd(int blocksize)
1469{
1470 int size;
1471
1472 size = blocksize -
1473 offsetof(struct ocfs2_group_desc, bg_list.l_recs);
1474
1475 return size / sizeof(struct ocfs2_extent_rec);
1476}
1477
Mark Fashehccd979b2005-12-15 14:31:24 -08001478static inline int ocfs2_local_alloc_size(int blocksize)
1479{
1480 int size;
1481
1482 size = blocksize -
1483 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
1484
1485 return size;
1486}
1487
Tao Ma85718822010-04-13 14:38:06 +08001488static inline int ocfs2_group_bitmap_size(int blocksize,
1489 int suballocator,
1490 uint32_t feature_incompat)
Mark Fashehccd979b2005-12-15 14:31:24 -08001491{
Tao Ma85718822010-04-13 14:38:06 +08001492 int size = sb->s_blocksize -
1493 offsetof(struct ocfs2_group_desc, bg_bitmap);
Mark Fashehccd979b2005-12-15 14:31:24 -08001494
Tao Ma85718822010-04-13 14:38:06 +08001495 /*
1496 * The cluster allocator uses the entire block. Suballocators have
1497 * never used more than OCFS2_MAX_BG_BITMAP_SIZE. Unfortunately, older
1498 * code expects bg_size set to the maximum. Thus we must keep
1499 * bg_size as-is unless discontig_bg is enabled.
1500 */
1501 if (suballocator &&
1502 (feature_incompat & OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG))
Joel Becker4cbe4242010-04-13 14:26:12 +08001503 size = OCFS2_MAX_BG_BITMAP_SIZE;
Mark Fashehccd979b2005-12-15 14:31:24 -08001504
1505 return size;
1506}
1507
1508static inline int ocfs2_truncate_recs_per_inode(int blocksize)
1509{
1510 int size;
1511
1512 size = blocksize -
1513 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
1514
1515 return size / sizeof(struct ocfs2_truncate_rec);
1516}
Mark Fasheh50af94b2007-01-21 14:44:59 -08001517
1518static inline uint64_t ocfs2_backup_super_blkno(int blocksize, int index)
1519{
1520 uint64_t offset = OCFS2_BACKUP_SB_START;
1521
1522 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
1523 offset <<= (2 * index);
1524 offset /= blocksize;
1525 return offset;
1526 }
1527
1528 return 0;
1529}
Tao Ma0c044f02008-08-18 17:38:50 +08001530
1531static inline int ocfs2_xattr_recs_per_xb(int blocksize)
1532{
1533 int size;
1534
1535 size = blocksize -
1536 offsetof(struct ocfs2_xattr_block,
1537 xb_attrs.xb_root.xt_list.l_recs);
1538
1539 return size / sizeof(struct ocfs2_extent_rec);
1540}
Mark Fashehccd979b2005-12-15 14:31:24 -08001541#endif /* __KERNEL__ */
1542
1543
1544static inline int ocfs2_system_inode_is_global(int type)
1545{
1546 return ((type >= 0) &&
1547 (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE));
1548}
1549
1550static inline int ocfs2_sprintf_system_inode_name(char *buf, int len,
1551 int type, int slot)
1552{
1553 int chars;
1554
1555 /*
1556 * Global system inodes can only have one copy. Everything
1557 * after OCFS2_LAST_GLOBAL_SYSTEM_INODE in the system inode
1558 * list has a copy per slot.
1559 */
1560 if (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE)
Joel Beckerfe9f3872008-06-12 22:39:18 -07001561 chars = snprintf(buf, len, "%s",
Mark Fashehccd979b2005-12-15 14:31:24 -08001562 ocfs2_system_inodes[type].si_name);
1563 else
1564 chars = snprintf(buf, len,
1565 ocfs2_system_inodes[type].si_name,
1566 slot);
1567
1568 return chars;
1569}
1570
1571static inline void ocfs2_set_de_type(struct ocfs2_dir_entry *de,
1572 umode_t mode)
1573{
1574 de->file_type = ocfs2_type_by_mode[(mode & S_IFMT)>>S_SHIFT];
1575}
1576
Tao Maaf2bf0d2010-05-17 15:14:17 +08001577static inline int ocfs2_gd_is_discontig(struct ocfs2_group_desc *gd)
1578{
1579 if ((offsetof(struct ocfs2_group_desc, bg_bitmap) +
1580 le16_to_cpu(gd->bg_size)) !=
1581 offsetof(struct ocfs2_group_desc, bg_list))
1582 return 0;
1583 /*
1584 * Only valid to check l_next_free_rec if
1585 * bg_bitmap + bg_size == bg_list.
1586 */
1587 if (!gd->bg_list.l_next_free_rec)
1588 return 0;
1589 return 1;
1590}
Mark Fashehccd979b2005-12-15 14:31:24 -08001591#endif /* _OCFS2_FS_H */
1592