blob: 036eb03950a36715d584c9ff9aceda29a23a6bf5 [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"
Mark Fashehccd979b2005-12-15 14:31:24 -080071
72/* Compatibility flags */
73#define OCFS2_HAS_COMPAT_FEATURE(sb,mask) \
74 ( OCFS2_SB(sb)->s_feature_compat & (mask) )
75#define OCFS2_HAS_RO_COMPAT_FEATURE(sb,mask) \
76 ( OCFS2_SB(sb)->s_feature_ro_compat & (mask) )
77#define OCFS2_HAS_INCOMPAT_FEATURE(sb,mask) \
78 ( OCFS2_SB(sb)->s_feature_incompat & (mask) )
79#define OCFS2_SET_COMPAT_FEATURE(sb,mask) \
80 OCFS2_SB(sb)->s_feature_compat |= (mask)
81#define OCFS2_SET_RO_COMPAT_FEATURE(sb,mask) \
82 OCFS2_SB(sb)->s_feature_ro_compat |= (mask)
83#define OCFS2_SET_INCOMPAT_FEATURE(sb,mask) \
84 OCFS2_SB(sb)->s_feature_incompat |= (mask)
85#define OCFS2_CLEAR_COMPAT_FEATURE(sb,mask) \
86 OCFS2_SB(sb)->s_feature_compat &= ~(mask)
87#define OCFS2_CLEAR_RO_COMPAT_FEATURE(sb,mask) \
88 OCFS2_SB(sb)->s_feature_ro_compat &= ~(mask)
89#define OCFS2_CLEAR_INCOMPAT_FEATURE(sb,mask) \
90 OCFS2_SB(sb)->s_feature_incompat &= ~(mask)
91
Joel Beckera9772182008-12-16 18:10:18 -080092#define OCFS2_FEATURE_COMPAT_SUPP (OCFS2_FEATURE_COMPAT_BACKUP_SB \
93 | OCFS2_FEATURE_COMPAT_JBD2_SB)
Mark Fashehdcd05382007-01-16 11:32:23 -080094#define OCFS2_FEATURE_INCOMPAT_SUPP (OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT \
Mark Fasheh15b1e362007-09-07 13:58:15 -070095 | OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC \
Joel Becker386a2ef2008-02-01 12:06:54 -080096 | OCFS2_FEATURE_INCOMPAT_INLINE_DATA \
Joel Beckerb61817e2008-02-01 15:08:23 -080097 | OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP \
Tiger Yang8154da32008-08-18 17:11:46 +080098 | OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK \
Joel Becker9d28cfb2008-10-16 17:53:29 -070099 | OCFS2_FEATURE_INCOMPAT_XATTR \
100 | OCFS2_FEATURE_INCOMPAT_META_ECC)
Jan Kara19ece542008-08-21 20:13:17 +0200101#define OCFS2_FEATURE_RO_COMPAT_SUPP (OCFS2_FEATURE_RO_COMPAT_UNWRITTEN \
102 | OCFS2_FEATURE_RO_COMPAT_USRQUOTA \
103 | OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)
Mark Fashehccd979b2005-12-15 14:31:24 -0800104
105/*
106 * Heartbeat-only devices are missing journals and other files. The
107 * filesystem driver can't load them, but the library can. Never put
108 * this in OCFS2_FEATURE_INCOMPAT_SUPP, *ever*.
109 */
110#define OCFS2_FEATURE_INCOMPAT_HEARTBEAT_DEV 0x0002
111
Mark Fasheh89039012006-12-07 18:05:37 -0800112/*
113 * tunefs sets this incompat flag before starting the resize and clears it
114 * at the end. This flag protects users from inadvertently mounting the fs
115 * after an aborted run without fsck-ing.
116 */
117#define OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG 0x0004
Mark Fashehccd979b2005-12-15 14:31:24 -0800118
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800119/* Used to denote a non-clustered volume */
120#define OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT 0x0008
121
Mark Fasheh89039012006-12-07 18:05:37 -0800122/* Support for sparse allocation in b-trees */
123#define OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC 0x0010
124
Mark Fashehccd979b2005-12-15 14:31:24 -0800125/*
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700126 * Tunefs sets this incompat flag before starting an operation which
127 * would require cleanup on abort. This is done to protect users from
128 * inadvertently mounting the fs after an aborted run without
129 * fsck-ing.
130 *
131 * s_tunefs_flags on the super block describes precisely which
132 * operations were in progress.
133 */
134#define OCFS2_FEATURE_INCOMPAT_TUNEFS_INPROG 0x0020
135
Mark Fasheh15b1e362007-09-07 13:58:15 -0700136/* Support for data packed into inode blocks */
137#define OCFS2_FEATURE_INCOMPAT_INLINE_DATA 0x0040
138
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700139/*
Joel Beckerb61817e2008-02-01 15:08:23 -0800140 * Support for alternate, userspace cluster stacks. If set, the superblock
141 * field s_cluster_info contains a tag for the alternate stack in use as
142 * well as the name of the cluster being joined.
143 * mount.ocfs2 must pass in a matching stack name.
144 *
145 * If not set, the classic stack will be used. This is compatbile with
146 * all older versions.
147 */
148#define OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK 0x0080
149
Tiger Yang8154da32008-08-18 17:11:46 +0800150/* Support for the extended slot map */
151#define OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP 0x100
152
153/* Support for extended attributes */
154#define OCFS2_FEATURE_INCOMPAT_XATTR 0x0200
155
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800156/* Support for indexed directores */
157#define OCFS2_FEATURE_INCOMPAT_INDEXED_DIRS 0x0400
158
Joel Beckerab552d52008-10-16 17:50:30 -0700159/* Metadata checksum and error correction */
160#define OCFS2_FEATURE_INCOMPAT_META_ECC 0x0800
161
Joel Beckerb61817e2008-02-01 15:08:23 -0800162/*
Mark Fasheh50af94b2007-01-21 14:44:59 -0800163 * backup superblock flag is used to indicate that this volume
164 * has backup superblocks.
165 */
166#define OCFS2_FEATURE_COMPAT_BACKUP_SB 0x0001
167
Mark Fasheh328d5752007-06-18 10:48:04 -0700168/*
Joel Beckera9772182008-12-16 18:10:18 -0800169 * The filesystem will correctly handle journal feature bits.
170 */
171#define OCFS2_FEATURE_COMPAT_JBD2_SB 0x0002
172
173/*
Mark Fasheh328d5752007-06-18 10:48:04 -0700174 * Unwritten extents support.
175 */
176#define OCFS2_FEATURE_RO_COMPAT_UNWRITTEN 0x0001
177
Jan Kara1a224ad2008-08-20 15:43:36 +0200178/*
179 * Maintain quota information for this filesystem
180 */
181#define OCFS2_FEATURE_RO_COMPAT_USRQUOTA 0x0002
182#define OCFS2_FEATURE_RO_COMPAT_GRPQUOTA 0x0004
183
Mark Fasheh50af94b2007-01-21 14:44:59 -0800184/* The byte offset of the first backup block will be 1G.
185 * The following will be 4G, 16G, 64G, 256G and 1T.
186 */
187#define OCFS2_BACKUP_SB_START 1 << 30
188
189/* the max backup superblock nums */
190#define OCFS2_MAX_BACKUP_SUPERBLOCKS 6
191
192/*
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700193 * Flags on ocfs2_super_block.s_tunefs_flags
194 */
195#define OCFS2_TUNEFS_INPROG_REMOVE_SLOT 0x0001 /* Removing slots */
196
197/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800198 * Flags on ocfs2_dinode.i_flags
199 */
200#define OCFS2_VALID_FL (0x00000001) /* Inode is valid */
201#define OCFS2_UNUSED2_FL (0x00000002)
202#define OCFS2_ORPHANED_FL (0x00000004) /* On the orphan list */
203#define OCFS2_UNUSED3_FL (0x00000008)
204/* System inode flags */
205#define OCFS2_SYSTEM_FL (0x00000010) /* System inode */
206#define OCFS2_SUPER_BLOCK_FL (0x00000020) /* Super block */
207#define OCFS2_LOCAL_ALLOC_FL (0x00000040) /* Slot local alloc bitmap */
208#define OCFS2_BITMAP_FL (0x00000080) /* Allocation bitmap */
209#define OCFS2_JOURNAL_FL (0x00000100) /* Slot local journal */
210#define OCFS2_HEARTBEAT_FL (0x00000200) /* Heartbeat area */
211#define OCFS2_CHAIN_FL (0x00000400) /* Chain allocator */
212#define OCFS2_DEALLOC_FL (0x00000800) /* Truncate log */
Jan Kara1a224ad2008-08-20 15:43:36 +0200213#define OCFS2_QUOTA_FL (0x00001000) /* Quota file */
Mark Fashehccd979b2005-12-15 14:31:24 -0800214
Mark Fasheh15b1e362007-09-07 13:58:15 -0700215/*
216 * Flags on ocfs2_dinode.i_dyn_features
217 *
218 * These can change much more often than i_flags. When adding flags,
219 * keep in mind that i_dyn_features is only 16 bits wide.
220 */
221#define OCFS2_INLINE_DATA_FL (0x0001) /* Data stored in inode block */
222#define OCFS2_HAS_XATTR_FL (0x0002)
223#define OCFS2_INLINE_XATTR_FL (0x0004)
224#define OCFS2_INDEXED_DIR_FL (0x0008)
225
Herbert Poetzlca4d1472006-07-03 17:27:12 -0700226/* Inode attributes, keep in sync with EXT2 */
227#define OCFS2_SECRM_FL (0x00000001) /* Secure deletion */
228#define OCFS2_UNRM_FL (0x00000002) /* Undelete */
229#define OCFS2_COMPR_FL (0x00000004) /* Compress file */
230#define OCFS2_SYNC_FL (0x00000008) /* Synchronous updates */
231#define OCFS2_IMMUTABLE_FL (0x00000010) /* Immutable file */
232#define OCFS2_APPEND_FL (0x00000020) /* writes to file may only append */
233#define OCFS2_NODUMP_FL (0x00000040) /* do not dump file */
234#define OCFS2_NOATIME_FL (0x00000080) /* do not update atime */
235#define OCFS2_DIRSYNC_FL (0x00010000) /* dirsync behaviour (directories only) */
236
237#define OCFS2_FL_VISIBLE (0x000100FF) /* User visible flags */
238#define OCFS2_FL_MODIFIABLE (0x000100FF) /* User modifiable flags */
239
240/*
Mark Fashehe48edee2007-03-07 16:46:57 -0800241 * Extent record flags (e_node.leaf.flags)
242 */
243#define OCFS2_EXT_UNWRITTEN (0x01) /* Extent is allocated but
244 * unwritten */
245
246/*
Herbert Poetzlca4d1472006-07-03 17:27:12 -0700247 * ioctl commands
248 */
249#define OCFS2_IOC_GETFLAGS _IOR('f', 1, long)
250#define OCFS2_IOC_SETFLAGS _IOW('f', 2, long)
Mark Fasheh586d2322007-03-09 15:56:28 -0800251#define OCFS2_IOC32_GETFLAGS _IOR('f', 1, int)
252#define OCFS2_IOC32_SETFLAGS _IOW('f', 2, int)
Herbert Poetzlca4d1472006-07-03 17:27:12 -0700253
Mark Fashehccd979b2005-12-15 14:31:24 -0800254/*
Mark Fashehb2580102007-03-09 16:53:21 -0800255 * Space reservation / allocation / free ioctls and argument structure
256 * are designed to be compatible with XFS.
257 *
258 * ALLOCSP* and FREESP* are not and will never be supported, but are
259 * included here for completeness.
260 */
261struct ocfs2_space_resv {
262 __s16 l_type;
263 __s16 l_whence;
264 __s64 l_start;
265 __s64 l_len; /* len == 0 means until end of file */
266 __s32 l_sysid;
267 __u32 l_pid;
268 __s32 l_pad[4]; /* reserve area */
269};
270
271#define OCFS2_IOC_ALLOCSP _IOW ('X', 10, struct ocfs2_space_resv)
272#define OCFS2_IOC_FREESP _IOW ('X', 11, struct ocfs2_space_resv)
273#define OCFS2_IOC_RESVSP _IOW ('X', 40, struct ocfs2_space_resv)
274#define OCFS2_IOC_UNRESVSP _IOW ('X', 41, struct ocfs2_space_resv)
275#define OCFS2_IOC_ALLOCSP64 _IOW ('X', 36, struct ocfs2_space_resv)
276#define OCFS2_IOC_FREESP64 _IOW ('X', 37, struct ocfs2_space_resv)
277#define OCFS2_IOC_RESVSP64 _IOW ('X', 42, struct ocfs2_space_resv)
278#define OCFS2_IOC_UNRESVSP64 _IOW ('X', 43, struct ocfs2_space_resv)
279
Tao Ma7909f2b2007-12-18 15:47:25 +0800280/* Used to pass group descriptor data when online resize is done */
281struct ocfs2_new_group_input {
282 __u64 group; /* Group descriptor's blkno. */
283 __u32 clusters; /* Total number of clusters in this group */
284 __u32 frees; /* Total free clusters in this group */
285 __u16 chain; /* Chain for this group */
286 __u16 reserved1;
287 __u32 reserved2;
288};
289
Tao Mad6590722007-12-18 15:47:03 +0800290#define OCFS2_IOC_GROUP_EXTEND _IOW('o', 1, int)
Tao Ma7909f2b2007-12-18 15:47:25 +0800291#define OCFS2_IOC_GROUP_ADD _IOW('o', 2,struct ocfs2_new_group_input)
292#define OCFS2_IOC_GROUP_ADD64 _IOW('o', 3,struct ocfs2_new_group_input)
Tao Mad6590722007-12-18 15:47:03 +0800293
Mark Fashehb2580102007-03-09 16:53:21 -0800294/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800295 * Journal Flags (ocfs2_dinode.id1.journal1.i_flags)
296 */
297#define OCFS2_JOURNAL_DIRTY_FL (0x00000001) /* Journal needs recovery */
298
299/*
300 * superblock s_state flags
301 */
302#define OCFS2_ERROR_FS (0x00000001) /* FS saw errors */
303
304/* Limit of space in ocfs2_dir_entry */
305#define OCFS2_MAX_FILENAME_LEN 255
306
307/* Maximum slots on an ocfs2 file system */
308#define OCFS2_MAX_SLOTS 255
309
310/* Slot map indicator for an empty slot */
311#define OCFS2_INVALID_SLOT -1
312
313#define OCFS2_VOL_UUID_LEN 16
314#define OCFS2_MAX_VOL_LABEL_LEN 64
315
Joel Beckerb61817e2008-02-01 15:08:23 -0800316/* The alternate, userspace stack fields */
317#define OCFS2_STACK_LABEL_LEN 4
318#define OCFS2_CLUSTER_NAME_LEN 16
319
Mark Fashehccd979b2005-12-15 14:31:24 -0800320/* Journal limits (in bytes) */
321#define OCFS2_MIN_JOURNAL_SIZE (4 * 1024 * 1024)
Mark Fashehccd979b2005-12-15 14:31:24 -0800322
Sunil Mushran2fbe8d12007-12-20 14:58:11 -0800323/*
324 * Default local alloc size (in megabytes)
325 *
326 * The value chosen should be such that most allocations, including new
327 * block groups, use local alloc.
328 */
329#define OCFS2_DEFAULT_LOCAL_ALLOC_SIZE 8
330
Tiger Yangfdd77702008-08-18 17:08:55 +0800331/*
332 * Inline extended attribute size (in bytes)
333 * The value chosen should be aligned to 16 byte boundaries.
334 */
335#define OCFS2_MIN_XATTR_INLINE_SIZE 256
336
Mark Fashehccd979b2005-12-15 14:31:24 -0800337struct ocfs2_system_inode_info {
338 char *si_name;
339 int si_iflags;
340 int si_mode;
341};
342
343/* System file index */
344enum {
345 BAD_BLOCK_SYSTEM_INODE = 0,
346 GLOBAL_INODE_ALLOC_SYSTEM_INODE,
347 SLOT_MAP_SYSTEM_INODE,
348#define OCFS2_FIRST_ONLINE_SYSTEM_INODE SLOT_MAP_SYSTEM_INODE
349 HEARTBEAT_SYSTEM_INODE,
350 GLOBAL_BITMAP_SYSTEM_INODE,
Jan Kara1a224ad2008-08-20 15:43:36 +0200351 USER_QUOTA_SYSTEM_INODE,
352 GROUP_QUOTA_SYSTEM_INODE,
353#define OCFS2_LAST_GLOBAL_SYSTEM_INODE GROUP_QUOTA_SYSTEM_INODE
Mark Fashehccd979b2005-12-15 14:31:24 -0800354 ORPHAN_DIR_SYSTEM_INODE,
355 EXTENT_ALLOC_SYSTEM_INODE,
356 INODE_ALLOC_SYSTEM_INODE,
357 JOURNAL_SYSTEM_INODE,
358 LOCAL_ALLOC_SYSTEM_INODE,
359 TRUNCATE_LOG_SYSTEM_INODE,
Jan Kara1a224ad2008-08-20 15:43:36 +0200360 LOCAL_USER_QUOTA_SYSTEM_INODE,
361 LOCAL_GROUP_QUOTA_SYSTEM_INODE,
Mark Fashehccd979b2005-12-15 14:31:24 -0800362 NUM_SYSTEM_INODES
363};
364
365static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = {
366 /* Global system inodes (single copy) */
367 /* The first two are only used from userspace mfks/tunefs */
368 [BAD_BLOCK_SYSTEM_INODE] = { "bad_blocks", 0, S_IFREG | 0644 },
369 [GLOBAL_INODE_ALLOC_SYSTEM_INODE] = { "global_inode_alloc", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
370
371 /* These are used by the running filesystem */
372 [SLOT_MAP_SYSTEM_INODE] = { "slot_map", 0, S_IFREG | 0644 },
373 [HEARTBEAT_SYSTEM_INODE] = { "heartbeat", OCFS2_HEARTBEAT_FL, S_IFREG | 0644 },
374 [GLOBAL_BITMAP_SYSTEM_INODE] = { "global_bitmap", 0, S_IFREG | 0644 },
Jan Kara1a224ad2008-08-20 15:43:36 +0200375 [USER_QUOTA_SYSTEM_INODE] = { "aquota.user", OCFS2_QUOTA_FL, S_IFREG | 0644 },
376 [GROUP_QUOTA_SYSTEM_INODE] = { "aquota.group", OCFS2_QUOTA_FL, S_IFREG | 0644 },
Mark Fashehccd979b2005-12-15 14:31:24 -0800377
378 /* Slot-specific system inodes (one copy per slot) */
379 [ORPHAN_DIR_SYSTEM_INODE] = { "orphan_dir:%04d", 0, S_IFDIR | 0755 },
380 [EXTENT_ALLOC_SYSTEM_INODE] = { "extent_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
381 [INODE_ALLOC_SYSTEM_INODE] = { "inode_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
382 [JOURNAL_SYSTEM_INODE] = { "journal:%04d", OCFS2_JOURNAL_FL, S_IFREG | 0644 },
383 [LOCAL_ALLOC_SYSTEM_INODE] = { "local_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_LOCAL_ALLOC_FL, S_IFREG | 0644 },
Jan Kara1a224ad2008-08-20 15:43:36 +0200384 [TRUNCATE_LOG_SYSTEM_INODE] = { "truncate_log:%04d", OCFS2_DEALLOC_FL, S_IFREG | 0644 },
385 [LOCAL_USER_QUOTA_SYSTEM_INODE] = { "aquota.user:%04d", OCFS2_QUOTA_FL, S_IFREG | 0644 },
386 [LOCAL_GROUP_QUOTA_SYSTEM_INODE] = { "aquota.group:%04d", OCFS2_QUOTA_FL, S_IFREG | 0644 },
Mark Fashehccd979b2005-12-15 14:31:24 -0800387};
388
389/* Parameter passed from mount.ocfs2 to module */
390#define OCFS2_HB_NONE "heartbeat=none"
391#define OCFS2_HB_LOCAL "heartbeat=local"
392
393/*
394 * OCFS2 directory file types. Only the low 3 bits are used. The
395 * other bits are reserved for now.
396 */
397#define OCFS2_FT_UNKNOWN 0
398#define OCFS2_FT_REG_FILE 1
399#define OCFS2_FT_DIR 2
400#define OCFS2_FT_CHRDEV 3
401#define OCFS2_FT_BLKDEV 4
402#define OCFS2_FT_FIFO 5
403#define OCFS2_FT_SOCK 6
404#define OCFS2_FT_SYMLINK 7
405
406#define OCFS2_FT_MAX 8
407
408/*
409 * OCFS2_DIR_PAD defines the directory entries boundaries
410 *
411 * NOTE: It must be a multiple of 4
412 */
413#define OCFS2_DIR_PAD 4
414#define OCFS2_DIR_ROUND (OCFS2_DIR_PAD - 1)
415#define OCFS2_DIR_MEMBER_LEN offsetof(struct ocfs2_dir_entry, name)
416#define OCFS2_DIR_REC_LEN(name_len) (((name_len) + OCFS2_DIR_MEMBER_LEN + \
417 OCFS2_DIR_ROUND) & \
418 ~OCFS2_DIR_ROUND)
419
420#define OCFS2_LINK_MAX 32000
421
422#define S_SHIFT 12
423static unsigned char ocfs2_type_by_mode[S_IFMT >> S_SHIFT] = {
424 [S_IFREG >> S_SHIFT] = OCFS2_FT_REG_FILE,
425 [S_IFDIR >> S_SHIFT] = OCFS2_FT_DIR,
426 [S_IFCHR >> S_SHIFT] = OCFS2_FT_CHRDEV,
427 [S_IFBLK >> S_SHIFT] = OCFS2_FT_BLKDEV,
428 [S_IFIFO >> S_SHIFT] = OCFS2_FT_FIFO,
429 [S_IFSOCK >> S_SHIFT] = OCFS2_FT_SOCK,
430 [S_IFLNK >> S_SHIFT] = OCFS2_FT_SYMLINK,
431};
432
433
434/*
435 * Convenience casts
436 */
437#define OCFS2_RAW_SB(dinode) (&((dinode)->id2.i_super))
438
439/*
Joel Beckerab552d52008-10-16 17:50:30 -0700440 * Block checking structure. This is used in metadata to validate the
441 * contents. If OCFS2_FEATURE_INCOMPAT_META_ECC is not set, it is all
442 * zeros.
443 */
444struct ocfs2_block_check {
445/*00*/ __le32 bc_crc32e; /* 802.3 Ethernet II CRC32 */
446 __le16 bc_ecc; /* Single-error-correction parity vector.
447 This is a simple Hamming code dependant
448 on the blocksize. OCFS2's maximum
449 blocksize, 4K, requires 16 parity bits,
450 so we fit in __le16. */
451 __le16 bc_reserved1;
452/*08*/
453};
454
455/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800456 * On disk extent record for OCFS2
457 * It describes a range of clusters on disk.
Mark Fashehe48edee2007-03-07 16:46:57 -0800458 *
459 * Length fields are divided into interior and leaf node versions.
460 * This leaves room for a flags field (OCFS2_EXT_*) in the leaf nodes.
Mark Fashehccd979b2005-12-15 14:31:24 -0800461 */
462struct ocfs2_extent_rec {
463/*00*/ __le32 e_cpos; /* Offset into the file, in clusters */
Mark Fashehe48edee2007-03-07 16:46:57 -0800464 union {
465 __le32 e_int_clusters; /* Clusters covered by all children */
466 struct {
467 __le16 e_leaf_clusters; /* Clusters covered by this
468 extent */
469 __u8 e_reserved1;
470 __u8 e_flags; /* Extent flags */
471 };
472 };
Mark Fashehccd979b2005-12-15 14:31:24 -0800473 __le64 e_blkno; /* Physical disk offset, in blocks */
474/*10*/
475};
476
477struct ocfs2_chain_rec {
478 __le32 c_free; /* Number of free bits in this chain. */
479 __le32 c_total; /* Number of total bits in this chain */
480 __le64 c_blkno; /* Physical disk offset (blocks) of 1st group */
481};
482
483struct ocfs2_truncate_rec {
484 __le32 t_start; /* 1st cluster in this log */
485 __le32 t_clusters; /* Number of total clusters covered */
486};
487
488/*
489 * On disk extent list for OCFS2 (node in the tree). Note that this
490 * is contained inside ocfs2_dinode or ocfs2_extent_block, so the
491 * offsets are relative to ocfs2_dinode.id2.i_list or
492 * ocfs2_extent_block.h_list, respectively.
493 */
494struct ocfs2_extent_list {
495/*00*/ __le16 l_tree_depth; /* Extent tree depth from this
496 point. 0 means data extents
497 hang directly off this
Mark Fashehdcd05382007-01-16 11:32:23 -0800498 header (a leaf)
499 NOTE: The high 8 bits cannot be
500 used - tree_depth is never that big.
501 */
Mark Fashehccd979b2005-12-15 14:31:24 -0800502 __le16 l_count; /* Number of extent records */
503 __le16 l_next_free_rec; /* Next unused extent slot */
504 __le16 l_reserved1;
505 __le64 l_reserved2; /* Pad to
506 sizeof(ocfs2_extent_rec) */
507/*10*/ struct ocfs2_extent_rec l_recs[0]; /* Extent records */
508};
509
510/*
511 * On disk allocation chain list for OCFS2. Note that this is
512 * contained inside ocfs2_dinode, so the offsets are relative to
513 * ocfs2_dinode.id2.i_chain.
514 */
515struct ocfs2_chain_list {
516/*00*/ __le16 cl_cpg; /* Clusters per Block Group */
517 __le16 cl_bpc; /* Bits per cluster */
518 __le16 cl_count; /* Total chains in this list */
519 __le16 cl_next_free_rec; /* Next unused chain slot */
520 __le64 cl_reserved1;
521/*10*/ struct ocfs2_chain_rec cl_recs[0]; /* Chain records */
522};
523
524/*
525 * On disk deallocation log for OCFS2. Note that this is
526 * contained inside ocfs2_dinode, so the offsets are relative to
527 * ocfs2_dinode.id2.i_dealloc.
528 */
529struct ocfs2_truncate_log {
530/*00*/ __le16 tl_count; /* Total records in this log */
531 __le16 tl_used; /* Number of records in use */
532 __le32 tl_reserved1;
533/*08*/ struct ocfs2_truncate_rec tl_recs[0]; /* Truncate records */
534};
535
536/*
537 * On disk extent block (indirect block) for OCFS2
538 */
539struct ocfs2_extent_block
540{
541/*00*/ __u8 h_signature[8]; /* Signature for verification */
Joel Beckerab552d52008-10-16 17:50:30 -0700542 struct ocfs2_block_check h_check; /* Error checking */
Mark Fashehccd979b2005-12-15 14:31:24 -0800543/*10*/ __le16 h_suballoc_slot; /* Slot suballocator this
544 extent_header belongs to */
545 __le16 h_suballoc_bit; /* Bit offset in suballocator
546 block group */
547 __le32 h_fs_generation; /* Must match super block */
548 __le64 h_blkno; /* Offset on disk, in blocks */
549/*20*/ __le64 h_reserved3;
550 __le64 h_next_leaf_blk; /* Offset on disk, in blocks,
551 of next leaf header pointing
552 to data */
553/*30*/ struct ocfs2_extent_list h_list; /* Extent record list */
554/* Actual on-disk size is one block */
555};
556
557/*
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800558 * On disk slot map for OCFS2. This defines the contents of the "slot_map"
Joel Becker386a2ef2008-02-01 12:06:54 -0800559 * system file. A slot is valid if it contains a node number >= 0. The
560 * value -1 (0xFFFF) is OCFS2_INVALID_SLOT. This marks a slot empty.
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800561 */
562struct ocfs2_slot_map {
563/*00*/ __le16 sm_slots[0];
564/*
565 * Actual on-disk size is one block. OCFS2_MAX_SLOTS is 255,
566 * 255 * sizeof(__le16) == 512B, within the 512B block minimum blocksize.
567 */
568};
569
Joel Becker386a2ef2008-02-01 12:06:54 -0800570struct ocfs2_extended_slot {
571/*00*/ __u8 es_valid;
572 __u8 es_reserved1[3];
573 __le32 es_node_num;
574/*10*/
575};
576
577/*
578 * The extended slot map, used when OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP
579 * is set. It separates out the valid marker from the node number, and
580 * has room to grow. Unlike the old slot map, this format is defined by
581 * i_size.
582 */
583struct ocfs2_slot_map_extended {
584/*00*/ struct ocfs2_extended_slot se_slots[0];
585/*
586 * Actual size is i_size of the slot_map system file. It should
587 * match s_max_slots * sizeof(struct ocfs2_extended_slot)
588 */
589};
590
Joel Beckerb61817e2008-02-01 15:08:23 -0800591struct ocfs2_cluster_info {
592/*00*/ __u8 ci_stack[OCFS2_STACK_LABEL_LEN];
593 __le32 ci_reserved;
594/*08*/ __u8 ci_cluster[OCFS2_CLUSTER_NAME_LEN];
595/*18*/
596};
597
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800598/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800599 * On disk superblock for OCFS2
600 * Note that it is contained inside an ocfs2_dinode, so all offsets
601 * are relative to the start of ocfs2_dinode.id2.
602 */
603struct ocfs2_super_block {
604/*00*/ __le16 s_major_rev_level;
605 __le16 s_minor_rev_level;
606 __le16 s_mnt_count;
607 __le16 s_max_mnt_count;
608 __le16 s_state; /* File system state */
609 __le16 s_errors; /* Behaviour when detecting errors */
610 __le32 s_checkinterval; /* Max time between checks */
611/*10*/ __le64 s_lastcheck; /* Time of last check */
612 __le32 s_creator_os; /* OS */
613 __le32 s_feature_compat; /* Compatible feature set */
614/*20*/ __le32 s_feature_incompat; /* Incompatible feature set */
615 __le32 s_feature_ro_compat; /* Readonly-compatible feature set */
616 __le64 s_root_blkno; /* Offset, in blocks, of root directory
617 dinode */
618/*30*/ __le64 s_system_dir_blkno; /* Offset, in blocks, of system
619 directory dinode */
620 __le32 s_blocksize_bits; /* Blocksize for this fs */
621 __le32 s_clustersize_bits; /* Clustersize for this fs */
622/*40*/ __le16 s_max_slots; /* Max number of simultaneous mounts
623 before tunefs required */
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700624 __le16 s_tunefs_flag;
Tiger Yangcf1d6c72008-08-18 17:11:00 +0800625 __le32 s_uuid_hash; /* hash value of uuid */
Mark Fashehccd979b2005-12-15 14:31:24 -0800626 __le64 s_first_cluster_group; /* Block offset of 1st cluster
627 * group header */
628/*50*/ __u8 s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */
629/*90*/ __u8 s_uuid[OCFS2_VOL_UUID_LEN]; /* 128-bit uuid */
Joel Beckerb61817e2008-02-01 15:08:23 -0800630/*A0*/ struct ocfs2_cluster_info s_cluster_info; /* Selected userspace
631 stack. Only valid
632 with INCOMPAT flag. */
Tiger Yang8154da32008-08-18 17:11:46 +0800633/*B8*/ __le16 s_xattr_inline_size; /* extended attribute inline size
634 for this fs*/
635 __le16 s_reserved0;
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800636 __le32 s_dx_seed[3]; /* seed[0-2] for dx dir hash.
637 * s_uuid_hash serves as seed[3]. */
638/*C0*/ __le64 s_reserved2[15]; /* Fill out superblock */
Joel Beckerb61817e2008-02-01 15:08:23 -0800639/*140*/
640
641 /*
642 * NOTE: As stated above, all offsets are relative to
643 * ocfs2_dinode.id2, which is at 0xC0 in the inode.
644 * 0xC0 + 0x140 = 0x200 or 512 bytes. A superblock must fit within
645 * our smallest blocksize, which is 512 bytes. To ensure this,
646 * we reserve the space in s_reserved2. Anything past s_reserved2
647 * will not be available on the smallest blocksize.
648 */
Mark Fashehccd979b2005-12-15 14:31:24 -0800649};
650
651/*
652 * Local allocation bitmap for OCFS2 slots
653 * Note that it exists inside an ocfs2_dinode, so all offsets are
654 * relative to the start of ocfs2_dinode.id2.
655 */
656struct ocfs2_local_alloc
657{
658/*00*/ __le32 la_bm_off; /* Starting bit offset in main bitmap */
659 __le16 la_size; /* Size of included bitmap, in bytes */
660 __le16 la_reserved1;
661 __le64 la_reserved2;
662/*10*/ __u8 la_bitmap[0];
663};
664
665/*
Mark Fasheh15b1e362007-09-07 13:58:15 -0700666 * Data-in-inode header. This is only used if i_dyn_features has
667 * OCFS2_INLINE_DATA_FL set.
668 */
669struct ocfs2_inline_data
670{
671/*00*/ __le16 id_count; /* Number of bytes that can be used
672 * for data, starting at id_data */
673 __le16 id_reserved0;
674 __le32 id_reserved1;
675 __u8 id_data[0]; /* Start of user data */
676};
677
678/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800679 * On disk inode for OCFS2
680 */
681struct ocfs2_dinode {
682/*00*/ __u8 i_signature[8]; /* Signature for validation */
683 __le32 i_generation; /* Generation number */
684 __le16 i_suballoc_slot; /* Slot suballocator this inode
685 belongs to */
686 __le16 i_suballoc_bit; /* Bit offset in suballocator
687 block group */
Tiger Yangfdd77702008-08-18 17:08:55 +0800688/*10*/ __le16 i_reserved0;
689 __le16 i_xattr_inline_size;
Mark Fashehccd979b2005-12-15 14:31:24 -0800690 __le32 i_clusters; /* Cluster count */
691 __le32 i_uid; /* Owner UID */
692 __le32 i_gid; /* Owning GID */
693/*20*/ __le64 i_size; /* Size in bytes */
694 __le16 i_mode; /* File mode */
695 __le16 i_links_count; /* Links count */
696 __le32 i_flags; /* File flags */
697/*30*/ __le64 i_atime; /* Access time */
698 __le64 i_ctime; /* Creation time */
699/*40*/ __le64 i_mtime; /* Modification time */
700 __le64 i_dtime; /* Deletion time */
701/*50*/ __le64 i_blkno; /* Offset on disk, in blocks */
702 __le64 i_last_eb_blk; /* Pointer to last extent
703 block */
704/*60*/ __le32 i_fs_generation; /* Generation per fs-instance */
705 __le32 i_atime_nsec;
706 __le32 i_ctime_nsec;
707 __le32 i_mtime_nsec;
Tiger Yangfdd77702008-08-18 17:08:55 +0800708/*70*/ __le32 i_attr;
Tiger Yang50008632007-03-20 16:01:38 -0700709 __le16 i_orphaned_slot; /* Only valid when OCFS2_ORPHANED_FL
710 was set in i_flags */
Mark Fasheh15b1e362007-09-07 13:58:15 -0700711 __le16 i_dyn_features;
Tiger Yangfdd77702008-08-18 17:08:55 +0800712 __le64 i_xattr_loc;
Joel Beckerab552d52008-10-16 17:50:30 -0700713/*80*/ struct ocfs2_block_check i_check; /* Error checking */
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800714/*88*/ __le64 i_dx_root; /* Pointer to dir index root block */
715 __le64 i_reserved2[5];
Mark Fashehccd979b2005-12-15 14:31:24 -0800716/*B8*/ union {
717 __le64 i_pad1; /* Generic way to refer to this
718 64bit union */
719 struct {
720 __le64 i_rdev; /* Device number */
721 } dev1;
722 struct { /* Info for bitmap system
723 inodes */
724 __le32 i_used; /* Bits (ie, clusters) used */
725 __le32 i_total; /* Total bits (clusters)
726 available */
727 } bitmap1;
728 struct { /* Info for journal system
729 inodes */
730 __le32 ij_flags; /* Mounted, version, etc. */
Sunil Mushranc69991a2008-07-14 17:31:09 -0700731 __le32 ij_recovery_generation; /* Incremented when the
732 journal is recovered
733 after an unclean
734 shutdown */
Mark Fashehccd979b2005-12-15 14:31:24 -0800735 } journal1;
736 } id1; /* Inode type dependant 1 */
737/*C0*/ union {
738 struct ocfs2_super_block i_super;
739 struct ocfs2_local_alloc i_lab;
740 struct ocfs2_chain_list i_chain;
741 struct ocfs2_extent_list i_list;
742 struct ocfs2_truncate_log i_dealloc;
Mark Fasheh15b1e362007-09-07 13:58:15 -0700743 struct ocfs2_inline_data i_data;
Mark Fashehccd979b2005-12-15 14:31:24 -0800744 __u8 i_symlink[0];
745 } id2;
746/* Actual on-disk size is one block */
747};
748
749/*
750 * On-disk directory entry structure for OCFS2
751 *
752 * Packed as this structure could be accessed unaligned on 64-bit platforms
753 */
754struct ocfs2_dir_entry {
755/*00*/ __le64 inode; /* Inode number */
756 __le16 rec_len; /* Directory entry length */
757 __u8 name_len; /* Name length */
758 __u8 file_type;
759/*0C*/ char name[OCFS2_MAX_FILENAME_LEN]; /* File name */
760/* Actual on-disk length specified by rec_len */
761} __attribute__ ((packed));
762
763/*
Mark Fasheh87d35a72008-12-10 17:36:25 -0800764 * Per-block record for the unindexed directory btree. This is carefully
765 * crafted so that the rec_len and name_len records of an ocfs2_dir_entry are
766 * mirrored. That way, the directory manipulation code needs a minimal amount
767 * of update.
768 *
769 * NOTE: Keep this structure aligned to a multiple of 4 bytes.
770 */
771struct ocfs2_dir_block_trailer {
772/*00*/ __le64 db_compat_inode; /* Always zero. Was inode */
773
774 __le16 db_compat_rec_len; /* Backwards compatible with
775 * ocfs2_dir_entry. */
776 __u8 db_compat_name_len; /* Always zero. Was name_len */
777 __u8 db_reserved0;
778 __le16 db_reserved1;
779 __le16 db_free_rec_len; /* Size of largest empty hole
780 * in this block. (unused) */
781/*10*/ __u8 db_signature[8]; /* Signature for verification */
782 __le64 db_reserved2;
783 __le64 db_free_next; /* Next block in list (unused) */
784/*20*/ __le64 db_blkno; /* Offset on disk, in blocks */
785 __le64 db_parent_dinode; /* dinode which owns me, in
786 blocks */
Joel Beckerc175a512008-12-10 17:58:22 -0800787/*30*/ struct ocfs2_block_check db_check; /* Error checking */
Mark Fasheh87d35a72008-12-10 17:36:25 -0800788/*40*/
789};
790
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800791 /*
792 * A directory entry in the indexed tree. We don't store the full name here,
793 * but instead provide a pointer to the full dirent in the unindexed tree.
794 *
795 * We also store name_len here so as to reduce the number of leaf blocks we
796 * need to search in case of collisions.
797 */
798struct ocfs2_dx_entry {
799 __le32 dx_major_hash; /* Used to find logical
800 * cluster in index */
801 __le32 dx_minor_hash; /* Lower bits used to find
802 * block in cluster */
803 __le64 dx_dirent_blk; /* Physical block in unindexed
804 * tree holding this dirent. */
805};
806
807struct ocfs2_dx_entry_list {
808 __le32 de_reserved;
809 __le16 de_count; /* Maximum number of entries
810 * possible in de_entries */
811 __le16 de_num_used; /* Current number of
812 * de_entries entries */
813 struct ocfs2_dx_entry de_entries[0]; /* Indexed dir entries
814 * in a packed array of
815 * length de_num_used */
816};
817
818/*
819 * A directory indexing block. Each indexed directory has one of these,
820 * pointed to by ocfs2_dinode.
821 *
822 * This block stores an indexed btree root, and a set of free space
823 * start-of-list pointers.
824 */
825struct ocfs2_dx_root_block {
826 __u8 dr_signature[8]; /* Signature for verification */
827 struct ocfs2_block_check dr_check; /* Error checking */
828 __le16 dr_suballoc_slot; /* Slot suballocator this
829 * block belongs to. */
830 __le16 dr_suballoc_bit; /* Bit offset in suballocator
831 * block group */
832 __le32 dr_fs_generation; /* Must match super block */
833 __le64 dr_blkno; /* Offset on disk, in blocks */
834 __le64 dr_last_eb_blk; /* Pointer to last
835 * extent block */
836 __le32 dr_clusters; /* Clusters allocated
837 * to the indexed tree. */
838 __le32 dr_reserved1;
839 __le64 dr_dir_blkno; /* Pointer to parent inode */
840 __le64 dr_reserved2;
841 __le64 dr_reserved3[16];
842 struct ocfs2_extent_list dr_list; /* Keep this aligned to 128
843 * bits for maximum space
844 * efficiency. */
845};
846
847/*
848 * The header of a leaf block in the indexed tree.
849 */
850struct ocfs2_dx_leaf {
851 __u8 dl_signature[8];/* Signature for verification */
852 struct ocfs2_block_check dl_check; /* Error checking */
853 __le64 dl_blkno; /* Offset on disk, in blocks */
854 __le32 dl_fs_generation;/* Must match super block */
855 __le32 dl_reserved0;
856 __le64 dl_reserved1;
857 struct ocfs2_dx_entry_list dl_list;
858};
859
Mark Fasheh87d35a72008-12-10 17:36:25 -0800860/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800861 * On disk allocator group structure for OCFS2
862 */
863struct ocfs2_group_desc
864{
865/*00*/ __u8 bg_signature[8]; /* Signature for validation */
866 __le16 bg_size; /* Size of included bitmap in
867 bytes. */
868 __le16 bg_bits; /* Bits represented by this
869 group. */
870 __le16 bg_free_bits_count; /* Free bits count */
871 __le16 bg_chain; /* What chain I am in. */
872/*10*/ __le32 bg_generation;
873 __le32 bg_reserved1;
874 __le64 bg_next_group; /* Next group in my list, in
875 blocks */
876/*20*/ __le64 bg_parent_dinode; /* dinode which owns me, in
877 blocks */
878 __le64 bg_blkno; /* Offset on disk, in blocks */
Joel Beckerab552d52008-10-16 17:50:30 -0700879/*30*/ struct ocfs2_block_check bg_check; /* Error checking */
880 __le64 bg_reserved2;
Mark Fashehccd979b2005-12-15 14:31:24 -0800881/*40*/ __u8 bg_bitmap[0];
882};
883
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800884/*
885 * On disk extended attribute structure for OCFS2.
886 */
887
888/*
889 * ocfs2_xattr_entry indicates one extend attribute.
890 *
891 * Note that it can be stored in inode, one block or one xattr bucket.
892 */
893struct ocfs2_xattr_entry {
894 __le32 xe_name_hash; /* hash value of xattr prefix+suffix. */
Tao Ma8573f792008-10-24 22:24:17 +0800895 __le16 xe_name_offset; /* byte offset from the 1st entry in the
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800896 local xattr storage(inode, xattr block or
897 xattr bucket). */
898 __u8 xe_name_len; /* xattr name len, does't include prefix. */
Tao Ma8573f792008-10-24 22:24:17 +0800899 __u8 xe_type; /* the low 7 bits indicate the name prefix
900 * type and the highest bit indicates whether
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800901 * the EA is stored in the local storage. */
902 __le64 xe_value_size; /* real xattr value length. */
903};
904
905/*
906 * On disk structure for xattr header.
907 *
908 * One ocfs2_xattr_header describes how many ocfs2_xattr_entry records in
909 * the local xattr storage.
910 */
911struct ocfs2_xattr_header {
912 __le16 xh_count; /* contains the count of how
913 many records are in the
914 local xattr storage. */
Tao Ma0c044f02008-08-18 17:38:50 +0800915 __le16 xh_free_start; /* current offset for storing
916 xattr. */
917 __le16 xh_name_value_len; /* total length of name/value
918 length in this bucket. */
Tao Ma8573f792008-10-24 22:24:17 +0800919 __le16 xh_num_buckets; /* Number of xattr buckets
920 in this extent record,
921 only valid in the first
922 bucket. */
Joel Beckerab552d52008-10-16 17:50:30 -0700923 struct ocfs2_block_check xh_check; /* Error checking
924 (Note, this is only
925 used for xattr
926 buckets. A block uses
927 xb_check and sets
928 this field to zero.) */
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800929 struct ocfs2_xattr_entry xh_entries[0]; /* xattr entry list. */
930};
931
932/*
933 * On disk structure for xattr value root.
934 *
Tao Ma8573f792008-10-24 22:24:17 +0800935 * When an xattr's value is large enough, it is stored in an external
936 * b-tree like file data. The xattr value root points to this structure.
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800937 */
938struct ocfs2_xattr_value_root {
939/*00*/ __le32 xr_clusters; /* clusters covered by xattr value. */
940 __le32 xr_reserved0;
941 __le64 xr_last_eb_blk; /* Pointer to last extent block */
942/*10*/ struct ocfs2_extent_list xr_list; /* Extent record list */
943};
944
945/*
946 * On disk structure for xattr tree root.
947 *
948 * It is used when there are too many extended attributes for one file. These
949 * attributes will be organized and stored in an indexed-btree.
950 */
951struct ocfs2_xattr_tree_root {
952/*00*/ __le32 xt_clusters; /* clusters covered by xattr. */
953 __le32 xt_reserved0;
954 __le64 xt_last_eb_blk; /* Pointer to last extent block */
955/*10*/ struct ocfs2_extent_list xt_list; /* Extent record list */
956};
957
Tiger Yangcf1d6c72008-08-18 17:11:00 +0800958#define OCFS2_XATTR_INDEXED 0x1
959#define OCFS2_HASH_SHIFT 5
960#define OCFS2_XATTR_ROUND 3
961#define OCFS2_XATTR_SIZE(size) (((size) + OCFS2_XATTR_ROUND) & \
962 ~(OCFS2_XATTR_ROUND))
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800963
Tao Ma0c044f02008-08-18 17:38:50 +0800964#define OCFS2_XATTR_BUCKET_SIZE 4096
965#define OCFS2_XATTR_MAX_BLOCKS_PER_BUCKET (OCFS2_XATTR_BUCKET_SIZE \
966 / OCFS2_MIN_BLOCKSIZE)
967
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800968/*
969 * On disk structure for xattr block.
970 */
971struct ocfs2_xattr_block {
972/*00*/ __u8 xb_signature[8]; /* Signature for verification */
973 __le16 xb_suballoc_slot; /* Slot suballocator this
974 block belongs to. */
975 __le16 xb_suballoc_bit; /* Bit offset in suballocator
976 block group */
977 __le32 xb_fs_generation; /* Must match super block */
978/*10*/ __le64 xb_blkno; /* Offset on disk, in blocks */
Joel Beckerab552d52008-10-16 17:50:30 -0700979 struct ocfs2_block_check xb_check; /* Error checking */
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800980/*20*/ __le16 xb_flags; /* Indicates whether this block contains
981 real xattr or a xattr tree. */
982 __le16 xb_reserved0;
983 __le32 xb_reserved1;
984 __le64 xb_reserved2;
985/*30*/ union {
986 struct ocfs2_xattr_header xb_header; /* xattr header if this
987 block contains xattr */
988 struct ocfs2_xattr_tree_root xb_root;/* xattr tree root if this
989 block cotains xattr
990 tree. */
991 } xb_attrs;
992};
993
994#define OCFS2_XATTR_ENTRY_LOCAL 0x80
995#define OCFS2_XATTR_TYPE_MASK 0x7F
996static inline void ocfs2_xattr_set_local(struct ocfs2_xattr_entry *xe,
997 int local)
998{
999 if (local)
1000 xe->xe_type |= OCFS2_XATTR_ENTRY_LOCAL;
1001 else
1002 xe->xe_type &= ~OCFS2_XATTR_ENTRY_LOCAL;
1003}
1004
1005static inline int ocfs2_xattr_is_local(struct ocfs2_xattr_entry *xe)
1006{
1007 return xe->xe_type & OCFS2_XATTR_ENTRY_LOCAL;
1008}
1009
1010static inline void ocfs2_xattr_set_type(struct ocfs2_xattr_entry *xe, int type)
1011{
1012 xe->xe_type |= type & OCFS2_XATTR_TYPE_MASK;
1013}
1014
1015static inline int ocfs2_xattr_get_type(struct ocfs2_xattr_entry *xe)
1016{
1017 return xe->xe_type & OCFS2_XATTR_TYPE_MASK;
1018}
1019
Jan Kara9e33d692008-08-25 19:56:50 +02001020/*
1021 * On disk structures for global quota file
1022 */
1023
1024/* Magic numbers and known versions for global quota files */
1025#define OCFS2_GLOBAL_QMAGICS {\
1026 0x0cf52470, /* USRQUOTA */ \
1027 0x0cf52471 /* GRPQUOTA */ \
1028}
1029
1030#define OCFS2_GLOBAL_QVERSIONS {\
1031 0, \
1032 0, \
1033}
1034
1035
1036/* Each block of each quota file has a certain fixed number of bytes reserved
1037 * for OCFS2 internal use at its end. OCFS2 can use it for things like
1038 * checksums, etc. */
1039#define OCFS2_QBLK_RESERVED_SPACE 8
1040
1041/* Generic header of all quota files */
1042struct ocfs2_disk_dqheader {
1043 __le32 dqh_magic; /* Magic number identifying file */
1044 __le32 dqh_version; /* Quota format version */
1045};
1046
1047#define OCFS2_GLOBAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
1048
1049/* Information header of global quota file (immediately follows the generic
1050 * header) */
1051struct ocfs2_global_disk_dqinfo {
1052/*00*/ __le32 dqi_bgrace; /* Grace time for space softlimit excess */
1053 __le32 dqi_igrace; /* Grace time for inode softlimit excess */
1054 __le32 dqi_syncms; /* Time after which we sync local changes to
1055 * global quota file */
1056 __le32 dqi_blocks; /* Number of blocks in quota file */
1057/*10*/ __le32 dqi_free_blk; /* First free block in quota file */
1058 __le32 dqi_free_entry; /* First block with free dquot entry in quota
1059 * file */
1060};
1061
1062/* Structure with global user / group information. We reserve some space
1063 * for future use. */
1064struct ocfs2_global_disk_dqblk {
1065/*00*/ __le32 dqb_id; /* ID the structure belongs to */
1066 __le32 dqb_use_count; /* Number of nodes having reference to this structure */
1067 __le64 dqb_ihardlimit; /* absolute limit on allocated inodes */
1068/*10*/ __le64 dqb_isoftlimit; /* preferred inode limit */
1069 __le64 dqb_curinodes; /* current # allocated inodes */
1070/*20*/ __le64 dqb_bhardlimit; /* absolute limit on disk space */
1071 __le64 dqb_bsoftlimit; /* preferred limit on disk space */
1072/*30*/ __le64 dqb_curspace; /* current space occupied */
1073 __le64 dqb_btime; /* time limit for excessive disk use */
1074/*40*/ __le64 dqb_itime; /* time limit for excessive inode use */
1075 __le64 dqb_pad1;
1076/*50*/ __le64 dqb_pad2;
1077};
1078
1079/*
1080 * On-disk structures for local quota file
1081 */
1082
1083/* Magic numbers and known versions for local quota files */
1084#define OCFS2_LOCAL_QMAGICS {\
1085 0x0cf524c0, /* USRQUOTA */ \
1086 0x0cf524c1 /* GRPQUOTA */ \
1087}
1088
1089#define OCFS2_LOCAL_QVERSIONS {\
1090 0, \
1091 0, \
1092}
1093
1094/* Quota flags in dqinfo header */
1095#define OLQF_CLEAN 0x0001 /* Quota file is empty (this should be after\
1096 * quota has been cleanly turned off) */
1097
1098#define OCFS2_LOCAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
1099
1100/* Information header of local quota file (immediately follows the generic
1101 * header) */
1102struct ocfs2_local_disk_dqinfo {
1103 __le32 dqi_flags; /* Flags for quota file */
1104 __le32 dqi_chunks; /* Number of chunks of quota structures
1105 * with a bitmap */
1106 __le32 dqi_blocks; /* Number of blocks allocated for quota file */
1107};
1108
1109/* Header of one chunk of a quota file */
1110struct ocfs2_local_disk_chunk {
1111 __le32 dqc_free; /* Number of free entries in the bitmap */
1112 u8 dqc_bitmap[0]; /* Bitmap of entries in the corresponding
1113 * chunk of quota file */
1114};
1115
1116/* One entry in local quota file */
1117struct ocfs2_local_disk_dqblk {
1118/*00*/ __le64 dqb_id; /* id this quota applies to */
1119 __le64 dqb_spacemod; /* Change in the amount of used space */
1120/*10*/ __le64 dqb_inodemod; /* Change in the amount of used inodes */
1121};
1122
Joel Beckerab552d52008-10-16 17:50:30 -07001123
1124/*
1125 * The quota trailer lives at the end of each quota block.
1126 */
1127
1128struct ocfs2_disk_dqtrailer {
1129/*00*/ struct ocfs2_block_check dq_check; /* Error checking */
1130/*08*/ /* Cannot be larger than OCFS2_QBLK_RESERVED_SPACE */
1131};
1132
1133static inline struct ocfs2_disk_dqtrailer *ocfs2_block_dqtrailer(int blocksize,
1134 void *buf)
1135{
1136 char *ptr = buf;
1137 ptr += blocksize - OCFS2_QBLK_RESERVED_SPACE;
1138
1139 return (struct ocfs2_disk_dqtrailer *)ptr;
1140}
1141
Mark Fashehccd979b2005-12-15 14:31:24 -08001142#ifdef __KERNEL__
1143static inline int ocfs2_fast_symlink_chars(struct super_block *sb)
1144{
1145 return sb->s_blocksize -
1146 offsetof(struct ocfs2_dinode, id2.i_symlink);
1147}
1148
Tiger Yangfdd77702008-08-18 17:08:55 +08001149static inline int ocfs2_max_inline_data_with_xattr(struct super_block *sb,
1150 struct ocfs2_dinode *di)
1151{
1152 unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
1153
1154 if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
1155 return sb->s_blocksize -
1156 offsetof(struct ocfs2_dinode, id2.i_data.id_data) -
1157 xattrsize;
1158 else
1159 return sb->s_blocksize -
1160 offsetof(struct ocfs2_dinode, id2.i_data.id_data);
1161}
1162
Mark Fashehccd979b2005-12-15 14:31:24 -08001163static inline int ocfs2_extent_recs_per_inode(struct super_block *sb)
1164{
1165 int size;
1166
1167 size = sb->s_blocksize -
1168 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1169
1170 return size / sizeof(struct ocfs2_extent_rec);
1171}
1172
Tiger Yangfdd77702008-08-18 17:08:55 +08001173static inline int ocfs2_extent_recs_per_inode_with_xattr(
1174 struct super_block *sb,
1175 struct ocfs2_dinode *di)
1176{
1177 int size;
1178 unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
1179
1180 if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
1181 size = sb->s_blocksize -
1182 offsetof(struct ocfs2_dinode, id2.i_list.l_recs) -
1183 xattrsize;
1184 else
1185 size = sb->s_blocksize -
1186 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1187
1188 return size / sizeof(struct ocfs2_extent_rec);
1189}
1190
Mark Fasheh9b7895e2008-11-12 16:27:44 -08001191static inline int ocfs2_extent_recs_per_dx_root(struct super_block *sb)
1192{
1193 int size;
1194
1195 size = sb->s_blocksize -
1196 offsetof(struct ocfs2_dx_root_block, dr_list.l_recs);
1197
1198 return size / sizeof(struct ocfs2_extent_rec);
1199}
1200
Mark Fashehccd979b2005-12-15 14:31:24 -08001201static inline int ocfs2_chain_recs_per_inode(struct super_block *sb)
1202{
1203 int size;
1204
1205 size = sb->s_blocksize -
1206 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
1207
1208 return size / sizeof(struct ocfs2_chain_rec);
1209}
1210
1211static inline u16 ocfs2_extent_recs_per_eb(struct super_block *sb)
1212{
1213 int size;
1214
1215 size = sb->s_blocksize -
1216 offsetof(struct ocfs2_extent_block, h_list.l_recs);
1217
1218 return size / sizeof(struct ocfs2_extent_rec);
1219}
1220
Mark Fasheh9b7895e2008-11-12 16:27:44 -08001221static inline int ocfs2_dx_entries_per_leaf(struct super_block *sb)
1222{
1223 int size;
1224
1225 size = sb->s_blocksize -
1226 offsetof(struct ocfs2_dx_leaf, dl_list.de_entries);
1227
1228 return size / sizeof(struct ocfs2_dx_entry);
1229}
1230
Mark Fashehccd979b2005-12-15 14:31:24 -08001231static inline u16 ocfs2_local_alloc_size(struct super_block *sb)
1232{
1233 u16 size;
1234
1235 size = sb->s_blocksize -
1236 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
1237
1238 return size;
1239}
1240
1241static inline int ocfs2_group_bitmap_size(struct super_block *sb)
1242{
1243 int size;
1244
1245 size = sb->s_blocksize -
1246 offsetof(struct ocfs2_group_desc, bg_bitmap);
1247
1248 return size;
1249}
1250
1251static inline int ocfs2_truncate_recs_per_inode(struct super_block *sb)
1252{
1253 int size;
1254
1255 size = sb->s_blocksize -
1256 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
1257
1258 return size / sizeof(struct ocfs2_truncate_rec);
1259}
Mark Fasheh50af94b2007-01-21 14:44:59 -08001260
1261static inline u64 ocfs2_backup_super_blkno(struct super_block *sb, int index)
1262{
1263 u64 offset = OCFS2_BACKUP_SB_START;
1264
1265 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
1266 offset <<= (2 * index);
Mark Fasheha8a75a22007-01-26 10:46:59 -08001267 offset >>= sb->s_blocksize_bits;
Mark Fasheh50af94b2007-01-21 14:44:59 -08001268 return offset;
1269 }
1270
1271 return 0;
1272
1273}
Tao Ma0c044f02008-08-18 17:38:50 +08001274
1275static inline u16 ocfs2_xattr_recs_per_xb(struct super_block *sb)
1276{
1277 int size;
1278
1279 size = sb->s_blocksize -
1280 offsetof(struct ocfs2_xattr_block,
1281 xb_attrs.xb_root.xt_list.l_recs);
1282
1283 return size / sizeof(struct ocfs2_extent_rec);
1284}
Mark Fashehccd979b2005-12-15 14:31:24 -08001285#else
1286static inline int ocfs2_fast_symlink_chars(int blocksize)
1287{
1288 return blocksize - offsetof(struct ocfs2_dinode, id2.i_symlink);
1289}
1290
Mark Fasheh15b1e362007-09-07 13:58:15 -07001291static inline int ocfs2_max_inline_data(int blocksize)
1292{
1293 return blocksize - offsetof(struct ocfs2_dinode, id2.i_data.id_data);
1294}
1295
Mark Fashehccd979b2005-12-15 14:31:24 -08001296static inline int ocfs2_extent_recs_per_inode(int blocksize)
1297{
1298 int size;
1299
1300 size = blocksize -
1301 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1302
1303 return size / sizeof(struct ocfs2_extent_rec);
1304}
1305
1306static inline int ocfs2_chain_recs_per_inode(int blocksize)
1307{
1308 int size;
1309
1310 size = blocksize -
1311 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
1312
1313 return size / sizeof(struct ocfs2_chain_rec);
1314}
1315
1316static inline int ocfs2_extent_recs_per_eb(int blocksize)
1317{
1318 int size;
1319
1320 size = blocksize -
1321 offsetof(struct ocfs2_extent_block, h_list.l_recs);
1322
1323 return size / sizeof(struct ocfs2_extent_rec);
1324}
1325
1326static inline int ocfs2_local_alloc_size(int blocksize)
1327{
1328 int size;
1329
1330 size = blocksize -
1331 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
1332
1333 return size;
1334}
1335
1336static inline int ocfs2_group_bitmap_size(int blocksize)
1337{
1338 int size;
1339
1340 size = blocksize -
1341 offsetof(struct ocfs2_group_desc, bg_bitmap);
1342
1343 return size;
1344}
1345
1346static inline int ocfs2_truncate_recs_per_inode(int blocksize)
1347{
1348 int size;
1349
1350 size = blocksize -
1351 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
1352
1353 return size / sizeof(struct ocfs2_truncate_rec);
1354}
Mark Fasheh50af94b2007-01-21 14:44:59 -08001355
1356static inline uint64_t ocfs2_backup_super_blkno(int blocksize, int index)
1357{
1358 uint64_t offset = OCFS2_BACKUP_SB_START;
1359
1360 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
1361 offset <<= (2 * index);
1362 offset /= blocksize;
1363 return offset;
1364 }
1365
1366 return 0;
1367}
Tao Ma0c044f02008-08-18 17:38:50 +08001368
1369static inline int ocfs2_xattr_recs_per_xb(int blocksize)
1370{
1371 int size;
1372
1373 size = blocksize -
1374 offsetof(struct ocfs2_xattr_block,
1375 xb_attrs.xb_root.xt_list.l_recs);
1376
1377 return size / sizeof(struct ocfs2_extent_rec);
1378}
Mark Fashehccd979b2005-12-15 14:31:24 -08001379#endif /* __KERNEL__ */
1380
1381
1382static inline int ocfs2_system_inode_is_global(int type)
1383{
1384 return ((type >= 0) &&
1385 (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE));
1386}
1387
1388static inline int ocfs2_sprintf_system_inode_name(char *buf, int len,
1389 int type, int slot)
1390{
1391 int chars;
1392
1393 /*
1394 * Global system inodes can only have one copy. Everything
1395 * after OCFS2_LAST_GLOBAL_SYSTEM_INODE in the system inode
1396 * list has a copy per slot.
1397 */
1398 if (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE)
Joel Beckerfe9f3872008-06-12 22:39:18 -07001399 chars = snprintf(buf, len, "%s",
Mark Fashehccd979b2005-12-15 14:31:24 -08001400 ocfs2_system_inodes[type].si_name);
1401 else
1402 chars = snprintf(buf, len,
1403 ocfs2_system_inodes[type].si_name,
1404 slot);
1405
1406 return chars;
1407}
1408
1409static inline void ocfs2_set_de_type(struct ocfs2_dir_entry *de,
1410 umode_t mode)
1411{
1412 de->file_type = ocfs2_type_by_mode[(mode & S_IFMT)>>S_SHIFT];
1413}
1414
1415#endif /* _OCFS2_FS_H */
1416