blob: d5b1d99abc3c574da39c54fac40ed4463f19efed [file] [log] [blame]
Mark Fashehccd979b2005-12-15 14:31:24 -08001/* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
3 *
4 * ocfs2_fs.h
5 *
6 * On-disk structures for OCFS2.
7 *
8 * Copyright (C) 2002, 2004 Oracle. All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public
12 * License, version 2, as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public
20 * License along with this program; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 021110-1307, USA.
23 */
24
25#ifndef _OCFS2_FS_H
26#define _OCFS2_FS_H
27
28/* Version */
29#define OCFS2_MAJOR_REV_LEVEL 0
30#define OCFS2_MINOR_REV_LEVEL 90
31
32/*
33 * An OCFS2 volume starts this way:
34 * Sector 0: Valid ocfs1_vol_disk_hdr that cleanly fails to mount OCFS.
35 * Sector 1: Valid ocfs1_vol_label that cleanly fails to mount OCFS.
36 * Block OCFS2_SUPER_BLOCK_BLKNO: OCFS2 superblock.
37 *
38 * All other structures are found from the superblock information.
39 *
40 * OCFS2_SUPER_BLOCK_BLKNO is in blocks, not sectors. eg, for a
41 * blocksize of 2K, it is 4096 bytes into disk.
42 */
43#define OCFS2_SUPER_BLOCK_BLKNO 2
44
45/*
46 * Cluster size limits. The maximum is kept arbitrarily at 1 MB, and could
47 * grow if needed.
48 */
49#define OCFS2_MIN_CLUSTERSIZE 4096
50#define OCFS2_MAX_CLUSTERSIZE 1048576
51
52/*
53 * Blocks cannot be bigger than clusters, so the maximum blocksize is the
54 * minimum cluster size.
55 */
56#define OCFS2_MIN_BLOCKSIZE 512
57#define OCFS2_MAX_BLOCKSIZE OCFS2_MIN_CLUSTERSIZE
58
59/* Filesystem magic number */
60#define OCFS2_SUPER_MAGIC 0x7461636f
61
62/* Object signatures */
63#define OCFS2_SUPER_BLOCK_SIGNATURE "OCFSV2"
64#define OCFS2_INODE_SIGNATURE "INODE01"
65#define OCFS2_EXTENT_BLOCK_SIGNATURE "EXBLK01"
66#define OCFS2_GROUP_DESC_SIGNATURE "GROUP01"
Tao Ma5a7bc8e2008-08-18 17:38:46 +080067#define OCFS2_XATTR_BLOCK_SIGNATURE "XATTR01"
Mark Fasheh87d35a72008-12-10 17:36:25 -080068#define OCFS2_DIR_TRAILER_SIGNATURE "DIRTRL1"
Mark Fasheh9b7895e2008-11-12 16:27:44 -080069#define OCFS2_DX_ROOT_SIGNATURE "DXDIR01"
70#define OCFS2_DX_LEAF_SIGNATURE "DXLEAF1"
Tao Ma721f69c2009-08-18 11:17:49 +080071#define OCFS2_REFCOUNT_BLOCK_SIGNATURE "REFCNT1"
Mark Fashehccd979b2005-12-15 14:31:24 -080072
73/* Compatibility flags */
74#define OCFS2_HAS_COMPAT_FEATURE(sb,mask) \
75 ( OCFS2_SB(sb)->s_feature_compat & (mask) )
76#define OCFS2_HAS_RO_COMPAT_FEATURE(sb,mask) \
77 ( OCFS2_SB(sb)->s_feature_ro_compat & (mask) )
78#define OCFS2_HAS_INCOMPAT_FEATURE(sb,mask) \
79 ( OCFS2_SB(sb)->s_feature_incompat & (mask) )
80#define OCFS2_SET_COMPAT_FEATURE(sb,mask) \
81 OCFS2_SB(sb)->s_feature_compat |= (mask)
82#define OCFS2_SET_RO_COMPAT_FEATURE(sb,mask) \
83 OCFS2_SB(sb)->s_feature_ro_compat |= (mask)
84#define OCFS2_SET_INCOMPAT_FEATURE(sb,mask) \
85 OCFS2_SB(sb)->s_feature_incompat |= (mask)
86#define OCFS2_CLEAR_COMPAT_FEATURE(sb,mask) \
87 OCFS2_SB(sb)->s_feature_compat &= ~(mask)
88#define OCFS2_CLEAR_RO_COMPAT_FEATURE(sb,mask) \
89 OCFS2_SB(sb)->s_feature_ro_compat &= ~(mask)
90#define OCFS2_CLEAR_INCOMPAT_FEATURE(sb,mask) \
91 OCFS2_SB(sb)->s_feature_incompat &= ~(mask)
92
Joel Beckera9772182008-12-16 18:10:18 -080093#define OCFS2_FEATURE_COMPAT_SUPP (OCFS2_FEATURE_COMPAT_BACKUP_SB \
94 | OCFS2_FEATURE_COMPAT_JBD2_SB)
Mark Fashehdcd05382007-01-16 11:32:23 -080095#define OCFS2_FEATURE_INCOMPAT_SUPP (OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT \
Mark Fasheh15b1e362007-09-07 13:58:15 -070096 | OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC \
Joel Becker386a2ef2008-02-01 12:06:54 -080097 | OCFS2_FEATURE_INCOMPAT_INLINE_DATA \
Joel Beckerb61817e2008-02-01 15:08:23 -080098 | OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP \
Tiger Yang8154da32008-08-18 17:11:46 +080099 | OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK \
Joel Becker9d28cfb2008-10-16 17:53:29 -0700100 | OCFS2_FEATURE_INCOMPAT_XATTR \
Mark Fasheh3a8df2b2008-11-24 17:14:09 -0800101 | OCFS2_FEATURE_INCOMPAT_META_ECC \
Tao Ma64871b82009-08-18 11:48:02 +0800102 | OCFS2_FEATURE_INCOMPAT_INDEXED_DIRS \
Tao Ma1a934c32010-03-18 15:54:22 +0800103 | OCFS2_FEATURE_INCOMPAT_REFCOUNT_TREE \
Sunil Mushran98f486f22010-10-09 10:24:46 -0700104 | OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG \
105 | OCFS2_FEATURE_INCOMPAT_CLUSTERINFO)
Jan Kara19ece542008-08-21 20:13:17 +0200106#define OCFS2_FEATURE_RO_COMPAT_SUPP (OCFS2_FEATURE_RO_COMPAT_UNWRITTEN \
107 | OCFS2_FEATURE_RO_COMPAT_USRQUOTA \
108 | OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)
Mark Fashehccd979b2005-12-15 14:31:24 -0800109
110/*
111 * Heartbeat-only devices are missing journals and other files. The
112 * filesystem driver can't load them, but the library can. Never put
113 * this in OCFS2_FEATURE_INCOMPAT_SUPP, *ever*.
114 */
115#define OCFS2_FEATURE_INCOMPAT_HEARTBEAT_DEV 0x0002
116
Mark Fasheh89039012006-12-07 18:05:37 -0800117/*
118 * tunefs sets this incompat flag before starting the resize and clears it
119 * at the end. This flag protects users from inadvertently mounting the fs
120 * after an aborted run without fsck-ing.
121 */
122#define OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG 0x0004
Mark Fashehccd979b2005-12-15 14:31:24 -0800123
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800124/* Used to denote a non-clustered volume */
125#define OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT 0x0008
126
Mark Fasheh89039012006-12-07 18:05:37 -0800127/* Support for sparse allocation in b-trees */
128#define OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC 0x0010
129
Mark Fashehccd979b2005-12-15 14:31:24 -0800130/*
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700131 * Tunefs sets this incompat flag before starting an operation which
132 * would require cleanup on abort. This is done to protect users from
133 * inadvertently mounting the fs after an aborted run without
134 * fsck-ing.
135 *
136 * s_tunefs_flags on the super block describes precisely which
137 * operations were in progress.
138 */
139#define OCFS2_FEATURE_INCOMPAT_TUNEFS_INPROG 0x0020
140
Mark Fasheh15b1e362007-09-07 13:58:15 -0700141/* Support for data packed into inode blocks */
142#define OCFS2_FEATURE_INCOMPAT_INLINE_DATA 0x0040
143
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700144/*
Joel Beckerb61817e2008-02-01 15:08:23 -0800145 * Support for alternate, userspace cluster stacks. If set, the superblock
146 * field s_cluster_info contains a tag for the alternate stack in use as
147 * well as the name of the cluster being joined.
148 * mount.ocfs2 must pass in a matching stack name.
149 *
150 * If not set, the classic stack will be used. This is compatbile with
151 * all older versions.
152 */
153#define OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK 0x0080
154
Tiger Yang8154da32008-08-18 17:11:46 +0800155/* Support for the extended slot map */
156#define OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP 0x100
157
158/* Support for extended attributes */
159#define OCFS2_FEATURE_INCOMPAT_XATTR 0x0200
160
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800161/* Support for indexed directores */
162#define OCFS2_FEATURE_INCOMPAT_INDEXED_DIRS 0x0400
163
Joel Beckerab552d52008-10-16 17:50:30 -0700164/* Metadata checksum and error correction */
165#define OCFS2_FEATURE_INCOMPAT_META_ECC 0x0800
166
Tao Ma721f69c2009-08-18 11:17:49 +0800167/* Refcount tree support */
168#define OCFS2_FEATURE_INCOMPAT_REFCOUNT_TREE 0x1000
169
Joel Becker4cbe4242010-04-13 14:26:12 +0800170/* Discontigous block groups */
171#define OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG 0x2000
172
Joel Beckerb61817e2008-02-01 15:08:23 -0800173/*
Sunil Mushran98f486f22010-10-09 10:24:46 -0700174 * Incompat bit to indicate useable clusterinfo with stackflags for all
175 * cluster stacks (userspace adnd o2cb). If this bit is set,
176 * INCOMPAT_USERSPACE_STACK becomes superfluous and thus should not be set.
177 */
178#define OCFS2_FEATURE_INCOMPAT_CLUSTERINFO 0x4000
179
180/*
Mark Fasheh50af94b2007-01-21 14:44:59 -0800181 * backup superblock flag is used to indicate that this volume
182 * has backup superblocks.
183 */
184#define OCFS2_FEATURE_COMPAT_BACKUP_SB 0x0001
185
Mark Fasheh328d5752007-06-18 10:48:04 -0700186/*
Joel Beckera9772182008-12-16 18:10:18 -0800187 * The filesystem will correctly handle journal feature bits.
188 */
189#define OCFS2_FEATURE_COMPAT_JBD2_SB 0x0002
190
191/*
Mark Fasheh328d5752007-06-18 10:48:04 -0700192 * Unwritten extents support.
193 */
194#define OCFS2_FEATURE_RO_COMPAT_UNWRITTEN 0x0001
195
Jan Kara1a224ad2008-08-20 15:43:36 +0200196/*
197 * Maintain quota information for this filesystem
198 */
199#define OCFS2_FEATURE_RO_COMPAT_USRQUOTA 0x0002
200#define OCFS2_FEATURE_RO_COMPAT_GRPQUOTA 0x0004
201
Mark Fasheh50af94b2007-01-21 14:44:59 -0800202/* The byte offset of the first backup block will be 1G.
203 * The following will be 4G, 16G, 64G, 256G and 1T.
204 */
205#define OCFS2_BACKUP_SB_START 1 << 30
206
207/* the max backup superblock nums */
208#define OCFS2_MAX_BACKUP_SUPERBLOCKS 6
209
210/*
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700211 * Flags on ocfs2_super_block.s_tunefs_flags
212 */
213#define OCFS2_TUNEFS_INPROG_REMOVE_SLOT 0x0001 /* Removing slots */
214
215/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800216 * Flags on ocfs2_dinode.i_flags
217 */
218#define OCFS2_VALID_FL (0x00000001) /* Inode is valid */
219#define OCFS2_UNUSED2_FL (0x00000002)
220#define OCFS2_ORPHANED_FL (0x00000004) /* On the orphan list */
221#define OCFS2_UNUSED3_FL (0x00000008)
222/* System inode flags */
223#define OCFS2_SYSTEM_FL (0x00000010) /* System inode */
224#define OCFS2_SUPER_BLOCK_FL (0x00000020) /* Super block */
225#define OCFS2_LOCAL_ALLOC_FL (0x00000040) /* Slot local alloc bitmap */
226#define OCFS2_BITMAP_FL (0x00000080) /* Allocation bitmap */
227#define OCFS2_JOURNAL_FL (0x00000100) /* Slot local journal */
228#define OCFS2_HEARTBEAT_FL (0x00000200) /* Heartbeat area */
229#define OCFS2_CHAIN_FL (0x00000400) /* Chain allocator */
230#define OCFS2_DEALLOC_FL (0x00000800) /* Truncate log */
Jan Kara1a224ad2008-08-20 15:43:36 +0200231#define OCFS2_QUOTA_FL (0x00001000) /* Quota file */
Mark Fashehccd979b2005-12-15 14:31:24 -0800232
Mark Fasheh15b1e362007-09-07 13:58:15 -0700233/*
234 * Flags on ocfs2_dinode.i_dyn_features
235 *
236 * These can change much more often than i_flags. When adding flags,
237 * keep in mind that i_dyn_features is only 16 bits wide.
238 */
239#define OCFS2_INLINE_DATA_FL (0x0001) /* Data stored in inode block */
240#define OCFS2_HAS_XATTR_FL (0x0002)
241#define OCFS2_INLINE_XATTR_FL (0x0004)
242#define OCFS2_INDEXED_DIR_FL (0x0008)
Tao Ma721f69c2009-08-18 11:17:49 +0800243#define OCFS2_HAS_REFCOUNT_FL (0x0010)
Mark Fasheh15b1e362007-09-07 13:58:15 -0700244
Herbert Poetzlca4d1472006-07-03 17:27:12 -0700245/* Inode attributes, keep in sync with EXT2 */
Tao Ma0000b862010-09-19 13:42:29 +0800246#define OCFS2_SECRM_FL FS_SECRM_FL /* Secure deletion */
247#define OCFS2_UNRM_FL FS_UNRM_FL /* Undelete */
248#define OCFS2_COMPR_FL FS_COMPR_FL /* Compress file */
249#define OCFS2_SYNC_FL FS_SYNC_FL /* Synchronous updates */
250#define OCFS2_IMMUTABLE_FL FS_IMMUTABLE_FL /* Immutable file */
251#define OCFS2_APPEND_FL FS_APPEND_FL /* writes to file may only append */
252#define OCFS2_NODUMP_FL FS_NODUMP_FL /* do not dump file */
253#define OCFS2_NOATIME_FL FS_NOATIME_FL /* do not update atime */
254/* Reserved for compression usage... */
255#define OCFS2_DIRTY_FL FS_DIRTY_FL
256#define OCFS2_COMPRBLK_FL FS_COMPRBLK_FL /* One or more compressed clusters */
257#define OCFS2_NOCOMP_FL FS_NOCOMP_FL /* Don't compress */
258#define OCFS2_ECOMPR_FL FS_ECOMPR_FL /* Compression error */
259/* End compression flags --- maybe not all used */
260#define OCFS2_BTREE_FL FS_BTREE_FL /* btree format dir */
261#define OCFS2_INDEX_FL FS_INDEX_FL /* hash-indexed directory */
262#define OCFS2_IMAGIC_FL FS_IMAGIC_FL /* AFS directory */
263#define OCFS2_JOURNAL_DATA_FL FS_JOURNAL_DATA_FL /* Reserved for ext3 */
264#define OCFS2_NOTAIL_FL FS_NOTAIL_FL /* file tail should not be merged */
265#define OCFS2_DIRSYNC_FL FS_DIRSYNC_FL /* dirsync behaviour (directories only) */
266#define OCFS2_TOPDIR_FL FS_TOPDIR_FL /* Top of directory hierarchies*/
267#define OCFS2_RESERVED_FL FS_RESERVED_FL /* reserved for ext2 lib */
Herbert Poetzlca4d1472006-07-03 17:27:12 -0700268
Tao Ma0000b862010-09-19 13:42:29 +0800269#define OCFS2_FL_VISIBLE FS_FL_USER_VISIBLE /* User visible flags */
270#define OCFS2_FL_MODIFIABLE FS_FL_USER_MODIFIABLE /* User modifiable flags */
Herbert Poetzlca4d1472006-07-03 17:27:12 -0700271
272/*
Mark Fashehe48edee2007-03-07 16:46:57 -0800273 * Extent record flags (e_node.leaf.flags)
274 */
Tao Ma721f69c2009-08-18 11:17:49 +0800275#define OCFS2_EXT_UNWRITTEN (0x01) /* Extent is allocated but
276 * unwritten */
277#define OCFS2_EXT_REFCOUNTED (0x02) /* Extent is reference
278 * counted in an associated
279 * refcount tree */
Mark Fashehe48edee2007-03-07 16:46:57 -0800280
281/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800282 * Journal Flags (ocfs2_dinode.id1.journal1.i_flags)
283 */
284#define OCFS2_JOURNAL_DIRTY_FL (0x00000001) /* Journal needs recovery */
285
286/*
287 * superblock s_state flags
288 */
289#define OCFS2_ERROR_FS (0x00000001) /* FS saw errors */
290
291/* Limit of space in ocfs2_dir_entry */
292#define OCFS2_MAX_FILENAME_LEN 255
293
294/* Maximum slots on an ocfs2 file system */
295#define OCFS2_MAX_SLOTS 255
296
297/* Slot map indicator for an empty slot */
298#define OCFS2_INVALID_SLOT -1
299
300#define OCFS2_VOL_UUID_LEN 16
301#define OCFS2_MAX_VOL_LABEL_LEN 64
302
Sunil Mushran98f486f22010-10-09 10:24:46 -0700303/* The cluster stack fields */
Joel Beckerb61817e2008-02-01 15:08:23 -0800304#define OCFS2_STACK_LABEL_LEN 4
305#define OCFS2_CLUSTER_NAME_LEN 16
306
Sunil Mushran98f486f22010-10-09 10:24:46 -0700307/* Classic (historically speaking) cluster stack */
308#define OCFS2_CLASSIC_CLUSTER_STACK "o2cb"
309
Mark Fashehccd979b2005-12-15 14:31:24 -0800310/* Journal limits (in bytes) */
311#define OCFS2_MIN_JOURNAL_SIZE (4 * 1024 * 1024)
Mark Fashehccd979b2005-12-15 14:31:24 -0800312
Sunil Mushran2fbe8d12007-12-20 14:58:11 -0800313/*
Tiger Yangfdd77702008-08-18 17:08:55 +0800314 * Inline extended attribute size (in bytes)
315 * The value chosen should be aligned to 16 byte boundaries.
316 */
317#define OCFS2_MIN_XATTR_INLINE_SIZE 256
318
Sunil Mushran98f486f22010-10-09 10:24:46 -0700319/*
320 * Cluster info flags (ocfs2_cluster_info.ci_stackflags)
321 */
322#define OCFS2_CLUSTER_O2CB_GLOBAL_HEARTBEAT (0x01)
323
Mark Fashehccd979b2005-12-15 14:31:24 -0800324struct ocfs2_system_inode_info {
325 char *si_name;
326 int si_iflags;
327 int si_mode;
328};
329
330/* System file index */
331enum {
332 BAD_BLOCK_SYSTEM_INODE = 0,
333 GLOBAL_INODE_ALLOC_SYSTEM_INODE,
334 SLOT_MAP_SYSTEM_INODE,
335#define OCFS2_FIRST_ONLINE_SYSTEM_INODE SLOT_MAP_SYSTEM_INODE
336 HEARTBEAT_SYSTEM_INODE,
337 GLOBAL_BITMAP_SYSTEM_INODE,
Jan Kara1a224ad2008-08-20 15:43:36 +0200338 USER_QUOTA_SYSTEM_INODE,
339 GROUP_QUOTA_SYSTEM_INODE,
340#define OCFS2_LAST_GLOBAL_SYSTEM_INODE GROUP_QUOTA_SYSTEM_INODE
Mark Fashehccd979b2005-12-15 14:31:24 -0800341 ORPHAN_DIR_SYSTEM_INODE,
342 EXTENT_ALLOC_SYSTEM_INODE,
343 INODE_ALLOC_SYSTEM_INODE,
344 JOURNAL_SYSTEM_INODE,
345 LOCAL_ALLOC_SYSTEM_INODE,
346 TRUNCATE_LOG_SYSTEM_INODE,
Jan Kara1a224ad2008-08-20 15:43:36 +0200347 LOCAL_USER_QUOTA_SYSTEM_INODE,
348 LOCAL_GROUP_QUOTA_SYSTEM_INODE,
Mark Fashehccd979b2005-12-15 14:31:24 -0800349 NUM_SYSTEM_INODES
350};
351
352static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = {
353 /* Global system inodes (single copy) */
354 /* The first two are only used from userspace mfks/tunefs */
355 [BAD_BLOCK_SYSTEM_INODE] = { "bad_blocks", 0, S_IFREG | 0644 },
356 [GLOBAL_INODE_ALLOC_SYSTEM_INODE] = { "global_inode_alloc", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
357
358 /* These are used by the running filesystem */
359 [SLOT_MAP_SYSTEM_INODE] = { "slot_map", 0, S_IFREG | 0644 },
360 [HEARTBEAT_SYSTEM_INODE] = { "heartbeat", OCFS2_HEARTBEAT_FL, S_IFREG | 0644 },
361 [GLOBAL_BITMAP_SYSTEM_INODE] = { "global_bitmap", 0, S_IFREG | 0644 },
Jan Kara1a224ad2008-08-20 15:43:36 +0200362 [USER_QUOTA_SYSTEM_INODE] = { "aquota.user", OCFS2_QUOTA_FL, S_IFREG | 0644 },
363 [GROUP_QUOTA_SYSTEM_INODE] = { "aquota.group", OCFS2_QUOTA_FL, S_IFREG | 0644 },
Mark Fashehccd979b2005-12-15 14:31:24 -0800364
365 /* Slot-specific system inodes (one copy per slot) */
366 [ORPHAN_DIR_SYSTEM_INODE] = { "orphan_dir:%04d", 0, S_IFDIR | 0755 },
367 [EXTENT_ALLOC_SYSTEM_INODE] = { "extent_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
368 [INODE_ALLOC_SYSTEM_INODE] = { "inode_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
369 [JOURNAL_SYSTEM_INODE] = { "journal:%04d", OCFS2_JOURNAL_FL, S_IFREG | 0644 },
370 [LOCAL_ALLOC_SYSTEM_INODE] = { "local_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_LOCAL_ALLOC_FL, S_IFREG | 0644 },
Jan Kara1a224ad2008-08-20 15:43:36 +0200371 [TRUNCATE_LOG_SYSTEM_INODE] = { "truncate_log:%04d", OCFS2_DEALLOC_FL, S_IFREG | 0644 },
372 [LOCAL_USER_QUOTA_SYSTEM_INODE] = { "aquota.user:%04d", OCFS2_QUOTA_FL, S_IFREG | 0644 },
373 [LOCAL_GROUP_QUOTA_SYSTEM_INODE] = { "aquota.group:%04d", OCFS2_QUOTA_FL, S_IFREG | 0644 },
Mark Fashehccd979b2005-12-15 14:31:24 -0800374};
375
376/* Parameter passed from mount.ocfs2 to module */
377#define OCFS2_HB_NONE "heartbeat=none"
378#define OCFS2_HB_LOCAL "heartbeat=local"
379
380/*
381 * OCFS2 directory file types. Only the low 3 bits are used. The
382 * other bits are reserved for now.
383 */
384#define OCFS2_FT_UNKNOWN 0
385#define OCFS2_FT_REG_FILE 1
386#define OCFS2_FT_DIR 2
387#define OCFS2_FT_CHRDEV 3
388#define OCFS2_FT_BLKDEV 4
389#define OCFS2_FT_FIFO 5
390#define OCFS2_FT_SOCK 6
391#define OCFS2_FT_SYMLINK 7
392
393#define OCFS2_FT_MAX 8
394
395/*
396 * OCFS2_DIR_PAD defines the directory entries boundaries
397 *
398 * NOTE: It must be a multiple of 4
399 */
400#define OCFS2_DIR_PAD 4
401#define OCFS2_DIR_ROUND (OCFS2_DIR_PAD - 1)
402#define OCFS2_DIR_MEMBER_LEN offsetof(struct ocfs2_dir_entry, name)
403#define OCFS2_DIR_REC_LEN(name_len) (((name_len) + OCFS2_DIR_MEMBER_LEN + \
404 OCFS2_DIR_ROUND) & \
405 ~OCFS2_DIR_ROUND)
Mark Fashehe7c17e42009-01-29 18:17:46 -0800406#define OCFS2_DIR_MIN_REC_LEN OCFS2_DIR_REC_LEN(1)
Mark Fashehccd979b2005-12-15 14:31:24 -0800407
408#define OCFS2_LINK_MAX 32000
Mark Fasheh198a1ca2008-11-20 17:54:57 -0800409#define OCFS2_DX_LINK_MAX ((1U << 31) - 1U)
410#define OCFS2_LINKS_HI_SHIFT 16
Mark Fashehe3a93c22009-02-17 15:29:35 -0800411#define OCFS2_DX_ENTRIES_MAX (0xffffffffU)
Mark Fashehccd979b2005-12-15 14:31:24 -0800412
413#define S_SHIFT 12
414static unsigned char ocfs2_type_by_mode[S_IFMT >> S_SHIFT] = {
415 [S_IFREG >> S_SHIFT] = OCFS2_FT_REG_FILE,
416 [S_IFDIR >> S_SHIFT] = OCFS2_FT_DIR,
417 [S_IFCHR >> S_SHIFT] = OCFS2_FT_CHRDEV,
418 [S_IFBLK >> S_SHIFT] = OCFS2_FT_BLKDEV,
419 [S_IFIFO >> S_SHIFT] = OCFS2_FT_FIFO,
420 [S_IFSOCK >> S_SHIFT] = OCFS2_FT_SOCK,
421 [S_IFLNK >> S_SHIFT] = OCFS2_FT_SYMLINK,
422};
423
424
425/*
426 * Convenience casts
427 */
428#define OCFS2_RAW_SB(dinode) (&((dinode)->id2.i_super))
429
430/*
Joel Beckerab552d52008-10-16 17:50:30 -0700431 * Block checking structure. This is used in metadata to validate the
432 * contents. If OCFS2_FEATURE_INCOMPAT_META_ECC is not set, it is all
433 * zeros.
434 */
435struct ocfs2_block_check {
436/*00*/ __le32 bc_crc32e; /* 802.3 Ethernet II CRC32 */
437 __le16 bc_ecc; /* Single-error-correction parity vector.
438 This is a simple Hamming code dependant
439 on the blocksize. OCFS2's maximum
440 blocksize, 4K, requires 16 parity bits,
441 so we fit in __le16. */
442 __le16 bc_reserved1;
443/*08*/
444};
445
446/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800447 * On disk extent record for OCFS2
448 * It describes a range of clusters on disk.
Mark Fashehe48edee2007-03-07 16:46:57 -0800449 *
450 * Length fields are divided into interior and leaf node versions.
451 * This leaves room for a flags field (OCFS2_EXT_*) in the leaf nodes.
Mark Fashehccd979b2005-12-15 14:31:24 -0800452 */
453struct ocfs2_extent_rec {
454/*00*/ __le32 e_cpos; /* Offset into the file, in clusters */
Mark Fashehe48edee2007-03-07 16:46:57 -0800455 union {
456 __le32 e_int_clusters; /* Clusters covered by all children */
457 struct {
458 __le16 e_leaf_clusters; /* Clusters covered by this
459 extent */
460 __u8 e_reserved1;
461 __u8 e_flags; /* Extent flags */
462 };
463 };
Mark Fashehccd979b2005-12-15 14:31:24 -0800464 __le64 e_blkno; /* Physical disk offset, in blocks */
465/*10*/
466};
467
468struct ocfs2_chain_rec {
469 __le32 c_free; /* Number of free bits in this chain. */
470 __le32 c_total; /* Number of total bits in this chain */
471 __le64 c_blkno; /* Physical disk offset (blocks) of 1st group */
472};
473
474struct ocfs2_truncate_rec {
475 __le32 t_start; /* 1st cluster in this log */
476 __le32 t_clusters; /* Number of total clusters covered */
477};
478
479/*
480 * On disk extent list for OCFS2 (node in the tree). Note that this
481 * is contained inside ocfs2_dinode or ocfs2_extent_block, so the
482 * offsets are relative to ocfs2_dinode.id2.i_list or
483 * ocfs2_extent_block.h_list, respectively.
484 */
485struct ocfs2_extent_list {
486/*00*/ __le16 l_tree_depth; /* Extent tree depth from this
487 point. 0 means data extents
488 hang directly off this
Mark Fashehdcd05382007-01-16 11:32:23 -0800489 header (a leaf)
490 NOTE: The high 8 bits cannot be
491 used - tree_depth is never that big.
492 */
Mark Fashehccd979b2005-12-15 14:31:24 -0800493 __le16 l_count; /* Number of extent records */
494 __le16 l_next_free_rec; /* Next unused extent slot */
495 __le16 l_reserved1;
496 __le64 l_reserved2; /* Pad to
497 sizeof(ocfs2_extent_rec) */
498/*10*/ struct ocfs2_extent_rec l_recs[0]; /* Extent records */
499};
500
501/*
502 * On disk allocation chain list for OCFS2. Note that this is
503 * contained inside ocfs2_dinode, so the offsets are relative to
504 * ocfs2_dinode.id2.i_chain.
505 */
506struct ocfs2_chain_list {
507/*00*/ __le16 cl_cpg; /* Clusters per Block Group */
508 __le16 cl_bpc; /* Bits per cluster */
509 __le16 cl_count; /* Total chains in this list */
510 __le16 cl_next_free_rec; /* Next unused chain slot */
511 __le64 cl_reserved1;
512/*10*/ struct ocfs2_chain_rec cl_recs[0]; /* Chain records */
513};
514
515/*
516 * On disk deallocation log for OCFS2. Note that this is
517 * contained inside ocfs2_dinode, so the offsets are relative to
518 * ocfs2_dinode.id2.i_dealloc.
519 */
520struct ocfs2_truncate_log {
521/*00*/ __le16 tl_count; /* Total records in this log */
522 __le16 tl_used; /* Number of records in use */
523 __le32 tl_reserved1;
524/*08*/ struct ocfs2_truncate_rec tl_recs[0]; /* Truncate records */
525};
526
527/*
528 * On disk extent block (indirect block) for OCFS2
529 */
530struct ocfs2_extent_block
531{
532/*00*/ __u8 h_signature[8]; /* Signature for verification */
Joel Beckerab552d52008-10-16 17:50:30 -0700533 struct ocfs2_block_check h_check; /* Error checking */
Mark Fashehccd979b2005-12-15 14:31:24 -0800534/*10*/ __le16 h_suballoc_slot; /* Slot suballocator this
535 extent_header belongs to */
536 __le16 h_suballoc_bit; /* Bit offset in suballocator
537 block group */
538 __le32 h_fs_generation; /* Must match super block */
539 __le64 h_blkno; /* Offset on disk, in blocks */
Joel Becker9cbc0122010-03-26 10:07:42 +0800540/*20*/ __le64 h_suballoc_loc; /* Suballocator block group this
541 eb belongs to. Only valid
542 if allocated from a
543 discontiguous block group */
Mark Fashehccd979b2005-12-15 14:31:24 -0800544 __le64 h_next_leaf_blk; /* Offset on disk, in blocks,
545 of next leaf header pointing
546 to data */
547/*30*/ struct ocfs2_extent_list h_list; /* Extent record list */
548/* Actual on-disk size is one block */
549};
550
551/*
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800552 * On disk slot map for OCFS2. This defines the contents of the "slot_map"
Joel Becker386a2ef2008-02-01 12:06:54 -0800553 * system file. A slot is valid if it contains a node number >= 0. The
554 * value -1 (0xFFFF) is OCFS2_INVALID_SLOT. This marks a slot empty.
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800555 */
556struct ocfs2_slot_map {
557/*00*/ __le16 sm_slots[0];
558/*
559 * Actual on-disk size is one block. OCFS2_MAX_SLOTS is 255,
560 * 255 * sizeof(__le16) == 512B, within the 512B block minimum blocksize.
561 */
562};
563
Joel Becker386a2ef2008-02-01 12:06:54 -0800564struct ocfs2_extended_slot {
565/*00*/ __u8 es_valid;
566 __u8 es_reserved1[3];
567 __le32 es_node_num;
568/*10*/
569};
570
571/*
572 * The extended slot map, used when OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP
573 * is set. It separates out the valid marker from the node number, and
574 * has room to grow. Unlike the old slot map, this format is defined by
575 * i_size.
576 */
577struct ocfs2_slot_map_extended {
578/*00*/ struct ocfs2_extended_slot se_slots[0];
579/*
580 * Actual size is i_size of the slot_map system file. It should
581 * match s_max_slots * sizeof(struct ocfs2_extended_slot)
582 */
583};
584
Sunil Mushran98f486f22010-10-09 10:24:46 -0700585/*
586 * ci_stackflags is only valid if the incompat bit
587 * OCFS2_FEATURE_INCOMPAT_CLUSTERINFO is set.
588 */
Joel Beckerb61817e2008-02-01 15:08:23 -0800589struct ocfs2_cluster_info {
590/*00*/ __u8 ci_stack[OCFS2_STACK_LABEL_LEN];
Sunil Mushran98f486f22010-10-09 10:24:46 -0700591 union {
592 __le32 ci_reserved;
593 struct {
594 __u8 ci_stackflags;
595 __u8 ci_reserved1;
596 __u8 ci_reserved2;
597 __u8 ci_reserved3;
598 };
599 };
Joel Beckerb61817e2008-02-01 15:08:23 -0800600/*08*/ __u8 ci_cluster[OCFS2_CLUSTER_NAME_LEN];
601/*18*/
602};
603
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800604/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800605 * On disk superblock for OCFS2
606 * Note that it is contained inside an ocfs2_dinode, so all offsets
607 * are relative to the start of ocfs2_dinode.id2.
608 */
609struct ocfs2_super_block {
610/*00*/ __le16 s_major_rev_level;
611 __le16 s_minor_rev_level;
612 __le16 s_mnt_count;
613 __le16 s_max_mnt_count;
614 __le16 s_state; /* File system state */
615 __le16 s_errors; /* Behaviour when detecting errors */
616 __le32 s_checkinterval; /* Max time between checks */
617/*10*/ __le64 s_lastcheck; /* Time of last check */
618 __le32 s_creator_os; /* OS */
619 __le32 s_feature_compat; /* Compatible feature set */
620/*20*/ __le32 s_feature_incompat; /* Incompatible feature set */
621 __le32 s_feature_ro_compat; /* Readonly-compatible feature set */
622 __le64 s_root_blkno; /* Offset, in blocks, of root directory
623 dinode */
624/*30*/ __le64 s_system_dir_blkno; /* Offset, in blocks, of system
625 directory dinode */
626 __le32 s_blocksize_bits; /* Blocksize for this fs */
627 __le32 s_clustersize_bits; /* Clustersize for this fs */
628/*40*/ __le16 s_max_slots; /* Max number of simultaneous mounts
629 before tunefs required */
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700630 __le16 s_tunefs_flag;
Tiger Yangcf1d6c72008-08-18 17:11:00 +0800631 __le32 s_uuid_hash; /* hash value of uuid */
Mark Fashehccd979b2005-12-15 14:31:24 -0800632 __le64 s_first_cluster_group; /* Block offset of 1st cluster
633 * group header */
634/*50*/ __u8 s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */
635/*90*/ __u8 s_uuid[OCFS2_VOL_UUID_LEN]; /* 128-bit uuid */
Sunil Mushran98f486f22010-10-09 10:24:46 -0700636/*A0*/ struct ocfs2_cluster_info s_cluster_info; /* Only valid if either
637 userspace or clusterinfo
638 INCOMPAT flag set. */
Tiger Yang8154da32008-08-18 17:11:46 +0800639/*B8*/ __le16 s_xattr_inline_size; /* extended attribute inline size
640 for this fs*/
641 __le16 s_reserved0;
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800642 __le32 s_dx_seed[3]; /* seed[0-2] for dx dir hash.
643 * s_uuid_hash serves as seed[3]. */
644/*C0*/ __le64 s_reserved2[15]; /* Fill out superblock */
Joel Beckerb61817e2008-02-01 15:08:23 -0800645/*140*/
646
647 /*
648 * NOTE: As stated above, all offsets are relative to
649 * ocfs2_dinode.id2, which is at 0xC0 in the inode.
650 * 0xC0 + 0x140 = 0x200 or 512 bytes. A superblock must fit within
651 * our smallest blocksize, which is 512 bytes. To ensure this,
652 * we reserve the space in s_reserved2. Anything past s_reserved2
653 * will not be available on the smallest blocksize.
654 */
Mark Fashehccd979b2005-12-15 14:31:24 -0800655};
656
657/*
658 * Local allocation bitmap for OCFS2 slots
659 * Note that it exists inside an ocfs2_dinode, so all offsets are
660 * relative to the start of ocfs2_dinode.id2.
661 */
662struct ocfs2_local_alloc
663{
664/*00*/ __le32 la_bm_off; /* Starting bit offset in main bitmap */
665 __le16 la_size; /* Size of included bitmap, in bytes */
666 __le16 la_reserved1;
667 __le64 la_reserved2;
668/*10*/ __u8 la_bitmap[0];
669};
670
671/*
Mark Fasheh15b1e362007-09-07 13:58:15 -0700672 * Data-in-inode header. This is only used if i_dyn_features has
673 * OCFS2_INLINE_DATA_FL set.
674 */
675struct ocfs2_inline_data
676{
677/*00*/ __le16 id_count; /* Number of bytes that can be used
678 * for data, starting at id_data */
679 __le16 id_reserved0;
680 __le32 id_reserved1;
681 __u8 id_data[0]; /* Start of user data */
682};
683
684/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800685 * On disk inode for OCFS2
686 */
687struct ocfs2_dinode {
688/*00*/ __u8 i_signature[8]; /* Signature for validation */
689 __le32 i_generation; /* Generation number */
690 __le16 i_suballoc_slot; /* Slot suballocator this inode
691 belongs to */
692 __le16 i_suballoc_bit; /* Bit offset in suballocator
693 block group */
Mark Fasheh198a1ca2008-11-20 17:54:57 -0800694/*10*/ __le16 i_links_count_hi; /* High 16 bits of links count */
Tiger Yangfdd77702008-08-18 17:08:55 +0800695 __le16 i_xattr_inline_size;
Mark Fashehccd979b2005-12-15 14:31:24 -0800696 __le32 i_clusters; /* Cluster count */
697 __le32 i_uid; /* Owner UID */
698 __le32 i_gid; /* Owning GID */
699/*20*/ __le64 i_size; /* Size in bytes */
700 __le16 i_mode; /* File mode */
701 __le16 i_links_count; /* Links count */
702 __le32 i_flags; /* File flags */
703/*30*/ __le64 i_atime; /* Access time */
704 __le64 i_ctime; /* Creation time */
705/*40*/ __le64 i_mtime; /* Modification time */
706 __le64 i_dtime; /* Deletion time */
707/*50*/ __le64 i_blkno; /* Offset on disk, in blocks */
708 __le64 i_last_eb_blk; /* Pointer to last extent
709 block */
710/*60*/ __le32 i_fs_generation; /* Generation per fs-instance */
711 __le32 i_atime_nsec;
712 __le32 i_ctime_nsec;
713 __le32 i_mtime_nsec;
Tiger Yangfdd77702008-08-18 17:08:55 +0800714/*70*/ __le32 i_attr;
Tiger Yang50008632007-03-20 16:01:38 -0700715 __le16 i_orphaned_slot; /* Only valid when OCFS2_ORPHANED_FL
716 was set in i_flags */
Mark Fasheh15b1e362007-09-07 13:58:15 -0700717 __le16 i_dyn_features;
Tiger Yangfdd77702008-08-18 17:08:55 +0800718 __le64 i_xattr_loc;
Joel Beckerab552d52008-10-16 17:50:30 -0700719/*80*/ struct ocfs2_block_check i_check; /* Error checking */
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800720/*88*/ __le64 i_dx_root; /* Pointer to dir index root block */
Tao Ma721f69c2009-08-18 11:17:49 +0800721/*90*/ __le64 i_refcount_loc;
Joel Becker9cbc0122010-03-26 10:07:42 +0800722 __le64 i_suballoc_loc; /* Suballocator block group this
723 inode belongs to. Only valid
724 if allocated from a
725 discontiguous block group */
726/*A0*/ __le64 i_reserved2[3];
Mark Fashehccd979b2005-12-15 14:31:24 -0800727/*B8*/ union {
728 __le64 i_pad1; /* Generic way to refer to this
729 64bit union */
730 struct {
731 __le64 i_rdev; /* Device number */
732 } dev1;
733 struct { /* Info for bitmap system
734 inodes */
735 __le32 i_used; /* Bits (ie, clusters) used */
736 __le32 i_total; /* Total bits (clusters)
737 available */
738 } bitmap1;
739 struct { /* Info for journal system
740 inodes */
741 __le32 ij_flags; /* Mounted, version, etc. */
Sunil Mushranc69991a2008-07-14 17:31:09 -0700742 __le32 ij_recovery_generation; /* Incremented when the
743 journal is recovered
744 after an unclean
745 shutdown */
Mark Fashehccd979b2005-12-15 14:31:24 -0800746 } journal1;
747 } id1; /* Inode type dependant 1 */
748/*C0*/ union {
749 struct ocfs2_super_block i_super;
750 struct ocfs2_local_alloc i_lab;
751 struct ocfs2_chain_list i_chain;
752 struct ocfs2_extent_list i_list;
753 struct ocfs2_truncate_log i_dealloc;
Mark Fasheh15b1e362007-09-07 13:58:15 -0700754 struct ocfs2_inline_data i_data;
Mark Fashehccd979b2005-12-15 14:31:24 -0800755 __u8 i_symlink[0];
756 } id2;
757/* Actual on-disk size is one block */
758};
759
760/*
761 * On-disk directory entry structure for OCFS2
762 *
763 * Packed as this structure could be accessed unaligned on 64-bit platforms
764 */
765struct ocfs2_dir_entry {
766/*00*/ __le64 inode; /* Inode number */
767 __le16 rec_len; /* Directory entry length */
768 __u8 name_len; /* Name length */
769 __u8 file_type;
770/*0C*/ char name[OCFS2_MAX_FILENAME_LEN]; /* File name */
771/* Actual on-disk length specified by rec_len */
772} __attribute__ ((packed));
773
774/*
Mark Fasheh87d35a72008-12-10 17:36:25 -0800775 * Per-block record for the unindexed directory btree. This is carefully
776 * crafted so that the rec_len and name_len records of an ocfs2_dir_entry are
777 * mirrored. That way, the directory manipulation code needs a minimal amount
778 * of update.
779 *
780 * NOTE: Keep this structure aligned to a multiple of 4 bytes.
781 */
782struct ocfs2_dir_block_trailer {
783/*00*/ __le64 db_compat_inode; /* Always zero. Was inode */
784
785 __le16 db_compat_rec_len; /* Backwards compatible with
786 * ocfs2_dir_entry. */
787 __u8 db_compat_name_len; /* Always zero. Was name_len */
788 __u8 db_reserved0;
789 __le16 db_reserved1;
790 __le16 db_free_rec_len; /* Size of largest empty hole
791 * in this block. (unused) */
792/*10*/ __u8 db_signature[8]; /* Signature for verification */
793 __le64 db_reserved2;
794 __le64 db_free_next; /* Next block in list (unused) */
795/*20*/ __le64 db_blkno; /* Offset on disk, in blocks */
796 __le64 db_parent_dinode; /* dinode which owns me, in
797 blocks */
Joel Beckerc175a512008-12-10 17:58:22 -0800798/*30*/ struct ocfs2_block_check db_check; /* Error checking */
Mark Fasheh87d35a72008-12-10 17:36:25 -0800799/*40*/
800};
801
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800802 /*
803 * A directory entry in the indexed tree. We don't store the full name here,
804 * but instead provide a pointer to the full dirent in the unindexed tree.
805 *
806 * We also store name_len here so as to reduce the number of leaf blocks we
807 * need to search in case of collisions.
808 */
809struct ocfs2_dx_entry {
810 __le32 dx_major_hash; /* Used to find logical
811 * cluster in index */
812 __le32 dx_minor_hash; /* Lower bits used to find
813 * block in cluster */
814 __le64 dx_dirent_blk; /* Physical block in unindexed
815 * tree holding this dirent. */
816};
817
818struct ocfs2_dx_entry_list {
819 __le32 de_reserved;
820 __le16 de_count; /* Maximum number of entries
821 * possible in de_entries */
822 __le16 de_num_used; /* Current number of
823 * de_entries entries */
824 struct ocfs2_dx_entry de_entries[0]; /* Indexed dir entries
825 * in a packed array of
826 * length de_num_used */
827};
828
Mark Fasheh4ed8a6b2008-11-24 17:02:08 -0800829#define OCFS2_DX_FLAG_INLINE 0x01
830
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800831/*
832 * A directory indexing block. Each indexed directory has one of these,
833 * pointed to by ocfs2_dinode.
834 *
835 * This block stores an indexed btree root, and a set of free space
836 * start-of-list pointers.
837 */
838struct ocfs2_dx_root_block {
839 __u8 dr_signature[8]; /* Signature for verification */
840 struct ocfs2_block_check dr_check; /* Error checking */
841 __le16 dr_suballoc_slot; /* Slot suballocator this
842 * block belongs to. */
843 __le16 dr_suballoc_bit; /* Bit offset in suballocator
844 * block group */
845 __le32 dr_fs_generation; /* Must match super block */
846 __le64 dr_blkno; /* Offset on disk, in blocks */
847 __le64 dr_last_eb_blk; /* Pointer to last
848 * extent block */
849 __le32 dr_clusters; /* Clusters allocated
850 * to the indexed tree. */
Mark Fasheh4ed8a6b2008-11-24 17:02:08 -0800851 __u8 dr_flags; /* OCFS2_DX_FLAG_* flags */
852 __u8 dr_reserved0;
853 __le16 dr_reserved1;
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800854 __le64 dr_dir_blkno; /* Pointer to parent inode */
Mark Fashehe3a93c22009-02-17 15:29:35 -0800855 __le32 dr_num_entries; /* Total number of
856 * names stored in
857 * this directory.*/
858 __le32 dr_reserved2;
Mark Fashehe7c17e42009-01-29 18:17:46 -0800859 __le64 dr_free_blk; /* Pointer to head of free
860 * unindexed block list. */
Joel Becker9cbc0122010-03-26 10:07:42 +0800861 __le64 dr_suballoc_loc; /* Suballocator block group
862 this root belongs to.
863 Only valid if allocated
864 from a discontiguous
865 block group */
866 __le64 dr_reserved3[14];
Mark Fasheh4ed8a6b2008-11-24 17:02:08 -0800867 union {
868 struct ocfs2_extent_list dr_list; /* Keep this aligned to 128
869 * bits for maximum space
870 * efficiency. */
871 struct ocfs2_dx_entry_list dr_entries; /* In-root-block list of
872 * entries. We grow out
873 * to extents if this
874 * gets too big. */
875 };
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800876};
877
878/*
879 * The header of a leaf block in the indexed tree.
880 */
881struct ocfs2_dx_leaf {
882 __u8 dl_signature[8];/* Signature for verification */
883 struct ocfs2_block_check dl_check; /* Error checking */
884 __le64 dl_blkno; /* Offset on disk, in blocks */
885 __le32 dl_fs_generation;/* Must match super block */
886 __le32 dl_reserved0;
887 __le64 dl_reserved1;
888 struct ocfs2_dx_entry_list dl_list;
889};
890
Mark Fasheh87d35a72008-12-10 17:36:25 -0800891/*
Joel Becker4cbe4242010-04-13 14:26:12 +0800892 * Largest bitmap for a block (suballocator) group in bytes. This limit
893 * does not affect cluster groups (global allocator). Cluster group
894 * bitmaps run to the end of the block.
895 */
896#define OCFS2_MAX_BG_BITMAP_SIZE 256
897
898/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800899 * On disk allocator group structure for OCFS2
900 */
901struct ocfs2_group_desc
902{
903/*00*/ __u8 bg_signature[8]; /* Signature for validation */
904 __le16 bg_size; /* Size of included bitmap in
905 bytes. */
906 __le16 bg_bits; /* Bits represented by this
907 group. */
908 __le16 bg_free_bits_count; /* Free bits count */
909 __le16 bg_chain; /* What chain I am in. */
910/*10*/ __le32 bg_generation;
911 __le32 bg_reserved1;
912 __le64 bg_next_group; /* Next group in my list, in
913 blocks */
914/*20*/ __le64 bg_parent_dinode; /* dinode which owns me, in
915 blocks */
916 __le64 bg_blkno; /* Offset on disk, in blocks */
Joel Beckerab552d52008-10-16 17:50:30 -0700917/*30*/ struct ocfs2_block_check bg_check; /* Error checking */
918 __le64 bg_reserved2;
Joel Becker4cbe4242010-04-13 14:26:12 +0800919/*40*/ union {
920 __u8 bg_bitmap[0];
921 struct {
922 /*
923 * Block groups may be discontiguous when
924 * OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG is set.
925 * The extents of a discontigous block group are
926 * stored in bg_list. It is a flat list.
927 * l_tree_depth must always be zero. A
928 * discontiguous group is signified by a non-zero
929 * bg_list->l_next_free_rec. Only block groups
930 * can be discontiguous; Cluster groups cannot.
931 * We've never made a block group with more than
932 * 2048 blocks (256 bytes of bg_bitmap). This
933 * codifies that limit so that we can fit bg_list.
934 * bg_size of a discontiguous block group will
935 * be 256 to match bg_bitmap_filler.
936 */
937 __u8 bg_bitmap_filler[OCFS2_MAX_BG_BITMAP_SIZE];
938/*140*/ struct ocfs2_extent_list bg_list;
939 };
940 };
941/* Actual on-disk size is one block */
Mark Fashehccd979b2005-12-15 14:31:24 -0800942};
943
Tao Ma721f69c2009-08-18 11:17:49 +0800944struct ocfs2_refcount_rec {
945/*00*/ __le64 r_cpos; /* Physical offset, in clusters */
946 __le32 r_clusters; /* Clusters covered by this extent */
947 __le32 r_refcount; /* Reference count of this extent */
948/*10*/
949};
Tao Mae73a8192009-08-11 14:33:14 +0800950#define OCFS2_32BIT_POS_MASK (0xffffffffULL)
Tao Ma721f69c2009-08-18 11:17:49 +0800951
952#define OCFS2_REFCOUNT_LEAF_FL (0x00000001)
953#define OCFS2_REFCOUNT_TREE_FL (0x00000002)
954
955struct ocfs2_refcount_list {
956/*00*/ __le16 rl_count; /* Maximum number of entries possible
957 in rl_records */
958 __le16 rl_used; /* Current number of used records */
959 __le32 rl_reserved2;
960 __le64 rl_reserved1; /* Pad to sizeof(ocfs2_refcount_record) */
961/*10*/ struct ocfs2_refcount_rec rl_recs[0]; /* Refcount records */
962};
963
964
965struct ocfs2_refcount_block {
966/*00*/ __u8 rf_signature[8]; /* Signature for verification */
967 __le16 rf_suballoc_slot; /* Slot suballocator this block
968 belongs to */
969 __le16 rf_suballoc_bit; /* Bit offset in suballocator
970 block group */
971 __le32 rf_fs_generation; /* Must match superblock */
972/*10*/ __le64 rf_blkno; /* Offset on disk, in blocks */
973 __le64 rf_parent; /* Parent block, only valid if
974 OCFS2_REFCOUNT_LEAF_FL is set in
975 rf_flags */
976/*20*/ struct ocfs2_block_check rf_check; /* Error checking */
977 __le64 rf_last_eb_blk; /* Pointer to last extent block */
978/*30*/ __le32 rf_count; /* Number of inodes sharing this
979 refcount tree */
980 __le32 rf_flags; /* See the flags above */
981 __le32 rf_clusters; /* clusters covered by refcount tree. */
982 __le32 rf_cpos; /* cluster offset in refcount tree.*/
983/*40*/ __le32 rf_generation; /* generation number. all be the same
984 * for the same refcount tree. */
985 __le32 rf_reserved0;
Joel Becker9cbc0122010-03-26 10:07:42 +0800986 __le64 rf_suballoc_loc; /* Suballocator block group this
987 refcount block belongs to. Only
988 valid if allocated from a
989 discontiguous block group */
990/*50*/ __le64 rf_reserved1[6];
Tao Ma721f69c2009-08-18 11:17:49 +0800991/*80*/ union {
992 struct ocfs2_refcount_list rf_records; /* List of refcount
993 records */
994 struct ocfs2_extent_list rf_list; /* Extent record list,
995 only valid if
996 OCFS2_REFCOUNT_TREE_FL
997 is set in rf_flags */
998 };
999/* Actual on-disk size is one block */
1000};
1001
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001002/*
1003 * On disk extended attribute structure for OCFS2.
1004 */
1005
1006/*
1007 * ocfs2_xattr_entry indicates one extend attribute.
1008 *
1009 * Note that it can be stored in inode, one block or one xattr bucket.
1010 */
1011struct ocfs2_xattr_entry {
1012 __le32 xe_name_hash; /* hash value of xattr prefix+suffix. */
Tao Ma8573f792008-10-24 22:24:17 +08001013 __le16 xe_name_offset; /* byte offset from the 1st entry in the
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001014 local xattr storage(inode, xattr block or
1015 xattr bucket). */
1016 __u8 xe_name_len; /* xattr name len, does't include prefix. */
Tao Ma8573f792008-10-24 22:24:17 +08001017 __u8 xe_type; /* the low 7 bits indicate the name prefix
1018 * type and the highest bit indicates whether
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001019 * the EA is stored in the local storage. */
1020 __le64 xe_value_size; /* real xattr value length. */
1021};
1022
1023/*
1024 * On disk structure for xattr header.
1025 *
1026 * One ocfs2_xattr_header describes how many ocfs2_xattr_entry records in
1027 * the local xattr storage.
1028 */
1029struct ocfs2_xattr_header {
1030 __le16 xh_count; /* contains the count of how
1031 many records are in the
1032 local xattr storage. */
Tao Ma0c044f02008-08-18 17:38:50 +08001033 __le16 xh_free_start; /* current offset for storing
1034 xattr. */
1035 __le16 xh_name_value_len; /* total length of name/value
1036 length in this bucket. */
Tao Ma8573f792008-10-24 22:24:17 +08001037 __le16 xh_num_buckets; /* Number of xattr buckets
1038 in this extent record,
1039 only valid in the first
1040 bucket. */
Joel Beckerab552d52008-10-16 17:50:30 -07001041 struct ocfs2_block_check xh_check; /* Error checking
1042 (Note, this is only
1043 used for xattr
1044 buckets. A block uses
1045 xb_check and sets
1046 this field to zero.) */
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001047 struct ocfs2_xattr_entry xh_entries[0]; /* xattr entry list. */
1048};
1049
1050/*
1051 * On disk structure for xattr value root.
1052 *
Tao Ma8573f792008-10-24 22:24:17 +08001053 * When an xattr's value is large enough, it is stored in an external
1054 * b-tree like file data. The xattr value root points to this structure.
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001055 */
1056struct ocfs2_xattr_value_root {
1057/*00*/ __le32 xr_clusters; /* clusters covered by xattr value. */
1058 __le32 xr_reserved0;
1059 __le64 xr_last_eb_blk; /* Pointer to last extent block */
1060/*10*/ struct ocfs2_extent_list xr_list; /* Extent record list */
1061};
1062
1063/*
1064 * On disk structure for xattr tree root.
1065 *
1066 * It is used when there are too many extended attributes for one file. These
1067 * attributes will be organized and stored in an indexed-btree.
1068 */
1069struct ocfs2_xattr_tree_root {
1070/*00*/ __le32 xt_clusters; /* clusters covered by xattr. */
1071 __le32 xt_reserved0;
1072 __le64 xt_last_eb_blk; /* Pointer to last extent block */
1073/*10*/ struct ocfs2_extent_list xt_list; /* Extent record list */
1074};
1075
Tiger Yangcf1d6c72008-08-18 17:11:00 +08001076#define OCFS2_XATTR_INDEXED 0x1
1077#define OCFS2_HASH_SHIFT 5
1078#define OCFS2_XATTR_ROUND 3
1079#define OCFS2_XATTR_SIZE(size) (((size) + OCFS2_XATTR_ROUND) & \
1080 ~(OCFS2_XATTR_ROUND))
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001081
Tao Ma0c044f02008-08-18 17:38:50 +08001082#define OCFS2_XATTR_BUCKET_SIZE 4096
1083#define OCFS2_XATTR_MAX_BLOCKS_PER_BUCKET (OCFS2_XATTR_BUCKET_SIZE \
1084 / OCFS2_MIN_BLOCKSIZE)
1085
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001086/*
1087 * On disk structure for xattr block.
1088 */
1089struct ocfs2_xattr_block {
1090/*00*/ __u8 xb_signature[8]; /* Signature for verification */
1091 __le16 xb_suballoc_slot; /* Slot suballocator this
1092 block belongs to. */
1093 __le16 xb_suballoc_bit; /* Bit offset in suballocator
1094 block group */
1095 __le32 xb_fs_generation; /* Must match super block */
1096/*10*/ __le64 xb_blkno; /* Offset on disk, in blocks */
Joel Beckerab552d52008-10-16 17:50:30 -07001097 struct ocfs2_block_check xb_check; /* Error checking */
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001098/*20*/ __le16 xb_flags; /* Indicates whether this block contains
1099 real xattr or a xattr tree. */
1100 __le16 xb_reserved0;
1101 __le32 xb_reserved1;
Joel Becker9cbc0122010-03-26 10:07:42 +08001102 __le64 xb_suballoc_loc; /* Suballocator block group this
1103 xattr block belongs to. Only
1104 valid if allocated from a
1105 discontiguous block group */
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001106/*30*/ union {
1107 struct ocfs2_xattr_header xb_header; /* xattr header if this
1108 block contains xattr */
1109 struct ocfs2_xattr_tree_root xb_root;/* xattr tree root if this
1110 block cotains xattr
1111 tree. */
1112 } xb_attrs;
1113};
1114
1115#define OCFS2_XATTR_ENTRY_LOCAL 0x80
1116#define OCFS2_XATTR_TYPE_MASK 0x7F
1117static inline void ocfs2_xattr_set_local(struct ocfs2_xattr_entry *xe,
1118 int local)
1119{
1120 if (local)
1121 xe->xe_type |= OCFS2_XATTR_ENTRY_LOCAL;
1122 else
1123 xe->xe_type &= ~OCFS2_XATTR_ENTRY_LOCAL;
1124}
1125
1126static inline int ocfs2_xattr_is_local(struct ocfs2_xattr_entry *xe)
1127{
1128 return xe->xe_type & OCFS2_XATTR_ENTRY_LOCAL;
1129}
1130
1131static inline void ocfs2_xattr_set_type(struct ocfs2_xattr_entry *xe, int type)
1132{
1133 xe->xe_type |= type & OCFS2_XATTR_TYPE_MASK;
1134}
1135
1136static inline int ocfs2_xattr_get_type(struct ocfs2_xattr_entry *xe)
1137{
1138 return xe->xe_type & OCFS2_XATTR_TYPE_MASK;
1139}
1140
Jan Kara9e33d692008-08-25 19:56:50 +02001141/*
1142 * On disk structures for global quota file
1143 */
1144
1145/* Magic numbers and known versions for global quota files */
1146#define OCFS2_GLOBAL_QMAGICS {\
1147 0x0cf52470, /* USRQUOTA */ \
1148 0x0cf52471 /* GRPQUOTA */ \
1149}
1150
1151#define OCFS2_GLOBAL_QVERSIONS {\
1152 0, \
1153 0, \
1154}
1155
1156
1157/* Each block of each quota file has a certain fixed number of bytes reserved
1158 * for OCFS2 internal use at its end. OCFS2 can use it for things like
1159 * checksums, etc. */
1160#define OCFS2_QBLK_RESERVED_SPACE 8
1161
1162/* Generic header of all quota files */
1163struct ocfs2_disk_dqheader {
1164 __le32 dqh_magic; /* Magic number identifying file */
1165 __le32 dqh_version; /* Quota format version */
1166};
1167
1168#define OCFS2_GLOBAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
1169
1170/* Information header of global quota file (immediately follows the generic
1171 * header) */
1172struct ocfs2_global_disk_dqinfo {
1173/*00*/ __le32 dqi_bgrace; /* Grace time for space softlimit excess */
1174 __le32 dqi_igrace; /* Grace time for inode softlimit excess */
1175 __le32 dqi_syncms; /* Time after which we sync local changes to
1176 * global quota file */
1177 __le32 dqi_blocks; /* Number of blocks in quota file */
1178/*10*/ __le32 dqi_free_blk; /* First free block in quota file */
1179 __le32 dqi_free_entry; /* First block with free dquot entry in quota
1180 * file */
1181};
1182
1183/* Structure with global user / group information. We reserve some space
1184 * for future use. */
1185struct ocfs2_global_disk_dqblk {
1186/*00*/ __le32 dqb_id; /* ID the structure belongs to */
1187 __le32 dqb_use_count; /* Number of nodes having reference to this structure */
1188 __le64 dqb_ihardlimit; /* absolute limit on allocated inodes */
1189/*10*/ __le64 dqb_isoftlimit; /* preferred inode limit */
1190 __le64 dqb_curinodes; /* current # allocated inodes */
1191/*20*/ __le64 dqb_bhardlimit; /* absolute limit on disk space */
1192 __le64 dqb_bsoftlimit; /* preferred limit on disk space */
1193/*30*/ __le64 dqb_curspace; /* current space occupied */
1194 __le64 dqb_btime; /* time limit for excessive disk use */
1195/*40*/ __le64 dqb_itime; /* time limit for excessive inode use */
1196 __le64 dqb_pad1;
1197/*50*/ __le64 dqb_pad2;
1198};
1199
1200/*
1201 * On-disk structures for local quota file
1202 */
1203
1204/* Magic numbers and known versions for local quota files */
1205#define OCFS2_LOCAL_QMAGICS {\
1206 0x0cf524c0, /* USRQUOTA */ \
1207 0x0cf524c1 /* GRPQUOTA */ \
1208}
1209
1210#define OCFS2_LOCAL_QVERSIONS {\
1211 0, \
1212 0, \
1213}
1214
1215/* Quota flags in dqinfo header */
1216#define OLQF_CLEAN 0x0001 /* Quota file is empty (this should be after\
1217 * quota has been cleanly turned off) */
1218
1219#define OCFS2_LOCAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
1220
1221/* Information header of local quota file (immediately follows the generic
1222 * header) */
1223struct ocfs2_local_disk_dqinfo {
1224 __le32 dqi_flags; /* Flags for quota file */
1225 __le32 dqi_chunks; /* Number of chunks of quota structures
1226 * with a bitmap */
1227 __le32 dqi_blocks; /* Number of blocks allocated for quota file */
1228};
1229
1230/* Header of one chunk of a quota file */
1231struct ocfs2_local_disk_chunk {
1232 __le32 dqc_free; /* Number of free entries in the bitmap */
Coly Li93654542009-12-06 22:38:53 +08001233 __u8 dqc_bitmap[0]; /* Bitmap of entries in the corresponding
Jan Kara9e33d692008-08-25 19:56:50 +02001234 * chunk of quota file */
1235};
1236
1237/* One entry in local quota file */
1238struct ocfs2_local_disk_dqblk {
1239/*00*/ __le64 dqb_id; /* id this quota applies to */
1240 __le64 dqb_spacemod; /* Change in the amount of used space */
1241/*10*/ __le64 dqb_inodemod; /* Change in the amount of used inodes */
1242};
1243
Joel Beckerab552d52008-10-16 17:50:30 -07001244
1245/*
1246 * The quota trailer lives at the end of each quota block.
1247 */
1248
1249struct ocfs2_disk_dqtrailer {
1250/*00*/ struct ocfs2_block_check dq_check; /* Error checking */
1251/*08*/ /* Cannot be larger than OCFS2_QBLK_RESERVED_SPACE */
1252};
1253
1254static inline struct ocfs2_disk_dqtrailer *ocfs2_block_dqtrailer(int blocksize,
1255 void *buf)
1256{
1257 char *ptr = buf;
1258 ptr += blocksize - OCFS2_QBLK_RESERVED_SPACE;
1259
1260 return (struct ocfs2_disk_dqtrailer *)ptr;
1261}
1262
Mark Fashehccd979b2005-12-15 14:31:24 -08001263#ifdef __KERNEL__
1264static inline int ocfs2_fast_symlink_chars(struct super_block *sb)
1265{
1266 return sb->s_blocksize -
1267 offsetof(struct ocfs2_dinode, id2.i_symlink);
1268}
1269
Tiger Yangfdd77702008-08-18 17:08:55 +08001270static inline int ocfs2_max_inline_data_with_xattr(struct super_block *sb,
1271 struct ocfs2_dinode *di)
1272{
1273 unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
1274
1275 if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
1276 return sb->s_blocksize -
1277 offsetof(struct ocfs2_dinode, id2.i_data.id_data) -
1278 xattrsize;
1279 else
1280 return sb->s_blocksize -
1281 offsetof(struct ocfs2_dinode, id2.i_data.id_data);
1282}
1283
Mark Fashehccd979b2005-12-15 14:31:24 -08001284static inline int ocfs2_extent_recs_per_inode(struct super_block *sb)
1285{
1286 int size;
1287
1288 size = sb->s_blocksize -
1289 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1290
1291 return size / sizeof(struct ocfs2_extent_rec);
1292}
1293
Tiger Yangfdd77702008-08-18 17:08:55 +08001294static inline int ocfs2_extent_recs_per_inode_with_xattr(
1295 struct super_block *sb,
1296 struct ocfs2_dinode *di)
1297{
1298 int size;
1299 unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
1300
1301 if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
1302 size = sb->s_blocksize -
1303 offsetof(struct ocfs2_dinode, id2.i_list.l_recs) -
1304 xattrsize;
1305 else
1306 size = sb->s_blocksize -
1307 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1308
1309 return size / sizeof(struct ocfs2_extent_rec);
1310}
1311
Mark Fasheh9b7895e2008-11-12 16:27:44 -08001312static inline int ocfs2_extent_recs_per_dx_root(struct super_block *sb)
1313{
1314 int size;
1315
1316 size = sb->s_blocksize -
1317 offsetof(struct ocfs2_dx_root_block, dr_list.l_recs);
1318
1319 return size / sizeof(struct ocfs2_extent_rec);
1320}
1321
Mark Fashehccd979b2005-12-15 14:31:24 -08001322static inline int ocfs2_chain_recs_per_inode(struct super_block *sb)
1323{
1324 int size;
1325
1326 size = sb->s_blocksize -
1327 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
1328
1329 return size / sizeof(struct ocfs2_chain_rec);
1330}
1331
1332static inline u16 ocfs2_extent_recs_per_eb(struct super_block *sb)
1333{
1334 int size;
1335
1336 size = sb->s_blocksize -
1337 offsetof(struct ocfs2_extent_block, h_list.l_recs);
1338
1339 return size / sizeof(struct ocfs2_extent_rec);
1340}
1341
Joel Becker798db352010-04-13 14:26:32 +08001342static inline u16 ocfs2_extent_recs_per_gd(struct super_block *sb)
1343{
1344 int size;
1345
1346 size = sb->s_blocksize -
1347 offsetof(struct ocfs2_group_desc, bg_list.l_recs);
1348
1349 return size / sizeof(struct ocfs2_extent_rec);
1350}
1351
Mark Fasheh9b7895e2008-11-12 16:27:44 -08001352static inline int ocfs2_dx_entries_per_leaf(struct super_block *sb)
1353{
1354 int size;
1355
1356 size = sb->s_blocksize -
1357 offsetof(struct ocfs2_dx_leaf, dl_list.de_entries);
1358
1359 return size / sizeof(struct ocfs2_dx_entry);
1360}
1361
Mark Fasheh4ed8a6b2008-11-24 17:02:08 -08001362static inline int ocfs2_dx_entries_per_root(struct super_block *sb)
1363{
1364 int size;
1365
1366 size = sb->s_blocksize -
1367 offsetof(struct ocfs2_dx_root_block, dr_entries.de_entries);
1368
1369 return size / sizeof(struct ocfs2_dx_entry);
1370}
1371
Mark Fashehccd979b2005-12-15 14:31:24 -08001372static inline u16 ocfs2_local_alloc_size(struct super_block *sb)
1373{
1374 u16 size;
1375
1376 size = sb->s_blocksize -
1377 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
1378
1379 return size;
1380}
1381
Joel Becker4cbe4242010-04-13 14:26:12 +08001382static inline int ocfs2_group_bitmap_size(struct super_block *sb,
Tao Ma85718822010-04-13 14:38:06 +08001383 int suballocator,
1384 u32 feature_incompat)
Mark Fashehccd979b2005-12-15 14:31:24 -08001385{
Tao Ma85718822010-04-13 14:38:06 +08001386 int size = sb->s_blocksize -
1387 offsetof(struct ocfs2_group_desc, bg_bitmap);
Mark Fashehccd979b2005-12-15 14:31:24 -08001388
Tao Ma85718822010-04-13 14:38:06 +08001389 /*
1390 * The cluster allocator uses the entire block. Suballocators have
1391 * never used more than OCFS2_MAX_BG_BITMAP_SIZE. Unfortunately, older
1392 * code expects bg_size set to the maximum. Thus we must keep
1393 * bg_size as-is unless discontig_bg is enabled.
1394 */
1395 if (suballocator &&
1396 (feature_incompat & OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG))
Joel Becker4cbe4242010-04-13 14:26:12 +08001397 size = OCFS2_MAX_BG_BITMAP_SIZE;
Mark Fashehccd979b2005-12-15 14:31:24 -08001398
1399 return size;
1400}
1401
1402static inline int ocfs2_truncate_recs_per_inode(struct super_block *sb)
1403{
1404 int size;
1405
1406 size = sb->s_blocksize -
1407 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
1408
1409 return size / sizeof(struct ocfs2_truncate_rec);
1410}
Mark Fasheh50af94b2007-01-21 14:44:59 -08001411
1412static inline u64 ocfs2_backup_super_blkno(struct super_block *sb, int index)
1413{
1414 u64 offset = OCFS2_BACKUP_SB_START;
1415
1416 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
1417 offset <<= (2 * index);
Mark Fasheha8a75a22007-01-26 10:46:59 -08001418 offset >>= sb->s_blocksize_bits;
Mark Fasheh50af94b2007-01-21 14:44:59 -08001419 return offset;
1420 }
1421
1422 return 0;
1423
1424}
Tao Ma0c044f02008-08-18 17:38:50 +08001425
1426static inline u16 ocfs2_xattr_recs_per_xb(struct super_block *sb)
1427{
1428 int size;
1429
1430 size = sb->s_blocksize -
1431 offsetof(struct ocfs2_xattr_block,
1432 xb_attrs.xb_root.xt_list.l_recs);
1433
1434 return size / sizeof(struct ocfs2_extent_rec);
1435}
Tao Ma721f69c2009-08-18 11:17:49 +08001436
1437static inline u16 ocfs2_extent_recs_per_rb(struct super_block *sb)
1438{
1439 int size;
1440
1441 size = sb->s_blocksize -
1442 offsetof(struct ocfs2_refcount_block, rf_list.l_recs);
1443
1444 return size / sizeof(struct ocfs2_extent_rec);
1445}
1446
1447static inline u16 ocfs2_refcount_recs_per_rb(struct super_block *sb)
1448{
1449 int size;
1450
1451 size = sb->s_blocksize -
1452 offsetof(struct ocfs2_refcount_block, rf_records.rl_recs);
1453
1454 return size / sizeof(struct ocfs2_refcount_rec);
1455}
Tao Mae73a8192009-08-11 14:33:14 +08001456
1457static inline u32
1458ocfs2_get_ref_rec_low_cpos(const struct ocfs2_refcount_rec *rec)
1459{
1460 return le64_to_cpu(rec->r_cpos) & OCFS2_32BIT_POS_MASK;
1461}
Mark Fashehccd979b2005-12-15 14:31:24 -08001462#else
1463static inline int ocfs2_fast_symlink_chars(int blocksize)
1464{
1465 return blocksize - offsetof(struct ocfs2_dinode, id2.i_symlink);
1466}
1467
Tao Ma1097df32010-01-20 11:31:11 +08001468static inline int ocfs2_max_inline_data_with_xattr(int blocksize,
1469 struct ocfs2_dinode *di)
Mark Fasheh15b1e362007-09-07 13:58:15 -07001470{
Tao Ma1097df32010-01-20 11:31:11 +08001471 if (di && (di->i_dyn_features & OCFS2_INLINE_XATTR_FL))
1472 return blocksize -
1473 offsetof(struct ocfs2_dinode, id2.i_data.id_data) -
1474 di->i_xattr_inline_size;
1475 else
1476 return blocksize -
1477 offsetof(struct ocfs2_dinode, id2.i_data.id_data);
Mark Fasheh15b1e362007-09-07 13:58:15 -07001478}
1479
Mark Fashehccd979b2005-12-15 14:31:24 -08001480static inline int ocfs2_extent_recs_per_inode(int blocksize)
1481{
1482 int size;
1483
1484 size = blocksize -
1485 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1486
1487 return size / sizeof(struct ocfs2_extent_rec);
1488}
1489
1490static inline int ocfs2_chain_recs_per_inode(int blocksize)
1491{
1492 int size;
1493
1494 size = blocksize -
1495 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
1496
1497 return size / sizeof(struct ocfs2_chain_rec);
1498}
1499
1500static inline int ocfs2_extent_recs_per_eb(int blocksize)
1501{
1502 int size;
1503
1504 size = blocksize -
1505 offsetof(struct ocfs2_extent_block, h_list.l_recs);
1506
1507 return size / sizeof(struct ocfs2_extent_rec);
1508}
1509
Joel Becker798db352010-04-13 14:26:32 +08001510static inline int ocfs2_extent_recs_per_gd(int blocksize)
1511{
1512 int size;
1513
1514 size = blocksize -
1515 offsetof(struct ocfs2_group_desc, bg_list.l_recs);
1516
1517 return size / sizeof(struct ocfs2_extent_rec);
1518}
1519
Mark Fashehccd979b2005-12-15 14:31:24 -08001520static inline int ocfs2_local_alloc_size(int blocksize)
1521{
1522 int size;
1523
1524 size = blocksize -
1525 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
1526
1527 return size;
1528}
1529
Tao Ma85718822010-04-13 14:38:06 +08001530static inline int ocfs2_group_bitmap_size(int blocksize,
1531 int suballocator,
1532 uint32_t feature_incompat)
Mark Fashehccd979b2005-12-15 14:31:24 -08001533{
Tao Ma85718822010-04-13 14:38:06 +08001534 int size = sb->s_blocksize -
1535 offsetof(struct ocfs2_group_desc, bg_bitmap);
Mark Fashehccd979b2005-12-15 14:31:24 -08001536
Tao Ma85718822010-04-13 14:38:06 +08001537 /*
1538 * The cluster allocator uses the entire block. Suballocators have
1539 * never used more than OCFS2_MAX_BG_BITMAP_SIZE. Unfortunately, older
1540 * code expects bg_size set to the maximum. Thus we must keep
1541 * bg_size as-is unless discontig_bg is enabled.
1542 */
1543 if (suballocator &&
1544 (feature_incompat & OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG))
Joel Becker4cbe4242010-04-13 14:26:12 +08001545 size = OCFS2_MAX_BG_BITMAP_SIZE;
Mark Fashehccd979b2005-12-15 14:31:24 -08001546
1547 return size;
1548}
1549
1550static inline int ocfs2_truncate_recs_per_inode(int blocksize)
1551{
1552 int size;
1553
1554 size = blocksize -
1555 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
1556
1557 return size / sizeof(struct ocfs2_truncate_rec);
1558}
Mark Fasheh50af94b2007-01-21 14:44:59 -08001559
1560static inline uint64_t ocfs2_backup_super_blkno(int blocksize, int index)
1561{
1562 uint64_t offset = OCFS2_BACKUP_SB_START;
1563
1564 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
1565 offset <<= (2 * index);
1566 offset /= blocksize;
1567 return offset;
1568 }
1569
1570 return 0;
1571}
Tao Ma0c044f02008-08-18 17:38:50 +08001572
1573static inline int ocfs2_xattr_recs_per_xb(int blocksize)
1574{
1575 int size;
1576
1577 size = blocksize -
1578 offsetof(struct ocfs2_xattr_block,
1579 xb_attrs.xb_root.xt_list.l_recs);
1580
1581 return size / sizeof(struct ocfs2_extent_rec);
1582}
Mark Fashehccd979b2005-12-15 14:31:24 -08001583#endif /* __KERNEL__ */
1584
1585
1586static inline int ocfs2_system_inode_is_global(int type)
1587{
1588 return ((type >= 0) &&
1589 (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE));
1590}
1591
1592static inline int ocfs2_sprintf_system_inode_name(char *buf, int len,
1593 int type, int slot)
1594{
1595 int chars;
1596
1597 /*
1598 * Global system inodes can only have one copy. Everything
1599 * after OCFS2_LAST_GLOBAL_SYSTEM_INODE in the system inode
1600 * list has a copy per slot.
1601 */
1602 if (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE)
Joel Beckerfe9f3872008-06-12 22:39:18 -07001603 chars = snprintf(buf, len, "%s",
Mark Fashehccd979b2005-12-15 14:31:24 -08001604 ocfs2_system_inodes[type].si_name);
1605 else
1606 chars = snprintf(buf, len,
1607 ocfs2_system_inodes[type].si_name,
1608 slot);
1609
1610 return chars;
1611}
1612
1613static inline void ocfs2_set_de_type(struct ocfs2_dir_entry *de,
1614 umode_t mode)
1615{
1616 de->file_type = ocfs2_type_by_mode[(mode & S_IFMT)>>S_SHIFT];
1617}
1618
Tao Maaf2bf0d2010-05-17 15:14:17 +08001619static inline int ocfs2_gd_is_discontig(struct ocfs2_group_desc *gd)
1620{
1621 if ((offsetof(struct ocfs2_group_desc, bg_bitmap) +
1622 le16_to_cpu(gd->bg_size)) !=
1623 offsetof(struct ocfs2_group_desc, bg_list))
1624 return 0;
1625 /*
1626 * Only valid to check l_next_free_rec if
1627 * bg_bitmap + bg_size == bg_list.
1628 */
1629 if (!gd->bg_list.l_next_free_rec)
1630 return 0;
1631 return 1;
1632}
Mark Fashehccd979b2005-12-15 14:31:24 -08001633#endif /* _OCFS2_FS_H */
1634