blob: d549b1799a61561786fa706b2a734e5b67a8d466 [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)
Mark Fashehe7c17e42009-01-29 18:17:46 -0800419#define OCFS2_DIR_MIN_REC_LEN OCFS2_DIR_REC_LEN(1)
Mark Fashehccd979b2005-12-15 14:31:24 -0800420
421#define OCFS2_LINK_MAX 32000
422
423#define S_SHIFT 12
424static unsigned char ocfs2_type_by_mode[S_IFMT >> S_SHIFT] = {
425 [S_IFREG >> S_SHIFT] = OCFS2_FT_REG_FILE,
426 [S_IFDIR >> S_SHIFT] = OCFS2_FT_DIR,
427 [S_IFCHR >> S_SHIFT] = OCFS2_FT_CHRDEV,
428 [S_IFBLK >> S_SHIFT] = OCFS2_FT_BLKDEV,
429 [S_IFIFO >> S_SHIFT] = OCFS2_FT_FIFO,
430 [S_IFSOCK >> S_SHIFT] = OCFS2_FT_SOCK,
431 [S_IFLNK >> S_SHIFT] = OCFS2_FT_SYMLINK,
432};
433
434
435/*
436 * Convenience casts
437 */
438#define OCFS2_RAW_SB(dinode) (&((dinode)->id2.i_super))
439
440/*
Joel Beckerab552d52008-10-16 17:50:30 -0700441 * Block checking structure. This is used in metadata to validate the
442 * contents. If OCFS2_FEATURE_INCOMPAT_META_ECC is not set, it is all
443 * zeros.
444 */
445struct ocfs2_block_check {
446/*00*/ __le32 bc_crc32e; /* 802.3 Ethernet II CRC32 */
447 __le16 bc_ecc; /* Single-error-correction parity vector.
448 This is a simple Hamming code dependant
449 on the blocksize. OCFS2's maximum
450 blocksize, 4K, requires 16 parity bits,
451 so we fit in __le16. */
452 __le16 bc_reserved1;
453/*08*/
454};
455
456/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800457 * On disk extent record for OCFS2
458 * It describes a range of clusters on disk.
Mark Fashehe48edee2007-03-07 16:46:57 -0800459 *
460 * Length fields are divided into interior and leaf node versions.
461 * This leaves room for a flags field (OCFS2_EXT_*) in the leaf nodes.
Mark Fashehccd979b2005-12-15 14:31:24 -0800462 */
463struct ocfs2_extent_rec {
464/*00*/ __le32 e_cpos; /* Offset into the file, in clusters */
Mark Fashehe48edee2007-03-07 16:46:57 -0800465 union {
466 __le32 e_int_clusters; /* Clusters covered by all children */
467 struct {
468 __le16 e_leaf_clusters; /* Clusters covered by this
469 extent */
470 __u8 e_reserved1;
471 __u8 e_flags; /* Extent flags */
472 };
473 };
Mark Fashehccd979b2005-12-15 14:31:24 -0800474 __le64 e_blkno; /* Physical disk offset, in blocks */
475/*10*/
476};
477
478struct ocfs2_chain_rec {
479 __le32 c_free; /* Number of free bits in this chain. */
480 __le32 c_total; /* Number of total bits in this chain */
481 __le64 c_blkno; /* Physical disk offset (blocks) of 1st group */
482};
483
484struct ocfs2_truncate_rec {
485 __le32 t_start; /* 1st cluster in this log */
486 __le32 t_clusters; /* Number of total clusters covered */
487};
488
489/*
490 * On disk extent list for OCFS2 (node in the tree). Note that this
491 * is contained inside ocfs2_dinode or ocfs2_extent_block, so the
492 * offsets are relative to ocfs2_dinode.id2.i_list or
493 * ocfs2_extent_block.h_list, respectively.
494 */
495struct ocfs2_extent_list {
496/*00*/ __le16 l_tree_depth; /* Extent tree depth from this
497 point. 0 means data extents
498 hang directly off this
Mark Fashehdcd05382007-01-16 11:32:23 -0800499 header (a leaf)
500 NOTE: The high 8 bits cannot be
501 used - tree_depth is never that big.
502 */
Mark Fashehccd979b2005-12-15 14:31:24 -0800503 __le16 l_count; /* Number of extent records */
504 __le16 l_next_free_rec; /* Next unused extent slot */
505 __le16 l_reserved1;
506 __le64 l_reserved2; /* Pad to
507 sizeof(ocfs2_extent_rec) */
508/*10*/ struct ocfs2_extent_rec l_recs[0]; /* Extent records */
509};
510
511/*
512 * On disk allocation chain list for OCFS2. Note that this is
513 * contained inside ocfs2_dinode, so the offsets are relative to
514 * ocfs2_dinode.id2.i_chain.
515 */
516struct ocfs2_chain_list {
517/*00*/ __le16 cl_cpg; /* Clusters per Block Group */
518 __le16 cl_bpc; /* Bits per cluster */
519 __le16 cl_count; /* Total chains in this list */
520 __le16 cl_next_free_rec; /* Next unused chain slot */
521 __le64 cl_reserved1;
522/*10*/ struct ocfs2_chain_rec cl_recs[0]; /* Chain records */
523};
524
525/*
526 * On disk deallocation log for OCFS2. Note that this is
527 * contained inside ocfs2_dinode, so the offsets are relative to
528 * ocfs2_dinode.id2.i_dealloc.
529 */
530struct ocfs2_truncate_log {
531/*00*/ __le16 tl_count; /* Total records in this log */
532 __le16 tl_used; /* Number of records in use */
533 __le32 tl_reserved1;
534/*08*/ struct ocfs2_truncate_rec tl_recs[0]; /* Truncate records */
535};
536
537/*
538 * On disk extent block (indirect block) for OCFS2
539 */
540struct ocfs2_extent_block
541{
542/*00*/ __u8 h_signature[8]; /* Signature for verification */
Joel Beckerab552d52008-10-16 17:50:30 -0700543 struct ocfs2_block_check h_check; /* Error checking */
Mark Fashehccd979b2005-12-15 14:31:24 -0800544/*10*/ __le16 h_suballoc_slot; /* Slot suballocator this
545 extent_header belongs to */
546 __le16 h_suballoc_bit; /* Bit offset in suballocator
547 block group */
548 __le32 h_fs_generation; /* Must match super block */
549 __le64 h_blkno; /* Offset on disk, in blocks */
550/*20*/ __le64 h_reserved3;
551 __le64 h_next_leaf_blk; /* Offset on disk, in blocks,
552 of next leaf header pointing
553 to data */
554/*30*/ struct ocfs2_extent_list h_list; /* Extent record list */
555/* Actual on-disk size is one block */
556};
557
558/*
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800559 * On disk slot map for OCFS2. This defines the contents of the "slot_map"
Joel Becker386a2ef2008-02-01 12:06:54 -0800560 * system file. A slot is valid if it contains a node number >= 0. The
561 * value -1 (0xFFFF) is OCFS2_INVALID_SLOT. This marks a slot empty.
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800562 */
563struct ocfs2_slot_map {
564/*00*/ __le16 sm_slots[0];
565/*
566 * Actual on-disk size is one block. OCFS2_MAX_SLOTS is 255,
567 * 255 * sizeof(__le16) == 512B, within the 512B block minimum blocksize.
568 */
569};
570
Joel Becker386a2ef2008-02-01 12:06:54 -0800571struct ocfs2_extended_slot {
572/*00*/ __u8 es_valid;
573 __u8 es_reserved1[3];
574 __le32 es_node_num;
575/*10*/
576};
577
578/*
579 * The extended slot map, used when OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP
580 * is set. It separates out the valid marker from the node number, and
581 * has room to grow. Unlike the old slot map, this format is defined by
582 * i_size.
583 */
584struct ocfs2_slot_map_extended {
585/*00*/ struct ocfs2_extended_slot se_slots[0];
586/*
587 * Actual size is i_size of the slot_map system file. It should
588 * match s_max_slots * sizeof(struct ocfs2_extended_slot)
589 */
590};
591
Joel Beckerb61817e2008-02-01 15:08:23 -0800592struct ocfs2_cluster_info {
593/*00*/ __u8 ci_stack[OCFS2_STACK_LABEL_LEN];
594 __le32 ci_reserved;
595/*08*/ __u8 ci_cluster[OCFS2_CLUSTER_NAME_LEN];
596/*18*/
597};
598
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800599/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800600 * On disk superblock for OCFS2
601 * Note that it is contained inside an ocfs2_dinode, so all offsets
602 * are relative to the start of ocfs2_dinode.id2.
603 */
604struct ocfs2_super_block {
605/*00*/ __le16 s_major_rev_level;
606 __le16 s_minor_rev_level;
607 __le16 s_mnt_count;
608 __le16 s_max_mnt_count;
609 __le16 s_state; /* File system state */
610 __le16 s_errors; /* Behaviour when detecting errors */
611 __le32 s_checkinterval; /* Max time between checks */
612/*10*/ __le64 s_lastcheck; /* Time of last check */
613 __le32 s_creator_os; /* OS */
614 __le32 s_feature_compat; /* Compatible feature set */
615/*20*/ __le32 s_feature_incompat; /* Incompatible feature set */
616 __le32 s_feature_ro_compat; /* Readonly-compatible feature set */
617 __le64 s_root_blkno; /* Offset, in blocks, of root directory
618 dinode */
619/*30*/ __le64 s_system_dir_blkno; /* Offset, in blocks, of system
620 directory dinode */
621 __le32 s_blocksize_bits; /* Blocksize for this fs */
622 __le32 s_clustersize_bits; /* Clustersize for this fs */
623/*40*/ __le16 s_max_slots; /* Max number of simultaneous mounts
624 before tunefs required */
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700625 __le16 s_tunefs_flag;
Tiger Yangcf1d6c72008-08-18 17:11:00 +0800626 __le32 s_uuid_hash; /* hash value of uuid */
Mark Fashehccd979b2005-12-15 14:31:24 -0800627 __le64 s_first_cluster_group; /* Block offset of 1st cluster
628 * group header */
629/*50*/ __u8 s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */
630/*90*/ __u8 s_uuid[OCFS2_VOL_UUID_LEN]; /* 128-bit uuid */
Joel Beckerb61817e2008-02-01 15:08:23 -0800631/*A0*/ struct ocfs2_cluster_info s_cluster_info; /* Selected userspace
632 stack. Only valid
633 with INCOMPAT flag. */
Tiger Yang8154da32008-08-18 17:11:46 +0800634/*B8*/ __le16 s_xattr_inline_size; /* extended attribute inline size
635 for this fs*/
636 __le16 s_reserved0;
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800637 __le32 s_dx_seed[3]; /* seed[0-2] for dx dir hash.
638 * s_uuid_hash serves as seed[3]. */
639/*C0*/ __le64 s_reserved2[15]; /* Fill out superblock */
Joel Beckerb61817e2008-02-01 15:08:23 -0800640/*140*/
641
642 /*
643 * NOTE: As stated above, all offsets are relative to
644 * ocfs2_dinode.id2, which is at 0xC0 in the inode.
645 * 0xC0 + 0x140 = 0x200 or 512 bytes. A superblock must fit within
646 * our smallest blocksize, which is 512 bytes. To ensure this,
647 * we reserve the space in s_reserved2. Anything past s_reserved2
648 * will not be available on the smallest blocksize.
649 */
Mark Fashehccd979b2005-12-15 14:31:24 -0800650};
651
652/*
653 * Local allocation bitmap for OCFS2 slots
654 * Note that it exists inside an ocfs2_dinode, so all offsets are
655 * relative to the start of ocfs2_dinode.id2.
656 */
657struct ocfs2_local_alloc
658{
659/*00*/ __le32 la_bm_off; /* Starting bit offset in main bitmap */
660 __le16 la_size; /* Size of included bitmap, in bytes */
661 __le16 la_reserved1;
662 __le64 la_reserved2;
663/*10*/ __u8 la_bitmap[0];
664};
665
666/*
Mark Fasheh15b1e362007-09-07 13:58:15 -0700667 * Data-in-inode header. This is only used if i_dyn_features has
668 * OCFS2_INLINE_DATA_FL set.
669 */
670struct ocfs2_inline_data
671{
672/*00*/ __le16 id_count; /* Number of bytes that can be used
673 * for data, starting at id_data */
674 __le16 id_reserved0;
675 __le32 id_reserved1;
676 __u8 id_data[0]; /* Start of user data */
677};
678
679/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800680 * On disk inode for OCFS2
681 */
682struct ocfs2_dinode {
683/*00*/ __u8 i_signature[8]; /* Signature for validation */
684 __le32 i_generation; /* Generation number */
685 __le16 i_suballoc_slot; /* Slot suballocator this inode
686 belongs to */
687 __le16 i_suballoc_bit; /* Bit offset in suballocator
688 block group */
Tiger Yangfdd77702008-08-18 17:08:55 +0800689/*10*/ __le16 i_reserved0;
690 __le16 i_xattr_inline_size;
Mark Fashehccd979b2005-12-15 14:31:24 -0800691 __le32 i_clusters; /* Cluster count */
692 __le32 i_uid; /* Owner UID */
693 __le32 i_gid; /* Owning GID */
694/*20*/ __le64 i_size; /* Size in bytes */
695 __le16 i_mode; /* File mode */
696 __le16 i_links_count; /* Links count */
697 __le32 i_flags; /* File flags */
698/*30*/ __le64 i_atime; /* Access time */
699 __le64 i_ctime; /* Creation time */
700/*40*/ __le64 i_mtime; /* Modification time */
701 __le64 i_dtime; /* Deletion time */
702/*50*/ __le64 i_blkno; /* Offset on disk, in blocks */
703 __le64 i_last_eb_blk; /* Pointer to last extent
704 block */
705/*60*/ __le32 i_fs_generation; /* Generation per fs-instance */
706 __le32 i_atime_nsec;
707 __le32 i_ctime_nsec;
708 __le32 i_mtime_nsec;
Tiger Yangfdd77702008-08-18 17:08:55 +0800709/*70*/ __le32 i_attr;
Tiger Yang50008632007-03-20 16:01:38 -0700710 __le16 i_orphaned_slot; /* Only valid when OCFS2_ORPHANED_FL
711 was set in i_flags */
Mark Fasheh15b1e362007-09-07 13:58:15 -0700712 __le16 i_dyn_features;
Tiger Yangfdd77702008-08-18 17:08:55 +0800713 __le64 i_xattr_loc;
Joel Beckerab552d52008-10-16 17:50:30 -0700714/*80*/ struct ocfs2_block_check i_check; /* Error checking */
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800715/*88*/ __le64 i_dx_root; /* Pointer to dir index root block */
716 __le64 i_reserved2[5];
Mark Fashehccd979b2005-12-15 14:31:24 -0800717/*B8*/ union {
718 __le64 i_pad1; /* Generic way to refer to this
719 64bit union */
720 struct {
721 __le64 i_rdev; /* Device number */
722 } dev1;
723 struct { /* Info for bitmap system
724 inodes */
725 __le32 i_used; /* Bits (ie, clusters) used */
726 __le32 i_total; /* Total bits (clusters)
727 available */
728 } bitmap1;
729 struct { /* Info for journal system
730 inodes */
731 __le32 ij_flags; /* Mounted, version, etc. */
Sunil Mushranc69991a2008-07-14 17:31:09 -0700732 __le32 ij_recovery_generation; /* Incremented when the
733 journal is recovered
734 after an unclean
735 shutdown */
Mark Fashehccd979b2005-12-15 14:31:24 -0800736 } journal1;
737 } id1; /* Inode type dependant 1 */
738/*C0*/ union {
739 struct ocfs2_super_block i_super;
740 struct ocfs2_local_alloc i_lab;
741 struct ocfs2_chain_list i_chain;
742 struct ocfs2_extent_list i_list;
743 struct ocfs2_truncate_log i_dealloc;
Mark Fasheh15b1e362007-09-07 13:58:15 -0700744 struct ocfs2_inline_data i_data;
Mark Fashehccd979b2005-12-15 14:31:24 -0800745 __u8 i_symlink[0];
746 } id2;
747/* Actual on-disk size is one block */
748};
749
750/*
751 * On-disk directory entry structure for OCFS2
752 *
753 * Packed as this structure could be accessed unaligned on 64-bit platforms
754 */
755struct ocfs2_dir_entry {
756/*00*/ __le64 inode; /* Inode number */
757 __le16 rec_len; /* Directory entry length */
758 __u8 name_len; /* Name length */
759 __u8 file_type;
760/*0C*/ char name[OCFS2_MAX_FILENAME_LEN]; /* File name */
761/* Actual on-disk length specified by rec_len */
762} __attribute__ ((packed));
763
764/*
Mark Fasheh87d35a72008-12-10 17:36:25 -0800765 * Per-block record for the unindexed directory btree. This is carefully
766 * crafted so that the rec_len and name_len records of an ocfs2_dir_entry are
767 * mirrored. That way, the directory manipulation code needs a minimal amount
768 * of update.
769 *
770 * NOTE: Keep this structure aligned to a multiple of 4 bytes.
771 */
772struct ocfs2_dir_block_trailer {
773/*00*/ __le64 db_compat_inode; /* Always zero. Was inode */
774
775 __le16 db_compat_rec_len; /* Backwards compatible with
776 * ocfs2_dir_entry. */
777 __u8 db_compat_name_len; /* Always zero. Was name_len */
778 __u8 db_reserved0;
779 __le16 db_reserved1;
780 __le16 db_free_rec_len; /* Size of largest empty hole
781 * in this block. (unused) */
782/*10*/ __u8 db_signature[8]; /* Signature for verification */
783 __le64 db_reserved2;
784 __le64 db_free_next; /* Next block in list (unused) */
785/*20*/ __le64 db_blkno; /* Offset on disk, in blocks */
786 __le64 db_parent_dinode; /* dinode which owns me, in
787 blocks */
Joel Beckerc175a512008-12-10 17:58:22 -0800788/*30*/ struct ocfs2_block_check db_check; /* Error checking */
Mark Fasheh87d35a72008-12-10 17:36:25 -0800789/*40*/
790};
791
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800792 /*
793 * A directory entry in the indexed tree. We don't store the full name here,
794 * but instead provide a pointer to the full dirent in the unindexed tree.
795 *
796 * We also store name_len here so as to reduce the number of leaf blocks we
797 * need to search in case of collisions.
798 */
799struct ocfs2_dx_entry {
800 __le32 dx_major_hash; /* Used to find logical
801 * cluster in index */
802 __le32 dx_minor_hash; /* Lower bits used to find
803 * block in cluster */
804 __le64 dx_dirent_blk; /* Physical block in unindexed
805 * tree holding this dirent. */
806};
807
808struct ocfs2_dx_entry_list {
809 __le32 de_reserved;
810 __le16 de_count; /* Maximum number of entries
811 * possible in de_entries */
812 __le16 de_num_used; /* Current number of
813 * de_entries entries */
814 struct ocfs2_dx_entry de_entries[0]; /* Indexed dir entries
815 * in a packed array of
816 * length de_num_used */
817};
818
Mark Fasheh4ed8a6b2008-11-24 17:02:08 -0800819#define OCFS2_DX_FLAG_INLINE 0x01
820
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800821/*
822 * A directory indexing block. Each indexed directory has one of these,
823 * pointed to by ocfs2_dinode.
824 *
825 * This block stores an indexed btree root, and a set of free space
826 * start-of-list pointers.
827 */
828struct ocfs2_dx_root_block {
829 __u8 dr_signature[8]; /* Signature for verification */
830 struct ocfs2_block_check dr_check; /* Error checking */
831 __le16 dr_suballoc_slot; /* Slot suballocator this
832 * block belongs to. */
833 __le16 dr_suballoc_bit; /* Bit offset in suballocator
834 * block group */
835 __le32 dr_fs_generation; /* Must match super block */
836 __le64 dr_blkno; /* Offset on disk, in blocks */
837 __le64 dr_last_eb_blk; /* Pointer to last
838 * extent block */
839 __le32 dr_clusters; /* Clusters allocated
840 * to the indexed tree. */
Mark Fasheh4ed8a6b2008-11-24 17:02:08 -0800841 __u8 dr_flags; /* OCFS2_DX_FLAG_* flags */
842 __u8 dr_reserved0;
843 __le16 dr_reserved1;
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800844 __le64 dr_dir_blkno; /* Pointer to parent inode */
845 __le64 dr_reserved2;
Mark Fashehe7c17e42009-01-29 18:17:46 -0800846 __le64 dr_free_blk; /* Pointer to head of free
847 * unindexed block list. */
848 __le64 dr_reserved3[15];
Mark Fasheh4ed8a6b2008-11-24 17:02:08 -0800849 union {
850 struct ocfs2_extent_list dr_list; /* Keep this aligned to 128
851 * bits for maximum space
852 * efficiency. */
853 struct ocfs2_dx_entry_list dr_entries; /* In-root-block list of
854 * entries. We grow out
855 * to extents if this
856 * gets too big. */
857 };
Mark Fasheh9b7895e2008-11-12 16:27:44 -0800858};
859
860/*
861 * The header of a leaf block in the indexed tree.
862 */
863struct ocfs2_dx_leaf {
864 __u8 dl_signature[8];/* Signature for verification */
865 struct ocfs2_block_check dl_check; /* Error checking */
866 __le64 dl_blkno; /* Offset on disk, in blocks */
867 __le32 dl_fs_generation;/* Must match super block */
868 __le32 dl_reserved0;
869 __le64 dl_reserved1;
870 struct ocfs2_dx_entry_list dl_list;
871};
872
Mark Fasheh87d35a72008-12-10 17:36:25 -0800873/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800874 * On disk allocator group structure for OCFS2
875 */
876struct ocfs2_group_desc
877{
878/*00*/ __u8 bg_signature[8]; /* Signature for validation */
879 __le16 bg_size; /* Size of included bitmap in
880 bytes. */
881 __le16 bg_bits; /* Bits represented by this
882 group. */
883 __le16 bg_free_bits_count; /* Free bits count */
884 __le16 bg_chain; /* What chain I am in. */
885/*10*/ __le32 bg_generation;
886 __le32 bg_reserved1;
887 __le64 bg_next_group; /* Next group in my list, in
888 blocks */
889/*20*/ __le64 bg_parent_dinode; /* dinode which owns me, in
890 blocks */
891 __le64 bg_blkno; /* Offset on disk, in blocks */
Joel Beckerab552d52008-10-16 17:50:30 -0700892/*30*/ struct ocfs2_block_check bg_check; /* Error checking */
893 __le64 bg_reserved2;
Mark Fashehccd979b2005-12-15 14:31:24 -0800894/*40*/ __u8 bg_bitmap[0];
895};
896
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800897/*
898 * On disk extended attribute structure for OCFS2.
899 */
900
901/*
902 * ocfs2_xattr_entry indicates one extend attribute.
903 *
904 * Note that it can be stored in inode, one block or one xattr bucket.
905 */
906struct ocfs2_xattr_entry {
907 __le32 xe_name_hash; /* hash value of xattr prefix+suffix. */
Tao Ma8573f792008-10-24 22:24:17 +0800908 __le16 xe_name_offset; /* byte offset from the 1st entry in the
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800909 local xattr storage(inode, xattr block or
910 xattr bucket). */
911 __u8 xe_name_len; /* xattr name len, does't include prefix. */
Tao Ma8573f792008-10-24 22:24:17 +0800912 __u8 xe_type; /* the low 7 bits indicate the name prefix
913 * type and the highest bit indicates whether
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800914 * the EA is stored in the local storage. */
915 __le64 xe_value_size; /* real xattr value length. */
916};
917
918/*
919 * On disk structure for xattr header.
920 *
921 * One ocfs2_xattr_header describes how many ocfs2_xattr_entry records in
922 * the local xattr storage.
923 */
924struct ocfs2_xattr_header {
925 __le16 xh_count; /* contains the count of how
926 many records are in the
927 local xattr storage. */
Tao Ma0c044f02008-08-18 17:38:50 +0800928 __le16 xh_free_start; /* current offset for storing
929 xattr. */
930 __le16 xh_name_value_len; /* total length of name/value
931 length in this bucket. */
Tao Ma8573f792008-10-24 22:24:17 +0800932 __le16 xh_num_buckets; /* Number of xattr buckets
933 in this extent record,
934 only valid in the first
935 bucket. */
Joel Beckerab552d52008-10-16 17:50:30 -0700936 struct ocfs2_block_check xh_check; /* Error checking
937 (Note, this is only
938 used for xattr
939 buckets. A block uses
940 xb_check and sets
941 this field to zero.) */
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800942 struct ocfs2_xattr_entry xh_entries[0]; /* xattr entry list. */
943};
944
945/*
946 * On disk structure for xattr value root.
947 *
Tao Ma8573f792008-10-24 22:24:17 +0800948 * When an xattr's value is large enough, it is stored in an external
949 * b-tree like file data. The xattr value root points to this structure.
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800950 */
951struct ocfs2_xattr_value_root {
952/*00*/ __le32 xr_clusters; /* clusters covered by xattr value. */
953 __le32 xr_reserved0;
954 __le64 xr_last_eb_blk; /* Pointer to last extent block */
955/*10*/ struct ocfs2_extent_list xr_list; /* Extent record list */
956};
957
958/*
959 * On disk structure for xattr tree root.
960 *
961 * It is used when there are too many extended attributes for one file. These
962 * attributes will be organized and stored in an indexed-btree.
963 */
964struct ocfs2_xattr_tree_root {
965/*00*/ __le32 xt_clusters; /* clusters covered by xattr. */
966 __le32 xt_reserved0;
967 __le64 xt_last_eb_blk; /* Pointer to last extent block */
968/*10*/ struct ocfs2_extent_list xt_list; /* Extent record list */
969};
970
Tiger Yangcf1d6c72008-08-18 17:11:00 +0800971#define OCFS2_XATTR_INDEXED 0x1
972#define OCFS2_HASH_SHIFT 5
973#define OCFS2_XATTR_ROUND 3
974#define OCFS2_XATTR_SIZE(size) (((size) + OCFS2_XATTR_ROUND) & \
975 ~(OCFS2_XATTR_ROUND))
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800976
Tao Ma0c044f02008-08-18 17:38:50 +0800977#define OCFS2_XATTR_BUCKET_SIZE 4096
978#define OCFS2_XATTR_MAX_BLOCKS_PER_BUCKET (OCFS2_XATTR_BUCKET_SIZE \
979 / OCFS2_MIN_BLOCKSIZE)
980
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800981/*
982 * On disk structure for xattr block.
983 */
984struct ocfs2_xattr_block {
985/*00*/ __u8 xb_signature[8]; /* Signature for verification */
986 __le16 xb_suballoc_slot; /* Slot suballocator this
987 block belongs to. */
988 __le16 xb_suballoc_bit; /* Bit offset in suballocator
989 block group */
990 __le32 xb_fs_generation; /* Must match super block */
991/*10*/ __le64 xb_blkno; /* Offset on disk, in blocks */
Joel Beckerab552d52008-10-16 17:50:30 -0700992 struct ocfs2_block_check xb_check; /* Error checking */
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800993/*20*/ __le16 xb_flags; /* Indicates whether this block contains
994 real xattr or a xattr tree. */
995 __le16 xb_reserved0;
996 __le32 xb_reserved1;
997 __le64 xb_reserved2;
998/*30*/ union {
999 struct ocfs2_xattr_header xb_header; /* xattr header if this
1000 block contains xattr */
1001 struct ocfs2_xattr_tree_root xb_root;/* xattr tree root if this
1002 block cotains xattr
1003 tree. */
1004 } xb_attrs;
1005};
1006
1007#define OCFS2_XATTR_ENTRY_LOCAL 0x80
1008#define OCFS2_XATTR_TYPE_MASK 0x7F
1009static inline void ocfs2_xattr_set_local(struct ocfs2_xattr_entry *xe,
1010 int local)
1011{
1012 if (local)
1013 xe->xe_type |= OCFS2_XATTR_ENTRY_LOCAL;
1014 else
1015 xe->xe_type &= ~OCFS2_XATTR_ENTRY_LOCAL;
1016}
1017
1018static inline int ocfs2_xattr_is_local(struct ocfs2_xattr_entry *xe)
1019{
1020 return xe->xe_type & OCFS2_XATTR_ENTRY_LOCAL;
1021}
1022
1023static inline void ocfs2_xattr_set_type(struct ocfs2_xattr_entry *xe, int type)
1024{
1025 xe->xe_type |= type & OCFS2_XATTR_TYPE_MASK;
1026}
1027
1028static inline int ocfs2_xattr_get_type(struct ocfs2_xattr_entry *xe)
1029{
1030 return xe->xe_type & OCFS2_XATTR_TYPE_MASK;
1031}
1032
Jan Kara9e33d692008-08-25 19:56:50 +02001033/*
1034 * On disk structures for global quota file
1035 */
1036
1037/* Magic numbers and known versions for global quota files */
1038#define OCFS2_GLOBAL_QMAGICS {\
1039 0x0cf52470, /* USRQUOTA */ \
1040 0x0cf52471 /* GRPQUOTA */ \
1041}
1042
1043#define OCFS2_GLOBAL_QVERSIONS {\
1044 0, \
1045 0, \
1046}
1047
1048
1049/* Each block of each quota file has a certain fixed number of bytes reserved
1050 * for OCFS2 internal use at its end. OCFS2 can use it for things like
1051 * checksums, etc. */
1052#define OCFS2_QBLK_RESERVED_SPACE 8
1053
1054/* Generic header of all quota files */
1055struct ocfs2_disk_dqheader {
1056 __le32 dqh_magic; /* Magic number identifying file */
1057 __le32 dqh_version; /* Quota format version */
1058};
1059
1060#define OCFS2_GLOBAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
1061
1062/* Information header of global quota file (immediately follows the generic
1063 * header) */
1064struct ocfs2_global_disk_dqinfo {
1065/*00*/ __le32 dqi_bgrace; /* Grace time for space softlimit excess */
1066 __le32 dqi_igrace; /* Grace time for inode softlimit excess */
1067 __le32 dqi_syncms; /* Time after which we sync local changes to
1068 * global quota file */
1069 __le32 dqi_blocks; /* Number of blocks in quota file */
1070/*10*/ __le32 dqi_free_blk; /* First free block in quota file */
1071 __le32 dqi_free_entry; /* First block with free dquot entry in quota
1072 * file */
1073};
1074
1075/* Structure with global user / group information. We reserve some space
1076 * for future use. */
1077struct ocfs2_global_disk_dqblk {
1078/*00*/ __le32 dqb_id; /* ID the structure belongs to */
1079 __le32 dqb_use_count; /* Number of nodes having reference to this structure */
1080 __le64 dqb_ihardlimit; /* absolute limit on allocated inodes */
1081/*10*/ __le64 dqb_isoftlimit; /* preferred inode limit */
1082 __le64 dqb_curinodes; /* current # allocated inodes */
1083/*20*/ __le64 dqb_bhardlimit; /* absolute limit on disk space */
1084 __le64 dqb_bsoftlimit; /* preferred limit on disk space */
1085/*30*/ __le64 dqb_curspace; /* current space occupied */
1086 __le64 dqb_btime; /* time limit for excessive disk use */
1087/*40*/ __le64 dqb_itime; /* time limit for excessive inode use */
1088 __le64 dqb_pad1;
1089/*50*/ __le64 dqb_pad2;
1090};
1091
1092/*
1093 * On-disk structures for local quota file
1094 */
1095
1096/* Magic numbers and known versions for local quota files */
1097#define OCFS2_LOCAL_QMAGICS {\
1098 0x0cf524c0, /* USRQUOTA */ \
1099 0x0cf524c1 /* GRPQUOTA */ \
1100}
1101
1102#define OCFS2_LOCAL_QVERSIONS {\
1103 0, \
1104 0, \
1105}
1106
1107/* Quota flags in dqinfo header */
1108#define OLQF_CLEAN 0x0001 /* Quota file is empty (this should be after\
1109 * quota has been cleanly turned off) */
1110
1111#define OCFS2_LOCAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
1112
1113/* Information header of local quota file (immediately follows the generic
1114 * header) */
1115struct ocfs2_local_disk_dqinfo {
1116 __le32 dqi_flags; /* Flags for quota file */
1117 __le32 dqi_chunks; /* Number of chunks of quota structures
1118 * with a bitmap */
1119 __le32 dqi_blocks; /* Number of blocks allocated for quota file */
1120};
1121
1122/* Header of one chunk of a quota file */
1123struct ocfs2_local_disk_chunk {
1124 __le32 dqc_free; /* Number of free entries in the bitmap */
1125 u8 dqc_bitmap[0]; /* Bitmap of entries in the corresponding
1126 * chunk of quota file */
1127};
1128
1129/* One entry in local quota file */
1130struct ocfs2_local_disk_dqblk {
1131/*00*/ __le64 dqb_id; /* id this quota applies to */
1132 __le64 dqb_spacemod; /* Change in the amount of used space */
1133/*10*/ __le64 dqb_inodemod; /* Change in the amount of used inodes */
1134};
1135
Joel Beckerab552d52008-10-16 17:50:30 -07001136
1137/*
1138 * The quota trailer lives at the end of each quota block.
1139 */
1140
1141struct ocfs2_disk_dqtrailer {
1142/*00*/ struct ocfs2_block_check dq_check; /* Error checking */
1143/*08*/ /* Cannot be larger than OCFS2_QBLK_RESERVED_SPACE */
1144};
1145
1146static inline struct ocfs2_disk_dqtrailer *ocfs2_block_dqtrailer(int blocksize,
1147 void *buf)
1148{
1149 char *ptr = buf;
1150 ptr += blocksize - OCFS2_QBLK_RESERVED_SPACE;
1151
1152 return (struct ocfs2_disk_dqtrailer *)ptr;
1153}
1154
Mark Fashehccd979b2005-12-15 14:31:24 -08001155#ifdef __KERNEL__
1156static inline int ocfs2_fast_symlink_chars(struct super_block *sb)
1157{
1158 return sb->s_blocksize -
1159 offsetof(struct ocfs2_dinode, id2.i_symlink);
1160}
1161
Tiger Yangfdd77702008-08-18 17:08:55 +08001162static inline int ocfs2_max_inline_data_with_xattr(struct super_block *sb,
1163 struct ocfs2_dinode *di)
1164{
1165 unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
1166
1167 if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
1168 return sb->s_blocksize -
1169 offsetof(struct ocfs2_dinode, id2.i_data.id_data) -
1170 xattrsize;
1171 else
1172 return sb->s_blocksize -
1173 offsetof(struct ocfs2_dinode, id2.i_data.id_data);
1174}
1175
Mark Fashehccd979b2005-12-15 14:31:24 -08001176static inline int ocfs2_extent_recs_per_inode(struct super_block *sb)
1177{
1178 int size;
1179
1180 size = sb->s_blocksize -
1181 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1182
1183 return size / sizeof(struct ocfs2_extent_rec);
1184}
1185
Tiger Yangfdd77702008-08-18 17:08:55 +08001186static inline int ocfs2_extent_recs_per_inode_with_xattr(
1187 struct super_block *sb,
1188 struct ocfs2_dinode *di)
1189{
1190 int size;
1191 unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
1192
1193 if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
1194 size = sb->s_blocksize -
1195 offsetof(struct ocfs2_dinode, id2.i_list.l_recs) -
1196 xattrsize;
1197 else
1198 size = sb->s_blocksize -
1199 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1200
1201 return size / sizeof(struct ocfs2_extent_rec);
1202}
1203
Mark Fasheh9b7895e2008-11-12 16:27:44 -08001204static inline int ocfs2_extent_recs_per_dx_root(struct super_block *sb)
1205{
1206 int size;
1207
1208 size = sb->s_blocksize -
1209 offsetof(struct ocfs2_dx_root_block, dr_list.l_recs);
1210
1211 return size / sizeof(struct ocfs2_extent_rec);
1212}
1213
Mark Fashehccd979b2005-12-15 14:31:24 -08001214static inline int ocfs2_chain_recs_per_inode(struct super_block *sb)
1215{
1216 int size;
1217
1218 size = sb->s_blocksize -
1219 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
1220
1221 return size / sizeof(struct ocfs2_chain_rec);
1222}
1223
1224static inline u16 ocfs2_extent_recs_per_eb(struct super_block *sb)
1225{
1226 int size;
1227
1228 size = sb->s_blocksize -
1229 offsetof(struct ocfs2_extent_block, h_list.l_recs);
1230
1231 return size / sizeof(struct ocfs2_extent_rec);
1232}
1233
Mark Fasheh9b7895e2008-11-12 16:27:44 -08001234static inline int ocfs2_dx_entries_per_leaf(struct super_block *sb)
1235{
1236 int size;
1237
1238 size = sb->s_blocksize -
1239 offsetof(struct ocfs2_dx_leaf, dl_list.de_entries);
1240
1241 return size / sizeof(struct ocfs2_dx_entry);
1242}
1243
Mark Fasheh4ed8a6b2008-11-24 17:02:08 -08001244static inline int ocfs2_dx_entries_per_root(struct super_block *sb)
1245{
1246 int size;
1247
1248 size = sb->s_blocksize -
1249 offsetof(struct ocfs2_dx_root_block, dr_entries.de_entries);
1250
1251 return size / sizeof(struct ocfs2_dx_entry);
1252}
1253
Mark Fashehccd979b2005-12-15 14:31:24 -08001254static inline u16 ocfs2_local_alloc_size(struct super_block *sb)
1255{
1256 u16 size;
1257
1258 size = sb->s_blocksize -
1259 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
1260
1261 return size;
1262}
1263
1264static inline int ocfs2_group_bitmap_size(struct super_block *sb)
1265{
1266 int size;
1267
1268 size = sb->s_blocksize -
1269 offsetof(struct ocfs2_group_desc, bg_bitmap);
1270
1271 return size;
1272}
1273
1274static inline int ocfs2_truncate_recs_per_inode(struct super_block *sb)
1275{
1276 int size;
1277
1278 size = sb->s_blocksize -
1279 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
1280
1281 return size / sizeof(struct ocfs2_truncate_rec);
1282}
Mark Fasheh50af94b2007-01-21 14:44:59 -08001283
1284static inline u64 ocfs2_backup_super_blkno(struct super_block *sb, int index)
1285{
1286 u64 offset = OCFS2_BACKUP_SB_START;
1287
1288 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
1289 offset <<= (2 * index);
Mark Fasheha8a75a22007-01-26 10:46:59 -08001290 offset >>= sb->s_blocksize_bits;
Mark Fasheh50af94b2007-01-21 14:44:59 -08001291 return offset;
1292 }
1293
1294 return 0;
1295
1296}
Tao Ma0c044f02008-08-18 17:38:50 +08001297
1298static inline u16 ocfs2_xattr_recs_per_xb(struct super_block *sb)
1299{
1300 int size;
1301
1302 size = sb->s_blocksize -
1303 offsetof(struct ocfs2_xattr_block,
1304 xb_attrs.xb_root.xt_list.l_recs);
1305
1306 return size / sizeof(struct ocfs2_extent_rec);
1307}
Mark Fashehccd979b2005-12-15 14:31:24 -08001308#else
1309static inline int ocfs2_fast_symlink_chars(int blocksize)
1310{
1311 return blocksize - offsetof(struct ocfs2_dinode, id2.i_symlink);
1312}
1313
Mark Fasheh15b1e362007-09-07 13:58:15 -07001314static inline int ocfs2_max_inline_data(int blocksize)
1315{
1316 return blocksize - offsetof(struct ocfs2_dinode, id2.i_data.id_data);
1317}
1318
Mark Fashehccd979b2005-12-15 14:31:24 -08001319static inline int ocfs2_extent_recs_per_inode(int blocksize)
1320{
1321 int size;
1322
1323 size = blocksize -
1324 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1325
1326 return size / sizeof(struct ocfs2_extent_rec);
1327}
1328
1329static inline int ocfs2_chain_recs_per_inode(int blocksize)
1330{
1331 int size;
1332
1333 size = blocksize -
1334 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
1335
1336 return size / sizeof(struct ocfs2_chain_rec);
1337}
1338
1339static inline int ocfs2_extent_recs_per_eb(int blocksize)
1340{
1341 int size;
1342
1343 size = blocksize -
1344 offsetof(struct ocfs2_extent_block, h_list.l_recs);
1345
1346 return size / sizeof(struct ocfs2_extent_rec);
1347}
1348
1349static inline int ocfs2_local_alloc_size(int blocksize)
1350{
1351 int size;
1352
1353 size = blocksize -
1354 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
1355
1356 return size;
1357}
1358
1359static inline int ocfs2_group_bitmap_size(int blocksize)
1360{
1361 int size;
1362
1363 size = blocksize -
1364 offsetof(struct ocfs2_group_desc, bg_bitmap);
1365
1366 return size;
1367}
1368
1369static inline int ocfs2_truncate_recs_per_inode(int blocksize)
1370{
1371 int size;
1372
1373 size = blocksize -
1374 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
1375
1376 return size / sizeof(struct ocfs2_truncate_rec);
1377}
Mark Fasheh50af94b2007-01-21 14:44:59 -08001378
1379static inline uint64_t ocfs2_backup_super_blkno(int blocksize, int index)
1380{
1381 uint64_t offset = OCFS2_BACKUP_SB_START;
1382
1383 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
1384 offset <<= (2 * index);
1385 offset /= blocksize;
1386 return offset;
1387 }
1388
1389 return 0;
1390}
Tao Ma0c044f02008-08-18 17:38:50 +08001391
1392static inline int ocfs2_xattr_recs_per_xb(int blocksize)
1393{
1394 int size;
1395
1396 size = blocksize -
1397 offsetof(struct ocfs2_xattr_block,
1398 xb_attrs.xb_root.xt_list.l_recs);
1399
1400 return size / sizeof(struct ocfs2_extent_rec);
1401}
Mark Fashehccd979b2005-12-15 14:31:24 -08001402#endif /* __KERNEL__ */
1403
1404
1405static inline int ocfs2_system_inode_is_global(int type)
1406{
1407 return ((type >= 0) &&
1408 (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE));
1409}
1410
1411static inline int ocfs2_sprintf_system_inode_name(char *buf, int len,
1412 int type, int slot)
1413{
1414 int chars;
1415
1416 /*
1417 * Global system inodes can only have one copy. Everything
1418 * after OCFS2_LAST_GLOBAL_SYSTEM_INODE in the system inode
1419 * list has a copy per slot.
1420 */
1421 if (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE)
Joel Beckerfe9f3872008-06-12 22:39:18 -07001422 chars = snprintf(buf, len, "%s",
Mark Fashehccd979b2005-12-15 14:31:24 -08001423 ocfs2_system_inodes[type].si_name);
1424 else
1425 chars = snprintf(buf, len,
1426 ocfs2_system_inodes[type].si_name,
1427 slot);
1428
1429 return chars;
1430}
1431
1432static inline void ocfs2_set_de_type(struct ocfs2_dir_entry *de,
1433 umode_t mode)
1434{
1435 de->file_type = ocfs2_type_by_mode[(mode & S_IFMT)>>S_SHIFT];
1436}
1437
1438#endif /* _OCFS2_FS_H */
1439