blob: 28ff536b4f8d2ea878208c0fa464220716bf1025 [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 Mushran98f486f2010-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 Mushran98f486f2010-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 Mushran98f486f2010-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 Mushran98f486f2010-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 Mushran98f486f2010-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"
Sunil Mushran2c442712010-10-07 15:23:50 -0700379#define OCFS2_HB_GLOBAL "heartbeat=global"
Mark Fashehccd979b2005-12-15 14:31:24 -0800380
381/*
382 * OCFS2 directory file types. Only the low 3 bits are used. The
383 * other bits are reserved for now.
384 */
385#define OCFS2_FT_UNKNOWN 0
386#define OCFS2_FT_REG_FILE 1
387#define OCFS2_FT_DIR 2
388#define OCFS2_FT_CHRDEV 3
389#define OCFS2_FT_BLKDEV 4
390#define OCFS2_FT_FIFO 5
391#define OCFS2_FT_SOCK 6
392#define OCFS2_FT_SYMLINK 7
393
394#define OCFS2_FT_MAX 8
395
396/*
397 * OCFS2_DIR_PAD defines the directory entries boundaries
398 *
399 * NOTE: It must be a multiple of 4
400 */
401#define OCFS2_DIR_PAD 4
402#define OCFS2_DIR_ROUND (OCFS2_DIR_PAD - 1)
403#define OCFS2_DIR_MEMBER_LEN offsetof(struct ocfs2_dir_entry, name)
404#define OCFS2_DIR_REC_LEN(name_len) (((name_len) + OCFS2_DIR_MEMBER_LEN + \
405 OCFS2_DIR_ROUND) & \
406 ~OCFS2_DIR_ROUND)
Mark Fashehe7c17e42009-01-29 18:17:46 -0800407#define OCFS2_DIR_MIN_REC_LEN OCFS2_DIR_REC_LEN(1)
Mark Fashehccd979b2005-12-15 14:31:24 -0800408
409#define OCFS2_LINK_MAX 32000
Mark Fasheh198a1ca2008-11-20 17:54:57 -0800410#define OCFS2_DX_LINK_MAX ((1U << 31) - 1U)
411#define OCFS2_LINKS_HI_SHIFT 16
Mark Fashehe3a93c22009-02-17 15:29:35 -0800412#define OCFS2_DX_ENTRIES_MAX (0xffffffffU)
Mark Fashehccd979b2005-12-15 14:31:24 -0800413
414#define S_SHIFT 12
415static unsigned char ocfs2_type_by_mode[S_IFMT >> S_SHIFT] = {
416 [S_IFREG >> S_SHIFT] = OCFS2_FT_REG_FILE,
417 [S_IFDIR >> S_SHIFT] = OCFS2_FT_DIR,
418 [S_IFCHR >> S_SHIFT] = OCFS2_FT_CHRDEV,
419 [S_IFBLK >> S_SHIFT] = OCFS2_FT_BLKDEV,
420 [S_IFIFO >> S_SHIFT] = OCFS2_FT_FIFO,
421 [S_IFSOCK >> S_SHIFT] = OCFS2_FT_SOCK,
422 [S_IFLNK >> S_SHIFT] = OCFS2_FT_SYMLINK,
423};
424
425
426/*
427 * Convenience casts
428 */
429#define OCFS2_RAW_SB(dinode) (&((dinode)->id2.i_super))
430
431/*
Joel Beckerab552d52008-10-16 17:50:30 -0700432 * Block checking structure. This is used in metadata to validate the
433 * contents. If OCFS2_FEATURE_INCOMPAT_META_ECC is not set, it is all
434 * zeros.
435 */
436struct ocfs2_block_check {
437/*00*/ __le32 bc_crc32e; /* 802.3 Ethernet II CRC32 */
438 __le16 bc_ecc; /* Single-error-correction parity vector.
439 This is a simple Hamming code dependant
440 on the blocksize. OCFS2's maximum
441 blocksize, 4K, requires 16 parity bits,
442 so we fit in __le16. */
443 __le16 bc_reserved1;
444/*08*/
445};
446
447/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800448 * On disk extent record for OCFS2
449 * It describes a range of clusters on disk.
Mark Fashehe48edee2007-03-07 16:46:57 -0800450 *
451 * Length fields are divided into interior and leaf node versions.
452 * This leaves room for a flags field (OCFS2_EXT_*) in the leaf nodes.
Mark Fashehccd979b2005-12-15 14:31:24 -0800453 */
454struct ocfs2_extent_rec {
455/*00*/ __le32 e_cpos; /* Offset into the file, in clusters */
Mark Fashehe48edee2007-03-07 16:46:57 -0800456 union {
457 __le32 e_int_clusters; /* Clusters covered by all children */
458 struct {
459 __le16 e_leaf_clusters; /* Clusters covered by this
460 extent */
461 __u8 e_reserved1;
462 __u8 e_flags; /* Extent flags */
463 };
464 };
Mark Fashehccd979b2005-12-15 14:31:24 -0800465 __le64 e_blkno; /* Physical disk offset, in blocks */
466/*10*/
467};
468
469struct ocfs2_chain_rec {
470 __le32 c_free; /* Number of free bits in this chain. */
471 __le32 c_total; /* Number of total bits in this chain */
472 __le64 c_blkno; /* Physical disk offset (blocks) of 1st group */
473};
474
475struct ocfs2_truncate_rec {
476 __le32 t_start; /* 1st cluster in this log */
477 __le32 t_clusters; /* Number of total clusters covered */
478};
479
480/*
481 * On disk extent list for OCFS2 (node in the tree). Note that this
482 * is contained inside ocfs2_dinode or ocfs2_extent_block, so the
483 * offsets are relative to ocfs2_dinode.id2.i_list or
484 * ocfs2_extent_block.h_list, respectively.
485 */
486struct ocfs2_extent_list {
487/*00*/ __le16 l_tree_depth; /* Extent tree depth from this
488 point. 0 means data extents
489 hang directly off this
Mark Fashehdcd05382007-01-16 11:32:23 -0800490 header (a leaf)
491 NOTE: The high 8 bits cannot be
492 used - tree_depth is never that big.
493 */
Mark Fashehccd979b2005-12-15 14:31:24 -0800494 __le16 l_count; /* Number of extent records */
495 __le16 l_next_free_rec; /* Next unused extent slot */
496 __le16 l_reserved1;
497 __le64 l_reserved2; /* Pad to
498 sizeof(ocfs2_extent_rec) */
499/*10*/ struct ocfs2_extent_rec l_recs[0]; /* Extent records */
500};
501
502/*
503 * On disk allocation chain list for OCFS2. Note that this is
504 * contained inside ocfs2_dinode, so the offsets are relative to
505 * ocfs2_dinode.id2.i_chain.
506 */
507struct ocfs2_chain_list {
508/*00*/ __le16 cl_cpg; /* Clusters per Block Group */
509 __le16 cl_bpc; /* Bits per cluster */
510 __le16 cl_count; /* Total chains in this list */
511 __le16 cl_next_free_rec; /* Next unused chain slot */
512 __le64 cl_reserved1;
513/*10*/ struct ocfs2_chain_rec cl_recs[0]; /* Chain records */
514};
515
516/*
517 * On disk deallocation log for OCFS2. Note that this is
518 * contained inside ocfs2_dinode, so the offsets are relative to
519 * ocfs2_dinode.id2.i_dealloc.
520 */
521struct ocfs2_truncate_log {
522/*00*/ __le16 tl_count; /* Total records in this log */
523 __le16 tl_used; /* Number of records in use */
524 __le32 tl_reserved1;
525/*08*/ struct ocfs2_truncate_rec tl_recs[0]; /* Truncate records */
526};
527
528/*
529 * On disk extent block (indirect block) for OCFS2
530 */
531struct ocfs2_extent_block
532{
533/*00*/ __u8 h_signature[8]; /* Signature for verification */
Joel Beckerab552d52008-10-16 17:50:30 -0700534 struct ocfs2_block_check h_check; /* Error checking */
Mark Fashehccd979b2005-12-15 14:31:24 -0800535/*10*/ __le16 h_suballoc_slot; /* Slot suballocator this
536 extent_header belongs to */
537 __le16 h_suballoc_bit; /* Bit offset in suballocator
538 block group */
539 __le32 h_fs_generation; /* Must match super block */
540 __le64 h_blkno; /* Offset on disk, in blocks */
Joel Becker9cbc0122010-03-26 10:07:42 +0800541/*20*/ __le64 h_suballoc_loc; /* Suballocator block group this
542 eb belongs to. Only valid
543 if allocated from a
544 discontiguous block group */
Mark Fashehccd979b2005-12-15 14:31:24 -0800545 __le64 h_next_leaf_blk; /* Offset on disk, in blocks,
546 of next leaf header pointing
547 to data */
548/*30*/ struct ocfs2_extent_list h_list; /* Extent record list */
549/* Actual on-disk size is one block */
550};
551
552/*
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800553 * On disk slot map for OCFS2. This defines the contents of the "slot_map"
Joel Becker386a2ef2008-02-01 12:06:54 -0800554 * system file. A slot is valid if it contains a node number >= 0. The
555 * value -1 (0xFFFF) is OCFS2_INVALID_SLOT. This marks a slot empty.
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800556 */
557struct ocfs2_slot_map {
558/*00*/ __le16 sm_slots[0];
559/*
560 * Actual on-disk size is one block. OCFS2_MAX_SLOTS is 255,
561 * 255 * sizeof(__le16) == 512B, within the 512B block minimum blocksize.
562 */
563};
564
Joel Becker386a2ef2008-02-01 12:06:54 -0800565struct ocfs2_extended_slot {
566/*00*/ __u8 es_valid;
567 __u8 es_reserved1[3];
568 __le32 es_node_num;
569/*10*/
570};
571
572/*
573 * The extended slot map, used when OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP
574 * is set. It separates out the valid marker from the node number, and
575 * has room to grow. Unlike the old slot map, this format is defined by
576 * i_size.
577 */
578struct ocfs2_slot_map_extended {
579/*00*/ struct ocfs2_extended_slot se_slots[0];
580/*
581 * Actual size is i_size of the slot_map system file. It should
582 * match s_max_slots * sizeof(struct ocfs2_extended_slot)
583 */
584};
585
Sunil Mushran98f486f2010-10-09 10:24:46 -0700586/*
587 * ci_stackflags is only valid if the incompat bit
588 * OCFS2_FEATURE_INCOMPAT_CLUSTERINFO is set.
589 */
Joel Beckerb61817e2008-02-01 15:08:23 -0800590struct ocfs2_cluster_info {
591/*00*/ __u8 ci_stack[OCFS2_STACK_LABEL_LEN];
Sunil Mushran98f486f2010-10-09 10:24:46 -0700592 union {
593 __le32 ci_reserved;
594 struct {
595 __u8 ci_stackflags;
596 __u8 ci_reserved1;
597 __u8 ci_reserved2;
598 __u8 ci_reserved3;
599 };
600 };
Joel Beckerb61817e2008-02-01 15:08:23 -0800601/*08*/ __u8 ci_cluster[OCFS2_CLUSTER_NAME_LEN];
602/*18*/
603};
604
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800605/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800606 * On disk superblock for OCFS2
607 * Note that it is contained inside an ocfs2_dinode, so all offsets
608 * are relative to the start of ocfs2_dinode.id2.
609 */
610struct ocfs2_super_block {
611/*00*/ __le16 s_major_rev_level;
612 __le16 s_minor_rev_level;
613 __le16 s_mnt_count;
614 __le16 s_max_mnt_count;
615 __le16 s_state; /* File system state */
616 __le16 s_errors; /* Behaviour when detecting errors */
617 __le32 s_checkinterval; /* Max time between checks */
618/*10*/ __le64 s_lastcheck; /* Time of last check */
619 __le32 s_creator_os; /* OS */
620 __le32 s_feature_compat; /* Compatible feature set */
621/*20*/ __le32 s_feature_incompat; /* Incompatible feature set */
622 __le32 s_feature_ro_compat; /* Readonly-compatible feature set */
623 __le64 s_root_blkno; /* Offset, in blocks, of root directory
624 dinode */
625/*30*/ __le64 s_system_dir_blkno; /* Offset, in blocks, of system
626 directory dinode */
627 __le32 s_blocksize_bits; /* Blocksize for this fs */
628 __le32 s_clustersize_bits; /* Clustersize for this fs */
629/*40*/ __le16 s_max_slots; /* Max number of simultaneous mounts
630 before tunefs required */
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700631 __le16 s_tunefs_flag;
Tiger Yangcf1d6c72008-08-18 17:11:00 +0800632 __le32 s_uuid_hash; /* hash value of uuid */
Mark Fashehccd979b2005-12-15 14:31:24 -0800633 __le64 s_first_cluster_group; /* Block offset of 1st cluster
634 * group header */
635/*50*/ __u8 s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */
636/*90*/ __u8 s_uuid[OCFS2_VOL_UUID_LEN]; /* 128-bit uuid */
Sunil Mushran98f486f2010-10-09 10:24:46 -0700637/*A0*/ struct ocfs2_cluster_info s_cluster_info; /* Only valid if either
638 userspace or clusterinfo
639 INCOMPAT flag set. */
Tiger Yang8154da32008-08-18 17:11:46 +0800640/*B8*/ __le16 s_xattr_inline_size; /* extended attribute inline size
641 for this fs*/
642 __le16 s_reserved0;
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800643 __le32 s_dx_seed[3]; /* seed[0-2] for dx dir hash.
644 * s_uuid_hash serves as seed[3]. */
645/*C0*/ __le64 s_reserved2[15]; /* Fill out superblock */
Joel Beckerb61817e2008-02-01 15:08:23 -0800646/*140*/
647
648 /*
649 * NOTE: As stated above, all offsets are relative to
650 * ocfs2_dinode.id2, which is at 0xC0 in the inode.
651 * 0xC0 + 0x140 = 0x200 or 512 bytes. A superblock must fit within
652 * our smallest blocksize, which is 512 bytes. To ensure this,
653 * we reserve the space in s_reserved2. Anything past s_reserved2
654 * will not be available on the smallest blocksize.
655 */
Mark Fashehccd979b2005-12-15 14:31:24 -0800656};
657
658/*
659 * Local allocation bitmap for OCFS2 slots
660 * Note that it exists inside an ocfs2_dinode, so all offsets are
661 * relative to the start of ocfs2_dinode.id2.
662 */
663struct ocfs2_local_alloc
664{
665/*00*/ __le32 la_bm_off; /* Starting bit offset in main bitmap */
666 __le16 la_size; /* Size of included bitmap, in bytes */
667 __le16 la_reserved1;
668 __le64 la_reserved2;
669/*10*/ __u8 la_bitmap[0];
670};
671
672/*
Mark Fasheh15b1e362007-09-07 13:58:15 -0700673 * Data-in-inode header. This is only used if i_dyn_features has
674 * OCFS2_INLINE_DATA_FL set.
675 */
676struct ocfs2_inline_data
677{
678/*00*/ __le16 id_count; /* Number of bytes that can be used
679 * for data, starting at id_data */
680 __le16 id_reserved0;
681 __le32 id_reserved1;
682 __u8 id_data[0]; /* Start of user data */
683};
684
685/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800686 * On disk inode for OCFS2
687 */
688struct ocfs2_dinode {
689/*00*/ __u8 i_signature[8]; /* Signature for validation */
690 __le32 i_generation; /* Generation number */
691 __le16 i_suballoc_slot; /* Slot suballocator this inode
692 belongs to */
693 __le16 i_suballoc_bit; /* Bit offset in suballocator
694 block group */
Mark Fasheh198a1ca2008-11-20 17:54:57 -0800695/*10*/ __le16 i_links_count_hi; /* High 16 bits of links count */
Tiger Yangfdd77702008-08-18 17:08:55 +0800696 __le16 i_xattr_inline_size;
Mark Fashehccd979b2005-12-15 14:31:24 -0800697 __le32 i_clusters; /* Cluster count */
698 __le32 i_uid; /* Owner UID */
699 __le32 i_gid; /* Owning GID */
700/*20*/ __le64 i_size; /* Size in bytes */
701 __le16 i_mode; /* File mode */
702 __le16 i_links_count; /* Links count */
703 __le32 i_flags; /* File flags */
704/*30*/ __le64 i_atime; /* Access time */
705 __le64 i_ctime; /* Creation time */
706/*40*/ __le64 i_mtime; /* Modification time */
707 __le64 i_dtime; /* Deletion time */
708/*50*/ __le64 i_blkno; /* Offset on disk, in blocks */
709 __le64 i_last_eb_blk; /* Pointer to last extent
710 block */
711/*60*/ __le32 i_fs_generation; /* Generation per fs-instance */
712 __le32 i_atime_nsec;
713 __le32 i_ctime_nsec;
714 __le32 i_mtime_nsec;
Tiger Yangfdd77702008-08-18 17:08:55 +0800715/*70*/ __le32 i_attr;
Tiger Yang50008632007-03-20 16:01:38 -0700716 __le16 i_orphaned_slot; /* Only valid when OCFS2_ORPHANED_FL
717 was set in i_flags */
Mark Fasheh15b1e362007-09-07 13:58:15 -0700718 __le16 i_dyn_features;
Tiger Yangfdd77702008-08-18 17:08:55 +0800719 __le64 i_xattr_loc;
Joel Beckerab552d52008-10-16 17:50:30 -0700720/*80*/ struct ocfs2_block_check i_check; /* Error checking */
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800721/*88*/ __le64 i_dx_root; /* Pointer to dir index root block */
Tao Ma721f69c2009-08-18 11:17:49 +0800722/*90*/ __le64 i_refcount_loc;
Joel Becker9cbc0122010-03-26 10:07:42 +0800723 __le64 i_suballoc_loc; /* Suballocator block group this
724 inode belongs to. Only valid
725 if allocated from a
726 discontiguous block group */
727/*A0*/ __le64 i_reserved2[3];
Mark Fashehccd979b2005-12-15 14:31:24 -0800728/*B8*/ union {
729 __le64 i_pad1; /* Generic way to refer to this
730 64bit union */
731 struct {
732 __le64 i_rdev; /* Device number */
733 } dev1;
734 struct { /* Info for bitmap system
735 inodes */
736 __le32 i_used; /* Bits (ie, clusters) used */
737 __le32 i_total; /* Total bits (clusters)
738 available */
739 } bitmap1;
740 struct { /* Info for journal system
741 inodes */
742 __le32 ij_flags; /* Mounted, version, etc. */
Sunil Mushranc69991a2008-07-14 17:31:09 -0700743 __le32 ij_recovery_generation; /* Incremented when the
744 journal is recovered
745 after an unclean
746 shutdown */
Mark Fashehccd979b2005-12-15 14:31:24 -0800747 } journal1;
748 } id1; /* Inode type dependant 1 */
749/*C0*/ union {
750 struct ocfs2_super_block i_super;
751 struct ocfs2_local_alloc i_lab;
752 struct ocfs2_chain_list i_chain;
753 struct ocfs2_extent_list i_list;
754 struct ocfs2_truncate_log i_dealloc;
Mark Fasheh15b1e362007-09-07 13:58:15 -0700755 struct ocfs2_inline_data i_data;
Mark Fashehccd979b2005-12-15 14:31:24 -0800756 __u8 i_symlink[0];
757 } id2;
758/* Actual on-disk size is one block */
759};
760
761/*
762 * On-disk directory entry structure for OCFS2
763 *
764 * Packed as this structure could be accessed unaligned on 64-bit platforms
765 */
766struct ocfs2_dir_entry {
767/*00*/ __le64 inode; /* Inode number */
768 __le16 rec_len; /* Directory entry length */
769 __u8 name_len; /* Name length */
770 __u8 file_type;
771/*0C*/ char name[OCFS2_MAX_FILENAME_LEN]; /* File name */
772/* Actual on-disk length specified by rec_len */
773} __attribute__ ((packed));
774
775/*
Mark Fasheh87d35a72008-12-10 17:36:25 -0800776 * Per-block record for the unindexed directory btree. This is carefully
777 * crafted so that the rec_len and name_len records of an ocfs2_dir_entry are
778 * mirrored. That way, the directory manipulation code needs a minimal amount
779 * of update.
780 *
781 * NOTE: Keep this structure aligned to a multiple of 4 bytes.
782 */
783struct ocfs2_dir_block_trailer {
784/*00*/ __le64 db_compat_inode; /* Always zero. Was inode */
785
786 __le16 db_compat_rec_len; /* Backwards compatible with
787 * ocfs2_dir_entry. */
788 __u8 db_compat_name_len; /* Always zero. Was name_len */
789 __u8 db_reserved0;
790 __le16 db_reserved1;
791 __le16 db_free_rec_len; /* Size of largest empty hole
792 * in this block. (unused) */
793/*10*/ __u8 db_signature[8]; /* Signature for verification */
794 __le64 db_reserved2;
795 __le64 db_free_next; /* Next block in list (unused) */
796/*20*/ __le64 db_blkno; /* Offset on disk, in blocks */
797 __le64 db_parent_dinode; /* dinode which owns me, in
798 blocks */
Joel Beckerc175a512008-12-10 17:58:22 -0800799/*30*/ struct ocfs2_block_check db_check; /* Error checking */
Mark Fasheh87d35a72008-12-10 17:36:25 -0800800/*40*/
801};
802
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800803 /*
804 * A directory entry in the indexed tree. We don't store the full name here,
805 * but instead provide a pointer to the full dirent in the unindexed tree.
806 *
807 * We also store name_len here so as to reduce the number of leaf blocks we
808 * need to search in case of collisions.
809 */
810struct ocfs2_dx_entry {
811 __le32 dx_major_hash; /* Used to find logical
812 * cluster in index */
813 __le32 dx_minor_hash; /* Lower bits used to find
814 * block in cluster */
815 __le64 dx_dirent_blk; /* Physical block in unindexed
816 * tree holding this dirent. */
817};
818
819struct ocfs2_dx_entry_list {
820 __le32 de_reserved;
821 __le16 de_count; /* Maximum number of entries
822 * possible in de_entries */
823 __le16 de_num_used; /* Current number of
824 * de_entries entries */
825 struct ocfs2_dx_entry de_entries[0]; /* Indexed dir entries
826 * in a packed array of
827 * length de_num_used */
828};
829
Mark Fasheh4ed8a6b2008-11-24 17:02:08 -0800830#define OCFS2_DX_FLAG_INLINE 0x01
831
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800832/*
833 * A directory indexing block. Each indexed directory has one of these,
834 * pointed to by ocfs2_dinode.
835 *
836 * This block stores an indexed btree root, and a set of free space
837 * start-of-list pointers.
838 */
839struct ocfs2_dx_root_block {
840 __u8 dr_signature[8]; /* Signature for verification */
841 struct ocfs2_block_check dr_check; /* Error checking */
842 __le16 dr_suballoc_slot; /* Slot suballocator this
843 * block belongs to. */
844 __le16 dr_suballoc_bit; /* Bit offset in suballocator
845 * block group */
846 __le32 dr_fs_generation; /* Must match super block */
847 __le64 dr_blkno; /* Offset on disk, in blocks */
848 __le64 dr_last_eb_blk; /* Pointer to last
849 * extent block */
850 __le32 dr_clusters; /* Clusters allocated
851 * to the indexed tree. */
Mark Fasheh4ed8a6b2008-11-24 17:02:08 -0800852 __u8 dr_flags; /* OCFS2_DX_FLAG_* flags */
853 __u8 dr_reserved0;
854 __le16 dr_reserved1;
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800855 __le64 dr_dir_blkno; /* Pointer to parent inode */
Mark Fashehe3a93c22009-02-17 15:29:35 -0800856 __le32 dr_num_entries; /* Total number of
857 * names stored in
858 * this directory.*/
859 __le32 dr_reserved2;
Mark Fashehe7c17e42009-01-29 18:17:46 -0800860 __le64 dr_free_blk; /* Pointer to head of free
861 * unindexed block list. */
Joel Becker9cbc0122010-03-26 10:07:42 +0800862 __le64 dr_suballoc_loc; /* Suballocator block group
863 this root belongs to.
864 Only valid if allocated
865 from a discontiguous
866 block group */
867 __le64 dr_reserved3[14];
Mark Fasheh4ed8a6b2008-11-24 17:02:08 -0800868 union {
869 struct ocfs2_extent_list dr_list; /* Keep this aligned to 128
870 * bits for maximum space
871 * efficiency. */
872 struct ocfs2_dx_entry_list dr_entries; /* In-root-block list of
873 * entries. We grow out
874 * to extents if this
875 * gets too big. */
876 };
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800877};
878
879/*
880 * The header of a leaf block in the indexed tree.
881 */
882struct ocfs2_dx_leaf {
883 __u8 dl_signature[8];/* Signature for verification */
884 struct ocfs2_block_check dl_check; /* Error checking */
885 __le64 dl_blkno; /* Offset on disk, in blocks */
886 __le32 dl_fs_generation;/* Must match super block */
887 __le32 dl_reserved0;
888 __le64 dl_reserved1;
889 struct ocfs2_dx_entry_list dl_list;
890};
891
Mark Fasheh87d35a72008-12-10 17:36:25 -0800892/*
Joel Becker4cbe4242010-04-13 14:26:12 +0800893 * Largest bitmap for a block (suballocator) group in bytes. This limit
894 * does not affect cluster groups (global allocator). Cluster group
895 * bitmaps run to the end of the block.
896 */
897#define OCFS2_MAX_BG_BITMAP_SIZE 256
898
899/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800900 * On disk allocator group structure for OCFS2
901 */
902struct ocfs2_group_desc
903{
904/*00*/ __u8 bg_signature[8]; /* Signature for validation */
905 __le16 bg_size; /* Size of included bitmap in
906 bytes. */
907 __le16 bg_bits; /* Bits represented by this
908 group. */
909 __le16 bg_free_bits_count; /* Free bits count */
910 __le16 bg_chain; /* What chain I am in. */
911/*10*/ __le32 bg_generation;
912 __le32 bg_reserved1;
913 __le64 bg_next_group; /* Next group in my list, in
914 blocks */
915/*20*/ __le64 bg_parent_dinode; /* dinode which owns me, in
916 blocks */
917 __le64 bg_blkno; /* Offset on disk, in blocks */
Joel Beckerab552d52008-10-16 17:50:30 -0700918/*30*/ struct ocfs2_block_check bg_check; /* Error checking */
919 __le64 bg_reserved2;
Joel Becker4cbe4242010-04-13 14:26:12 +0800920/*40*/ union {
921 __u8 bg_bitmap[0];
922 struct {
923 /*
924 * Block groups may be discontiguous when
925 * OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG is set.
926 * The extents of a discontigous block group are
927 * stored in bg_list. It is a flat list.
928 * l_tree_depth must always be zero. A
929 * discontiguous group is signified by a non-zero
930 * bg_list->l_next_free_rec. Only block groups
931 * can be discontiguous; Cluster groups cannot.
932 * We've never made a block group with more than
933 * 2048 blocks (256 bytes of bg_bitmap). This
934 * codifies that limit so that we can fit bg_list.
935 * bg_size of a discontiguous block group will
936 * be 256 to match bg_bitmap_filler.
937 */
938 __u8 bg_bitmap_filler[OCFS2_MAX_BG_BITMAP_SIZE];
939/*140*/ struct ocfs2_extent_list bg_list;
940 };
941 };
942/* Actual on-disk size is one block */
Mark Fashehccd979b2005-12-15 14:31:24 -0800943};
944
Tao Ma721f69c2009-08-18 11:17:49 +0800945struct ocfs2_refcount_rec {
946/*00*/ __le64 r_cpos; /* Physical offset, in clusters */
947 __le32 r_clusters; /* Clusters covered by this extent */
948 __le32 r_refcount; /* Reference count of this extent */
949/*10*/
950};
Tao Mae73a8192009-08-11 14:33:14 +0800951#define OCFS2_32BIT_POS_MASK (0xffffffffULL)
Tao Ma721f69c2009-08-18 11:17:49 +0800952
953#define OCFS2_REFCOUNT_LEAF_FL (0x00000001)
954#define OCFS2_REFCOUNT_TREE_FL (0x00000002)
955
956struct ocfs2_refcount_list {
957/*00*/ __le16 rl_count; /* Maximum number of entries possible
958 in rl_records */
959 __le16 rl_used; /* Current number of used records */
960 __le32 rl_reserved2;
961 __le64 rl_reserved1; /* Pad to sizeof(ocfs2_refcount_record) */
962/*10*/ struct ocfs2_refcount_rec rl_recs[0]; /* Refcount records */
963};
964
965
966struct ocfs2_refcount_block {
967/*00*/ __u8 rf_signature[8]; /* Signature for verification */
968 __le16 rf_suballoc_slot; /* Slot suballocator this block
969 belongs to */
970 __le16 rf_suballoc_bit; /* Bit offset in suballocator
971 block group */
972 __le32 rf_fs_generation; /* Must match superblock */
973/*10*/ __le64 rf_blkno; /* Offset on disk, in blocks */
974 __le64 rf_parent; /* Parent block, only valid if
975 OCFS2_REFCOUNT_LEAF_FL is set in
976 rf_flags */
977/*20*/ struct ocfs2_block_check rf_check; /* Error checking */
978 __le64 rf_last_eb_blk; /* Pointer to last extent block */
979/*30*/ __le32 rf_count; /* Number of inodes sharing this
980 refcount tree */
981 __le32 rf_flags; /* See the flags above */
982 __le32 rf_clusters; /* clusters covered by refcount tree. */
983 __le32 rf_cpos; /* cluster offset in refcount tree.*/
984/*40*/ __le32 rf_generation; /* generation number. all be the same
985 * for the same refcount tree. */
986 __le32 rf_reserved0;
Joel Becker9cbc0122010-03-26 10:07:42 +0800987 __le64 rf_suballoc_loc; /* Suballocator block group this
988 refcount block belongs to. Only
989 valid if allocated from a
990 discontiguous block group */
991/*50*/ __le64 rf_reserved1[6];
Tao Ma721f69c2009-08-18 11:17:49 +0800992/*80*/ union {
993 struct ocfs2_refcount_list rf_records; /* List of refcount
994 records */
995 struct ocfs2_extent_list rf_list; /* Extent record list,
996 only valid if
997 OCFS2_REFCOUNT_TREE_FL
998 is set in rf_flags */
999 };
1000/* Actual on-disk size is one block */
1001};
1002
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001003/*
1004 * On disk extended attribute structure for OCFS2.
1005 */
1006
1007/*
1008 * ocfs2_xattr_entry indicates one extend attribute.
1009 *
1010 * Note that it can be stored in inode, one block or one xattr bucket.
1011 */
1012struct ocfs2_xattr_entry {
1013 __le32 xe_name_hash; /* hash value of xattr prefix+suffix. */
Tao Ma8573f792008-10-24 22:24:17 +08001014 __le16 xe_name_offset; /* byte offset from the 1st entry in the
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001015 local xattr storage(inode, xattr block or
1016 xattr bucket). */
1017 __u8 xe_name_len; /* xattr name len, does't include prefix. */
Tao Ma8573f792008-10-24 22:24:17 +08001018 __u8 xe_type; /* the low 7 bits indicate the name prefix
1019 * type and the highest bit indicates whether
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001020 * the EA is stored in the local storage. */
1021 __le64 xe_value_size; /* real xattr value length. */
1022};
1023
1024/*
1025 * On disk structure for xattr header.
1026 *
1027 * One ocfs2_xattr_header describes how many ocfs2_xattr_entry records in
1028 * the local xattr storage.
1029 */
1030struct ocfs2_xattr_header {
1031 __le16 xh_count; /* contains the count of how
1032 many records are in the
1033 local xattr storage. */
Tao Ma0c044f02008-08-18 17:38:50 +08001034 __le16 xh_free_start; /* current offset for storing
1035 xattr. */
1036 __le16 xh_name_value_len; /* total length of name/value
1037 length in this bucket. */
Tao Ma8573f792008-10-24 22:24:17 +08001038 __le16 xh_num_buckets; /* Number of xattr buckets
1039 in this extent record,
1040 only valid in the first
1041 bucket. */
Joel Beckerab552d52008-10-16 17:50:30 -07001042 struct ocfs2_block_check xh_check; /* Error checking
1043 (Note, this is only
1044 used for xattr
1045 buckets. A block uses
1046 xb_check and sets
1047 this field to zero.) */
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001048 struct ocfs2_xattr_entry xh_entries[0]; /* xattr entry list. */
1049};
1050
1051/*
1052 * On disk structure for xattr value root.
1053 *
Tao Ma8573f792008-10-24 22:24:17 +08001054 * When an xattr's value is large enough, it is stored in an external
1055 * b-tree like file data. The xattr value root points to this structure.
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001056 */
1057struct ocfs2_xattr_value_root {
1058/*00*/ __le32 xr_clusters; /* clusters covered by xattr value. */
1059 __le32 xr_reserved0;
1060 __le64 xr_last_eb_blk; /* Pointer to last extent block */
1061/*10*/ struct ocfs2_extent_list xr_list; /* Extent record list */
1062};
1063
1064/*
1065 * On disk structure for xattr tree root.
1066 *
1067 * It is used when there are too many extended attributes for one file. These
1068 * attributes will be organized and stored in an indexed-btree.
1069 */
1070struct ocfs2_xattr_tree_root {
1071/*00*/ __le32 xt_clusters; /* clusters covered by xattr. */
1072 __le32 xt_reserved0;
1073 __le64 xt_last_eb_blk; /* Pointer to last extent block */
1074/*10*/ struct ocfs2_extent_list xt_list; /* Extent record list */
1075};
1076
Tiger Yangcf1d6c72008-08-18 17:11:00 +08001077#define OCFS2_XATTR_INDEXED 0x1
1078#define OCFS2_HASH_SHIFT 5
1079#define OCFS2_XATTR_ROUND 3
1080#define OCFS2_XATTR_SIZE(size) (((size) + OCFS2_XATTR_ROUND) & \
1081 ~(OCFS2_XATTR_ROUND))
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001082
Tao Ma0c044f02008-08-18 17:38:50 +08001083#define OCFS2_XATTR_BUCKET_SIZE 4096
1084#define OCFS2_XATTR_MAX_BLOCKS_PER_BUCKET (OCFS2_XATTR_BUCKET_SIZE \
1085 / OCFS2_MIN_BLOCKSIZE)
1086
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001087/*
1088 * On disk structure for xattr block.
1089 */
1090struct ocfs2_xattr_block {
1091/*00*/ __u8 xb_signature[8]; /* Signature for verification */
1092 __le16 xb_suballoc_slot; /* Slot suballocator this
1093 block belongs to. */
1094 __le16 xb_suballoc_bit; /* Bit offset in suballocator
1095 block group */
1096 __le32 xb_fs_generation; /* Must match super block */
1097/*10*/ __le64 xb_blkno; /* Offset on disk, in blocks */
Joel Beckerab552d52008-10-16 17:50:30 -07001098 struct ocfs2_block_check xb_check; /* Error checking */
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001099/*20*/ __le16 xb_flags; /* Indicates whether this block contains
1100 real xattr or a xattr tree. */
1101 __le16 xb_reserved0;
1102 __le32 xb_reserved1;
Joel Becker9cbc0122010-03-26 10:07:42 +08001103 __le64 xb_suballoc_loc; /* Suballocator block group this
1104 xattr block belongs to. Only
1105 valid if allocated from a
1106 discontiguous block group */
Tao Ma5a7bc8e2008-08-18 17:38:46 +08001107/*30*/ union {
1108 struct ocfs2_xattr_header xb_header; /* xattr header if this
1109 block contains xattr */
1110 struct ocfs2_xattr_tree_root xb_root;/* xattr tree root if this
1111 block cotains xattr
1112 tree. */
1113 } xb_attrs;
1114};
1115
1116#define OCFS2_XATTR_ENTRY_LOCAL 0x80
1117#define OCFS2_XATTR_TYPE_MASK 0x7F
1118static inline void ocfs2_xattr_set_local(struct ocfs2_xattr_entry *xe,
1119 int local)
1120{
1121 if (local)
1122 xe->xe_type |= OCFS2_XATTR_ENTRY_LOCAL;
1123 else
1124 xe->xe_type &= ~OCFS2_XATTR_ENTRY_LOCAL;
1125}
1126
1127static inline int ocfs2_xattr_is_local(struct ocfs2_xattr_entry *xe)
1128{
1129 return xe->xe_type & OCFS2_XATTR_ENTRY_LOCAL;
1130}
1131
1132static inline void ocfs2_xattr_set_type(struct ocfs2_xattr_entry *xe, int type)
1133{
1134 xe->xe_type |= type & OCFS2_XATTR_TYPE_MASK;
1135}
1136
1137static inline int ocfs2_xattr_get_type(struct ocfs2_xattr_entry *xe)
1138{
1139 return xe->xe_type & OCFS2_XATTR_TYPE_MASK;
1140}
1141
Jan Kara9e33d692008-08-25 19:56:50 +02001142/*
1143 * On disk structures for global quota file
1144 */
1145
1146/* Magic numbers and known versions for global quota files */
1147#define OCFS2_GLOBAL_QMAGICS {\
1148 0x0cf52470, /* USRQUOTA */ \
1149 0x0cf52471 /* GRPQUOTA */ \
1150}
1151
1152#define OCFS2_GLOBAL_QVERSIONS {\
1153 0, \
1154 0, \
1155}
1156
1157
1158/* Each block of each quota file has a certain fixed number of bytes reserved
1159 * for OCFS2 internal use at its end. OCFS2 can use it for things like
1160 * checksums, etc. */
1161#define OCFS2_QBLK_RESERVED_SPACE 8
1162
1163/* Generic header of all quota files */
1164struct ocfs2_disk_dqheader {
1165 __le32 dqh_magic; /* Magic number identifying file */
1166 __le32 dqh_version; /* Quota format version */
1167};
1168
1169#define OCFS2_GLOBAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
1170
1171/* Information header of global quota file (immediately follows the generic
1172 * header) */
1173struct ocfs2_global_disk_dqinfo {
1174/*00*/ __le32 dqi_bgrace; /* Grace time for space softlimit excess */
1175 __le32 dqi_igrace; /* Grace time for inode softlimit excess */
1176 __le32 dqi_syncms; /* Time after which we sync local changes to
1177 * global quota file */
1178 __le32 dqi_blocks; /* Number of blocks in quota file */
1179/*10*/ __le32 dqi_free_blk; /* First free block in quota file */
1180 __le32 dqi_free_entry; /* First block with free dquot entry in quota
1181 * file */
1182};
1183
1184/* Structure with global user / group information. We reserve some space
1185 * for future use. */
1186struct ocfs2_global_disk_dqblk {
1187/*00*/ __le32 dqb_id; /* ID the structure belongs to */
1188 __le32 dqb_use_count; /* Number of nodes having reference to this structure */
1189 __le64 dqb_ihardlimit; /* absolute limit on allocated inodes */
1190/*10*/ __le64 dqb_isoftlimit; /* preferred inode limit */
1191 __le64 dqb_curinodes; /* current # allocated inodes */
1192/*20*/ __le64 dqb_bhardlimit; /* absolute limit on disk space */
1193 __le64 dqb_bsoftlimit; /* preferred limit on disk space */
1194/*30*/ __le64 dqb_curspace; /* current space occupied */
1195 __le64 dqb_btime; /* time limit for excessive disk use */
1196/*40*/ __le64 dqb_itime; /* time limit for excessive inode use */
1197 __le64 dqb_pad1;
1198/*50*/ __le64 dqb_pad2;
1199};
1200
1201/*
1202 * On-disk structures for local quota file
1203 */
1204
1205/* Magic numbers and known versions for local quota files */
1206#define OCFS2_LOCAL_QMAGICS {\
1207 0x0cf524c0, /* USRQUOTA */ \
1208 0x0cf524c1 /* GRPQUOTA */ \
1209}
1210
1211#define OCFS2_LOCAL_QVERSIONS {\
1212 0, \
1213 0, \
1214}
1215
1216/* Quota flags in dqinfo header */
1217#define OLQF_CLEAN 0x0001 /* Quota file is empty (this should be after\
1218 * quota has been cleanly turned off) */
1219
1220#define OCFS2_LOCAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
1221
1222/* Information header of local quota file (immediately follows the generic
1223 * header) */
1224struct ocfs2_local_disk_dqinfo {
1225 __le32 dqi_flags; /* Flags for quota file */
1226 __le32 dqi_chunks; /* Number of chunks of quota structures
1227 * with a bitmap */
1228 __le32 dqi_blocks; /* Number of blocks allocated for quota file */
1229};
1230
1231/* Header of one chunk of a quota file */
1232struct ocfs2_local_disk_chunk {
1233 __le32 dqc_free; /* Number of free entries in the bitmap */
Coly Li93654542009-12-06 22:38:53 +08001234 __u8 dqc_bitmap[0]; /* Bitmap of entries in the corresponding
Jan Kara9e33d692008-08-25 19:56:50 +02001235 * chunk of quota file */
1236};
1237
1238/* One entry in local quota file */
1239struct ocfs2_local_disk_dqblk {
1240/*00*/ __le64 dqb_id; /* id this quota applies to */
1241 __le64 dqb_spacemod; /* Change in the amount of used space */
1242/*10*/ __le64 dqb_inodemod; /* Change in the amount of used inodes */
1243};
1244
Joel Beckerab552d52008-10-16 17:50:30 -07001245
1246/*
1247 * The quota trailer lives at the end of each quota block.
1248 */
1249
1250struct ocfs2_disk_dqtrailer {
1251/*00*/ struct ocfs2_block_check dq_check; /* Error checking */
1252/*08*/ /* Cannot be larger than OCFS2_QBLK_RESERVED_SPACE */
1253};
1254
1255static inline struct ocfs2_disk_dqtrailer *ocfs2_block_dqtrailer(int blocksize,
1256 void *buf)
1257{
1258 char *ptr = buf;
1259 ptr += blocksize - OCFS2_QBLK_RESERVED_SPACE;
1260
1261 return (struct ocfs2_disk_dqtrailer *)ptr;
1262}
1263
Mark Fashehccd979b2005-12-15 14:31:24 -08001264#ifdef __KERNEL__
1265static inline int ocfs2_fast_symlink_chars(struct super_block *sb)
1266{
1267 return sb->s_blocksize -
1268 offsetof(struct ocfs2_dinode, id2.i_symlink);
1269}
1270
Tiger Yangfdd77702008-08-18 17:08:55 +08001271static inline int ocfs2_max_inline_data_with_xattr(struct super_block *sb,
1272 struct ocfs2_dinode *di)
1273{
1274 unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
1275
1276 if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
1277 return sb->s_blocksize -
1278 offsetof(struct ocfs2_dinode, id2.i_data.id_data) -
1279 xattrsize;
1280 else
1281 return sb->s_blocksize -
1282 offsetof(struct ocfs2_dinode, id2.i_data.id_data);
1283}
1284
Mark Fashehccd979b2005-12-15 14:31:24 -08001285static inline int ocfs2_extent_recs_per_inode(struct super_block *sb)
1286{
1287 int size;
1288
1289 size = sb->s_blocksize -
1290 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1291
1292 return size / sizeof(struct ocfs2_extent_rec);
1293}
1294
Tiger Yangfdd77702008-08-18 17:08:55 +08001295static inline int ocfs2_extent_recs_per_inode_with_xattr(
1296 struct super_block *sb,
1297 struct ocfs2_dinode *di)
1298{
1299 int size;
1300 unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
1301
1302 if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
1303 size = sb->s_blocksize -
1304 offsetof(struct ocfs2_dinode, id2.i_list.l_recs) -
1305 xattrsize;
1306 else
1307 size = sb->s_blocksize -
1308 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1309
1310 return size / sizeof(struct ocfs2_extent_rec);
1311}
1312
Mark Fasheh9b7895e2008-11-12 16:27:44 -08001313static inline int ocfs2_extent_recs_per_dx_root(struct super_block *sb)
1314{
1315 int size;
1316
1317 size = sb->s_blocksize -
1318 offsetof(struct ocfs2_dx_root_block, dr_list.l_recs);
1319
1320 return size / sizeof(struct ocfs2_extent_rec);
1321}
1322
Mark Fashehccd979b2005-12-15 14:31:24 -08001323static inline int ocfs2_chain_recs_per_inode(struct super_block *sb)
1324{
1325 int size;
1326
1327 size = sb->s_blocksize -
1328 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
1329
1330 return size / sizeof(struct ocfs2_chain_rec);
1331}
1332
1333static inline u16 ocfs2_extent_recs_per_eb(struct super_block *sb)
1334{
1335 int size;
1336
1337 size = sb->s_blocksize -
1338 offsetof(struct ocfs2_extent_block, h_list.l_recs);
1339
1340 return size / sizeof(struct ocfs2_extent_rec);
1341}
1342
Joel Becker798db352010-04-13 14:26:32 +08001343static inline u16 ocfs2_extent_recs_per_gd(struct super_block *sb)
1344{
1345 int size;
1346
1347 size = sb->s_blocksize -
1348 offsetof(struct ocfs2_group_desc, bg_list.l_recs);
1349
1350 return size / sizeof(struct ocfs2_extent_rec);
1351}
1352
Mark Fasheh9b7895e2008-11-12 16:27:44 -08001353static inline int ocfs2_dx_entries_per_leaf(struct super_block *sb)
1354{
1355 int size;
1356
1357 size = sb->s_blocksize -
1358 offsetof(struct ocfs2_dx_leaf, dl_list.de_entries);
1359
1360 return size / sizeof(struct ocfs2_dx_entry);
1361}
1362
Mark Fasheh4ed8a6b2008-11-24 17:02:08 -08001363static inline int ocfs2_dx_entries_per_root(struct super_block *sb)
1364{
1365 int size;
1366
1367 size = sb->s_blocksize -
1368 offsetof(struct ocfs2_dx_root_block, dr_entries.de_entries);
1369
1370 return size / sizeof(struct ocfs2_dx_entry);
1371}
1372
Mark Fashehccd979b2005-12-15 14:31:24 -08001373static inline u16 ocfs2_local_alloc_size(struct super_block *sb)
1374{
1375 u16 size;
1376
1377 size = sb->s_blocksize -
1378 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
1379
1380 return size;
1381}
1382
Joel Becker4cbe4242010-04-13 14:26:12 +08001383static inline int ocfs2_group_bitmap_size(struct super_block *sb,
Tao Ma85718822010-04-13 14:38:06 +08001384 int suballocator,
1385 u32 feature_incompat)
Mark Fashehccd979b2005-12-15 14:31:24 -08001386{
Tao Ma85718822010-04-13 14:38:06 +08001387 int size = sb->s_blocksize -
1388 offsetof(struct ocfs2_group_desc, bg_bitmap);
Mark Fashehccd979b2005-12-15 14:31:24 -08001389
Tao Ma85718822010-04-13 14:38:06 +08001390 /*
1391 * The cluster allocator uses the entire block. Suballocators have
1392 * never used more than OCFS2_MAX_BG_BITMAP_SIZE. Unfortunately, older
1393 * code expects bg_size set to the maximum. Thus we must keep
1394 * bg_size as-is unless discontig_bg is enabled.
1395 */
1396 if (suballocator &&
1397 (feature_incompat & OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG))
Joel Becker4cbe4242010-04-13 14:26:12 +08001398 size = OCFS2_MAX_BG_BITMAP_SIZE;
Mark Fashehccd979b2005-12-15 14:31:24 -08001399
1400 return size;
1401}
1402
1403static inline int ocfs2_truncate_recs_per_inode(struct super_block *sb)
1404{
1405 int size;
1406
1407 size = sb->s_blocksize -
1408 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
1409
1410 return size / sizeof(struct ocfs2_truncate_rec);
1411}
Mark Fasheh50af94b2007-01-21 14:44:59 -08001412
1413static inline u64 ocfs2_backup_super_blkno(struct super_block *sb, int index)
1414{
1415 u64 offset = OCFS2_BACKUP_SB_START;
1416
1417 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
1418 offset <<= (2 * index);
Mark Fasheha8a75a22007-01-26 10:46:59 -08001419 offset >>= sb->s_blocksize_bits;
Mark Fasheh50af94b2007-01-21 14:44:59 -08001420 return offset;
1421 }
1422
1423 return 0;
1424
1425}
Tao Ma0c044f02008-08-18 17:38:50 +08001426
1427static inline u16 ocfs2_xattr_recs_per_xb(struct super_block *sb)
1428{
1429 int size;
1430
1431 size = sb->s_blocksize -
1432 offsetof(struct ocfs2_xattr_block,
1433 xb_attrs.xb_root.xt_list.l_recs);
1434
1435 return size / sizeof(struct ocfs2_extent_rec);
1436}
Tao Ma721f69c2009-08-18 11:17:49 +08001437
1438static inline u16 ocfs2_extent_recs_per_rb(struct super_block *sb)
1439{
1440 int size;
1441
1442 size = sb->s_blocksize -
1443 offsetof(struct ocfs2_refcount_block, rf_list.l_recs);
1444
1445 return size / sizeof(struct ocfs2_extent_rec);
1446}
1447
1448static inline u16 ocfs2_refcount_recs_per_rb(struct super_block *sb)
1449{
1450 int size;
1451
1452 size = sb->s_blocksize -
1453 offsetof(struct ocfs2_refcount_block, rf_records.rl_recs);
1454
1455 return size / sizeof(struct ocfs2_refcount_rec);
1456}
Tao Mae73a8192009-08-11 14:33:14 +08001457
1458static inline u32
1459ocfs2_get_ref_rec_low_cpos(const struct ocfs2_refcount_rec *rec)
1460{
1461 return le64_to_cpu(rec->r_cpos) & OCFS2_32BIT_POS_MASK;
1462}
Mark Fashehccd979b2005-12-15 14:31:24 -08001463#else
1464static inline int ocfs2_fast_symlink_chars(int blocksize)
1465{
1466 return blocksize - offsetof(struct ocfs2_dinode, id2.i_symlink);
1467}
1468
Tao Ma1097df32010-01-20 11:31:11 +08001469static inline int ocfs2_max_inline_data_with_xattr(int blocksize,
1470 struct ocfs2_dinode *di)
Mark Fasheh15b1e362007-09-07 13:58:15 -07001471{
Tao Ma1097df32010-01-20 11:31:11 +08001472 if (di && (di->i_dyn_features & OCFS2_INLINE_XATTR_FL))
1473 return blocksize -
1474 offsetof(struct ocfs2_dinode, id2.i_data.id_data) -
1475 di->i_xattr_inline_size;
1476 else
1477 return blocksize -
1478 offsetof(struct ocfs2_dinode, id2.i_data.id_data);
Mark Fasheh15b1e362007-09-07 13:58:15 -07001479}
1480
Mark Fashehccd979b2005-12-15 14:31:24 -08001481static inline int ocfs2_extent_recs_per_inode(int blocksize)
1482{
1483 int size;
1484
1485 size = blocksize -
1486 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1487
1488 return size / sizeof(struct ocfs2_extent_rec);
1489}
1490
1491static inline int ocfs2_chain_recs_per_inode(int blocksize)
1492{
1493 int size;
1494
1495 size = blocksize -
1496 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
1497
1498 return size / sizeof(struct ocfs2_chain_rec);
1499}
1500
1501static inline int ocfs2_extent_recs_per_eb(int blocksize)
1502{
1503 int size;
1504
1505 size = blocksize -
1506 offsetof(struct ocfs2_extent_block, h_list.l_recs);
1507
1508 return size / sizeof(struct ocfs2_extent_rec);
1509}
1510
Joel Becker798db352010-04-13 14:26:32 +08001511static inline int ocfs2_extent_recs_per_gd(int blocksize)
1512{
1513 int size;
1514
1515 size = blocksize -
1516 offsetof(struct ocfs2_group_desc, bg_list.l_recs);
1517
1518 return size / sizeof(struct ocfs2_extent_rec);
1519}
1520
Mark Fashehccd979b2005-12-15 14:31:24 -08001521static inline int ocfs2_local_alloc_size(int blocksize)
1522{
1523 int size;
1524
1525 size = blocksize -
1526 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
1527
1528 return size;
1529}
1530
Tao Ma85718822010-04-13 14:38:06 +08001531static inline int ocfs2_group_bitmap_size(int blocksize,
1532 int suballocator,
1533 uint32_t feature_incompat)
Mark Fashehccd979b2005-12-15 14:31:24 -08001534{
Tao Ma85718822010-04-13 14:38:06 +08001535 int size = sb->s_blocksize -
1536 offsetof(struct ocfs2_group_desc, bg_bitmap);
Mark Fashehccd979b2005-12-15 14:31:24 -08001537
Tao Ma85718822010-04-13 14:38:06 +08001538 /*
1539 * The cluster allocator uses the entire block. Suballocators have
1540 * never used more than OCFS2_MAX_BG_BITMAP_SIZE. Unfortunately, older
1541 * code expects bg_size set to the maximum. Thus we must keep
1542 * bg_size as-is unless discontig_bg is enabled.
1543 */
1544 if (suballocator &&
1545 (feature_incompat & OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG))
Joel Becker4cbe4242010-04-13 14:26:12 +08001546 size = OCFS2_MAX_BG_BITMAP_SIZE;
Mark Fashehccd979b2005-12-15 14:31:24 -08001547
1548 return size;
1549}
1550
1551static inline int ocfs2_truncate_recs_per_inode(int blocksize)
1552{
1553 int size;
1554
1555 size = blocksize -
1556 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
1557
1558 return size / sizeof(struct ocfs2_truncate_rec);
1559}
Mark Fasheh50af94b2007-01-21 14:44:59 -08001560
1561static inline uint64_t ocfs2_backup_super_blkno(int blocksize, int index)
1562{
1563 uint64_t offset = OCFS2_BACKUP_SB_START;
1564
1565 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
1566 offset <<= (2 * index);
1567 offset /= blocksize;
1568 return offset;
1569 }
1570
1571 return 0;
1572}
Tao Ma0c044f02008-08-18 17:38:50 +08001573
1574static inline int ocfs2_xattr_recs_per_xb(int blocksize)
1575{
1576 int size;
1577
1578 size = blocksize -
1579 offsetof(struct ocfs2_xattr_block,
1580 xb_attrs.xb_root.xt_list.l_recs);
1581
1582 return size / sizeof(struct ocfs2_extent_rec);
1583}
Mark Fashehccd979b2005-12-15 14:31:24 -08001584#endif /* __KERNEL__ */
1585
1586
1587static inline int ocfs2_system_inode_is_global(int type)
1588{
1589 return ((type >= 0) &&
1590 (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE));
1591}
1592
1593static inline int ocfs2_sprintf_system_inode_name(char *buf, int len,
1594 int type, int slot)
1595{
1596 int chars;
1597
1598 /*
1599 * Global system inodes can only have one copy. Everything
1600 * after OCFS2_LAST_GLOBAL_SYSTEM_INODE in the system inode
1601 * list has a copy per slot.
1602 */
1603 if (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE)
Joel Beckerfe9f3872008-06-12 22:39:18 -07001604 chars = snprintf(buf, len, "%s",
Mark Fashehccd979b2005-12-15 14:31:24 -08001605 ocfs2_system_inodes[type].si_name);
1606 else
1607 chars = snprintf(buf, len,
1608 ocfs2_system_inodes[type].si_name,
1609 slot);
1610
1611 return chars;
1612}
1613
1614static inline void ocfs2_set_de_type(struct ocfs2_dir_entry *de,
1615 umode_t mode)
1616{
1617 de->file_type = ocfs2_type_by_mode[(mode & S_IFMT)>>S_SHIFT];
1618}
1619
Tao Maaf2bf0d2010-05-17 15:14:17 +08001620static inline int ocfs2_gd_is_discontig(struct ocfs2_group_desc *gd)
1621{
1622 if ((offsetof(struct ocfs2_group_desc, bg_bitmap) +
1623 le16_to_cpu(gd->bg_size)) !=
1624 offsetof(struct ocfs2_group_desc, bg_list))
1625 return 0;
1626 /*
1627 * Only valid to check l_next_free_rec if
1628 * bg_bitmap + bg_size == bg_list.
1629 */
1630 if (!gd->bg_list.l_next_free_rec)
1631 return 0;
1632 return 1;
1633}
Mark Fashehccd979b2005-12-15 14:31:24 -08001634#endif /* _OCFS2_FS_H */
1635