blob: e4288b446ec0f7dc6e86d5b97195bebbd7ed5331 [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 \
102 | OCFS2_FEATURE_INCOMPAT_INDEXED_DIRS)
Jan Kara19ece542008-08-21 20:13:17 +0200103#define OCFS2_FEATURE_RO_COMPAT_SUPP (OCFS2_FEATURE_RO_COMPAT_UNWRITTEN \
104 | OCFS2_FEATURE_RO_COMPAT_USRQUOTA \
105 | OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)
Mark Fashehccd979b2005-12-15 14:31:24 -0800106
107/*
108 * Heartbeat-only devices are missing journals and other files. The
109 * filesystem driver can't load them, but the library can. Never put
110 * this in OCFS2_FEATURE_INCOMPAT_SUPP, *ever*.
111 */
112#define OCFS2_FEATURE_INCOMPAT_HEARTBEAT_DEV 0x0002
113
Mark Fasheh89039012006-12-07 18:05:37 -0800114/*
115 * tunefs sets this incompat flag before starting the resize and clears it
116 * at the end. This flag protects users from inadvertently mounting the fs
117 * after an aborted run without fsck-ing.
118 */
119#define OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG 0x0004
Mark Fashehccd979b2005-12-15 14:31:24 -0800120
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800121/* Used to denote a non-clustered volume */
122#define OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT 0x0008
123
Mark Fasheh89039012006-12-07 18:05:37 -0800124/* Support for sparse allocation in b-trees */
125#define OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC 0x0010
126
Mark Fashehccd979b2005-12-15 14:31:24 -0800127/*
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700128 * Tunefs sets this incompat flag before starting an operation which
129 * would require cleanup on abort. This is done to protect users from
130 * inadvertently mounting the fs after an aborted run without
131 * fsck-ing.
132 *
133 * s_tunefs_flags on the super block describes precisely which
134 * operations were in progress.
135 */
136#define OCFS2_FEATURE_INCOMPAT_TUNEFS_INPROG 0x0020
137
Mark Fasheh15b1e362007-09-07 13:58:15 -0700138/* Support for data packed into inode blocks */
139#define OCFS2_FEATURE_INCOMPAT_INLINE_DATA 0x0040
140
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700141/*
Joel Beckerb61817e2008-02-01 15:08:23 -0800142 * Support for alternate, userspace cluster stacks. If set, the superblock
143 * field s_cluster_info contains a tag for the alternate stack in use as
144 * well as the name of the cluster being joined.
145 * mount.ocfs2 must pass in a matching stack name.
146 *
147 * If not set, the classic stack will be used. This is compatbile with
148 * all older versions.
149 */
150#define OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK 0x0080
151
Tiger Yang8154da32008-08-18 17:11:46 +0800152/* Support for the extended slot map */
153#define OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP 0x100
154
155/* Support for extended attributes */
156#define OCFS2_FEATURE_INCOMPAT_XATTR 0x0200
157
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800158/* Support for indexed directores */
159#define OCFS2_FEATURE_INCOMPAT_INDEXED_DIRS 0x0400
160
Joel Beckerab552d52008-10-16 17:50:30 -0700161/* Metadata checksum and error correction */
162#define OCFS2_FEATURE_INCOMPAT_META_ECC 0x0800
163
Tao Ma721f69c2009-08-18 11:17:49 +0800164/* Refcount tree support */
165#define OCFS2_FEATURE_INCOMPAT_REFCOUNT_TREE 0x1000
166
Joel Beckerb61817e2008-02-01 15:08:23 -0800167/*
Mark Fasheh50af94b2007-01-21 14:44:59 -0800168 * backup superblock flag is used to indicate that this volume
169 * has backup superblocks.
170 */
171#define OCFS2_FEATURE_COMPAT_BACKUP_SB 0x0001
172
Mark Fasheh328d5752007-06-18 10:48:04 -0700173/*
Joel Beckera9772182008-12-16 18:10:18 -0800174 * The filesystem will correctly handle journal feature bits.
175 */
176#define OCFS2_FEATURE_COMPAT_JBD2_SB 0x0002
177
178/*
Mark Fasheh328d5752007-06-18 10:48:04 -0700179 * Unwritten extents support.
180 */
181#define OCFS2_FEATURE_RO_COMPAT_UNWRITTEN 0x0001
182
Jan Kara1a224ad2008-08-20 15:43:36 +0200183/*
184 * Maintain quota information for this filesystem
185 */
186#define OCFS2_FEATURE_RO_COMPAT_USRQUOTA 0x0002
187#define OCFS2_FEATURE_RO_COMPAT_GRPQUOTA 0x0004
188
Mark Fasheh50af94b2007-01-21 14:44:59 -0800189/* The byte offset of the first backup block will be 1G.
190 * The following will be 4G, 16G, 64G, 256G and 1T.
191 */
192#define OCFS2_BACKUP_SB_START 1 << 30
193
194/* the max backup superblock nums */
195#define OCFS2_MAX_BACKUP_SUPERBLOCKS 6
196
197/*
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700198 * Flags on ocfs2_super_block.s_tunefs_flags
199 */
200#define OCFS2_TUNEFS_INPROG_REMOVE_SLOT 0x0001 /* Removing slots */
201
202/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800203 * Flags on ocfs2_dinode.i_flags
204 */
205#define OCFS2_VALID_FL (0x00000001) /* Inode is valid */
206#define OCFS2_UNUSED2_FL (0x00000002)
207#define OCFS2_ORPHANED_FL (0x00000004) /* On the orphan list */
208#define OCFS2_UNUSED3_FL (0x00000008)
209/* System inode flags */
210#define OCFS2_SYSTEM_FL (0x00000010) /* System inode */
211#define OCFS2_SUPER_BLOCK_FL (0x00000020) /* Super block */
212#define OCFS2_LOCAL_ALLOC_FL (0x00000040) /* Slot local alloc bitmap */
213#define OCFS2_BITMAP_FL (0x00000080) /* Allocation bitmap */
214#define OCFS2_JOURNAL_FL (0x00000100) /* Slot local journal */
215#define OCFS2_HEARTBEAT_FL (0x00000200) /* Heartbeat area */
216#define OCFS2_CHAIN_FL (0x00000400) /* Chain allocator */
217#define OCFS2_DEALLOC_FL (0x00000800) /* Truncate log */
Jan Kara1a224ad2008-08-20 15:43:36 +0200218#define OCFS2_QUOTA_FL (0x00001000) /* Quota file */
Mark Fashehccd979b2005-12-15 14:31:24 -0800219
Mark Fasheh15b1e362007-09-07 13:58:15 -0700220/*
221 * Flags on ocfs2_dinode.i_dyn_features
222 *
223 * These can change much more often than i_flags. When adding flags,
224 * keep in mind that i_dyn_features is only 16 bits wide.
225 */
226#define OCFS2_INLINE_DATA_FL (0x0001) /* Data stored in inode block */
227#define OCFS2_HAS_XATTR_FL (0x0002)
228#define OCFS2_INLINE_XATTR_FL (0x0004)
229#define OCFS2_INDEXED_DIR_FL (0x0008)
Tao Ma721f69c2009-08-18 11:17:49 +0800230#define OCFS2_HAS_REFCOUNT_FL (0x0010)
Mark Fasheh15b1e362007-09-07 13:58:15 -0700231
Herbert Poetzlca4d1472006-07-03 17:27:12 -0700232/* Inode attributes, keep in sync with EXT2 */
233#define OCFS2_SECRM_FL (0x00000001) /* Secure deletion */
234#define OCFS2_UNRM_FL (0x00000002) /* Undelete */
235#define OCFS2_COMPR_FL (0x00000004) /* Compress file */
236#define OCFS2_SYNC_FL (0x00000008) /* Synchronous updates */
237#define OCFS2_IMMUTABLE_FL (0x00000010) /* Immutable file */
238#define OCFS2_APPEND_FL (0x00000020) /* writes to file may only append */
239#define OCFS2_NODUMP_FL (0x00000040) /* do not dump file */
240#define OCFS2_NOATIME_FL (0x00000080) /* do not update atime */
241#define OCFS2_DIRSYNC_FL (0x00010000) /* dirsync behaviour (directories only) */
242
243#define OCFS2_FL_VISIBLE (0x000100FF) /* User visible flags */
244#define OCFS2_FL_MODIFIABLE (0x000100FF) /* User modifiable flags */
245
246/*
Mark Fashehe48edee2007-03-07 16:46:57 -0800247 * Extent record flags (e_node.leaf.flags)
248 */
Tao Ma721f69c2009-08-18 11:17:49 +0800249#define OCFS2_EXT_UNWRITTEN (0x01) /* Extent is allocated but
250 * unwritten */
251#define OCFS2_EXT_REFCOUNTED (0x02) /* Extent is reference
252 * counted in an associated
253 * refcount tree */
Mark Fashehe48edee2007-03-07 16:46:57 -0800254
255/*
Herbert Poetzlca4d1472006-07-03 17:27:12 -0700256 * ioctl commands
257 */
258#define OCFS2_IOC_GETFLAGS _IOR('f', 1, long)
259#define OCFS2_IOC_SETFLAGS _IOW('f', 2, long)
Mark Fasheh586d2322007-03-09 15:56:28 -0800260#define OCFS2_IOC32_GETFLAGS _IOR('f', 1, int)
261#define OCFS2_IOC32_SETFLAGS _IOW('f', 2, int)
Herbert Poetzlca4d1472006-07-03 17:27:12 -0700262
Mark Fashehccd979b2005-12-15 14:31:24 -0800263/*
Mark Fashehb2580102007-03-09 16:53:21 -0800264 * Space reservation / allocation / free ioctls and argument structure
265 * are designed to be compatible with XFS.
266 *
267 * ALLOCSP* and FREESP* are not and will never be supported, but are
268 * included here for completeness.
269 */
270struct ocfs2_space_resv {
271 __s16 l_type;
272 __s16 l_whence;
273 __s64 l_start;
274 __s64 l_len; /* len == 0 means until end of file */
275 __s32 l_sysid;
276 __u32 l_pid;
277 __s32 l_pad[4]; /* reserve area */
278};
279
280#define OCFS2_IOC_ALLOCSP _IOW ('X', 10, struct ocfs2_space_resv)
281#define OCFS2_IOC_FREESP _IOW ('X', 11, struct ocfs2_space_resv)
282#define OCFS2_IOC_RESVSP _IOW ('X', 40, struct ocfs2_space_resv)
283#define OCFS2_IOC_UNRESVSP _IOW ('X', 41, struct ocfs2_space_resv)
284#define OCFS2_IOC_ALLOCSP64 _IOW ('X', 36, struct ocfs2_space_resv)
285#define OCFS2_IOC_FREESP64 _IOW ('X', 37, struct ocfs2_space_resv)
286#define OCFS2_IOC_RESVSP64 _IOW ('X', 42, struct ocfs2_space_resv)
287#define OCFS2_IOC_UNRESVSP64 _IOW ('X', 43, struct ocfs2_space_resv)
288
Tao Ma7909f2b2007-12-18 15:47:25 +0800289/* Used to pass group descriptor data when online resize is done */
290struct ocfs2_new_group_input {
291 __u64 group; /* Group descriptor's blkno. */
292 __u32 clusters; /* Total number of clusters in this group */
293 __u32 frees; /* Total free clusters in this group */
294 __u16 chain; /* Chain for this group */
295 __u16 reserved1;
296 __u32 reserved2;
297};
298
Tao Mad6590722007-12-18 15:47:03 +0800299#define OCFS2_IOC_GROUP_EXTEND _IOW('o', 1, int)
Tao Ma7909f2b2007-12-18 15:47:25 +0800300#define OCFS2_IOC_GROUP_ADD _IOW('o', 2,struct ocfs2_new_group_input)
301#define OCFS2_IOC_GROUP_ADD64 _IOW('o', 3,struct ocfs2_new_group_input)
Tao Mad6590722007-12-18 15:47:03 +0800302
Mark Fashehb2580102007-03-09 16:53:21 -0800303/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800304 * Journal Flags (ocfs2_dinode.id1.journal1.i_flags)
305 */
306#define OCFS2_JOURNAL_DIRTY_FL (0x00000001) /* Journal needs recovery */
307
308/*
309 * superblock s_state flags
310 */
311#define OCFS2_ERROR_FS (0x00000001) /* FS saw errors */
312
313/* Limit of space in ocfs2_dir_entry */
314#define OCFS2_MAX_FILENAME_LEN 255
315
316/* Maximum slots on an ocfs2 file system */
317#define OCFS2_MAX_SLOTS 255
318
319/* Slot map indicator for an empty slot */
320#define OCFS2_INVALID_SLOT -1
321
322#define OCFS2_VOL_UUID_LEN 16
323#define OCFS2_MAX_VOL_LABEL_LEN 64
324
Joel Beckerb61817e2008-02-01 15:08:23 -0800325/* The alternate, userspace stack fields */
326#define OCFS2_STACK_LABEL_LEN 4
327#define OCFS2_CLUSTER_NAME_LEN 16
328
Mark Fashehccd979b2005-12-15 14:31:24 -0800329/* Journal limits (in bytes) */
330#define OCFS2_MIN_JOURNAL_SIZE (4 * 1024 * 1024)
Mark Fashehccd979b2005-12-15 14:31:24 -0800331
Sunil Mushran2fbe8d12007-12-20 14:58:11 -0800332/*
333 * Default local alloc size (in megabytes)
334 *
335 * The value chosen should be such that most allocations, including new
336 * block groups, use local alloc.
337 */
338#define OCFS2_DEFAULT_LOCAL_ALLOC_SIZE 8
339
Tiger Yangfdd77702008-08-18 17:08:55 +0800340/*
341 * Inline extended attribute size (in bytes)
342 * The value chosen should be aligned to 16 byte boundaries.
343 */
344#define OCFS2_MIN_XATTR_INLINE_SIZE 256
345
Mark Fashehccd979b2005-12-15 14:31:24 -0800346struct ocfs2_system_inode_info {
347 char *si_name;
348 int si_iflags;
349 int si_mode;
350};
351
352/* System file index */
353enum {
354 BAD_BLOCK_SYSTEM_INODE = 0,
355 GLOBAL_INODE_ALLOC_SYSTEM_INODE,
356 SLOT_MAP_SYSTEM_INODE,
357#define OCFS2_FIRST_ONLINE_SYSTEM_INODE SLOT_MAP_SYSTEM_INODE
358 HEARTBEAT_SYSTEM_INODE,
359 GLOBAL_BITMAP_SYSTEM_INODE,
Jan Kara1a224ad2008-08-20 15:43:36 +0200360 USER_QUOTA_SYSTEM_INODE,
361 GROUP_QUOTA_SYSTEM_INODE,
362#define OCFS2_LAST_GLOBAL_SYSTEM_INODE GROUP_QUOTA_SYSTEM_INODE
Mark Fashehccd979b2005-12-15 14:31:24 -0800363 ORPHAN_DIR_SYSTEM_INODE,
364 EXTENT_ALLOC_SYSTEM_INODE,
365 INODE_ALLOC_SYSTEM_INODE,
366 JOURNAL_SYSTEM_INODE,
367 LOCAL_ALLOC_SYSTEM_INODE,
368 TRUNCATE_LOG_SYSTEM_INODE,
Jan Kara1a224ad2008-08-20 15:43:36 +0200369 LOCAL_USER_QUOTA_SYSTEM_INODE,
370 LOCAL_GROUP_QUOTA_SYSTEM_INODE,
Mark Fashehccd979b2005-12-15 14:31:24 -0800371 NUM_SYSTEM_INODES
372};
373
374static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = {
375 /* Global system inodes (single copy) */
376 /* The first two are only used from userspace mfks/tunefs */
377 [BAD_BLOCK_SYSTEM_INODE] = { "bad_blocks", 0, S_IFREG | 0644 },
378 [GLOBAL_INODE_ALLOC_SYSTEM_INODE] = { "global_inode_alloc", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
379
380 /* These are used by the running filesystem */
381 [SLOT_MAP_SYSTEM_INODE] = { "slot_map", 0, S_IFREG | 0644 },
382 [HEARTBEAT_SYSTEM_INODE] = { "heartbeat", OCFS2_HEARTBEAT_FL, S_IFREG | 0644 },
383 [GLOBAL_BITMAP_SYSTEM_INODE] = { "global_bitmap", 0, S_IFREG | 0644 },
Jan Kara1a224ad2008-08-20 15:43:36 +0200384 [USER_QUOTA_SYSTEM_INODE] = { "aquota.user", OCFS2_QUOTA_FL, S_IFREG | 0644 },
385 [GROUP_QUOTA_SYSTEM_INODE] = { "aquota.group", OCFS2_QUOTA_FL, S_IFREG | 0644 },
Mark Fashehccd979b2005-12-15 14:31:24 -0800386
387 /* Slot-specific system inodes (one copy per slot) */
388 [ORPHAN_DIR_SYSTEM_INODE] = { "orphan_dir:%04d", 0, S_IFDIR | 0755 },
389 [EXTENT_ALLOC_SYSTEM_INODE] = { "extent_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
390 [INODE_ALLOC_SYSTEM_INODE] = { "inode_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
391 [JOURNAL_SYSTEM_INODE] = { "journal:%04d", OCFS2_JOURNAL_FL, S_IFREG | 0644 },
392 [LOCAL_ALLOC_SYSTEM_INODE] = { "local_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_LOCAL_ALLOC_FL, S_IFREG | 0644 },
Jan Kara1a224ad2008-08-20 15:43:36 +0200393 [TRUNCATE_LOG_SYSTEM_INODE] = { "truncate_log:%04d", OCFS2_DEALLOC_FL, S_IFREG | 0644 },
394 [LOCAL_USER_QUOTA_SYSTEM_INODE] = { "aquota.user:%04d", OCFS2_QUOTA_FL, S_IFREG | 0644 },
395 [LOCAL_GROUP_QUOTA_SYSTEM_INODE] = { "aquota.group:%04d", OCFS2_QUOTA_FL, S_IFREG | 0644 },
Mark Fashehccd979b2005-12-15 14:31:24 -0800396};
397
398/* Parameter passed from mount.ocfs2 to module */
399#define OCFS2_HB_NONE "heartbeat=none"
400#define OCFS2_HB_LOCAL "heartbeat=local"
401
402/*
403 * OCFS2 directory file types. Only the low 3 bits are used. The
404 * other bits are reserved for now.
405 */
406#define OCFS2_FT_UNKNOWN 0
407#define OCFS2_FT_REG_FILE 1
408#define OCFS2_FT_DIR 2
409#define OCFS2_FT_CHRDEV 3
410#define OCFS2_FT_BLKDEV 4
411#define OCFS2_FT_FIFO 5
412#define OCFS2_FT_SOCK 6
413#define OCFS2_FT_SYMLINK 7
414
415#define OCFS2_FT_MAX 8
416
417/*
418 * OCFS2_DIR_PAD defines the directory entries boundaries
419 *
420 * NOTE: It must be a multiple of 4
421 */
422#define OCFS2_DIR_PAD 4
423#define OCFS2_DIR_ROUND (OCFS2_DIR_PAD - 1)
424#define OCFS2_DIR_MEMBER_LEN offsetof(struct ocfs2_dir_entry, name)
425#define OCFS2_DIR_REC_LEN(name_len) (((name_len) + OCFS2_DIR_MEMBER_LEN + \
426 OCFS2_DIR_ROUND) & \
427 ~OCFS2_DIR_ROUND)
Mark Fashehe7c17e42009-01-29 18:17:46 -0800428#define OCFS2_DIR_MIN_REC_LEN OCFS2_DIR_REC_LEN(1)
Mark Fashehccd979b2005-12-15 14:31:24 -0800429
430#define OCFS2_LINK_MAX 32000
Mark Fasheh198a1ca2008-11-20 17:54:57 -0800431#define OCFS2_DX_LINK_MAX ((1U << 31) - 1U)
432#define OCFS2_LINKS_HI_SHIFT 16
Mark Fashehe3a93c22009-02-17 15:29:35 -0800433#define OCFS2_DX_ENTRIES_MAX (0xffffffffU)
Mark Fashehccd979b2005-12-15 14:31:24 -0800434
435#define S_SHIFT 12
436static unsigned char ocfs2_type_by_mode[S_IFMT >> S_SHIFT] = {
437 [S_IFREG >> S_SHIFT] = OCFS2_FT_REG_FILE,
438 [S_IFDIR >> S_SHIFT] = OCFS2_FT_DIR,
439 [S_IFCHR >> S_SHIFT] = OCFS2_FT_CHRDEV,
440 [S_IFBLK >> S_SHIFT] = OCFS2_FT_BLKDEV,
441 [S_IFIFO >> S_SHIFT] = OCFS2_FT_FIFO,
442 [S_IFSOCK >> S_SHIFT] = OCFS2_FT_SOCK,
443 [S_IFLNK >> S_SHIFT] = OCFS2_FT_SYMLINK,
444};
445
446
447/*
448 * Convenience casts
449 */
450#define OCFS2_RAW_SB(dinode) (&((dinode)->id2.i_super))
451
452/*
Joel Beckerab552d52008-10-16 17:50:30 -0700453 * Block checking structure. This is used in metadata to validate the
454 * contents. If OCFS2_FEATURE_INCOMPAT_META_ECC is not set, it is all
455 * zeros.
456 */
457struct ocfs2_block_check {
458/*00*/ __le32 bc_crc32e; /* 802.3 Ethernet II CRC32 */
459 __le16 bc_ecc; /* Single-error-correction parity vector.
460 This is a simple Hamming code dependant
461 on the blocksize. OCFS2's maximum
462 blocksize, 4K, requires 16 parity bits,
463 so we fit in __le16. */
464 __le16 bc_reserved1;
465/*08*/
466};
467
468/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800469 * On disk extent record for OCFS2
470 * It describes a range of clusters on disk.
Mark Fashehe48edee2007-03-07 16:46:57 -0800471 *
472 * Length fields are divided into interior and leaf node versions.
473 * This leaves room for a flags field (OCFS2_EXT_*) in the leaf nodes.
Mark Fashehccd979b2005-12-15 14:31:24 -0800474 */
475struct ocfs2_extent_rec {
476/*00*/ __le32 e_cpos; /* Offset into the file, in clusters */
Mark Fashehe48edee2007-03-07 16:46:57 -0800477 union {
478 __le32 e_int_clusters; /* Clusters covered by all children */
479 struct {
480 __le16 e_leaf_clusters; /* Clusters covered by this
481 extent */
482 __u8 e_reserved1;
483 __u8 e_flags; /* Extent flags */
484 };
485 };
Mark Fashehccd979b2005-12-15 14:31:24 -0800486 __le64 e_blkno; /* Physical disk offset, in blocks */
487/*10*/
488};
489
490struct ocfs2_chain_rec {
491 __le32 c_free; /* Number of free bits in this chain. */
492 __le32 c_total; /* Number of total bits in this chain */
493 __le64 c_blkno; /* Physical disk offset (blocks) of 1st group */
494};
495
496struct ocfs2_truncate_rec {
497 __le32 t_start; /* 1st cluster in this log */
498 __le32 t_clusters; /* Number of total clusters covered */
499};
500
501/*
502 * On disk extent list for OCFS2 (node in the tree). Note that this
503 * is contained inside ocfs2_dinode or ocfs2_extent_block, so the
504 * offsets are relative to ocfs2_dinode.id2.i_list or
505 * ocfs2_extent_block.h_list, respectively.
506 */
507struct ocfs2_extent_list {
508/*00*/ __le16 l_tree_depth; /* Extent tree depth from this
509 point. 0 means data extents
510 hang directly off this
Mark Fashehdcd05382007-01-16 11:32:23 -0800511 header (a leaf)
512 NOTE: The high 8 bits cannot be
513 used - tree_depth is never that big.
514 */
Mark Fashehccd979b2005-12-15 14:31:24 -0800515 __le16 l_count; /* Number of extent records */
516 __le16 l_next_free_rec; /* Next unused extent slot */
517 __le16 l_reserved1;
518 __le64 l_reserved2; /* Pad to
519 sizeof(ocfs2_extent_rec) */
520/*10*/ struct ocfs2_extent_rec l_recs[0]; /* Extent records */
521};
522
523/*
524 * On disk allocation chain list for OCFS2. Note that this is
525 * contained inside ocfs2_dinode, so the offsets are relative to
526 * ocfs2_dinode.id2.i_chain.
527 */
528struct ocfs2_chain_list {
529/*00*/ __le16 cl_cpg; /* Clusters per Block Group */
530 __le16 cl_bpc; /* Bits per cluster */
531 __le16 cl_count; /* Total chains in this list */
532 __le16 cl_next_free_rec; /* Next unused chain slot */
533 __le64 cl_reserved1;
534/*10*/ struct ocfs2_chain_rec cl_recs[0]; /* Chain records */
535};
536
537/*
538 * On disk deallocation log for OCFS2. Note that this is
539 * contained inside ocfs2_dinode, so the offsets are relative to
540 * ocfs2_dinode.id2.i_dealloc.
541 */
542struct ocfs2_truncate_log {
543/*00*/ __le16 tl_count; /* Total records in this log */
544 __le16 tl_used; /* Number of records in use */
545 __le32 tl_reserved1;
546/*08*/ struct ocfs2_truncate_rec tl_recs[0]; /* Truncate records */
547};
548
549/*
550 * On disk extent block (indirect block) for OCFS2
551 */
552struct ocfs2_extent_block
553{
554/*00*/ __u8 h_signature[8]; /* Signature for verification */
Joel Beckerab552d52008-10-16 17:50:30 -0700555 struct ocfs2_block_check h_check; /* Error checking */
Mark Fashehccd979b2005-12-15 14:31:24 -0800556/*10*/ __le16 h_suballoc_slot; /* Slot suballocator this
557 extent_header belongs to */
558 __le16 h_suballoc_bit; /* Bit offset in suballocator
559 block group */
560 __le32 h_fs_generation; /* Must match super block */
561 __le64 h_blkno; /* Offset on disk, in blocks */
562/*20*/ __le64 h_reserved3;
563 __le64 h_next_leaf_blk; /* Offset on disk, in blocks,
564 of next leaf header pointing
565 to data */
566/*30*/ struct ocfs2_extent_list h_list; /* Extent record list */
567/* Actual on-disk size is one block */
568};
569
570/*
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800571 * On disk slot map for OCFS2. This defines the contents of the "slot_map"
Joel Becker386a2ef2008-02-01 12:06:54 -0800572 * system file. A slot is valid if it contains a node number >= 0. The
573 * value -1 (0xFFFF) is OCFS2_INVALID_SLOT. This marks a slot empty.
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800574 */
575struct ocfs2_slot_map {
576/*00*/ __le16 sm_slots[0];
577/*
578 * Actual on-disk size is one block. OCFS2_MAX_SLOTS is 255,
579 * 255 * sizeof(__le16) == 512B, within the 512B block minimum blocksize.
580 */
581};
582
Joel Becker386a2ef2008-02-01 12:06:54 -0800583struct ocfs2_extended_slot {
584/*00*/ __u8 es_valid;
585 __u8 es_reserved1[3];
586 __le32 es_node_num;
587/*10*/
588};
589
590/*
591 * The extended slot map, used when OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP
592 * is set. It separates out the valid marker from the node number, and
593 * has room to grow. Unlike the old slot map, this format is defined by
594 * i_size.
595 */
596struct ocfs2_slot_map_extended {
597/*00*/ struct ocfs2_extended_slot se_slots[0];
598/*
599 * Actual size is i_size of the slot_map system file. It should
600 * match s_max_slots * sizeof(struct ocfs2_extended_slot)
601 */
602};
603
Joel Beckerb61817e2008-02-01 15:08:23 -0800604struct ocfs2_cluster_info {
605/*00*/ __u8 ci_stack[OCFS2_STACK_LABEL_LEN];
606 __le32 ci_reserved;
607/*08*/ __u8 ci_cluster[OCFS2_CLUSTER_NAME_LEN];
608/*18*/
609};
610
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800611/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800612 * On disk superblock for OCFS2
613 * Note that it is contained inside an ocfs2_dinode, so all offsets
614 * are relative to the start of ocfs2_dinode.id2.
615 */
616struct ocfs2_super_block {
617/*00*/ __le16 s_major_rev_level;
618 __le16 s_minor_rev_level;
619 __le16 s_mnt_count;
620 __le16 s_max_mnt_count;
621 __le16 s_state; /* File system state */
622 __le16 s_errors; /* Behaviour when detecting errors */
623 __le32 s_checkinterval; /* Max time between checks */
624/*10*/ __le64 s_lastcheck; /* Time of last check */
625 __le32 s_creator_os; /* OS */
626 __le32 s_feature_compat; /* Compatible feature set */
627/*20*/ __le32 s_feature_incompat; /* Incompatible feature set */
628 __le32 s_feature_ro_compat; /* Readonly-compatible feature set */
629 __le64 s_root_blkno; /* Offset, in blocks, of root directory
630 dinode */
631/*30*/ __le64 s_system_dir_blkno; /* Offset, in blocks, of system
632 directory dinode */
633 __le32 s_blocksize_bits; /* Blocksize for this fs */
634 __le32 s_clustersize_bits; /* Clustersize for this fs */
635/*40*/ __le16 s_max_slots; /* Max number of simultaneous mounts
636 before tunefs required */
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700637 __le16 s_tunefs_flag;
Tiger Yangcf1d6c72008-08-18 17:11:00 +0800638 __le32 s_uuid_hash; /* hash value of uuid */
Mark Fashehccd979b2005-12-15 14:31:24 -0800639 __le64 s_first_cluster_group; /* Block offset of 1st cluster
640 * group header */
641/*50*/ __u8 s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */
642/*90*/ __u8 s_uuid[OCFS2_VOL_UUID_LEN]; /* 128-bit uuid */
Joel Beckerb61817e2008-02-01 15:08:23 -0800643/*A0*/ struct ocfs2_cluster_info s_cluster_info; /* Selected userspace
644 stack. Only valid
645 with INCOMPAT flag. */
Tiger Yang8154da32008-08-18 17:11:46 +0800646/*B8*/ __le16 s_xattr_inline_size; /* extended attribute inline size
647 for this fs*/
648 __le16 s_reserved0;
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800649 __le32 s_dx_seed[3]; /* seed[0-2] for dx dir hash.
650 * s_uuid_hash serves as seed[3]. */
651/*C0*/ __le64 s_reserved2[15]; /* Fill out superblock */
Joel Beckerb61817e2008-02-01 15:08:23 -0800652/*140*/
653
654 /*
655 * NOTE: As stated above, all offsets are relative to
656 * ocfs2_dinode.id2, which is at 0xC0 in the inode.
657 * 0xC0 + 0x140 = 0x200 or 512 bytes. A superblock must fit within
658 * our smallest blocksize, which is 512 bytes. To ensure this,
659 * we reserve the space in s_reserved2. Anything past s_reserved2
660 * will not be available on the smallest blocksize.
661 */
Mark Fashehccd979b2005-12-15 14:31:24 -0800662};
663
664/*
665 * Local allocation bitmap for OCFS2 slots
666 * Note that it exists inside an ocfs2_dinode, so all offsets are
667 * relative to the start of ocfs2_dinode.id2.
668 */
669struct ocfs2_local_alloc
670{
671/*00*/ __le32 la_bm_off; /* Starting bit offset in main bitmap */
672 __le16 la_size; /* Size of included bitmap, in bytes */
673 __le16 la_reserved1;
674 __le64 la_reserved2;
675/*10*/ __u8 la_bitmap[0];
676};
677
678/*
Mark Fasheh15b1e362007-09-07 13:58:15 -0700679 * Data-in-inode header. This is only used if i_dyn_features has
680 * OCFS2_INLINE_DATA_FL set.
681 */
682struct ocfs2_inline_data
683{
684/*00*/ __le16 id_count; /* Number of bytes that can be used
685 * for data, starting at id_data */
686 __le16 id_reserved0;
687 __le32 id_reserved1;
688 __u8 id_data[0]; /* Start of user data */
689};
690
691/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800692 * On disk inode for OCFS2
693 */
694struct ocfs2_dinode {
695/*00*/ __u8 i_signature[8]; /* Signature for validation */
696 __le32 i_generation; /* Generation number */
697 __le16 i_suballoc_slot; /* Slot suballocator this inode
698 belongs to */
699 __le16 i_suballoc_bit; /* Bit offset in suballocator
700 block group */
Mark Fasheh198a1ca2008-11-20 17:54:57 -0800701/*10*/ __le16 i_links_count_hi; /* High 16 bits of links count */
Tiger Yangfdd77702008-08-18 17:08:55 +0800702 __le16 i_xattr_inline_size;
Mark Fashehccd979b2005-12-15 14:31:24 -0800703 __le32 i_clusters; /* Cluster count */
704 __le32 i_uid; /* Owner UID */
705 __le32 i_gid; /* Owning GID */
706/*20*/ __le64 i_size; /* Size in bytes */
707 __le16 i_mode; /* File mode */
708 __le16 i_links_count; /* Links count */
709 __le32 i_flags; /* File flags */
710/*30*/ __le64 i_atime; /* Access time */
711 __le64 i_ctime; /* Creation time */
712/*40*/ __le64 i_mtime; /* Modification time */
713 __le64 i_dtime; /* Deletion time */
714/*50*/ __le64 i_blkno; /* Offset on disk, in blocks */
715 __le64 i_last_eb_blk; /* Pointer to last extent
716 block */
717/*60*/ __le32 i_fs_generation; /* Generation per fs-instance */
718 __le32 i_atime_nsec;
719 __le32 i_ctime_nsec;
720 __le32 i_mtime_nsec;
Tiger Yangfdd77702008-08-18 17:08:55 +0800721/*70*/ __le32 i_attr;
Tiger Yang50008632007-03-20 16:01:38 -0700722 __le16 i_orphaned_slot; /* Only valid when OCFS2_ORPHANED_FL
723 was set in i_flags */
Mark Fasheh15b1e362007-09-07 13:58:15 -0700724 __le16 i_dyn_features;
Tiger Yangfdd77702008-08-18 17:08:55 +0800725 __le64 i_xattr_loc;
Joel Beckerab552d52008-10-16 17:50:30 -0700726/*80*/ struct ocfs2_block_check i_check; /* Error checking */
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800727/*88*/ __le64 i_dx_root; /* Pointer to dir index root block */
Tao Ma721f69c2009-08-18 11:17:49 +0800728/*90*/ __le64 i_refcount_loc;
729 __le64 i_reserved2[4];
Mark Fashehccd979b2005-12-15 14:31:24 -0800730/*B8*/ union {
731 __le64 i_pad1; /* Generic way to refer to this
732 64bit union */
733 struct {
734 __le64 i_rdev; /* Device number */
735 } dev1;
736 struct { /* Info for bitmap system
737 inodes */
738 __le32 i_used; /* Bits (ie, clusters) used */
739 __le32 i_total; /* Total bits (clusters)
740 available */
741 } bitmap1;
742 struct { /* Info for journal system
743 inodes */
744 __le32 ij_flags; /* Mounted, version, etc. */
Sunil Mushranc69991a2008-07-14 17:31:09 -0700745 __le32 ij_recovery_generation; /* Incremented when the
746 journal is recovered
747 after an unclean
748 shutdown */
Mark Fashehccd979b2005-12-15 14:31:24 -0800749 } journal1;
750 } id1; /* Inode type dependant 1 */
751/*C0*/ union {
752 struct ocfs2_super_block i_super;
753 struct ocfs2_local_alloc i_lab;
754 struct ocfs2_chain_list i_chain;
755 struct ocfs2_extent_list i_list;
756 struct ocfs2_truncate_log i_dealloc;
Mark Fasheh15b1e362007-09-07 13:58:15 -0700757 struct ocfs2_inline_data i_data;
Mark Fashehccd979b2005-12-15 14:31:24 -0800758 __u8 i_symlink[0];
759 } id2;
760/* Actual on-disk size is one block */
761};
762
763/*
764 * On-disk directory entry structure for OCFS2
765 *
766 * Packed as this structure could be accessed unaligned on 64-bit platforms
767 */
768struct ocfs2_dir_entry {
769/*00*/ __le64 inode; /* Inode number */
770 __le16 rec_len; /* Directory entry length */
771 __u8 name_len; /* Name length */
772 __u8 file_type;
773/*0C*/ char name[OCFS2_MAX_FILENAME_LEN]; /* File name */
774/* Actual on-disk length specified by rec_len */
775} __attribute__ ((packed));
776
777/*
Mark Fasheh87d35a72008-12-10 17:36:25 -0800778 * Per-block record for the unindexed directory btree. This is carefully
779 * crafted so that the rec_len and name_len records of an ocfs2_dir_entry are
780 * mirrored. That way, the directory manipulation code needs a minimal amount
781 * of update.
782 *
783 * NOTE: Keep this structure aligned to a multiple of 4 bytes.
784 */
785struct ocfs2_dir_block_trailer {
786/*00*/ __le64 db_compat_inode; /* Always zero. Was inode */
787
788 __le16 db_compat_rec_len; /* Backwards compatible with
789 * ocfs2_dir_entry. */
790 __u8 db_compat_name_len; /* Always zero. Was name_len */
791 __u8 db_reserved0;
792 __le16 db_reserved1;
793 __le16 db_free_rec_len; /* Size of largest empty hole
794 * in this block. (unused) */
795/*10*/ __u8 db_signature[8]; /* Signature for verification */
796 __le64 db_reserved2;
797 __le64 db_free_next; /* Next block in list (unused) */
798/*20*/ __le64 db_blkno; /* Offset on disk, in blocks */
799 __le64 db_parent_dinode; /* dinode which owns me, in
800 blocks */
Joel Beckerc175a512008-12-10 17:58:22 -0800801/*30*/ struct ocfs2_block_check db_check; /* Error checking */
Mark Fasheh87d35a72008-12-10 17:36:25 -0800802/*40*/
803};
804
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800805 /*
806 * A directory entry in the indexed tree. We don't store the full name here,
807 * but instead provide a pointer to the full dirent in the unindexed tree.
808 *
809 * We also store name_len here so as to reduce the number of leaf blocks we
810 * need to search in case of collisions.
811 */
812struct ocfs2_dx_entry {
813 __le32 dx_major_hash; /* Used to find logical
814 * cluster in index */
815 __le32 dx_minor_hash; /* Lower bits used to find
816 * block in cluster */
817 __le64 dx_dirent_blk; /* Physical block in unindexed
818 * tree holding this dirent. */
819};
820
821struct ocfs2_dx_entry_list {
822 __le32 de_reserved;
823 __le16 de_count; /* Maximum number of entries
824 * possible in de_entries */
825 __le16 de_num_used; /* Current number of
826 * de_entries entries */
827 struct ocfs2_dx_entry de_entries[0]; /* Indexed dir entries
828 * in a packed array of
829 * length de_num_used */
830};
831
Mark Fasheh4ed8a6b2008-11-24 17:02:08 -0800832#define OCFS2_DX_FLAG_INLINE 0x01
833
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800834/*
835 * A directory indexing block. Each indexed directory has one of these,
836 * pointed to by ocfs2_dinode.
837 *
838 * This block stores an indexed btree root, and a set of free space
839 * start-of-list pointers.
840 */
841struct ocfs2_dx_root_block {
842 __u8 dr_signature[8]; /* Signature for verification */
843 struct ocfs2_block_check dr_check; /* Error checking */
844 __le16 dr_suballoc_slot; /* Slot suballocator this
845 * block belongs to. */
846 __le16 dr_suballoc_bit; /* Bit offset in suballocator
847 * block group */
848 __le32 dr_fs_generation; /* Must match super block */
849 __le64 dr_blkno; /* Offset on disk, in blocks */
850 __le64 dr_last_eb_blk; /* Pointer to last
851 * extent block */
852 __le32 dr_clusters; /* Clusters allocated
853 * to the indexed tree. */
Mark Fasheh4ed8a6b2008-11-24 17:02:08 -0800854 __u8 dr_flags; /* OCFS2_DX_FLAG_* flags */
855 __u8 dr_reserved0;
856 __le16 dr_reserved1;
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800857 __le64 dr_dir_blkno; /* Pointer to parent inode */
Mark Fashehe3a93c22009-02-17 15:29:35 -0800858 __le32 dr_num_entries; /* Total number of
859 * names stored in
860 * this directory.*/
861 __le32 dr_reserved2;
Mark Fashehe7c17e42009-01-29 18:17:46 -0800862 __le64 dr_free_blk; /* Pointer to head of free
863 * unindexed block list. */
864 __le64 dr_reserved3[15];
Mark Fasheh4ed8a6b2008-11-24 17:02:08 -0800865 union {
866 struct ocfs2_extent_list dr_list; /* Keep this aligned to 128
867 * bits for maximum space
868 * efficiency. */
869 struct ocfs2_dx_entry_list dr_entries; /* In-root-block list of
870 * entries. We grow out
871 * to extents if this
872 * gets too big. */
873 };
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800874};
875
876/*
877 * The header of a leaf block in the indexed tree.
878 */
879struct ocfs2_dx_leaf {
880 __u8 dl_signature[8];/* Signature for verification */
881 struct ocfs2_block_check dl_check; /* Error checking */
882 __le64 dl_blkno; /* Offset on disk, in blocks */
883 __le32 dl_fs_generation;/* Must match super block */
884 __le32 dl_reserved0;
885 __le64 dl_reserved1;
886 struct ocfs2_dx_entry_list dl_list;
887};
888
Mark Fasheh87d35a72008-12-10 17:36:25 -0800889/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800890 * On disk allocator group structure for OCFS2
891 */
892struct ocfs2_group_desc
893{
894/*00*/ __u8 bg_signature[8]; /* Signature for validation */
895 __le16 bg_size; /* Size of included bitmap in
896 bytes. */
897 __le16 bg_bits; /* Bits represented by this
898 group. */
899 __le16 bg_free_bits_count; /* Free bits count */
900 __le16 bg_chain; /* What chain I am in. */
901/*10*/ __le32 bg_generation;
902 __le32 bg_reserved1;
903 __le64 bg_next_group; /* Next group in my list, in
904 blocks */
905/*20*/ __le64 bg_parent_dinode; /* dinode which owns me, in
906 blocks */
907 __le64 bg_blkno; /* Offset on disk, in blocks */
Joel Beckerab552d52008-10-16 17:50:30 -0700908/*30*/ struct ocfs2_block_check bg_check; /* Error checking */
909 __le64 bg_reserved2;
Mark Fashehccd979b2005-12-15 14:31:24 -0800910/*40*/ __u8 bg_bitmap[0];
911};
912
Tao Ma721f69c2009-08-18 11:17:49 +0800913struct ocfs2_refcount_rec {
914/*00*/ __le64 r_cpos; /* Physical offset, in clusters */
915 __le32 r_clusters; /* Clusters covered by this extent */
916 __le32 r_refcount; /* Reference count of this extent */
917/*10*/
918};
919
920#define OCFS2_REFCOUNT_LEAF_FL (0x00000001)
921#define OCFS2_REFCOUNT_TREE_FL (0x00000002)
922
923struct ocfs2_refcount_list {
924/*00*/ __le16 rl_count; /* Maximum number of entries possible
925 in rl_records */
926 __le16 rl_used; /* Current number of used records */
927 __le32 rl_reserved2;
928 __le64 rl_reserved1; /* Pad to sizeof(ocfs2_refcount_record) */
929/*10*/ struct ocfs2_refcount_rec rl_recs[0]; /* Refcount records */
930};
931
932
933struct ocfs2_refcount_block {
934/*00*/ __u8 rf_signature[8]; /* Signature for verification */
935 __le16 rf_suballoc_slot; /* Slot suballocator this block
936 belongs to */
937 __le16 rf_suballoc_bit; /* Bit offset in suballocator
938 block group */
939 __le32 rf_fs_generation; /* Must match superblock */
940/*10*/ __le64 rf_blkno; /* Offset on disk, in blocks */
941 __le64 rf_parent; /* Parent block, only valid if
942 OCFS2_REFCOUNT_LEAF_FL is set in
943 rf_flags */
944/*20*/ struct ocfs2_block_check rf_check; /* Error checking */
945 __le64 rf_last_eb_blk; /* Pointer to last extent block */
946/*30*/ __le32 rf_count; /* Number of inodes sharing this
947 refcount tree */
948 __le32 rf_flags; /* See the flags above */
949 __le32 rf_clusters; /* clusters covered by refcount tree. */
950 __le32 rf_cpos; /* cluster offset in refcount tree.*/
951/*40*/ __le32 rf_generation; /* generation number. all be the same
952 * for the same refcount tree. */
953 __le32 rf_reserved0;
954 __le64 rf_reserved1[7];
955/*80*/ union {
956 struct ocfs2_refcount_list rf_records; /* List of refcount
957 records */
958 struct ocfs2_extent_list rf_list; /* Extent record list,
959 only valid if
960 OCFS2_REFCOUNT_TREE_FL
961 is set in rf_flags */
962 };
963/* Actual on-disk size is one block */
964};
965
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800966/*
967 * On disk extended attribute structure for OCFS2.
968 */
969
970/*
971 * ocfs2_xattr_entry indicates one extend attribute.
972 *
973 * Note that it can be stored in inode, one block or one xattr bucket.
974 */
975struct ocfs2_xattr_entry {
976 __le32 xe_name_hash; /* hash value of xattr prefix+suffix. */
Tao Ma8573f792008-10-24 22:24:17 +0800977 __le16 xe_name_offset; /* byte offset from the 1st entry in the
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800978 local xattr storage(inode, xattr block or
979 xattr bucket). */
980 __u8 xe_name_len; /* xattr name len, does't include prefix. */
Tao Ma8573f792008-10-24 22:24:17 +0800981 __u8 xe_type; /* the low 7 bits indicate the name prefix
982 * type and the highest bit indicates whether
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800983 * the EA is stored in the local storage. */
984 __le64 xe_value_size; /* real xattr value length. */
985};
986
987/*
988 * On disk structure for xattr header.
989 *
990 * One ocfs2_xattr_header describes how many ocfs2_xattr_entry records in
991 * the local xattr storage.
992 */
993struct ocfs2_xattr_header {
994 __le16 xh_count; /* contains the count of how
995 many records are in the
996 local xattr storage. */
Tao Ma0c044f02008-08-18 17:38:50 +0800997 __le16 xh_free_start; /* current offset for storing
998 xattr. */
999 __le16 xh_name_value_len; /* total length of name/value
1000 length in this bucket. */
Tao Ma8573f792008-10-24 22:24:17 +08001001 __le16 xh_num_buckets; /* Number of xattr buckets
1002 in this extent record,
1003 only valid in the first
1004 bucket. */
Joel Beckerab552d52008-10-16 17:50:30 -07001005 struct ocfs2_block_check xh_check; /* Error checking
1006 (Note, this is only
1007 used for xattr
1008 buckets. A block uses
1009 xb_check and sets
1010 this field to zero.) */
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001011 struct ocfs2_xattr_entry xh_entries[0]; /* xattr entry list. */
1012};
1013
1014/*
1015 * On disk structure for xattr value root.
1016 *
Tao Ma8573f792008-10-24 22:24:17 +08001017 * When an xattr's value is large enough, it is stored in an external
1018 * b-tree like file data. The xattr value root points to this structure.
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001019 */
1020struct ocfs2_xattr_value_root {
1021/*00*/ __le32 xr_clusters; /* clusters covered by xattr value. */
1022 __le32 xr_reserved0;
1023 __le64 xr_last_eb_blk; /* Pointer to last extent block */
1024/*10*/ struct ocfs2_extent_list xr_list; /* Extent record list */
1025};
1026
1027/*
1028 * On disk structure for xattr tree root.
1029 *
1030 * It is used when there are too many extended attributes for one file. These
1031 * attributes will be organized and stored in an indexed-btree.
1032 */
1033struct ocfs2_xattr_tree_root {
1034/*00*/ __le32 xt_clusters; /* clusters covered by xattr. */
1035 __le32 xt_reserved0;
1036 __le64 xt_last_eb_blk; /* Pointer to last extent block */
1037/*10*/ struct ocfs2_extent_list xt_list; /* Extent record list */
1038};
1039
Tiger Yangcf1d6c72008-08-18 17:11:00 +08001040#define OCFS2_XATTR_INDEXED 0x1
1041#define OCFS2_HASH_SHIFT 5
1042#define OCFS2_XATTR_ROUND 3
1043#define OCFS2_XATTR_SIZE(size) (((size) + OCFS2_XATTR_ROUND) & \
1044 ~(OCFS2_XATTR_ROUND))
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001045
Tao Ma0c044f02008-08-18 17:38:50 +08001046#define OCFS2_XATTR_BUCKET_SIZE 4096
1047#define OCFS2_XATTR_MAX_BLOCKS_PER_BUCKET (OCFS2_XATTR_BUCKET_SIZE \
1048 / OCFS2_MIN_BLOCKSIZE)
1049
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001050/*
1051 * On disk structure for xattr block.
1052 */
1053struct ocfs2_xattr_block {
1054/*00*/ __u8 xb_signature[8]; /* Signature for verification */
1055 __le16 xb_suballoc_slot; /* Slot suballocator this
1056 block belongs to. */
1057 __le16 xb_suballoc_bit; /* Bit offset in suballocator
1058 block group */
1059 __le32 xb_fs_generation; /* Must match super block */
1060/*10*/ __le64 xb_blkno; /* Offset on disk, in blocks */
Joel Beckerab552d52008-10-16 17:50:30 -07001061 struct ocfs2_block_check xb_check; /* Error checking */
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001062/*20*/ __le16 xb_flags; /* Indicates whether this block contains
1063 real xattr or a xattr tree. */
1064 __le16 xb_reserved0;
1065 __le32 xb_reserved1;
1066 __le64 xb_reserved2;
1067/*30*/ union {
1068 struct ocfs2_xattr_header xb_header; /* xattr header if this
1069 block contains xattr */
1070 struct ocfs2_xattr_tree_root xb_root;/* xattr tree root if this
1071 block cotains xattr
1072 tree. */
1073 } xb_attrs;
1074};
1075
1076#define OCFS2_XATTR_ENTRY_LOCAL 0x80
1077#define OCFS2_XATTR_TYPE_MASK 0x7F
1078static inline void ocfs2_xattr_set_local(struct ocfs2_xattr_entry *xe,
1079 int local)
1080{
1081 if (local)
1082 xe->xe_type |= OCFS2_XATTR_ENTRY_LOCAL;
1083 else
1084 xe->xe_type &= ~OCFS2_XATTR_ENTRY_LOCAL;
1085}
1086
1087static inline int ocfs2_xattr_is_local(struct ocfs2_xattr_entry *xe)
1088{
1089 return xe->xe_type & OCFS2_XATTR_ENTRY_LOCAL;
1090}
1091
1092static inline void ocfs2_xattr_set_type(struct ocfs2_xattr_entry *xe, int type)
1093{
1094 xe->xe_type |= type & OCFS2_XATTR_TYPE_MASK;
1095}
1096
1097static inline int ocfs2_xattr_get_type(struct ocfs2_xattr_entry *xe)
1098{
1099 return xe->xe_type & OCFS2_XATTR_TYPE_MASK;
1100}
1101
Jan Kara9e33d692008-08-25 19:56:50 +02001102/*
1103 * On disk structures for global quota file
1104 */
1105
1106/* Magic numbers and known versions for global quota files */
1107#define OCFS2_GLOBAL_QMAGICS {\
1108 0x0cf52470, /* USRQUOTA */ \
1109 0x0cf52471 /* GRPQUOTA */ \
1110}
1111
1112#define OCFS2_GLOBAL_QVERSIONS {\
1113 0, \
1114 0, \
1115}
1116
1117
1118/* Each block of each quota file has a certain fixed number of bytes reserved
1119 * for OCFS2 internal use at its end. OCFS2 can use it for things like
1120 * checksums, etc. */
1121#define OCFS2_QBLK_RESERVED_SPACE 8
1122
1123/* Generic header of all quota files */
1124struct ocfs2_disk_dqheader {
1125 __le32 dqh_magic; /* Magic number identifying file */
1126 __le32 dqh_version; /* Quota format version */
1127};
1128
1129#define OCFS2_GLOBAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
1130
1131/* Information header of global quota file (immediately follows the generic
1132 * header) */
1133struct ocfs2_global_disk_dqinfo {
1134/*00*/ __le32 dqi_bgrace; /* Grace time for space softlimit excess */
1135 __le32 dqi_igrace; /* Grace time for inode softlimit excess */
1136 __le32 dqi_syncms; /* Time after which we sync local changes to
1137 * global quota file */
1138 __le32 dqi_blocks; /* Number of blocks in quota file */
1139/*10*/ __le32 dqi_free_blk; /* First free block in quota file */
1140 __le32 dqi_free_entry; /* First block with free dquot entry in quota
1141 * file */
1142};
1143
1144/* Structure with global user / group information. We reserve some space
1145 * for future use. */
1146struct ocfs2_global_disk_dqblk {
1147/*00*/ __le32 dqb_id; /* ID the structure belongs to */
1148 __le32 dqb_use_count; /* Number of nodes having reference to this structure */
1149 __le64 dqb_ihardlimit; /* absolute limit on allocated inodes */
1150/*10*/ __le64 dqb_isoftlimit; /* preferred inode limit */
1151 __le64 dqb_curinodes; /* current # allocated inodes */
1152/*20*/ __le64 dqb_bhardlimit; /* absolute limit on disk space */
1153 __le64 dqb_bsoftlimit; /* preferred limit on disk space */
1154/*30*/ __le64 dqb_curspace; /* current space occupied */
1155 __le64 dqb_btime; /* time limit for excessive disk use */
1156/*40*/ __le64 dqb_itime; /* time limit for excessive inode use */
1157 __le64 dqb_pad1;
1158/*50*/ __le64 dqb_pad2;
1159};
1160
1161/*
1162 * On-disk structures for local quota file
1163 */
1164
1165/* Magic numbers and known versions for local quota files */
1166#define OCFS2_LOCAL_QMAGICS {\
1167 0x0cf524c0, /* USRQUOTA */ \
1168 0x0cf524c1 /* GRPQUOTA */ \
1169}
1170
1171#define OCFS2_LOCAL_QVERSIONS {\
1172 0, \
1173 0, \
1174}
1175
1176/* Quota flags in dqinfo header */
1177#define OLQF_CLEAN 0x0001 /* Quota file is empty (this should be after\
1178 * quota has been cleanly turned off) */
1179
1180#define OCFS2_LOCAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
1181
1182/* Information header of local quota file (immediately follows the generic
1183 * header) */
1184struct ocfs2_local_disk_dqinfo {
1185 __le32 dqi_flags; /* Flags for quota file */
1186 __le32 dqi_chunks; /* Number of chunks of quota structures
1187 * with a bitmap */
1188 __le32 dqi_blocks; /* Number of blocks allocated for quota file */
1189};
1190
1191/* Header of one chunk of a quota file */
1192struct ocfs2_local_disk_chunk {
1193 __le32 dqc_free; /* Number of free entries in the bitmap */
1194 u8 dqc_bitmap[0]; /* Bitmap of entries in the corresponding
1195 * chunk of quota file */
1196};
1197
1198/* One entry in local quota file */
1199struct ocfs2_local_disk_dqblk {
1200/*00*/ __le64 dqb_id; /* id this quota applies to */
1201 __le64 dqb_spacemod; /* Change in the amount of used space */
1202/*10*/ __le64 dqb_inodemod; /* Change in the amount of used inodes */
1203};
1204
Joel Beckerab552d52008-10-16 17:50:30 -07001205
1206/*
1207 * The quota trailer lives at the end of each quota block.
1208 */
1209
1210struct ocfs2_disk_dqtrailer {
1211/*00*/ struct ocfs2_block_check dq_check; /* Error checking */
1212/*08*/ /* Cannot be larger than OCFS2_QBLK_RESERVED_SPACE */
1213};
1214
1215static inline struct ocfs2_disk_dqtrailer *ocfs2_block_dqtrailer(int blocksize,
1216 void *buf)
1217{
1218 char *ptr = buf;
1219 ptr += blocksize - OCFS2_QBLK_RESERVED_SPACE;
1220
1221 return (struct ocfs2_disk_dqtrailer *)ptr;
1222}
1223
Mark Fashehccd979b2005-12-15 14:31:24 -08001224#ifdef __KERNEL__
1225static inline int ocfs2_fast_symlink_chars(struct super_block *sb)
1226{
1227 return sb->s_blocksize -
1228 offsetof(struct ocfs2_dinode, id2.i_symlink);
1229}
1230
Tiger Yangfdd77702008-08-18 17:08:55 +08001231static inline int ocfs2_max_inline_data_with_xattr(struct super_block *sb,
1232 struct ocfs2_dinode *di)
1233{
1234 unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
1235
1236 if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
1237 return sb->s_blocksize -
1238 offsetof(struct ocfs2_dinode, id2.i_data.id_data) -
1239 xattrsize;
1240 else
1241 return sb->s_blocksize -
1242 offsetof(struct ocfs2_dinode, id2.i_data.id_data);
1243}
1244
Mark Fashehccd979b2005-12-15 14:31:24 -08001245static inline int ocfs2_extent_recs_per_inode(struct super_block *sb)
1246{
1247 int size;
1248
1249 size = sb->s_blocksize -
1250 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1251
1252 return size / sizeof(struct ocfs2_extent_rec);
1253}
1254
Tiger Yangfdd77702008-08-18 17:08:55 +08001255static inline int ocfs2_extent_recs_per_inode_with_xattr(
1256 struct super_block *sb,
1257 struct ocfs2_dinode *di)
1258{
1259 int size;
1260 unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
1261
1262 if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
1263 size = sb->s_blocksize -
1264 offsetof(struct ocfs2_dinode, id2.i_list.l_recs) -
1265 xattrsize;
1266 else
1267 size = sb->s_blocksize -
1268 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1269
1270 return size / sizeof(struct ocfs2_extent_rec);
1271}
1272
Mark Fasheh9b7895e2008-11-12 16:27:44 -08001273static inline int ocfs2_extent_recs_per_dx_root(struct super_block *sb)
1274{
1275 int size;
1276
1277 size = sb->s_blocksize -
1278 offsetof(struct ocfs2_dx_root_block, dr_list.l_recs);
1279
1280 return size / sizeof(struct ocfs2_extent_rec);
1281}
1282
Mark Fashehccd979b2005-12-15 14:31:24 -08001283static inline int ocfs2_chain_recs_per_inode(struct super_block *sb)
1284{
1285 int size;
1286
1287 size = sb->s_blocksize -
1288 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
1289
1290 return size / sizeof(struct ocfs2_chain_rec);
1291}
1292
1293static inline u16 ocfs2_extent_recs_per_eb(struct super_block *sb)
1294{
1295 int size;
1296
1297 size = sb->s_blocksize -
1298 offsetof(struct ocfs2_extent_block, h_list.l_recs);
1299
1300 return size / sizeof(struct ocfs2_extent_rec);
1301}
1302
Mark Fasheh9b7895e2008-11-12 16:27:44 -08001303static inline int ocfs2_dx_entries_per_leaf(struct super_block *sb)
1304{
1305 int size;
1306
1307 size = sb->s_blocksize -
1308 offsetof(struct ocfs2_dx_leaf, dl_list.de_entries);
1309
1310 return size / sizeof(struct ocfs2_dx_entry);
1311}
1312
Mark Fasheh4ed8a6b2008-11-24 17:02:08 -08001313static inline int ocfs2_dx_entries_per_root(struct super_block *sb)
1314{
1315 int size;
1316
1317 size = sb->s_blocksize -
1318 offsetof(struct ocfs2_dx_root_block, dr_entries.de_entries);
1319
1320 return size / sizeof(struct ocfs2_dx_entry);
1321}
1322
Mark Fashehccd979b2005-12-15 14:31:24 -08001323static inline u16 ocfs2_local_alloc_size(struct super_block *sb)
1324{
1325 u16 size;
1326
1327 size = sb->s_blocksize -
1328 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
1329
1330 return size;
1331}
1332
1333static inline int ocfs2_group_bitmap_size(struct super_block *sb)
1334{
1335 int size;
1336
1337 size = sb->s_blocksize -
1338 offsetof(struct ocfs2_group_desc, bg_bitmap);
1339
1340 return size;
1341}
1342
1343static inline int ocfs2_truncate_recs_per_inode(struct super_block *sb)
1344{
1345 int size;
1346
1347 size = sb->s_blocksize -
1348 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
1349
1350 return size / sizeof(struct ocfs2_truncate_rec);
1351}
Mark Fasheh50af94b2007-01-21 14:44:59 -08001352
1353static inline u64 ocfs2_backup_super_blkno(struct super_block *sb, int index)
1354{
1355 u64 offset = OCFS2_BACKUP_SB_START;
1356
1357 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
1358 offset <<= (2 * index);
Mark Fasheha8a75a22007-01-26 10:46:59 -08001359 offset >>= sb->s_blocksize_bits;
Mark Fasheh50af94b2007-01-21 14:44:59 -08001360 return offset;
1361 }
1362
1363 return 0;
1364
1365}
Tao Ma0c044f02008-08-18 17:38:50 +08001366
1367static inline u16 ocfs2_xattr_recs_per_xb(struct super_block *sb)
1368{
1369 int size;
1370
1371 size = sb->s_blocksize -
1372 offsetof(struct ocfs2_xattr_block,
1373 xb_attrs.xb_root.xt_list.l_recs);
1374
1375 return size / sizeof(struct ocfs2_extent_rec);
1376}
Tao Ma721f69c2009-08-18 11:17:49 +08001377
1378static inline u16 ocfs2_extent_recs_per_rb(struct super_block *sb)
1379{
1380 int size;
1381
1382 size = sb->s_blocksize -
1383 offsetof(struct ocfs2_refcount_block, rf_list.l_recs);
1384
1385 return size / sizeof(struct ocfs2_extent_rec);
1386}
1387
1388static inline u16 ocfs2_refcount_recs_per_rb(struct super_block *sb)
1389{
1390 int size;
1391
1392 size = sb->s_blocksize -
1393 offsetof(struct ocfs2_refcount_block, rf_records.rl_recs);
1394
1395 return size / sizeof(struct ocfs2_refcount_rec);
1396}
Mark Fashehccd979b2005-12-15 14:31:24 -08001397#else
1398static inline int ocfs2_fast_symlink_chars(int blocksize)
1399{
1400 return blocksize - offsetof(struct ocfs2_dinode, id2.i_symlink);
1401}
1402
Mark Fasheh15b1e362007-09-07 13:58:15 -07001403static inline int ocfs2_max_inline_data(int blocksize)
1404{
1405 return blocksize - offsetof(struct ocfs2_dinode, id2.i_data.id_data);
1406}
1407
Mark Fashehccd979b2005-12-15 14:31:24 -08001408static inline int ocfs2_extent_recs_per_inode(int blocksize)
1409{
1410 int size;
1411
1412 size = blocksize -
1413 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1414
1415 return size / sizeof(struct ocfs2_extent_rec);
1416}
1417
1418static inline int ocfs2_chain_recs_per_inode(int blocksize)
1419{
1420 int size;
1421
1422 size = blocksize -
1423 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
1424
1425 return size / sizeof(struct ocfs2_chain_rec);
1426}
1427
1428static inline int ocfs2_extent_recs_per_eb(int blocksize)
1429{
1430 int size;
1431
1432 size = blocksize -
1433 offsetof(struct ocfs2_extent_block, h_list.l_recs);
1434
1435 return size / sizeof(struct ocfs2_extent_rec);
1436}
1437
1438static inline int ocfs2_local_alloc_size(int blocksize)
1439{
1440 int size;
1441
1442 size = blocksize -
1443 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
1444
1445 return size;
1446}
1447
1448static inline int ocfs2_group_bitmap_size(int blocksize)
1449{
1450 int size;
1451
1452 size = blocksize -
1453 offsetof(struct ocfs2_group_desc, bg_bitmap);
1454
1455 return size;
1456}
1457
1458static inline int ocfs2_truncate_recs_per_inode(int blocksize)
1459{
1460 int size;
1461
1462 size = blocksize -
1463 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
1464
1465 return size / sizeof(struct ocfs2_truncate_rec);
1466}
Mark Fasheh50af94b2007-01-21 14:44:59 -08001467
1468static inline uint64_t ocfs2_backup_super_blkno(int blocksize, int index)
1469{
1470 uint64_t offset = OCFS2_BACKUP_SB_START;
1471
1472 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
1473 offset <<= (2 * index);
1474 offset /= blocksize;
1475 return offset;
1476 }
1477
1478 return 0;
1479}
Tao Ma0c044f02008-08-18 17:38:50 +08001480
1481static inline int ocfs2_xattr_recs_per_xb(int blocksize)
1482{
1483 int size;
1484
1485 size = blocksize -
1486 offsetof(struct ocfs2_xattr_block,
1487 xb_attrs.xb_root.xt_list.l_recs);
1488
1489 return size / sizeof(struct ocfs2_extent_rec);
1490}
Mark Fashehccd979b2005-12-15 14:31:24 -08001491#endif /* __KERNEL__ */
1492
1493
1494static inline int ocfs2_system_inode_is_global(int type)
1495{
1496 return ((type >= 0) &&
1497 (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE));
1498}
1499
1500static inline int ocfs2_sprintf_system_inode_name(char *buf, int len,
1501 int type, int slot)
1502{
1503 int chars;
1504
1505 /*
1506 * Global system inodes can only have one copy. Everything
1507 * after OCFS2_LAST_GLOBAL_SYSTEM_INODE in the system inode
1508 * list has a copy per slot.
1509 */
1510 if (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE)
Joel Beckerfe9f3872008-06-12 22:39:18 -07001511 chars = snprintf(buf, len, "%s",
Mark Fashehccd979b2005-12-15 14:31:24 -08001512 ocfs2_system_inodes[type].si_name);
1513 else
1514 chars = snprintf(buf, len,
1515 ocfs2_system_inodes[type].si_name,
1516 slot);
1517
1518 return chars;
1519}
1520
1521static inline void ocfs2_set_de_type(struct ocfs2_dir_entry *de,
1522 umode_t mode)
1523{
1524 de->file_type = ocfs2_type_by_mode[(mode & S_IFMT)>>S_SHIFT];
1525}
1526
1527#endif /* _OCFS2_FS_H */
1528