blob: 4a4565b7bc149e7fca5b095872e0985c5a1f8e9f [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 Beckerb61817e2008-02-01 15:08:23 -0800168/*
Mark Fasheh50af94b2007-01-21 14:44:59 -0800169 * backup superblock flag is used to indicate that this volume
170 * has backup superblocks.
171 */
172#define OCFS2_FEATURE_COMPAT_BACKUP_SB 0x0001
173
Mark Fasheh328d5752007-06-18 10:48:04 -0700174/*
Joel Beckera9772182008-12-16 18:10:18 -0800175 * The filesystem will correctly handle journal feature bits.
176 */
177#define OCFS2_FEATURE_COMPAT_JBD2_SB 0x0002
178
179/*
Mark Fasheh328d5752007-06-18 10:48:04 -0700180 * Unwritten extents support.
181 */
182#define OCFS2_FEATURE_RO_COMPAT_UNWRITTEN 0x0001
183
Jan Kara1a224ad2008-08-20 15:43:36 +0200184/*
185 * Maintain quota information for this filesystem
186 */
187#define OCFS2_FEATURE_RO_COMPAT_USRQUOTA 0x0002
188#define OCFS2_FEATURE_RO_COMPAT_GRPQUOTA 0x0004
189
Mark Fasheh50af94b2007-01-21 14:44:59 -0800190/* The byte offset of the first backup block will be 1G.
191 * The following will be 4G, 16G, 64G, 256G and 1T.
192 */
193#define OCFS2_BACKUP_SB_START 1 << 30
194
195/* the max backup superblock nums */
196#define OCFS2_MAX_BACKUP_SUPERBLOCKS 6
197
198/*
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700199 * Flags on ocfs2_super_block.s_tunefs_flags
200 */
201#define OCFS2_TUNEFS_INPROG_REMOVE_SLOT 0x0001 /* Removing slots */
202
203/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800204 * Flags on ocfs2_dinode.i_flags
205 */
206#define OCFS2_VALID_FL (0x00000001) /* Inode is valid */
207#define OCFS2_UNUSED2_FL (0x00000002)
208#define OCFS2_ORPHANED_FL (0x00000004) /* On the orphan list */
209#define OCFS2_UNUSED3_FL (0x00000008)
210/* System inode flags */
211#define OCFS2_SYSTEM_FL (0x00000010) /* System inode */
212#define OCFS2_SUPER_BLOCK_FL (0x00000020) /* Super block */
213#define OCFS2_LOCAL_ALLOC_FL (0x00000040) /* Slot local alloc bitmap */
214#define OCFS2_BITMAP_FL (0x00000080) /* Allocation bitmap */
215#define OCFS2_JOURNAL_FL (0x00000100) /* Slot local journal */
216#define OCFS2_HEARTBEAT_FL (0x00000200) /* Heartbeat area */
217#define OCFS2_CHAIN_FL (0x00000400) /* Chain allocator */
218#define OCFS2_DEALLOC_FL (0x00000800) /* Truncate log */
Jan Kara1a224ad2008-08-20 15:43:36 +0200219#define OCFS2_QUOTA_FL (0x00001000) /* Quota file */
Mark Fashehccd979b2005-12-15 14:31:24 -0800220
Mark Fasheh15b1e362007-09-07 13:58:15 -0700221/*
222 * Flags on ocfs2_dinode.i_dyn_features
223 *
224 * These can change much more often than i_flags. When adding flags,
225 * keep in mind that i_dyn_features is only 16 bits wide.
226 */
227#define OCFS2_INLINE_DATA_FL (0x0001) /* Data stored in inode block */
228#define OCFS2_HAS_XATTR_FL (0x0002)
229#define OCFS2_INLINE_XATTR_FL (0x0004)
230#define OCFS2_INDEXED_DIR_FL (0x0008)
Tao Ma721f69c2009-08-18 11:17:49 +0800231#define OCFS2_HAS_REFCOUNT_FL (0x0010)
Mark Fasheh15b1e362007-09-07 13:58:15 -0700232
Herbert Poetzlca4d1472006-07-03 17:27:12 -0700233/* Inode attributes, keep in sync with EXT2 */
234#define OCFS2_SECRM_FL (0x00000001) /* Secure deletion */
235#define OCFS2_UNRM_FL (0x00000002) /* Undelete */
236#define OCFS2_COMPR_FL (0x00000004) /* Compress file */
237#define OCFS2_SYNC_FL (0x00000008) /* Synchronous updates */
238#define OCFS2_IMMUTABLE_FL (0x00000010) /* Immutable file */
239#define OCFS2_APPEND_FL (0x00000020) /* writes to file may only append */
240#define OCFS2_NODUMP_FL (0x00000040) /* do not dump file */
241#define OCFS2_NOATIME_FL (0x00000080) /* do not update atime */
242#define OCFS2_DIRSYNC_FL (0x00010000) /* dirsync behaviour (directories only) */
243
244#define OCFS2_FL_VISIBLE (0x000100FF) /* User visible flags */
245#define OCFS2_FL_MODIFIABLE (0x000100FF) /* User modifiable flags */
246
247/*
Mark Fashehe48edee2007-03-07 16:46:57 -0800248 * Extent record flags (e_node.leaf.flags)
249 */
Tao Ma721f69c2009-08-18 11:17:49 +0800250#define OCFS2_EXT_UNWRITTEN (0x01) /* Extent is allocated but
251 * unwritten */
252#define OCFS2_EXT_REFCOUNTED (0x02) /* Extent is reference
253 * counted in an associated
254 * refcount tree */
Mark Fashehe48edee2007-03-07 16:46:57 -0800255
256/*
Herbert Poetzlca4d1472006-07-03 17:27:12 -0700257 * ioctl commands
258 */
259#define OCFS2_IOC_GETFLAGS _IOR('f', 1, long)
260#define OCFS2_IOC_SETFLAGS _IOW('f', 2, long)
Mark Fasheh586d2322007-03-09 15:56:28 -0800261#define OCFS2_IOC32_GETFLAGS _IOR('f', 1, int)
262#define OCFS2_IOC32_SETFLAGS _IOW('f', 2, int)
Herbert Poetzlca4d1472006-07-03 17:27:12 -0700263
Mark Fashehccd979b2005-12-15 14:31:24 -0800264/*
Mark Fashehb2580102007-03-09 16:53:21 -0800265 * Space reservation / allocation / free ioctls and argument structure
266 * are designed to be compatible with XFS.
267 *
268 * ALLOCSP* and FREESP* are not and will never be supported, but are
269 * included here for completeness.
270 */
271struct ocfs2_space_resv {
272 __s16 l_type;
273 __s16 l_whence;
274 __s64 l_start;
275 __s64 l_len; /* len == 0 means until end of file */
276 __s32 l_sysid;
277 __u32 l_pid;
278 __s32 l_pad[4]; /* reserve area */
279};
280
281#define OCFS2_IOC_ALLOCSP _IOW ('X', 10, struct ocfs2_space_resv)
282#define OCFS2_IOC_FREESP _IOW ('X', 11, struct ocfs2_space_resv)
283#define OCFS2_IOC_RESVSP _IOW ('X', 40, struct ocfs2_space_resv)
284#define OCFS2_IOC_UNRESVSP _IOW ('X', 41, struct ocfs2_space_resv)
285#define OCFS2_IOC_ALLOCSP64 _IOW ('X', 36, struct ocfs2_space_resv)
286#define OCFS2_IOC_FREESP64 _IOW ('X', 37, struct ocfs2_space_resv)
287#define OCFS2_IOC_RESVSP64 _IOW ('X', 42, struct ocfs2_space_resv)
288#define OCFS2_IOC_UNRESVSP64 _IOW ('X', 43, struct ocfs2_space_resv)
289
Tao Ma7909f2b2007-12-18 15:47:25 +0800290/* Used to pass group descriptor data when online resize is done */
291struct ocfs2_new_group_input {
292 __u64 group; /* Group descriptor's blkno. */
293 __u32 clusters; /* Total number of clusters in this group */
294 __u32 frees; /* Total free clusters in this group */
295 __u16 chain; /* Chain for this group */
296 __u16 reserved1;
297 __u32 reserved2;
298};
299
Tao Mad6590722007-12-18 15:47:03 +0800300#define OCFS2_IOC_GROUP_EXTEND _IOW('o', 1, int)
Tao Ma7909f2b2007-12-18 15:47:25 +0800301#define OCFS2_IOC_GROUP_ADD _IOW('o', 2,struct ocfs2_new_group_input)
302#define OCFS2_IOC_GROUP_ADD64 _IOW('o', 3,struct ocfs2_new_group_input)
Tao Mad6590722007-12-18 15:47:03 +0800303
Mark Fashehb2580102007-03-09 16:53:21 -0800304/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800305 * Journal Flags (ocfs2_dinode.id1.journal1.i_flags)
306 */
307#define OCFS2_JOURNAL_DIRTY_FL (0x00000001) /* Journal needs recovery */
308
309/*
310 * superblock s_state flags
311 */
312#define OCFS2_ERROR_FS (0x00000001) /* FS saw errors */
313
314/* Limit of space in ocfs2_dir_entry */
315#define OCFS2_MAX_FILENAME_LEN 255
316
317/* Maximum slots on an ocfs2 file system */
318#define OCFS2_MAX_SLOTS 255
319
320/* Slot map indicator for an empty slot */
321#define OCFS2_INVALID_SLOT -1
322
323#define OCFS2_VOL_UUID_LEN 16
324#define OCFS2_MAX_VOL_LABEL_LEN 64
325
Joel Beckerb61817e2008-02-01 15:08:23 -0800326/* The alternate, userspace stack fields */
327#define OCFS2_STACK_LABEL_LEN 4
328#define OCFS2_CLUSTER_NAME_LEN 16
329
Mark Fashehccd979b2005-12-15 14:31:24 -0800330/* Journal limits (in bytes) */
331#define OCFS2_MIN_JOURNAL_SIZE (4 * 1024 * 1024)
Mark Fashehccd979b2005-12-15 14:31:24 -0800332
Sunil Mushran2fbe8d12007-12-20 14:58:11 -0800333/*
334 * Default local alloc size (in megabytes)
335 *
336 * The value chosen should be such that most allocations, including new
337 * block groups, use local alloc.
338 */
339#define OCFS2_DEFAULT_LOCAL_ALLOC_SIZE 8
340
Tiger Yangfdd77702008-08-18 17:08:55 +0800341/*
342 * Inline extended attribute size (in bytes)
343 * The value chosen should be aligned to 16 byte boundaries.
344 */
345#define OCFS2_MIN_XATTR_INLINE_SIZE 256
346
Mark Fashehccd979b2005-12-15 14:31:24 -0800347struct ocfs2_system_inode_info {
348 char *si_name;
349 int si_iflags;
350 int si_mode;
351};
352
353/* System file index */
354enum {
355 BAD_BLOCK_SYSTEM_INODE = 0,
356 GLOBAL_INODE_ALLOC_SYSTEM_INODE,
357 SLOT_MAP_SYSTEM_INODE,
358#define OCFS2_FIRST_ONLINE_SYSTEM_INODE SLOT_MAP_SYSTEM_INODE
359 HEARTBEAT_SYSTEM_INODE,
360 GLOBAL_BITMAP_SYSTEM_INODE,
Jan Kara1a224ad2008-08-20 15:43:36 +0200361 USER_QUOTA_SYSTEM_INODE,
362 GROUP_QUOTA_SYSTEM_INODE,
363#define OCFS2_LAST_GLOBAL_SYSTEM_INODE GROUP_QUOTA_SYSTEM_INODE
Mark Fashehccd979b2005-12-15 14:31:24 -0800364 ORPHAN_DIR_SYSTEM_INODE,
365 EXTENT_ALLOC_SYSTEM_INODE,
366 INODE_ALLOC_SYSTEM_INODE,
367 JOURNAL_SYSTEM_INODE,
368 LOCAL_ALLOC_SYSTEM_INODE,
369 TRUNCATE_LOG_SYSTEM_INODE,
Jan Kara1a224ad2008-08-20 15:43:36 +0200370 LOCAL_USER_QUOTA_SYSTEM_INODE,
371 LOCAL_GROUP_QUOTA_SYSTEM_INODE,
Mark Fashehccd979b2005-12-15 14:31:24 -0800372 NUM_SYSTEM_INODES
373};
374
375static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = {
376 /* Global system inodes (single copy) */
377 /* The first two are only used from userspace mfks/tunefs */
378 [BAD_BLOCK_SYSTEM_INODE] = { "bad_blocks", 0, S_IFREG | 0644 },
379 [GLOBAL_INODE_ALLOC_SYSTEM_INODE] = { "global_inode_alloc", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
380
381 /* These are used by the running filesystem */
382 [SLOT_MAP_SYSTEM_INODE] = { "slot_map", 0, S_IFREG | 0644 },
383 [HEARTBEAT_SYSTEM_INODE] = { "heartbeat", OCFS2_HEARTBEAT_FL, S_IFREG | 0644 },
384 [GLOBAL_BITMAP_SYSTEM_INODE] = { "global_bitmap", 0, S_IFREG | 0644 },
Jan Kara1a224ad2008-08-20 15:43:36 +0200385 [USER_QUOTA_SYSTEM_INODE] = { "aquota.user", OCFS2_QUOTA_FL, S_IFREG | 0644 },
386 [GROUP_QUOTA_SYSTEM_INODE] = { "aquota.group", OCFS2_QUOTA_FL, S_IFREG | 0644 },
Mark Fashehccd979b2005-12-15 14:31:24 -0800387
388 /* Slot-specific system inodes (one copy per slot) */
389 [ORPHAN_DIR_SYSTEM_INODE] = { "orphan_dir:%04d", 0, S_IFDIR | 0755 },
390 [EXTENT_ALLOC_SYSTEM_INODE] = { "extent_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
391 [INODE_ALLOC_SYSTEM_INODE] = { "inode_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
392 [JOURNAL_SYSTEM_INODE] = { "journal:%04d", OCFS2_JOURNAL_FL, S_IFREG | 0644 },
393 [LOCAL_ALLOC_SYSTEM_INODE] = { "local_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_LOCAL_ALLOC_FL, S_IFREG | 0644 },
Jan Kara1a224ad2008-08-20 15:43:36 +0200394 [TRUNCATE_LOG_SYSTEM_INODE] = { "truncate_log:%04d", OCFS2_DEALLOC_FL, S_IFREG | 0644 },
395 [LOCAL_USER_QUOTA_SYSTEM_INODE] = { "aquota.user:%04d", OCFS2_QUOTA_FL, S_IFREG | 0644 },
396 [LOCAL_GROUP_QUOTA_SYSTEM_INODE] = { "aquota.group:%04d", OCFS2_QUOTA_FL, S_IFREG | 0644 },
Mark Fashehccd979b2005-12-15 14:31:24 -0800397};
398
399/* Parameter passed from mount.ocfs2 to module */
400#define OCFS2_HB_NONE "heartbeat=none"
401#define OCFS2_HB_LOCAL "heartbeat=local"
402
403/*
404 * OCFS2 directory file types. Only the low 3 bits are used. The
405 * other bits are reserved for now.
406 */
407#define OCFS2_FT_UNKNOWN 0
408#define OCFS2_FT_REG_FILE 1
409#define OCFS2_FT_DIR 2
410#define OCFS2_FT_CHRDEV 3
411#define OCFS2_FT_BLKDEV 4
412#define OCFS2_FT_FIFO 5
413#define OCFS2_FT_SOCK 6
414#define OCFS2_FT_SYMLINK 7
415
416#define OCFS2_FT_MAX 8
417
418/*
419 * OCFS2_DIR_PAD defines the directory entries boundaries
420 *
421 * NOTE: It must be a multiple of 4
422 */
423#define OCFS2_DIR_PAD 4
424#define OCFS2_DIR_ROUND (OCFS2_DIR_PAD - 1)
425#define OCFS2_DIR_MEMBER_LEN offsetof(struct ocfs2_dir_entry, name)
426#define OCFS2_DIR_REC_LEN(name_len) (((name_len) + OCFS2_DIR_MEMBER_LEN + \
427 OCFS2_DIR_ROUND) & \
428 ~OCFS2_DIR_ROUND)
Mark Fashehe7c17e42009-01-29 18:17:46 -0800429#define OCFS2_DIR_MIN_REC_LEN OCFS2_DIR_REC_LEN(1)
Mark Fashehccd979b2005-12-15 14:31:24 -0800430
431#define OCFS2_LINK_MAX 32000
Mark Fasheh198a1ca2008-11-20 17:54:57 -0800432#define OCFS2_DX_LINK_MAX ((1U << 31) - 1U)
433#define OCFS2_LINKS_HI_SHIFT 16
Mark Fashehe3a93c22009-02-17 15:29:35 -0800434#define OCFS2_DX_ENTRIES_MAX (0xffffffffU)
Mark Fashehccd979b2005-12-15 14:31:24 -0800435
436#define S_SHIFT 12
437static unsigned char ocfs2_type_by_mode[S_IFMT >> S_SHIFT] = {
438 [S_IFREG >> S_SHIFT] = OCFS2_FT_REG_FILE,
439 [S_IFDIR >> S_SHIFT] = OCFS2_FT_DIR,
440 [S_IFCHR >> S_SHIFT] = OCFS2_FT_CHRDEV,
441 [S_IFBLK >> S_SHIFT] = OCFS2_FT_BLKDEV,
442 [S_IFIFO >> S_SHIFT] = OCFS2_FT_FIFO,
443 [S_IFSOCK >> S_SHIFT] = OCFS2_FT_SOCK,
444 [S_IFLNK >> S_SHIFT] = OCFS2_FT_SYMLINK,
445};
446
447
448/*
449 * Convenience casts
450 */
451#define OCFS2_RAW_SB(dinode) (&((dinode)->id2.i_super))
452
453/*
Joel Beckerab552d52008-10-16 17:50:30 -0700454 * Block checking structure. This is used in metadata to validate the
455 * contents. If OCFS2_FEATURE_INCOMPAT_META_ECC is not set, it is all
456 * zeros.
457 */
458struct ocfs2_block_check {
459/*00*/ __le32 bc_crc32e; /* 802.3 Ethernet II CRC32 */
460 __le16 bc_ecc; /* Single-error-correction parity vector.
461 This is a simple Hamming code dependant
462 on the blocksize. OCFS2's maximum
463 blocksize, 4K, requires 16 parity bits,
464 so we fit in __le16. */
465 __le16 bc_reserved1;
466/*08*/
467};
468
469/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800470 * On disk extent record for OCFS2
471 * It describes a range of clusters on disk.
Mark Fashehe48edee2007-03-07 16:46:57 -0800472 *
473 * Length fields are divided into interior and leaf node versions.
474 * This leaves room for a flags field (OCFS2_EXT_*) in the leaf nodes.
Mark Fashehccd979b2005-12-15 14:31:24 -0800475 */
476struct ocfs2_extent_rec {
477/*00*/ __le32 e_cpos; /* Offset into the file, in clusters */
Mark Fashehe48edee2007-03-07 16:46:57 -0800478 union {
479 __le32 e_int_clusters; /* Clusters covered by all children */
480 struct {
481 __le16 e_leaf_clusters; /* Clusters covered by this
482 extent */
483 __u8 e_reserved1;
484 __u8 e_flags; /* Extent flags */
485 };
486 };
Mark Fashehccd979b2005-12-15 14:31:24 -0800487 __le64 e_blkno; /* Physical disk offset, in blocks */
488/*10*/
489};
490
491struct ocfs2_chain_rec {
492 __le32 c_free; /* Number of free bits in this chain. */
493 __le32 c_total; /* Number of total bits in this chain */
494 __le64 c_blkno; /* Physical disk offset (blocks) of 1st group */
495};
496
497struct ocfs2_truncate_rec {
498 __le32 t_start; /* 1st cluster in this log */
499 __le32 t_clusters; /* Number of total clusters covered */
500};
501
502/*
503 * On disk extent list for OCFS2 (node in the tree). Note that this
504 * is contained inside ocfs2_dinode or ocfs2_extent_block, so the
505 * offsets are relative to ocfs2_dinode.id2.i_list or
506 * ocfs2_extent_block.h_list, respectively.
507 */
508struct ocfs2_extent_list {
509/*00*/ __le16 l_tree_depth; /* Extent tree depth from this
510 point. 0 means data extents
511 hang directly off this
Mark Fashehdcd05382007-01-16 11:32:23 -0800512 header (a leaf)
513 NOTE: The high 8 bits cannot be
514 used - tree_depth is never that big.
515 */
Mark Fashehccd979b2005-12-15 14:31:24 -0800516 __le16 l_count; /* Number of extent records */
517 __le16 l_next_free_rec; /* Next unused extent slot */
518 __le16 l_reserved1;
519 __le64 l_reserved2; /* Pad to
520 sizeof(ocfs2_extent_rec) */
521/*10*/ struct ocfs2_extent_rec l_recs[0]; /* Extent records */
522};
523
524/*
525 * On disk allocation chain list for OCFS2. Note that this is
526 * contained inside ocfs2_dinode, so the offsets are relative to
527 * ocfs2_dinode.id2.i_chain.
528 */
529struct ocfs2_chain_list {
530/*00*/ __le16 cl_cpg; /* Clusters per Block Group */
531 __le16 cl_bpc; /* Bits per cluster */
532 __le16 cl_count; /* Total chains in this list */
533 __le16 cl_next_free_rec; /* Next unused chain slot */
534 __le64 cl_reserved1;
535/*10*/ struct ocfs2_chain_rec cl_recs[0]; /* Chain records */
536};
537
538/*
539 * On disk deallocation log for OCFS2. Note that this is
540 * contained inside ocfs2_dinode, so the offsets are relative to
541 * ocfs2_dinode.id2.i_dealloc.
542 */
543struct ocfs2_truncate_log {
544/*00*/ __le16 tl_count; /* Total records in this log */
545 __le16 tl_used; /* Number of records in use */
546 __le32 tl_reserved1;
547/*08*/ struct ocfs2_truncate_rec tl_recs[0]; /* Truncate records */
548};
549
550/*
551 * On disk extent block (indirect block) for OCFS2
552 */
553struct ocfs2_extent_block
554{
555/*00*/ __u8 h_signature[8]; /* Signature for verification */
Joel Beckerab552d52008-10-16 17:50:30 -0700556 struct ocfs2_block_check h_check; /* Error checking */
Mark Fashehccd979b2005-12-15 14:31:24 -0800557/*10*/ __le16 h_suballoc_slot; /* Slot suballocator this
558 extent_header belongs to */
559 __le16 h_suballoc_bit; /* Bit offset in suballocator
560 block group */
561 __le32 h_fs_generation; /* Must match super block */
562 __le64 h_blkno; /* Offset on disk, in blocks */
563/*20*/ __le64 h_reserved3;
564 __le64 h_next_leaf_blk; /* Offset on disk, in blocks,
565 of next leaf header pointing
566 to data */
567/*30*/ struct ocfs2_extent_list h_list; /* Extent record list */
568/* Actual on-disk size is one block */
569};
570
571/*
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800572 * On disk slot map for OCFS2. This defines the contents of the "slot_map"
Joel Becker386a2ef2008-02-01 12:06:54 -0800573 * system file. A slot is valid if it contains a node number >= 0. The
574 * value -1 (0xFFFF) is OCFS2_INVALID_SLOT. This marks a slot empty.
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800575 */
576struct ocfs2_slot_map {
577/*00*/ __le16 sm_slots[0];
578/*
579 * Actual on-disk size is one block. OCFS2_MAX_SLOTS is 255,
580 * 255 * sizeof(__le16) == 512B, within the 512B block minimum blocksize.
581 */
582};
583
Joel Becker386a2ef2008-02-01 12:06:54 -0800584struct ocfs2_extended_slot {
585/*00*/ __u8 es_valid;
586 __u8 es_reserved1[3];
587 __le32 es_node_num;
588/*10*/
589};
590
591/*
592 * The extended slot map, used when OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP
593 * is set. It separates out the valid marker from the node number, and
594 * has room to grow. Unlike the old slot map, this format is defined by
595 * i_size.
596 */
597struct ocfs2_slot_map_extended {
598/*00*/ struct ocfs2_extended_slot se_slots[0];
599/*
600 * Actual size is i_size of the slot_map system file. It should
601 * match s_max_slots * sizeof(struct ocfs2_extended_slot)
602 */
603};
604
Joel Beckerb61817e2008-02-01 15:08:23 -0800605struct ocfs2_cluster_info {
606/*00*/ __u8 ci_stack[OCFS2_STACK_LABEL_LEN];
607 __le32 ci_reserved;
608/*08*/ __u8 ci_cluster[OCFS2_CLUSTER_NAME_LEN];
609/*18*/
610};
611
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800612/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800613 * On disk superblock for OCFS2
614 * Note that it is contained inside an ocfs2_dinode, so all offsets
615 * are relative to the start of ocfs2_dinode.id2.
616 */
617struct ocfs2_super_block {
618/*00*/ __le16 s_major_rev_level;
619 __le16 s_minor_rev_level;
620 __le16 s_mnt_count;
621 __le16 s_max_mnt_count;
622 __le16 s_state; /* File system state */
623 __le16 s_errors; /* Behaviour when detecting errors */
624 __le32 s_checkinterval; /* Max time between checks */
625/*10*/ __le64 s_lastcheck; /* Time of last check */
626 __le32 s_creator_os; /* OS */
627 __le32 s_feature_compat; /* Compatible feature set */
628/*20*/ __le32 s_feature_incompat; /* Incompatible feature set */
629 __le32 s_feature_ro_compat; /* Readonly-compatible feature set */
630 __le64 s_root_blkno; /* Offset, in blocks, of root directory
631 dinode */
632/*30*/ __le64 s_system_dir_blkno; /* Offset, in blocks, of system
633 directory dinode */
634 __le32 s_blocksize_bits; /* Blocksize for this fs */
635 __le32 s_clustersize_bits; /* Clustersize for this fs */
636/*40*/ __le16 s_max_slots; /* Max number of simultaneous mounts
637 before tunefs required */
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700638 __le16 s_tunefs_flag;
Tiger Yangcf1d6c72008-08-18 17:11:00 +0800639 __le32 s_uuid_hash; /* hash value of uuid */
Mark Fashehccd979b2005-12-15 14:31:24 -0800640 __le64 s_first_cluster_group; /* Block offset of 1st cluster
641 * group header */
642/*50*/ __u8 s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */
643/*90*/ __u8 s_uuid[OCFS2_VOL_UUID_LEN]; /* 128-bit uuid */
Joel Beckerb61817e2008-02-01 15:08:23 -0800644/*A0*/ struct ocfs2_cluster_info s_cluster_info; /* Selected userspace
645 stack. Only valid
646 with INCOMPAT flag. */
Tiger Yang8154da32008-08-18 17:11:46 +0800647/*B8*/ __le16 s_xattr_inline_size; /* extended attribute inline size
648 for this fs*/
649 __le16 s_reserved0;
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800650 __le32 s_dx_seed[3]; /* seed[0-2] for dx dir hash.
651 * s_uuid_hash serves as seed[3]. */
652/*C0*/ __le64 s_reserved2[15]; /* Fill out superblock */
Joel Beckerb61817e2008-02-01 15:08:23 -0800653/*140*/
654
655 /*
656 * NOTE: As stated above, all offsets are relative to
657 * ocfs2_dinode.id2, which is at 0xC0 in the inode.
658 * 0xC0 + 0x140 = 0x200 or 512 bytes. A superblock must fit within
659 * our smallest blocksize, which is 512 bytes. To ensure this,
660 * we reserve the space in s_reserved2. Anything past s_reserved2
661 * will not be available on the smallest blocksize.
662 */
Mark Fashehccd979b2005-12-15 14:31:24 -0800663};
664
665/*
666 * Local allocation bitmap for OCFS2 slots
667 * Note that it exists inside an ocfs2_dinode, so all offsets are
668 * relative to the start of ocfs2_dinode.id2.
669 */
670struct ocfs2_local_alloc
671{
672/*00*/ __le32 la_bm_off; /* Starting bit offset in main bitmap */
673 __le16 la_size; /* Size of included bitmap, in bytes */
674 __le16 la_reserved1;
675 __le64 la_reserved2;
676/*10*/ __u8 la_bitmap[0];
677};
678
679/*
Mark Fasheh15b1e362007-09-07 13:58:15 -0700680 * Data-in-inode header. This is only used if i_dyn_features has
681 * OCFS2_INLINE_DATA_FL set.
682 */
683struct ocfs2_inline_data
684{
685/*00*/ __le16 id_count; /* Number of bytes that can be used
686 * for data, starting at id_data */
687 __le16 id_reserved0;
688 __le32 id_reserved1;
689 __u8 id_data[0]; /* Start of user data */
690};
691
692/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800693 * On disk inode for OCFS2
694 */
695struct ocfs2_dinode {
696/*00*/ __u8 i_signature[8]; /* Signature for validation */
697 __le32 i_generation; /* Generation number */
698 __le16 i_suballoc_slot; /* Slot suballocator this inode
699 belongs to */
700 __le16 i_suballoc_bit; /* Bit offset in suballocator
701 block group */
Mark Fasheh198a1ca2008-11-20 17:54:57 -0800702/*10*/ __le16 i_links_count_hi; /* High 16 bits of links count */
Tiger Yangfdd77702008-08-18 17:08:55 +0800703 __le16 i_xattr_inline_size;
Mark Fashehccd979b2005-12-15 14:31:24 -0800704 __le32 i_clusters; /* Cluster count */
705 __le32 i_uid; /* Owner UID */
706 __le32 i_gid; /* Owning GID */
707/*20*/ __le64 i_size; /* Size in bytes */
708 __le16 i_mode; /* File mode */
709 __le16 i_links_count; /* Links count */
710 __le32 i_flags; /* File flags */
711/*30*/ __le64 i_atime; /* Access time */
712 __le64 i_ctime; /* Creation time */
713/*40*/ __le64 i_mtime; /* Modification time */
714 __le64 i_dtime; /* Deletion time */
715/*50*/ __le64 i_blkno; /* Offset on disk, in blocks */
716 __le64 i_last_eb_blk; /* Pointer to last extent
717 block */
718/*60*/ __le32 i_fs_generation; /* Generation per fs-instance */
719 __le32 i_atime_nsec;
720 __le32 i_ctime_nsec;
721 __le32 i_mtime_nsec;
Tiger Yangfdd77702008-08-18 17:08:55 +0800722/*70*/ __le32 i_attr;
Tiger Yang50008632007-03-20 16:01:38 -0700723 __le16 i_orphaned_slot; /* Only valid when OCFS2_ORPHANED_FL
724 was set in i_flags */
Mark Fasheh15b1e362007-09-07 13:58:15 -0700725 __le16 i_dyn_features;
Tiger Yangfdd77702008-08-18 17:08:55 +0800726 __le64 i_xattr_loc;
Joel Beckerab552d52008-10-16 17:50:30 -0700727/*80*/ struct ocfs2_block_check i_check; /* Error checking */
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800728/*88*/ __le64 i_dx_root; /* Pointer to dir index root block */
Tao Ma721f69c2009-08-18 11:17:49 +0800729/*90*/ __le64 i_refcount_loc;
730 __le64 i_reserved2[4];
Mark Fashehccd979b2005-12-15 14:31:24 -0800731/*B8*/ union {
732 __le64 i_pad1; /* Generic way to refer to this
733 64bit union */
734 struct {
735 __le64 i_rdev; /* Device number */
736 } dev1;
737 struct { /* Info for bitmap system
738 inodes */
739 __le32 i_used; /* Bits (ie, clusters) used */
740 __le32 i_total; /* Total bits (clusters)
741 available */
742 } bitmap1;
743 struct { /* Info for journal system
744 inodes */
745 __le32 ij_flags; /* Mounted, version, etc. */
Sunil Mushranc69991a2008-07-14 17:31:09 -0700746 __le32 ij_recovery_generation; /* Incremented when the
747 journal is recovered
748 after an unclean
749 shutdown */
Mark Fashehccd979b2005-12-15 14:31:24 -0800750 } journal1;
751 } id1; /* Inode type dependant 1 */
752/*C0*/ union {
753 struct ocfs2_super_block i_super;
754 struct ocfs2_local_alloc i_lab;
755 struct ocfs2_chain_list i_chain;
756 struct ocfs2_extent_list i_list;
757 struct ocfs2_truncate_log i_dealloc;
Mark Fasheh15b1e362007-09-07 13:58:15 -0700758 struct ocfs2_inline_data i_data;
Mark Fashehccd979b2005-12-15 14:31:24 -0800759 __u8 i_symlink[0];
760 } id2;
761/* Actual on-disk size is one block */
762};
763
764/*
765 * On-disk directory entry structure for OCFS2
766 *
767 * Packed as this structure could be accessed unaligned on 64-bit platforms
768 */
769struct ocfs2_dir_entry {
770/*00*/ __le64 inode; /* Inode number */
771 __le16 rec_len; /* Directory entry length */
772 __u8 name_len; /* Name length */
773 __u8 file_type;
774/*0C*/ char name[OCFS2_MAX_FILENAME_LEN]; /* File name */
775/* Actual on-disk length specified by rec_len */
776} __attribute__ ((packed));
777
778/*
Mark Fasheh87d35a72008-12-10 17:36:25 -0800779 * Per-block record for the unindexed directory btree. This is carefully
780 * crafted so that the rec_len and name_len records of an ocfs2_dir_entry are
781 * mirrored. That way, the directory manipulation code needs a minimal amount
782 * of update.
783 *
784 * NOTE: Keep this structure aligned to a multiple of 4 bytes.
785 */
786struct ocfs2_dir_block_trailer {
787/*00*/ __le64 db_compat_inode; /* Always zero. Was inode */
788
789 __le16 db_compat_rec_len; /* Backwards compatible with
790 * ocfs2_dir_entry. */
791 __u8 db_compat_name_len; /* Always zero. Was name_len */
792 __u8 db_reserved0;
793 __le16 db_reserved1;
794 __le16 db_free_rec_len; /* Size of largest empty hole
795 * in this block. (unused) */
796/*10*/ __u8 db_signature[8]; /* Signature for verification */
797 __le64 db_reserved2;
798 __le64 db_free_next; /* Next block in list (unused) */
799/*20*/ __le64 db_blkno; /* Offset on disk, in blocks */
800 __le64 db_parent_dinode; /* dinode which owns me, in
801 blocks */
Joel Beckerc175a512008-12-10 17:58:22 -0800802/*30*/ struct ocfs2_block_check db_check; /* Error checking */
Mark Fasheh87d35a72008-12-10 17:36:25 -0800803/*40*/
804};
805
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800806 /*
807 * A directory entry in the indexed tree. We don't store the full name here,
808 * but instead provide a pointer to the full dirent in the unindexed tree.
809 *
810 * We also store name_len here so as to reduce the number of leaf blocks we
811 * need to search in case of collisions.
812 */
813struct ocfs2_dx_entry {
814 __le32 dx_major_hash; /* Used to find logical
815 * cluster in index */
816 __le32 dx_minor_hash; /* Lower bits used to find
817 * block in cluster */
818 __le64 dx_dirent_blk; /* Physical block in unindexed
819 * tree holding this dirent. */
820};
821
822struct ocfs2_dx_entry_list {
823 __le32 de_reserved;
824 __le16 de_count; /* Maximum number of entries
825 * possible in de_entries */
826 __le16 de_num_used; /* Current number of
827 * de_entries entries */
828 struct ocfs2_dx_entry de_entries[0]; /* Indexed dir entries
829 * in a packed array of
830 * length de_num_used */
831};
832
Mark Fasheh4ed8a6b2008-11-24 17:02:08 -0800833#define OCFS2_DX_FLAG_INLINE 0x01
834
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800835/*
836 * A directory indexing block. Each indexed directory has one of these,
837 * pointed to by ocfs2_dinode.
838 *
839 * This block stores an indexed btree root, and a set of free space
840 * start-of-list pointers.
841 */
842struct ocfs2_dx_root_block {
843 __u8 dr_signature[8]; /* Signature for verification */
844 struct ocfs2_block_check dr_check; /* Error checking */
845 __le16 dr_suballoc_slot; /* Slot suballocator this
846 * block belongs to. */
847 __le16 dr_suballoc_bit; /* Bit offset in suballocator
848 * block group */
849 __le32 dr_fs_generation; /* Must match super block */
850 __le64 dr_blkno; /* Offset on disk, in blocks */
851 __le64 dr_last_eb_blk; /* Pointer to last
852 * extent block */
853 __le32 dr_clusters; /* Clusters allocated
854 * to the indexed tree. */
Mark Fasheh4ed8a6b2008-11-24 17:02:08 -0800855 __u8 dr_flags; /* OCFS2_DX_FLAG_* flags */
856 __u8 dr_reserved0;
857 __le16 dr_reserved1;
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800858 __le64 dr_dir_blkno; /* Pointer to parent inode */
Mark Fashehe3a93c22009-02-17 15:29:35 -0800859 __le32 dr_num_entries; /* Total number of
860 * names stored in
861 * this directory.*/
862 __le32 dr_reserved2;
Mark Fashehe7c17e42009-01-29 18:17:46 -0800863 __le64 dr_free_blk; /* Pointer to head of free
864 * unindexed block list. */
865 __le64 dr_reserved3[15];
Mark Fasheh4ed8a6b2008-11-24 17:02:08 -0800866 union {
867 struct ocfs2_extent_list dr_list; /* Keep this aligned to 128
868 * bits for maximum space
869 * efficiency. */
870 struct ocfs2_dx_entry_list dr_entries; /* In-root-block list of
871 * entries. We grow out
872 * to extents if this
873 * gets too big. */
874 };
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800875};
876
877/*
878 * The header of a leaf block in the indexed tree.
879 */
880struct ocfs2_dx_leaf {
881 __u8 dl_signature[8];/* Signature for verification */
882 struct ocfs2_block_check dl_check; /* Error checking */
883 __le64 dl_blkno; /* Offset on disk, in blocks */
884 __le32 dl_fs_generation;/* Must match super block */
885 __le32 dl_reserved0;
886 __le64 dl_reserved1;
887 struct ocfs2_dx_entry_list dl_list;
888};
889
Mark Fasheh87d35a72008-12-10 17:36:25 -0800890/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800891 * On disk allocator group structure for OCFS2
892 */
893struct ocfs2_group_desc
894{
895/*00*/ __u8 bg_signature[8]; /* Signature for validation */
896 __le16 bg_size; /* Size of included bitmap in
897 bytes. */
898 __le16 bg_bits; /* Bits represented by this
899 group. */
900 __le16 bg_free_bits_count; /* Free bits count */
901 __le16 bg_chain; /* What chain I am in. */
902/*10*/ __le32 bg_generation;
903 __le32 bg_reserved1;
904 __le64 bg_next_group; /* Next group in my list, in
905 blocks */
906/*20*/ __le64 bg_parent_dinode; /* dinode which owns me, in
907 blocks */
908 __le64 bg_blkno; /* Offset on disk, in blocks */
Joel Beckerab552d52008-10-16 17:50:30 -0700909/*30*/ struct ocfs2_block_check bg_check; /* Error checking */
910 __le64 bg_reserved2;
Mark Fashehccd979b2005-12-15 14:31:24 -0800911/*40*/ __u8 bg_bitmap[0];
912};
913
Tao Ma721f69c2009-08-18 11:17:49 +0800914struct ocfs2_refcount_rec {
915/*00*/ __le64 r_cpos; /* Physical offset, in clusters */
916 __le32 r_clusters; /* Clusters covered by this extent */
917 __le32 r_refcount; /* Reference count of this extent */
918/*10*/
919};
Tao Mae73a8192009-08-11 14:33:14 +0800920#define OCFS2_32BIT_POS_MASK (0xffffffffULL)
Tao Ma721f69c2009-08-18 11:17:49 +0800921
922#define OCFS2_REFCOUNT_LEAF_FL (0x00000001)
923#define OCFS2_REFCOUNT_TREE_FL (0x00000002)
924
925struct ocfs2_refcount_list {
926/*00*/ __le16 rl_count; /* Maximum number of entries possible
927 in rl_records */
928 __le16 rl_used; /* Current number of used records */
929 __le32 rl_reserved2;
930 __le64 rl_reserved1; /* Pad to sizeof(ocfs2_refcount_record) */
931/*10*/ struct ocfs2_refcount_rec rl_recs[0]; /* Refcount records */
932};
933
934
935struct ocfs2_refcount_block {
936/*00*/ __u8 rf_signature[8]; /* Signature for verification */
937 __le16 rf_suballoc_slot; /* Slot suballocator this block
938 belongs to */
939 __le16 rf_suballoc_bit; /* Bit offset in suballocator
940 block group */
941 __le32 rf_fs_generation; /* Must match superblock */
942/*10*/ __le64 rf_blkno; /* Offset on disk, in blocks */
943 __le64 rf_parent; /* Parent block, only valid if
944 OCFS2_REFCOUNT_LEAF_FL is set in
945 rf_flags */
946/*20*/ struct ocfs2_block_check rf_check; /* Error checking */
947 __le64 rf_last_eb_blk; /* Pointer to last extent block */
948/*30*/ __le32 rf_count; /* Number of inodes sharing this
949 refcount tree */
950 __le32 rf_flags; /* See the flags above */
951 __le32 rf_clusters; /* clusters covered by refcount tree. */
952 __le32 rf_cpos; /* cluster offset in refcount tree.*/
953/*40*/ __le32 rf_generation; /* generation number. all be the same
954 * for the same refcount tree. */
955 __le32 rf_reserved0;
956 __le64 rf_reserved1[7];
957/*80*/ union {
958 struct ocfs2_refcount_list rf_records; /* List of refcount
959 records */
960 struct ocfs2_extent_list rf_list; /* Extent record list,
961 only valid if
962 OCFS2_REFCOUNT_TREE_FL
963 is set in rf_flags */
964 };
965/* Actual on-disk size is one block */
966};
967
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800968/*
969 * On disk extended attribute structure for OCFS2.
970 */
971
972/*
973 * ocfs2_xattr_entry indicates one extend attribute.
974 *
975 * Note that it can be stored in inode, one block or one xattr bucket.
976 */
977struct ocfs2_xattr_entry {
978 __le32 xe_name_hash; /* hash value of xattr prefix+suffix. */
Tao Ma8573f792008-10-24 22:24:17 +0800979 __le16 xe_name_offset; /* byte offset from the 1st entry in the
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800980 local xattr storage(inode, xattr block or
981 xattr bucket). */
982 __u8 xe_name_len; /* xattr name len, does't include prefix. */
Tao Ma8573f792008-10-24 22:24:17 +0800983 __u8 xe_type; /* the low 7 bits indicate the name prefix
984 * type and the highest bit indicates whether
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800985 * the EA is stored in the local storage. */
986 __le64 xe_value_size; /* real xattr value length. */
987};
988
989/*
990 * On disk structure for xattr header.
991 *
992 * One ocfs2_xattr_header describes how many ocfs2_xattr_entry records in
993 * the local xattr storage.
994 */
995struct ocfs2_xattr_header {
996 __le16 xh_count; /* contains the count of how
997 many records are in the
998 local xattr storage. */
Tao Ma0c044f02008-08-18 17:38:50 +0800999 __le16 xh_free_start; /* current offset for storing
1000 xattr. */
1001 __le16 xh_name_value_len; /* total length of name/value
1002 length in this bucket. */
Tao Ma8573f792008-10-24 22:24:17 +08001003 __le16 xh_num_buckets; /* Number of xattr buckets
1004 in this extent record,
1005 only valid in the first
1006 bucket. */
Joel Beckerab552d52008-10-16 17:50:30 -07001007 struct ocfs2_block_check xh_check; /* Error checking
1008 (Note, this is only
1009 used for xattr
1010 buckets. A block uses
1011 xb_check and sets
1012 this field to zero.) */
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001013 struct ocfs2_xattr_entry xh_entries[0]; /* xattr entry list. */
1014};
1015
1016/*
1017 * On disk structure for xattr value root.
1018 *
Tao Ma8573f792008-10-24 22:24:17 +08001019 * When an xattr's value is large enough, it is stored in an external
1020 * b-tree like file data. The xattr value root points to this structure.
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001021 */
1022struct ocfs2_xattr_value_root {
1023/*00*/ __le32 xr_clusters; /* clusters covered by xattr value. */
1024 __le32 xr_reserved0;
1025 __le64 xr_last_eb_blk; /* Pointer to last extent block */
1026/*10*/ struct ocfs2_extent_list xr_list; /* Extent record list */
1027};
1028
1029/*
1030 * On disk structure for xattr tree root.
1031 *
1032 * It is used when there are too many extended attributes for one file. These
1033 * attributes will be organized and stored in an indexed-btree.
1034 */
1035struct ocfs2_xattr_tree_root {
1036/*00*/ __le32 xt_clusters; /* clusters covered by xattr. */
1037 __le32 xt_reserved0;
1038 __le64 xt_last_eb_blk; /* Pointer to last extent block */
1039/*10*/ struct ocfs2_extent_list xt_list; /* Extent record list */
1040};
1041
Tiger Yangcf1d6c72008-08-18 17:11:00 +08001042#define OCFS2_XATTR_INDEXED 0x1
1043#define OCFS2_HASH_SHIFT 5
1044#define OCFS2_XATTR_ROUND 3
1045#define OCFS2_XATTR_SIZE(size) (((size) + OCFS2_XATTR_ROUND) & \
1046 ~(OCFS2_XATTR_ROUND))
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001047
Tao Ma0c044f02008-08-18 17:38:50 +08001048#define OCFS2_XATTR_BUCKET_SIZE 4096
1049#define OCFS2_XATTR_MAX_BLOCKS_PER_BUCKET (OCFS2_XATTR_BUCKET_SIZE \
1050 / OCFS2_MIN_BLOCKSIZE)
1051
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001052/*
1053 * On disk structure for xattr block.
1054 */
1055struct ocfs2_xattr_block {
1056/*00*/ __u8 xb_signature[8]; /* Signature for verification */
1057 __le16 xb_suballoc_slot; /* Slot suballocator this
1058 block belongs to. */
1059 __le16 xb_suballoc_bit; /* Bit offset in suballocator
1060 block group */
1061 __le32 xb_fs_generation; /* Must match super block */
1062/*10*/ __le64 xb_blkno; /* Offset on disk, in blocks */
Joel Beckerab552d52008-10-16 17:50:30 -07001063 struct ocfs2_block_check xb_check; /* Error checking */
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001064/*20*/ __le16 xb_flags; /* Indicates whether this block contains
1065 real xattr or a xattr tree. */
1066 __le16 xb_reserved0;
1067 __le32 xb_reserved1;
1068 __le64 xb_reserved2;
1069/*30*/ union {
1070 struct ocfs2_xattr_header xb_header; /* xattr header if this
1071 block contains xattr */
1072 struct ocfs2_xattr_tree_root xb_root;/* xattr tree root if this
1073 block cotains xattr
1074 tree. */
1075 } xb_attrs;
1076};
1077
1078#define OCFS2_XATTR_ENTRY_LOCAL 0x80
1079#define OCFS2_XATTR_TYPE_MASK 0x7F
1080static inline void ocfs2_xattr_set_local(struct ocfs2_xattr_entry *xe,
1081 int local)
1082{
1083 if (local)
1084 xe->xe_type |= OCFS2_XATTR_ENTRY_LOCAL;
1085 else
1086 xe->xe_type &= ~OCFS2_XATTR_ENTRY_LOCAL;
1087}
1088
1089static inline int ocfs2_xattr_is_local(struct ocfs2_xattr_entry *xe)
1090{
1091 return xe->xe_type & OCFS2_XATTR_ENTRY_LOCAL;
1092}
1093
1094static inline void ocfs2_xattr_set_type(struct ocfs2_xattr_entry *xe, int type)
1095{
1096 xe->xe_type |= type & OCFS2_XATTR_TYPE_MASK;
1097}
1098
1099static inline int ocfs2_xattr_get_type(struct ocfs2_xattr_entry *xe)
1100{
1101 return xe->xe_type & OCFS2_XATTR_TYPE_MASK;
1102}
1103
Jan Kara9e33d692008-08-25 19:56:50 +02001104/*
1105 * On disk structures for global quota file
1106 */
1107
1108/* Magic numbers and known versions for global quota files */
1109#define OCFS2_GLOBAL_QMAGICS {\
1110 0x0cf52470, /* USRQUOTA */ \
1111 0x0cf52471 /* GRPQUOTA */ \
1112}
1113
1114#define OCFS2_GLOBAL_QVERSIONS {\
1115 0, \
1116 0, \
1117}
1118
1119
1120/* Each block of each quota file has a certain fixed number of bytes reserved
1121 * for OCFS2 internal use at its end. OCFS2 can use it for things like
1122 * checksums, etc. */
1123#define OCFS2_QBLK_RESERVED_SPACE 8
1124
1125/* Generic header of all quota files */
1126struct ocfs2_disk_dqheader {
1127 __le32 dqh_magic; /* Magic number identifying file */
1128 __le32 dqh_version; /* Quota format version */
1129};
1130
1131#define OCFS2_GLOBAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
1132
1133/* Information header of global quota file (immediately follows the generic
1134 * header) */
1135struct ocfs2_global_disk_dqinfo {
1136/*00*/ __le32 dqi_bgrace; /* Grace time for space softlimit excess */
1137 __le32 dqi_igrace; /* Grace time for inode softlimit excess */
1138 __le32 dqi_syncms; /* Time after which we sync local changes to
1139 * global quota file */
1140 __le32 dqi_blocks; /* Number of blocks in quota file */
1141/*10*/ __le32 dqi_free_blk; /* First free block in quota file */
1142 __le32 dqi_free_entry; /* First block with free dquot entry in quota
1143 * file */
1144};
1145
1146/* Structure with global user / group information. We reserve some space
1147 * for future use. */
1148struct ocfs2_global_disk_dqblk {
1149/*00*/ __le32 dqb_id; /* ID the structure belongs to */
1150 __le32 dqb_use_count; /* Number of nodes having reference to this structure */
1151 __le64 dqb_ihardlimit; /* absolute limit on allocated inodes */
1152/*10*/ __le64 dqb_isoftlimit; /* preferred inode limit */
1153 __le64 dqb_curinodes; /* current # allocated inodes */
1154/*20*/ __le64 dqb_bhardlimit; /* absolute limit on disk space */
1155 __le64 dqb_bsoftlimit; /* preferred limit on disk space */
1156/*30*/ __le64 dqb_curspace; /* current space occupied */
1157 __le64 dqb_btime; /* time limit for excessive disk use */
1158/*40*/ __le64 dqb_itime; /* time limit for excessive inode use */
1159 __le64 dqb_pad1;
1160/*50*/ __le64 dqb_pad2;
1161};
1162
1163/*
1164 * On-disk structures for local quota file
1165 */
1166
1167/* Magic numbers and known versions for local quota files */
1168#define OCFS2_LOCAL_QMAGICS {\
1169 0x0cf524c0, /* USRQUOTA */ \
1170 0x0cf524c1 /* GRPQUOTA */ \
1171}
1172
1173#define OCFS2_LOCAL_QVERSIONS {\
1174 0, \
1175 0, \
1176}
1177
1178/* Quota flags in dqinfo header */
1179#define OLQF_CLEAN 0x0001 /* Quota file is empty (this should be after\
1180 * quota has been cleanly turned off) */
1181
1182#define OCFS2_LOCAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
1183
1184/* Information header of local quota file (immediately follows the generic
1185 * header) */
1186struct ocfs2_local_disk_dqinfo {
1187 __le32 dqi_flags; /* Flags for quota file */
1188 __le32 dqi_chunks; /* Number of chunks of quota structures
1189 * with a bitmap */
1190 __le32 dqi_blocks; /* Number of blocks allocated for quota file */
1191};
1192
1193/* Header of one chunk of a quota file */
1194struct ocfs2_local_disk_chunk {
1195 __le32 dqc_free; /* Number of free entries in the bitmap */
1196 u8 dqc_bitmap[0]; /* Bitmap of entries in the corresponding
1197 * chunk of quota file */
1198};
1199
1200/* One entry in local quota file */
1201struct ocfs2_local_disk_dqblk {
1202/*00*/ __le64 dqb_id; /* id this quota applies to */
1203 __le64 dqb_spacemod; /* Change in the amount of used space */
1204/*10*/ __le64 dqb_inodemod; /* Change in the amount of used inodes */
1205};
1206
Joel Beckerab552d52008-10-16 17:50:30 -07001207
1208/*
1209 * The quota trailer lives at the end of each quota block.
1210 */
1211
1212struct ocfs2_disk_dqtrailer {
1213/*00*/ struct ocfs2_block_check dq_check; /* Error checking */
1214/*08*/ /* Cannot be larger than OCFS2_QBLK_RESERVED_SPACE */
1215};
1216
1217static inline struct ocfs2_disk_dqtrailer *ocfs2_block_dqtrailer(int blocksize,
1218 void *buf)
1219{
1220 char *ptr = buf;
1221 ptr += blocksize - OCFS2_QBLK_RESERVED_SPACE;
1222
1223 return (struct ocfs2_disk_dqtrailer *)ptr;
1224}
1225
Mark Fashehccd979b2005-12-15 14:31:24 -08001226#ifdef __KERNEL__
1227static inline int ocfs2_fast_symlink_chars(struct super_block *sb)
1228{
1229 return sb->s_blocksize -
1230 offsetof(struct ocfs2_dinode, id2.i_symlink);
1231}
1232
Tiger Yangfdd77702008-08-18 17:08:55 +08001233static inline int ocfs2_max_inline_data_with_xattr(struct super_block *sb,
1234 struct ocfs2_dinode *di)
1235{
1236 unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
1237
1238 if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
1239 return sb->s_blocksize -
1240 offsetof(struct ocfs2_dinode, id2.i_data.id_data) -
1241 xattrsize;
1242 else
1243 return sb->s_blocksize -
1244 offsetof(struct ocfs2_dinode, id2.i_data.id_data);
1245}
1246
Mark Fashehccd979b2005-12-15 14:31:24 -08001247static inline int ocfs2_extent_recs_per_inode(struct super_block *sb)
1248{
1249 int size;
1250
1251 size = sb->s_blocksize -
1252 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1253
1254 return size / sizeof(struct ocfs2_extent_rec);
1255}
1256
Tiger Yangfdd77702008-08-18 17:08:55 +08001257static inline int ocfs2_extent_recs_per_inode_with_xattr(
1258 struct super_block *sb,
1259 struct ocfs2_dinode *di)
1260{
1261 int size;
1262 unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
1263
1264 if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
1265 size = sb->s_blocksize -
1266 offsetof(struct ocfs2_dinode, id2.i_list.l_recs) -
1267 xattrsize;
1268 else
1269 size = sb->s_blocksize -
1270 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1271
1272 return size / sizeof(struct ocfs2_extent_rec);
1273}
1274
Mark Fasheh9b7895e2008-11-12 16:27:44 -08001275static inline int ocfs2_extent_recs_per_dx_root(struct super_block *sb)
1276{
1277 int size;
1278
1279 size = sb->s_blocksize -
1280 offsetof(struct ocfs2_dx_root_block, dr_list.l_recs);
1281
1282 return size / sizeof(struct ocfs2_extent_rec);
1283}
1284
Mark Fashehccd979b2005-12-15 14:31:24 -08001285static inline int ocfs2_chain_recs_per_inode(struct super_block *sb)
1286{
1287 int size;
1288
1289 size = sb->s_blocksize -
1290 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
1291
1292 return size / sizeof(struct ocfs2_chain_rec);
1293}
1294
1295static inline u16 ocfs2_extent_recs_per_eb(struct super_block *sb)
1296{
1297 int size;
1298
1299 size = sb->s_blocksize -
1300 offsetof(struct ocfs2_extent_block, h_list.l_recs);
1301
1302 return size / sizeof(struct ocfs2_extent_rec);
1303}
1304
Mark Fasheh9b7895e2008-11-12 16:27:44 -08001305static inline int ocfs2_dx_entries_per_leaf(struct super_block *sb)
1306{
1307 int size;
1308
1309 size = sb->s_blocksize -
1310 offsetof(struct ocfs2_dx_leaf, dl_list.de_entries);
1311
1312 return size / sizeof(struct ocfs2_dx_entry);
1313}
1314
Mark Fasheh4ed8a6b2008-11-24 17:02:08 -08001315static inline int ocfs2_dx_entries_per_root(struct super_block *sb)
1316{
1317 int size;
1318
1319 size = sb->s_blocksize -
1320 offsetof(struct ocfs2_dx_root_block, dr_entries.de_entries);
1321
1322 return size / sizeof(struct ocfs2_dx_entry);
1323}
1324
Mark Fashehccd979b2005-12-15 14:31:24 -08001325static inline u16 ocfs2_local_alloc_size(struct super_block *sb)
1326{
1327 u16 size;
1328
1329 size = sb->s_blocksize -
1330 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
1331
1332 return size;
1333}
1334
1335static inline int ocfs2_group_bitmap_size(struct super_block *sb)
1336{
1337 int size;
1338
1339 size = sb->s_blocksize -
1340 offsetof(struct ocfs2_group_desc, bg_bitmap);
1341
1342 return size;
1343}
1344
1345static inline int ocfs2_truncate_recs_per_inode(struct super_block *sb)
1346{
1347 int size;
1348
1349 size = sb->s_blocksize -
1350 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
1351
1352 return size / sizeof(struct ocfs2_truncate_rec);
1353}
Mark Fasheh50af94b2007-01-21 14:44:59 -08001354
1355static inline u64 ocfs2_backup_super_blkno(struct super_block *sb, int index)
1356{
1357 u64 offset = OCFS2_BACKUP_SB_START;
1358
1359 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
1360 offset <<= (2 * index);
Mark Fasheha8a75a22007-01-26 10:46:59 -08001361 offset >>= sb->s_blocksize_bits;
Mark Fasheh50af94b2007-01-21 14:44:59 -08001362 return offset;
1363 }
1364
1365 return 0;
1366
1367}
Tao Ma0c044f02008-08-18 17:38:50 +08001368
1369static inline u16 ocfs2_xattr_recs_per_xb(struct super_block *sb)
1370{
1371 int size;
1372
1373 size = sb->s_blocksize -
1374 offsetof(struct ocfs2_xattr_block,
1375 xb_attrs.xb_root.xt_list.l_recs);
1376
1377 return size / sizeof(struct ocfs2_extent_rec);
1378}
Tao Ma721f69c2009-08-18 11:17:49 +08001379
1380static inline u16 ocfs2_extent_recs_per_rb(struct super_block *sb)
1381{
1382 int size;
1383
1384 size = sb->s_blocksize -
1385 offsetof(struct ocfs2_refcount_block, rf_list.l_recs);
1386
1387 return size / sizeof(struct ocfs2_extent_rec);
1388}
1389
1390static inline u16 ocfs2_refcount_recs_per_rb(struct super_block *sb)
1391{
1392 int size;
1393
1394 size = sb->s_blocksize -
1395 offsetof(struct ocfs2_refcount_block, rf_records.rl_recs);
1396
1397 return size / sizeof(struct ocfs2_refcount_rec);
1398}
Tao Mae73a8192009-08-11 14:33:14 +08001399
1400static inline u32
1401ocfs2_get_ref_rec_low_cpos(const struct ocfs2_refcount_rec *rec)
1402{
1403 return le64_to_cpu(rec->r_cpos) & OCFS2_32BIT_POS_MASK;
1404}
Mark Fashehccd979b2005-12-15 14:31:24 -08001405#else
1406static inline int ocfs2_fast_symlink_chars(int blocksize)
1407{
1408 return blocksize - offsetof(struct ocfs2_dinode, id2.i_symlink);
1409}
1410
Mark Fasheh15b1e362007-09-07 13:58:15 -07001411static inline int ocfs2_max_inline_data(int blocksize)
1412{
1413 return blocksize - offsetof(struct ocfs2_dinode, id2.i_data.id_data);
1414}
1415
Mark Fashehccd979b2005-12-15 14:31:24 -08001416static inline int ocfs2_extent_recs_per_inode(int blocksize)
1417{
1418 int size;
1419
1420 size = blocksize -
1421 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1422
1423 return size / sizeof(struct ocfs2_extent_rec);
1424}
1425
1426static inline int ocfs2_chain_recs_per_inode(int blocksize)
1427{
1428 int size;
1429
1430 size = blocksize -
1431 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
1432
1433 return size / sizeof(struct ocfs2_chain_rec);
1434}
1435
1436static inline int ocfs2_extent_recs_per_eb(int blocksize)
1437{
1438 int size;
1439
1440 size = blocksize -
1441 offsetof(struct ocfs2_extent_block, h_list.l_recs);
1442
1443 return size / sizeof(struct ocfs2_extent_rec);
1444}
1445
1446static inline int ocfs2_local_alloc_size(int blocksize)
1447{
1448 int size;
1449
1450 size = blocksize -
1451 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
1452
1453 return size;
1454}
1455
1456static inline int ocfs2_group_bitmap_size(int blocksize)
1457{
1458 int size;
1459
1460 size = blocksize -
1461 offsetof(struct ocfs2_group_desc, bg_bitmap);
1462
1463 return size;
1464}
1465
1466static inline int ocfs2_truncate_recs_per_inode(int blocksize)
1467{
1468 int size;
1469
1470 size = blocksize -
1471 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
1472
1473 return size / sizeof(struct ocfs2_truncate_rec);
1474}
Mark Fasheh50af94b2007-01-21 14:44:59 -08001475
1476static inline uint64_t ocfs2_backup_super_blkno(int blocksize, int index)
1477{
1478 uint64_t offset = OCFS2_BACKUP_SB_START;
1479
1480 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
1481 offset <<= (2 * index);
1482 offset /= blocksize;
1483 return offset;
1484 }
1485
1486 return 0;
1487}
Tao Ma0c044f02008-08-18 17:38:50 +08001488
1489static inline int ocfs2_xattr_recs_per_xb(int blocksize)
1490{
1491 int size;
1492
1493 size = blocksize -
1494 offsetof(struct ocfs2_xattr_block,
1495 xb_attrs.xb_root.xt_list.l_recs);
1496
1497 return size / sizeof(struct ocfs2_extent_rec);
1498}
Mark Fashehccd979b2005-12-15 14:31:24 -08001499#endif /* __KERNEL__ */
1500
1501
1502static inline int ocfs2_system_inode_is_global(int type)
1503{
1504 return ((type >= 0) &&
1505 (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE));
1506}
1507
1508static inline int ocfs2_sprintf_system_inode_name(char *buf, int len,
1509 int type, int slot)
1510{
1511 int chars;
1512
1513 /*
1514 * Global system inodes can only have one copy. Everything
1515 * after OCFS2_LAST_GLOBAL_SYSTEM_INODE in the system inode
1516 * list has a copy per slot.
1517 */
1518 if (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE)
Joel Beckerfe9f3872008-06-12 22:39:18 -07001519 chars = snprintf(buf, len, "%s",
Mark Fashehccd979b2005-12-15 14:31:24 -08001520 ocfs2_system_inodes[type].si_name);
1521 else
1522 chars = snprintf(buf, len,
1523 ocfs2_system_inodes[type].si_name,
1524 slot);
1525
1526 return chars;
1527}
1528
1529static inline void ocfs2_set_de_type(struct ocfs2_dir_entry *de,
1530 umode_t mode)
1531{
1532 de->file_type = ocfs2_type_by_mode[(mode & S_IFMT)>>S_SHIFT];
1533}
1534
1535#endif /* _OCFS2_FS_H */
1536