blob: 448aa8d11a973724adad501d98b7dfcdc3ab4439 [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 */
510/*20*/ __le64 h_reserved3;
511 __le64 h_next_leaf_blk; /* Offset on disk, in blocks,
512 of next leaf header pointing
513 to data */
514/*30*/ struct ocfs2_extent_list h_list; /* Extent record list */
515/* Actual on-disk size is one block */
516};
517
518/*
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800519 * On disk slot map for OCFS2. This defines the contents of the "slot_map"
Joel Becker386a2ef2008-02-01 12:06:54 -0800520 * system file. A slot is valid if it contains a node number >= 0. The
521 * value -1 (0xFFFF) is OCFS2_INVALID_SLOT. This marks a slot empty.
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800522 */
523struct ocfs2_slot_map {
524/*00*/ __le16 sm_slots[0];
525/*
526 * Actual on-disk size is one block. OCFS2_MAX_SLOTS is 255,
527 * 255 * sizeof(__le16) == 512B, within the 512B block minimum blocksize.
528 */
529};
530
Joel Becker386a2ef2008-02-01 12:06:54 -0800531struct ocfs2_extended_slot {
532/*00*/ __u8 es_valid;
533 __u8 es_reserved1[3];
534 __le32 es_node_num;
535/*10*/
536};
537
538/*
539 * The extended slot map, used when OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP
540 * is set. It separates out the valid marker from the node number, and
541 * has room to grow. Unlike the old slot map, this format is defined by
542 * i_size.
543 */
544struct ocfs2_slot_map_extended {
545/*00*/ struct ocfs2_extended_slot se_slots[0];
546/*
547 * Actual size is i_size of the slot_map system file. It should
548 * match s_max_slots * sizeof(struct ocfs2_extended_slot)
549 */
550};
551
Joel Beckerb61817e2008-02-01 15:08:23 -0800552struct ocfs2_cluster_info {
553/*00*/ __u8 ci_stack[OCFS2_STACK_LABEL_LEN];
554 __le32 ci_reserved;
555/*08*/ __u8 ci_cluster[OCFS2_CLUSTER_NAME_LEN];
556/*18*/
557};
558
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800559/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800560 * On disk superblock for OCFS2
561 * Note that it is contained inside an ocfs2_dinode, so all offsets
562 * are relative to the start of ocfs2_dinode.id2.
563 */
564struct ocfs2_super_block {
565/*00*/ __le16 s_major_rev_level;
566 __le16 s_minor_rev_level;
567 __le16 s_mnt_count;
568 __le16 s_max_mnt_count;
569 __le16 s_state; /* File system state */
570 __le16 s_errors; /* Behaviour when detecting errors */
571 __le32 s_checkinterval; /* Max time between checks */
572/*10*/ __le64 s_lastcheck; /* Time of last check */
573 __le32 s_creator_os; /* OS */
574 __le32 s_feature_compat; /* Compatible feature set */
575/*20*/ __le32 s_feature_incompat; /* Incompatible feature set */
576 __le32 s_feature_ro_compat; /* Readonly-compatible feature set */
577 __le64 s_root_blkno; /* Offset, in blocks, of root directory
578 dinode */
579/*30*/ __le64 s_system_dir_blkno; /* Offset, in blocks, of system
580 directory dinode */
581 __le32 s_blocksize_bits; /* Blocksize for this fs */
582 __le32 s_clustersize_bits; /* Clustersize for this fs */
583/*40*/ __le16 s_max_slots; /* Max number of simultaneous mounts
584 before tunefs required */
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700585 __le16 s_tunefs_flag;
Tiger Yangcf1d6c72008-08-18 17:11:00 +0800586 __le32 s_uuid_hash; /* hash value of uuid */
Mark Fashehccd979b2005-12-15 14:31:24 -0800587 __le64 s_first_cluster_group; /* Block offset of 1st cluster
588 * group header */
589/*50*/ __u8 s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */
590/*90*/ __u8 s_uuid[OCFS2_VOL_UUID_LEN]; /* 128-bit uuid */
Joel Beckerb61817e2008-02-01 15:08:23 -0800591/*A0*/ struct ocfs2_cluster_info s_cluster_info; /* Selected userspace
592 stack. Only valid
593 with INCOMPAT flag. */
Tiger Yang8154da32008-08-18 17:11:46 +0800594/*B8*/ __le16 s_xattr_inline_size; /* extended attribute inline size
595 for this fs*/
596 __le16 s_reserved0;
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800597 __le32 s_dx_seed[3]; /* seed[0-2] for dx dir hash.
598 * s_uuid_hash serves as seed[3]. */
599/*C0*/ __le64 s_reserved2[15]; /* Fill out superblock */
Joel Beckerb61817e2008-02-01 15:08:23 -0800600/*140*/
601
602 /*
603 * NOTE: As stated above, all offsets are relative to
604 * ocfs2_dinode.id2, which is at 0xC0 in the inode.
605 * 0xC0 + 0x140 = 0x200 or 512 bytes. A superblock must fit within
606 * our smallest blocksize, which is 512 bytes. To ensure this,
607 * we reserve the space in s_reserved2. Anything past s_reserved2
608 * will not be available on the smallest blocksize.
609 */
Mark Fashehccd979b2005-12-15 14:31:24 -0800610};
611
612/*
613 * Local allocation bitmap for OCFS2 slots
614 * Note that it exists inside an ocfs2_dinode, so all offsets are
615 * relative to the start of ocfs2_dinode.id2.
616 */
617struct ocfs2_local_alloc
618{
619/*00*/ __le32 la_bm_off; /* Starting bit offset in main bitmap */
620 __le16 la_size; /* Size of included bitmap, in bytes */
621 __le16 la_reserved1;
622 __le64 la_reserved2;
623/*10*/ __u8 la_bitmap[0];
624};
625
626/*
Mark Fasheh15b1e362007-09-07 13:58:15 -0700627 * Data-in-inode header. This is only used if i_dyn_features has
628 * OCFS2_INLINE_DATA_FL set.
629 */
630struct ocfs2_inline_data
631{
632/*00*/ __le16 id_count; /* Number of bytes that can be used
633 * for data, starting at id_data */
634 __le16 id_reserved0;
635 __le32 id_reserved1;
636 __u8 id_data[0]; /* Start of user data */
637};
638
639/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800640 * On disk inode for OCFS2
641 */
642struct ocfs2_dinode {
643/*00*/ __u8 i_signature[8]; /* Signature for validation */
644 __le32 i_generation; /* Generation number */
645 __le16 i_suballoc_slot; /* Slot suballocator this inode
646 belongs to */
647 __le16 i_suballoc_bit; /* Bit offset in suballocator
648 block group */
Mark Fasheh198a1ca2008-11-20 17:54:57 -0800649/*10*/ __le16 i_links_count_hi; /* High 16 bits of links count */
Tiger Yangfdd77702008-08-18 17:08:55 +0800650 __le16 i_xattr_inline_size;
Mark Fashehccd979b2005-12-15 14:31:24 -0800651 __le32 i_clusters; /* Cluster count */
652 __le32 i_uid; /* Owner UID */
653 __le32 i_gid; /* Owning GID */
654/*20*/ __le64 i_size; /* Size in bytes */
655 __le16 i_mode; /* File mode */
656 __le16 i_links_count; /* Links count */
657 __le32 i_flags; /* File flags */
658/*30*/ __le64 i_atime; /* Access time */
659 __le64 i_ctime; /* Creation time */
660/*40*/ __le64 i_mtime; /* Modification time */
661 __le64 i_dtime; /* Deletion time */
662/*50*/ __le64 i_blkno; /* Offset on disk, in blocks */
663 __le64 i_last_eb_blk; /* Pointer to last extent
664 block */
665/*60*/ __le32 i_fs_generation; /* Generation per fs-instance */
666 __le32 i_atime_nsec;
667 __le32 i_ctime_nsec;
668 __le32 i_mtime_nsec;
Tiger Yangfdd77702008-08-18 17:08:55 +0800669/*70*/ __le32 i_attr;
Tiger Yang50008632007-03-20 16:01:38 -0700670 __le16 i_orphaned_slot; /* Only valid when OCFS2_ORPHANED_FL
671 was set in i_flags */
Mark Fasheh15b1e362007-09-07 13:58:15 -0700672 __le16 i_dyn_features;
Tiger Yangfdd77702008-08-18 17:08:55 +0800673 __le64 i_xattr_loc;
Joel Beckerab552d52008-10-16 17:50:30 -0700674/*80*/ struct ocfs2_block_check i_check; /* Error checking */
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800675/*88*/ __le64 i_dx_root; /* Pointer to dir index root block */
Tao Ma721f69c2009-08-18 11:17:49 +0800676/*90*/ __le64 i_refcount_loc;
677 __le64 i_reserved2[4];
Mark Fashehccd979b2005-12-15 14:31:24 -0800678/*B8*/ union {
679 __le64 i_pad1; /* Generic way to refer to this
680 64bit union */
681 struct {
682 __le64 i_rdev; /* Device number */
683 } dev1;
684 struct { /* Info for bitmap system
685 inodes */
686 __le32 i_used; /* Bits (ie, clusters) used */
687 __le32 i_total; /* Total bits (clusters)
688 available */
689 } bitmap1;
690 struct { /* Info for journal system
691 inodes */
692 __le32 ij_flags; /* Mounted, version, etc. */
Sunil Mushranc69991a2008-07-14 17:31:09 -0700693 __le32 ij_recovery_generation; /* Incremented when the
694 journal is recovered
695 after an unclean
696 shutdown */
Mark Fashehccd979b2005-12-15 14:31:24 -0800697 } journal1;
698 } id1; /* Inode type dependant 1 */
699/*C0*/ union {
700 struct ocfs2_super_block i_super;
701 struct ocfs2_local_alloc i_lab;
702 struct ocfs2_chain_list i_chain;
703 struct ocfs2_extent_list i_list;
704 struct ocfs2_truncate_log i_dealloc;
Mark Fasheh15b1e362007-09-07 13:58:15 -0700705 struct ocfs2_inline_data i_data;
Mark Fashehccd979b2005-12-15 14:31:24 -0800706 __u8 i_symlink[0];
707 } id2;
708/* Actual on-disk size is one block */
709};
710
711/*
712 * On-disk directory entry structure for OCFS2
713 *
714 * Packed as this structure could be accessed unaligned on 64-bit platforms
715 */
716struct ocfs2_dir_entry {
717/*00*/ __le64 inode; /* Inode number */
718 __le16 rec_len; /* Directory entry length */
719 __u8 name_len; /* Name length */
720 __u8 file_type;
721/*0C*/ char name[OCFS2_MAX_FILENAME_LEN]; /* File name */
722/* Actual on-disk length specified by rec_len */
723} __attribute__ ((packed));
724
725/*
Mark Fasheh87d35a72008-12-10 17:36:25 -0800726 * Per-block record for the unindexed directory btree. This is carefully
727 * crafted so that the rec_len and name_len records of an ocfs2_dir_entry are
728 * mirrored. That way, the directory manipulation code needs a minimal amount
729 * of update.
730 *
731 * NOTE: Keep this structure aligned to a multiple of 4 bytes.
732 */
733struct ocfs2_dir_block_trailer {
734/*00*/ __le64 db_compat_inode; /* Always zero. Was inode */
735
736 __le16 db_compat_rec_len; /* Backwards compatible with
737 * ocfs2_dir_entry. */
738 __u8 db_compat_name_len; /* Always zero. Was name_len */
739 __u8 db_reserved0;
740 __le16 db_reserved1;
741 __le16 db_free_rec_len; /* Size of largest empty hole
742 * in this block. (unused) */
743/*10*/ __u8 db_signature[8]; /* Signature for verification */
744 __le64 db_reserved2;
745 __le64 db_free_next; /* Next block in list (unused) */
746/*20*/ __le64 db_blkno; /* Offset on disk, in blocks */
747 __le64 db_parent_dinode; /* dinode which owns me, in
748 blocks */
Joel Beckerc175a512008-12-10 17:58:22 -0800749/*30*/ struct ocfs2_block_check db_check; /* Error checking */
Mark Fasheh87d35a72008-12-10 17:36:25 -0800750/*40*/
751};
752
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800753 /*
754 * A directory entry in the indexed tree. We don't store the full name here,
755 * but instead provide a pointer to the full dirent in the unindexed tree.
756 *
757 * We also store name_len here so as to reduce the number of leaf blocks we
758 * need to search in case of collisions.
759 */
760struct ocfs2_dx_entry {
761 __le32 dx_major_hash; /* Used to find logical
762 * cluster in index */
763 __le32 dx_minor_hash; /* Lower bits used to find
764 * block in cluster */
765 __le64 dx_dirent_blk; /* Physical block in unindexed
766 * tree holding this dirent. */
767};
768
769struct ocfs2_dx_entry_list {
770 __le32 de_reserved;
771 __le16 de_count; /* Maximum number of entries
772 * possible in de_entries */
773 __le16 de_num_used; /* Current number of
774 * de_entries entries */
775 struct ocfs2_dx_entry de_entries[0]; /* Indexed dir entries
776 * in a packed array of
777 * length de_num_used */
778};
779
Mark Fasheh4ed8a6b2008-11-24 17:02:08 -0800780#define OCFS2_DX_FLAG_INLINE 0x01
781
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800782/*
783 * A directory indexing block. Each indexed directory has one of these,
784 * pointed to by ocfs2_dinode.
785 *
786 * This block stores an indexed btree root, and a set of free space
787 * start-of-list pointers.
788 */
789struct ocfs2_dx_root_block {
790 __u8 dr_signature[8]; /* Signature for verification */
791 struct ocfs2_block_check dr_check; /* Error checking */
792 __le16 dr_suballoc_slot; /* Slot suballocator this
793 * block belongs to. */
794 __le16 dr_suballoc_bit; /* Bit offset in suballocator
795 * block group */
796 __le32 dr_fs_generation; /* Must match super block */
797 __le64 dr_blkno; /* Offset on disk, in blocks */
798 __le64 dr_last_eb_blk; /* Pointer to last
799 * extent block */
800 __le32 dr_clusters; /* Clusters allocated
801 * to the indexed tree. */
Mark Fasheh4ed8a6b2008-11-24 17:02:08 -0800802 __u8 dr_flags; /* OCFS2_DX_FLAG_* flags */
803 __u8 dr_reserved0;
804 __le16 dr_reserved1;
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800805 __le64 dr_dir_blkno; /* Pointer to parent inode */
Mark Fashehe3a93c22009-02-17 15:29:35 -0800806 __le32 dr_num_entries; /* Total number of
807 * names stored in
808 * this directory.*/
809 __le32 dr_reserved2;
Mark Fashehe7c17e42009-01-29 18:17:46 -0800810 __le64 dr_free_blk; /* Pointer to head of free
811 * unindexed block list. */
812 __le64 dr_reserved3[15];
Mark Fasheh4ed8a6b2008-11-24 17:02:08 -0800813 union {
814 struct ocfs2_extent_list dr_list; /* Keep this aligned to 128
815 * bits for maximum space
816 * efficiency. */
817 struct ocfs2_dx_entry_list dr_entries; /* In-root-block list of
818 * entries. We grow out
819 * to extents if this
820 * gets too big. */
821 };
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800822};
823
824/*
825 * The header of a leaf block in the indexed tree.
826 */
827struct ocfs2_dx_leaf {
828 __u8 dl_signature[8];/* Signature for verification */
829 struct ocfs2_block_check dl_check; /* Error checking */
830 __le64 dl_blkno; /* Offset on disk, in blocks */
831 __le32 dl_fs_generation;/* Must match super block */
832 __le32 dl_reserved0;
833 __le64 dl_reserved1;
834 struct ocfs2_dx_entry_list dl_list;
835};
836
Mark Fasheh87d35a72008-12-10 17:36:25 -0800837/*
Joel Becker4cbe4242010-04-13 14:26:12 +0800838 * Largest bitmap for a block (suballocator) group in bytes. This limit
839 * does not affect cluster groups (global allocator). Cluster group
840 * bitmaps run to the end of the block.
841 */
842#define OCFS2_MAX_BG_BITMAP_SIZE 256
843
844/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800845 * On disk allocator group structure for OCFS2
846 */
847struct ocfs2_group_desc
848{
849/*00*/ __u8 bg_signature[8]; /* Signature for validation */
850 __le16 bg_size; /* Size of included bitmap in
851 bytes. */
852 __le16 bg_bits; /* Bits represented by this
853 group. */
854 __le16 bg_free_bits_count; /* Free bits count */
855 __le16 bg_chain; /* What chain I am in. */
856/*10*/ __le32 bg_generation;
857 __le32 bg_reserved1;
858 __le64 bg_next_group; /* Next group in my list, in
859 blocks */
860/*20*/ __le64 bg_parent_dinode; /* dinode which owns me, in
861 blocks */
862 __le64 bg_blkno; /* Offset on disk, in blocks */
Joel Beckerab552d52008-10-16 17:50:30 -0700863/*30*/ struct ocfs2_block_check bg_check; /* Error checking */
864 __le64 bg_reserved2;
Joel Becker4cbe4242010-04-13 14:26:12 +0800865/*40*/ union {
866 __u8 bg_bitmap[0];
867 struct {
868 /*
869 * Block groups may be discontiguous when
870 * OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG is set.
871 * The extents of a discontigous block group are
872 * stored in bg_list. It is a flat list.
873 * l_tree_depth must always be zero. A
874 * discontiguous group is signified by a non-zero
875 * bg_list->l_next_free_rec. Only block groups
876 * can be discontiguous; Cluster groups cannot.
877 * We've never made a block group with more than
878 * 2048 blocks (256 bytes of bg_bitmap). This
879 * codifies that limit so that we can fit bg_list.
880 * bg_size of a discontiguous block group will
881 * be 256 to match bg_bitmap_filler.
882 */
883 __u8 bg_bitmap_filler[OCFS2_MAX_BG_BITMAP_SIZE];
884/*140*/ struct ocfs2_extent_list bg_list;
885 };
886 };
887/* Actual on-disk size is one block */
Mark Fashehccd979b2005-12-15 14:31:24 -0800888};
889
Tao Ma721f69c2009-08-18 11:17:49 +0800890struct ocfs2_refcount_rec {
891/*00*/ __le64 r_cpos; /* Physical offset, in clusters */
892 __le32 r_clusters; /* Clusters covered by this extent */
893 __le32 r_refcount; /* Reference count of this extent */
894/*10*/
895};
Tao Mae73a8192009-08-11 14:33:14 +0800896#define OCFS2_32BIT_POS_MASK (0xffffffffULL)
Tao Ma721f69c2009-08-18 11:17:49 +0800897
898#define OCFS2_REFCOUNT_LEAF_FL (0x00000001)
899#define OCFS2_REFCOUNT_TREE_FL (0x00000002)
900
901struct ocfs2_refcount_list {
902/*00*/ __le16 rl_count; /* Maximum number of entries possible
903 in rl_records */
904 __le16 rl_used; /* Current number of used records */
905 __le32 rl_reserved2;
906 __le64 rl_reserved1; /* Pad to sizeof(ocfs2_refcount_record) */
907/*10*/ struct ocfs2_refcount_rec rl_recs[0]; /* Refcount records */
908};
909
910
911struct ocfs2_refcount_block {
912/*00*/ __u8 rf_signature[8]; /* Signature for verification */
913 __le16 rf_suballoc_slot; /* Slot suballocator this block
914 belongs to */
915 __le16 rf_suballoc_bit; /* Bit offset in suballocator
916 block group */
917 __le32 rf_fs_generation; /* Must match superblock */
918/*10*/ __le64 rf_blkno; /* Offset on disk, in blocks */
919 __le64 rf_parent; /* Parent block, only valid if
920 OCFS2_REFCOUNT_LEAF_FL is set in
921 rf_flags */
922/*20*/ struct ocfs2_block_check rf_check; /* Error checking */
923 __le64 rf_last_eb_blk; /* Pointer to last extent block */
924/*30*/ __le32 rf_count; /* Number of inodes sharing this
925 refcount tree */
926 __le32 rf_flags; /* See the flags above */
927 __le32 rf_clusters; /* clusters covered by refcount tree. */
928 __le32 rf_cpos; /* cluster offset in refcount tree.*/
929/*40*/ __le32 rf_generation; /* generation number. all be the same
930 * for the same refcount tree. */
931 __le32 rf_reserved0;
932 __le64 rf_reserved1[7];
933/*80*/ union {
934 struct ocfs2_refcount_list rf_records; /* List of refcount
935 records */
936 struct ocfs2_extent_list rf_list; /* Extent record list,
937 only valid if
938 OCFS2_REFCOUNT_TREE_FL
939 is set in rf_flags */
940 };
941/* Actual on-disk size is one block */
942};
943
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800944/*
945 * On disk extended attribute structure for OCFS2.
946 */
947
948/*
949 * ocfs2_xattr_entry indicates one extend attribute.
950 *
951 * Note that it can be stored in inode, one block or one xattr bucket.
952 */
953struct ocfs2_xattr_entry {
954 __le32 xe_name_hash; /* hash value of xattr prefix+suffix. */
Tao Ma8573f792008-10-24 22:24:17 +0800955 __le16 xe_name_offset; /* byte offset from the 1st entry in the
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800956 local xattr storage(inode, xattr block or
957 xattr bucket). */
958 __u8 xe_name_len; /* xattr name len, does't include prefix. */
Tao Ma8573f792008-10-24 22:24:17 +0800959 __u8 xe_type; /* the low 7 bits indicate the name prefix
960 * type and the highest bit indicates whether
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800961 * the EA is stored in the local storage. */
962 __le64 xe_value_size; /* real xattr value length. */
963};
964
965/*
966 * On disk structure for xattr header.
967 *
968 * One ocfs2_xattr_header describes how many ocfs2_xattr_entry records in
969 * the local xattr storage.
970 */
971struct ocfs2_xattr_header {
972 __le16 xh_count; /* contains the count of how
973 many records are in the
974 local xattr storage. */
Tao Ma0c044f02008-08-18 17:38:50 +0800975 __le16 xh_free_start; /* current offset for storing
976 xattr. */
977 __le16 xh_name_value_len; /* total length of name/value
978 length in this bucket. */
Tao Ma8573f792008-10-24 22:24:17 +0800979 __le16 xh_num_buckets; /* Number of xattr buckets
980 in this extent record,
981 only valid in the first
982 bucket. */
Joel Beckerab552d52008-10-16 17:50:30 -0700983 struct ocfs2_block_check xh_check; /* Error checking
984 (Note, this is only
985 used for xattr
986 buckets. A block uses
987 xb_check and sets
988 this field to zero.) */
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800989 struct ocfs2_xattr_entry xh_entries[0]; /* xattr entry list. */
990};
991
992/*
993 * On disk structure for xattr value root.
994 *
Tao Ma8573f792008-10-24 22:24:17 +0800995 * When an xattr's value is large enough, it is stored in an external
996 * b-tree like file data. The xattr value root points to this structure.
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800997 */
998struct ocfs2_xattr_value_root {
999/*00*/ __le32 xr_clusters; /* clusters covered by xattr value. */
1000 __le32 xr_reserved0;
1001 __le64 xr_last_eb_blk; /* Pointer to last extent block */
1002/*10*/ struct ocfs2_extent_list xr_list; /* Extent record list */
1003};
1004
1005/*
1006 * On disk structure for xattr tree root.
1007 *
1008 * It is used when there are too many extended attributes for one file. These
1009 * attributes will be organized and stored in an indexed-btree.
1010 */
1011struct ocfs2_xattr_tree_root {
1012/*00*/ __le32 xt_clusters; /* clusters covered by xattr. */
1013 __le32 xt_reserved0;
1014 __le64 xt_last_eb_blk; /* Pointer to last extent block */
1015/*10*/ struct ocfs2_extent_list xt_list; /* Extent record list */
1016};
1017
Tiger Yangcf1d6c72008-08-18 17:11:00 +08001018#define OCFS2_XATTR_INDEXED 0x1
1019#define OCFS2_HASH_SHIFT 5
1020#define OCFS2_XATTR_ROUND 3
1021#define OCFS2_XATTR_SIZE(size) (((size) + OCFS2_XATTR_ROUND) & \
1022 ~(OCFS2_XATTR_ROUND))
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001023
Tao Ma0c044f02008-08-18 17:38:50 +08001024#define OCFS2_XATTR_BUCKET_SIZE 4096
1025#define OCFS2_XATTR_MAX_BLOCKS_PER_BUCKET (OCFS2_XATTR_BUCKET_SIZE \
1026 / OCFS2_MIN_BLOCKSIZE)
1027
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001028/*
1029 * On disk structure for xattr block.
1030 */
1031struct ocfs2_xattr_block {
1032/*00*/ __u8 xb_signature[8]; /* Signature for verification */
1033 __le16 xb_suballoc_slot; /* Slot suballocator this
1034 block belongs to. */
1035 __le16 xb_suballoc_bit; /* Bit offset in suballocator
1036 block group */
1037 __le32 xb_fs_generation; /* Must match super block */
1038/*10*/ __le64 xb_blkno; /* Offset on disk, in blocks */
Joel Beckerab552d52008-10-16 17:50:30 -07001039 struct ocfs2_block_check xb_check; /* Error checking */
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001040/*20*/ __le16 xb_flags; /* Indicates whether this block contains
1041 real xattr or a xattr tree. */
1042 __le16 xb_reserved0;
1043 __le32 xb_reserved1;
1044 __le64 xb_reserved2;
1045/*30*/ union {
1046 struct ocfs2_xattr_header xb_header; /* xattr header if this
1047 block contains xattr */
1048 struct ocfs2_xattr_tree_root xb_root;/* xattr tree root if this
1049 block cotains xattr
1050 tree. */
1051 } xb_attrs;
1052};
1053
1054#define OCFS2_XATTR_ENTRY_LOCAL 0x80
1055#define OCFS2_XATTR_TYPE_MASK 0x7F
1056static inline void ocfs2_xattr_set_local(struct ocfs2_xattr_entry *xe,
1057 int local)
1058{
1059 if (local)
1060 xe->xe_type |= OCFS2_XATTR_ENTRY_LOCAL;
1061 else
1062 xe->xe_type &= ~OCFS2_XATTR_ENTRY_LOCAL;
1063}
1064
1065static inline int ocfs2_xattr_is_local(struct ocfs2_xattr_entry *xe)
1066{
1067 return xe->xe_type & OCFS2_XATTR_ENTRY_LOCAL;
1068}
1069
1070static inline void ocfs2_xattr_set_type(struct ocfs2_xattr_entry *xe, int type)
1071{
1072 xe->xe_type |= type & OCFS2_XATTR_TYPE_MASK;
1073}
1074
1075static inline int ocfs2_xattr_get_type(struct ocfs2_xattr_entry *xe)
1076{
1077 return xe->xe_type & OCFS2_XATTR_TYPE_MASK;
1078}
1079
Jan Kara9e33d692008-08-25 19:56:50 +02001080/*
1081 * On disk structures for global quota file
1082 */
1083
1084/* Magic numbers and known versions for global quota files */
1085#define OCFS2_GLOBAL_QMAGICS {\
1086 0x0cf52470, /* USRQUOTA */ \
1087 0x0cf52471 /* GRPQUOTA */ \
1088}
1089
1090#define OCFS2_GLOBAL_QVERSIONS {\
1091 0, \
1092 0, \
1093}
1094
1095
1096/* Each block of each quota file has a certain fixed number of bytes reserved
1097 * for OCFS2 internal use at its end. OCFS2 can use it for things like
1098 * checksums, etc. */
1099#define OCFS2_QBLK_RESERVED_SPACE 8
1100
1101/* Generic header of all quota files */
1102struct ocfs2_disk_dqheader {
1103 __le32 dqh_magic; /* Magic number identifying file */
1104 __le32 dqh_version; /* Quota format version */
1105};
1106
1107#define OCFS2_GLOBAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
1108
1109/* Information header of global quota file (immediately follows the generic
1110 * header) */
1111struct ocfs2_global_disk_dqinfo {
1112/*00*/ __le32 dqi_bgrace; /* Grace time for space softlimit excess */
1113 __le32 dqi_igrace; /* Grace time for inode softlimit excess */
1114 __le32 dqi_syncms; /* Time after which we sync local changes to
1115 * global quota file */
1116 __le32 dqi_blocks; /* Number of blocks in quota file */
1117/*10*/ __le32 dqi_free_blk; /* First free block in quota file */
1118 __le32 dqi_free_entry; /* First block with free dquot entry in quota
1119 * file */
1120};
1121
1122/* Structure with global user / group information. We reserve some space
1123 * for future use. */
1124struct ocfs2_global_disk_dqblk {
1125/*00*/ __le32 dqb_id; /* ID the structure belongs to */
1126 __le32 dqb_use_count; /* Number of nodes having reference to this structure */
1127 __le64 dqb_ihardlimit; /* absolute limit on allocated inodes */
1128/*10*/ __le64 dqb_isoftlimit; /* preferred inode limit */
1129 __le64 dqb_curinodes; /* current # allocated inodes */
1130/*20*/ __le64 dqb_bhardlimit; /* absolute limit on disk space */
1131 __le64 dqb_bsoftlimit; /* preferred limit on disk space */
1132/*30*/ __le64 dqb_curspace; /* current space occupied */
1133 __le64 dqb_btime; /* time limit for excessive disk use */
1134/*40*/ __le64 dqb_itime; /* time limit for excessive inode use */
1135 __le64 dqb_pad1;
1136/*50*/ __le64 dqb_pad2;
1137};
1138
1139/*
1140 * On-disk structures for local quota file
1141 */
1142
1143/* Magic numbers and known versions for local quota files */
1144#define OCFS2_LOCAL_QMAGICS {\
1145 0x0cf524c0, /* USRQUOTA */ \
1146 0x0cf524c1 /* GRPQUOTA */ \
1147}
1148
1149#define OCFS2_LOCAL_QVERSIONS {\
1150 0, \
1151 0, \
1152}
1153
1154/* Quota flags in dqinfo header */
1155#define OLQF_CLEAN 0x0001 /* Quota file is empty (this should be after\
1156 * quota has been cleanly turned off) */
1157
1158#define OCFS2_LOCAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
1159
1160/* Information header of local quota file (immediately follows the generic
1161 * header) */
1162struct ocfs2_local_disk_dqinfo {
1163 __le32 dqi_flags; /* Flags for quota file */
1164 __le32 dqi_chunks; /* Number of chunks of quota structures
1165 * with a bitmap */
1166 __le32 dqi_blocks; /* Number of blocks allocated for quota file */
1167};
1168
1169/* Header of one chunk of a quota file */
1170struct ocfs2_local_disk_chunk {
1171 __le32 dqc_free; /* Number of free entries in the bitmap */
Coly Li93654542009-12-06 22:38:53 +08001172 __u8 dqc_bitmap[0]; /* Bitmap of entries in the corresponding
Jan Kara9e33d692008-08-25 19:56:50 +02001173 * chunk of quota file */
1174};
1175
1176/* One entry in local quota file */
1177struct ocfs2_local_disk_dqblk {
1178/*00*/ __le64 dqb_id; /* id this quota applies to */
1179 __le64 dqb_spacemod; /* Change in the amount of used space */
1180/*10*/ __le64 dqb_inodemod; /* Change in the amount of used inodes */
1181};
1182
Joel Beckerab552d52008-10-16 17:50:30 -07001183
1184/*
1185 * The quota trailer lives at the end of each quota block.
1186 */
1187
1188struct ocfs2_disk_dqtrailer {
1189/*00*/ struct ocfs2_block_check dq_check; /* Error checking */
1190/*08*/ /* Cannot be larger than OCFS2_QBLK_RESERVED_SPACE */
1191};
1192
1193static inline struct ocfs2_disk_dqtrailer *ocfs2_block_dqtrailer(int blocksize,
1194 void *buf)
1195{
1196 char *ptr = buf;
1197 ptr += blocksize - OCFS2_QBLK_RESERVED_SPACE;
1198
1199 return (struct ocfs2_disk_dqtrailer *)ptr;
1200}
1201
Mark Fashehccd979b2005-12-15 14:31:24 -08001202#ifdef __KERNEL__
1203static inline int ocfs2_fast_symlink_chars(struct super_block *sb)
1204{
1205 return sb->s_blocksize -
1206 offsetof(struct ocfs2_dinode, id2.i_symlink);
1207}
1208
Tiger Yangfdd77702008-08-18 17:08:55 +08001209static inline int ocfs2_max_inline_data_with_xattr(struct super_block *sb,
1210 struct ocfs2_dinode *di)
1211{
1212 unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
1213
1214 if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
1215 return sb->s_blocksize -
1216 offsetof(struct ocfs2_dinode, id2.i_data.id_data) -
1217 xattrsize;
1218 else
1219 return sb->s_blocksize -
1220 offsetof(struct ocfs2_dinode, id2.i_data.id_data);
1221}
1222
Mark Fashehccd979b2005-12-15 14:31:24 -08001223static inline int ocfs2_extent_recs_per_inode(struct super_block *sb)
1224{
1225 int size;
1226
1227 size = sb->s_blocksize -
1228 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1229
1230 return size / sizeof(struct ocfs2_extent_rec);
1231}
1232
Tiger Yangfdd77702008-08-18 17:08:55 +08001233static inline int ocfs2_extent_recs_per_inode_with_xattr(
1234 struct super_block *sb,
1235 struct ocfs2_dinode *di)
1236{
1237 int size;
1238 unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
1239
1240 if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
1241 size = sb->s_blocksize -
1242 offsetof(struct ocfs2_dinode, id2.i_list.l_recs) -
1243 xattrsize;
1244 else
1245 size = sb->s_blocksize -
1246 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1247
1248 return size / sizeof(struct ocfs2_extent_rec);
1249}
1250
Mark Fasheh9b7895e2008-11-12 16:27:44 -08001251static inline int ocfs2_extent_recs_per_dx_root(struct super_block *sb)
1252{
1253 int size;
1254
1255 size = sb->s_blocksize -
1256 offsetof(struct ocfs2_dx_root_block, dr_list.l_recs);
1257
1258 return size / sizeof(struct ocfs2_extent_rec);
1259}
1260
Mark Fashehccd979b2005-12-15 14:31:24 -08001261static inline int ocfs2_chain_recs_per_inode(struct super_block *sb)
1262{
1263 int size;
1264
1265 size = sb->s_blocksize -
1266 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
1267
1268 return size / sizeof(struct ocfs2_chain_rec);
1269}
1270
1271static inline u16 ocfs2_extent_recs_per_eb(struct super_block *sb)
1272{
1273 int size;
1274
1275 size = sb->s_blocksize -
1276 offsetof(struct ocfs2_extent_block, h_list.l_recs);
1277
1278 return size / sizeof(struct ocfs2_extent_rec);
1279}
1280
Mark Fasheh9b7895e2008-11-12 16:27:44 -08001281static inline int ocfs2_dx_entries_per_leaf(struct super_block *sb)
1282{
1283 int size;
1284
1285 size = sb->s_blocksize -
1286 offsetof(struct ocfs2_dx_leaf, dl_list.de_entries);
1287
1288 return size / sizeof(struct ocfs2_dx_entry);
1289}
1290
Mark Fasheh4ed8a6b2008-11-24 17:02:08 -08001291static inline int ocfs2_dx_entries_per_root(struct super_block *sb)
1292{
1293 int size;
1294
1295 size = sb->s_blocksize -
1296 offsetof(struct ocfs2_dx_root_block, dr_entries.de_entries);
1297
1298 return size / sizeof(struct ocfs2_dx_entry);
1299}
1300
Mark Fashehccd979b2005-12-15 14:31:24 -08001301static inline u16 ocfs2_local_alloc_size(struct super_block *sb)
1302{
1303 u16 size;
1304
1305 size = sb->s_blocksize -
1306 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
1307
1308 return size;
1309}
1310
Joel Becker4cbe4242010-04-13 14:26:12 +08001311static inline int ocfs2_group_bitmap_size(struct super_block *sb,
1312 int suballocator)
Mark Fashehccd979b2005-12-15 14:31:24 -08001313{
1314 int size;
1315
Joel Becker4cbe4242010-04-13 14:26:12 +08001316 if (suballocator)
1317 size = OCFS2_MAX_BG_BITMAP_SIZE;
1318 else
1319 size = sb->s_blocksize -
1320 offsetof(struct ocfs2_group_desc, bg_bitmap);
Mark Fashehccd979b2005-12-15 14:31:24 -08001321
1322 return size;
1323}
1324
1325static inline int ocfs2_truncate_recs_per_inode(struct super_block *sb)
1326{
1327 int size;
1328
1329 size = sb->s_blocksize -
1330 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
1331
1332 return size / sizeof(struct ocfs2_truncate_rec);
1333}
Mark Fasheh50af94b2007-01-21 14:44:59 -08001334
1335static inline u64 ocfs2_backup_super_blkno(struct super_block *sb, int index)
1336{
1337 u64 offset = OCFS2_BACKUP_SB_START;
1338
1339 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
1340 offset <<= (2 * index);
Mark Fasheha8a75a22007-01-26 10:46:59 -08001341 offset >>= sb->s_blocksize_bits;
Mark Fasheh50af94b2007-01-21 14:44:59 -08001342 return offset;
1343 }
1344
1345 return 0;
1346
1347}
Tao Ma0c044f02008-08-18 17:38:50 +08001348
1349static inline u16 ocfs2_xattr_recs_per_xb(struct super_block *sb)
1350{
1351 int size;
1352
1353 size = sb->s_blocksize -
1354 offsetof(struct ocfs2_xattr_block,
1355 xb_attrs.xb_root.xt_list.l_recs);
1356
1357 return size / sizeof(struct ocfs2_extent_rec);
1358}
Tao Ma721f69c2009-08-18 11:17:49 +08001359
1360static inline u16 ocfs2_extent_recs_per_rb(struct super_block *sb)
1361{
1362 int size;
1363
1364 size = sb->s_blocksize -
1365 offsetof(struct ocfs2_refcount_block, rf_list.l_recs);
1366
1367 return size / sizeof(struct ocfs2_extent_rec);
1368}
1369
1370static inline u16 ocfs2_refcount_recs_per_rb(struct super_block *sb)
1371{
1372 int size;
1373
1374 size = sb->s_blocksize -
1375 offsetof(struct ocfs2_refcount_block, rf_records.rl_recs);
1376
1377 return size / sizeof(struct ocfs2_refcount_rec);
1378}
Tao Mae73a8192009-08-11 14:33:14 +08001379
1380static inline u32
1381ocfs2_get_ref_rec_low_cpos(const struct ocfs2_refcount_rec *rec)
1382{
1383 return le64_to_cpu(rec->r_cpos) & OCFS2_32BIT_POS_MASK;
1384}
Mark Fashehccd979b2005-12-15 14:31:24 -08001385#else
1386static inline int ocfs2_fast_symlink_chars(int blocksize)
1387{
1388 return blocksize - offsetof(struct ocfs2_dinode, id2.i_symlink);
1389}
1390
Tao Ma1097df32010-01-20 11:31:11 +08001391static inline int ocfs2_max_inline_data_with_xattr(int blocksize,
1392 struct ocfs2_dinode *di)
Mark Fasheh15b1e362007-09-07 13:58:15 -07001393{
Tao Ma1097df32010-01-20 11:31:11 +08001394 if (di && (di->i_dyn_features & OCFS2_INLINE_XATTR_FL))
1395 return blocksize -
1396 offsetof(struct ocfs2_dinode, id2.i_data.id_data) -
1397 di->i_xattr_inline_size;
1398 else
1399 return blocksize -
1400 offsetof(struct ocfs2_dinode, id2.i_data.id_data);
Mark Fasheh15b1e362007-09-07 13:58:15 -07001401}
1402
Mark Fashehccd979b2005-12-15 14:31:24 -08001403static inline int ocfs2_extent_recs_per_inode(int blocksize)
1404{
1405 int size;
1406
1407 size = blocksize -
1408 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1409
1410 return size / sizeof(struct ocfs2_extent_rec);
1411}
1412
1413static inline int ocfs2_chain_recs_per_inode(int blocksize)
1414{
1415 int size;
1416
1417 size = blocksize -
1418 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
1419
1420 return size / sizeof(struct ocfs2_chain_rec);
1421}
1422
1423static inline int ocfs2_extent_recs_per_eb(int blocksize)
1424{
1425 int size;
1426
1427 size = blocksize -
1428 offsetof(struct ocfs2_extent_block, h_list.l_recs);
1429
1430 return size / sizeof(struct ocfs2_extent_rec);
1431}
1432
1433static inline int ocfs2_local_alloc_size(int blocksize)
1434{
1435 int size;
1436
1437 size = blocksize -
1438 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
1439
1440 return size;
1441}
1442
Joel Becker4cbe4242010-04-13 14:26:12 +08001443static inline int ocfs2_group_bitmap_size(int blocksize, int suballocator)
Mark Fashehccd979b2005-12-15 14:31:24 -08001444{
1445 int size;
1446
Joel Becker4cbe4242010-04-13 14:26:12 +08001447 if (suballocator)
1448 size = OCFS2_MAX_BG_BITMAP_SIZE;
1449 else
1450 size = blocksize -
1451 offsetof(struct ocfs2_group_desc, bg_bitmap);
Mark Fashehccd979b2005-12-15 14:31:24 -08001452
1453 return size;
1454}
1455
1456static inline int ocfs2_truncate_recs_per_inode(int blocksize)
1457{
1458 int size;
1459
1460 size = blocksize -
1461 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
1462
1463 return size / sizeof(struct ocfs2_truncate_rec);
1464}
Mark Fasheh50af94b2007-01-21 14:44:59 -08001465
1466static inline uint64_t ocfs2_backup_super_blkno(int blocksize, int index)
1467{
1468 uint64_t offset = OCFS2_BACKUP_SB_START;
1469
1470 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
1471 offset <<= (2 * index);
1472 offset /= blocksize;
1473 return offset;
1474 }
1475
1476 return 0;
1477}
Tao Ma0c044f02008-08-18 17:38:50 +08001478
1479static inline int ocfs2_xattr_recs_per_xb(int blocksize)
1480{
1481 int size;
1482
1483 size = blocksize -
1484 offsetof(struct ocfs2_xattr_block,
1485 xb_attrs.xb_root.xt_list.l_recs);
1486
1487 return size / sizeof(struct ocfs2_extent_rec);
1488}
Mark Fashehccd979b2005-12-15 14:31:24 -08001489#endif /* __KERNEL__ */
1490
1491
1492static inline int ocfs2_system_inode_is_global(int type)
1493{
1494 return ((type >= 0) &&
1495 (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE));
1496}
1497
1498static inline int ocfs2_sprintf_system_inode_name(char *buf, int len,
1499 int type, int slot)
1500{
1501 int chars;
1502
1503 /*
1504 * Global system inodes can only have one copy. Everything
1505 * after OCFS2_LAST_GLOBAL_SYSTEM_INODE in the system inode
1506 * list has a copy per slot.
1507 */
1508 if (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE)
Joel Beckerfe9f3872008-06-12 22:39:18 -07001509 chars = snprintf(buf, len, "%s",
Mark Fashehccd979b2005-12-15 14:31:24 -08001510 ocfs2_system_inodes[type].si_name);
1511 else
1512 chars = snprintf(buf, len,
1513 ocfs2_system_inodes[type].si_name,
1514 slot);
1515
1516 return chars;
1517}
1518
1519static inline void ocfs2_set_de_type(struct ocfs2_dir_entry *de,
1520 umode_t mode)
1521{
1522 de->file_type = ocfs2_type_by_mode[(mode & S_IFMT)>>S_SHIFT];
1523}
1524
1525#endif /* _OCFS2_FS_H */
1526