blob: 698ef3d271213fe4dfddc579b42c317877a061a7 [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 Fashehccd979b2005-12-15 14:31:24 -080069
70/* Compatibility flags */
71#define OCFS2_HAS_COMPAT_FEATURE(sb,mask) \
72 ( OCFS2_SB(sb)->s_feature_compat & (mask) )
73#define OCFS2_HAS_RO_COMPAT_FEATURE(sb,mask) \
74 ( OCFS2_SB(sb)->s_feature_ro_compat & (mask) )
75#define OCFS2_HAS_INCOMPAT_FEATURE(sb,mask) \
76 ( OCFS2_SB(sb)->s_feature_incompat & (mask) )
77#define OCFS2_SET_COMPAT_FEATURE(sb,mask) \
78 OCFS2_SB(sb)->s_feature_compat |= (mask)
79#define OCFS2_SET_RO_COMPAT_FEATURE(sb,mask) \
80 OCFS2_SB(sb)->s_feature_ro_compat |= (mask)
81#define OCFS2_SET_INCOMPAT_FEATURE(sb,mask) \
82 OCFS2_SB(sb)->s_feature_incompat |= (mask)
83#define OCFS2_CLEAR_COMPAT_FEATURE(sb,mask) \
84 OCFS2_SB(sb)->s_feature_compat &= ~(mask)
85#define OCFS2_CLEAR_RO_COMPAT_FEATURE(sb,mask) \
86 OCFS2_SB(sb)->s_feature_ro_compat &= ~(mask)
87#define OCFS2_CLEAR_INCOMPAT_FEATURE(sb,mask) \
88 OCFS2_SB(sb)->s_feature_incompat &= ~(mask)
89
Joel Beckera9772182008-12-16 18:10:18 -080090#define OCFS2_FEATURE_COMPAT_SUPP (OCFS2_FEATURE_COMPAT_BACKUP_SB \
91 | OCFS2_FEATURE_COMPAT_JBD2_SB)
Mark Fashehdcd05382007-01-16 11:32:23 -080092#define OCFS2_FEATURE_INCOMPAT_SUPP (OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT \
Mark Fasheh15b1e362007-09-07 13:58:15 -070093 | OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC \
Joel Becker386a2ef2008-02-01 12:06:54 -080094 | OCFS2_FEATURE_INCOMPAT_INLINE_DATA \
Joel Beckerb61817e2008-02-01 15:08:23 -080095 | OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP \
Tiger Yang8154da32008-08-18 17:11:46 +080096 | OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK \
97 | OCFS2_FEATURE_INCOMPAT_XATTR)
Jan Kara19ece542008-08-21 20:13:17 +020098#define OCFS2_FEATURE_RO_COMPAT_SUPP (OCFS2_FEATURE_RO_COMPAT_UNWRITTEN \
99 | OCFS2_FEATURE_RO_COMPAT_USRQUOTA \
100 | OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)
Mark Fashehccd979b2005-12-15 14:31:24 -0800101
102/*
103 * Heartbeat-only devices are missing journals and other files. The
104 * filesystem driver can't load them, but the library can. Never put
105 * this in OCFS2_FEATURE_INCOMPAT_SUPP, *ever*.
106 */
107#define OCFS2_FEATURE_INCOMPAT_HEARTBEAT_DEV 0x0002
108
Mark Fasheh89039012006-12-07 18:05:37 -0800109/*
110 * tunefs sets this incompat flag before starting the resize and clears it
111 * at the end. This flag protects users from inadvertently mounting the fs
112 * after an aborted run without fsck-ing.
113 */
114#define OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG 0x0004
Mark Fashehccd979b2005-12-15 14:31:24 -0800115
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800116/* Used to denote a non-clustered volume */
117#define OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT 0x0008
118
Mark Fasheh89039012006-12-07 18:05:37 -0800119/* Support for sparse allocation in b-trees */
120#define OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC 0x0010
121
Mark Fashehccd979b2005-12-15 14:31:24 -0800122/*
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700123 * Tunefs sets this incompat flag before starting an operation which
124 * would require cleanup on abort. This is done to protect users from
125 * inadvertently mounting the fs after an aborted run without
126 * fsck-ing.
127 *
128 * s_tunefs_flags on the super block describes precisely which
129 * operations were in progress.
130 */
131#define OCFS2_FEATURE_INCOMPAT_TUNEFS_INPROG 0x0020
132
Mark Fasheh15b1e362007-09-07 13:58:15 -0700133/* Support for data packed into inode blocks */
134#define OCFS2_FEATURE_INCOMPAT_INLINE_DATA 0x0040
135
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700136/*
Joel Beckerb61817e2008-02-01 15:08:23 -0800137 * Support for alternate, userspace cluster stacks. If set, the superblock
138 * field s_cluster_info contains a tag for the alternate stack in use as
139 * well as the name of the cluster being joined.
140 * mount.ocfs2 must pass in a matching stack name.
141 *
142 * If not set, the classic stack will be used. This is compatbile with
143 * all older versions.
144 */
145#define OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK 0x0080
146
Tiger Yang8154da32008-08-18 17:11:46 +0800147/* Support for the extended slot map */
148#define OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP 0x100
149
150/* Support for extended attributes */
151#define OCFS2_FEATURE_INCOMPAT_XATTR 0x0200
152
Joel Beckerab552d52008-10-16 17:50:30 -0700153/* Metadata checksum and error correction */
154#define OCFS2_FEATURE_INCOMPAT_META_ECC 0x0800
155
Joel Beckerb61817e2008-02-01 15:08:23 -0800156/*
Mark Fasheh50af94b2007-01-21 14:44:59 -0800157 * backup superblock flag is used to indicate that this volume
158 * has backup superblocks.
159 */
160#define OCFS2_FEATURE_COMPAT_BACKUP_SB 0x0001
161
Mark Fasheh328d5752007-06-18 10:48:04 -0700162/*
Joel Beckera9772182008-12-16 18:10:18 -0800163 * The filesystem will correctly handle journal feature bits.
164 */
165#define OCFS2_FEATURE_COMPAT_JBD2_SB 0x0002
166
167/*
Mark Fasheh328d5752007-06-18 10:48:04 -0700168 * Unwritten extents support.
169 */
170#define OCFS2_FEATURE_RO_COMPAT_UNWRITTEN 0x0001
171
Jan Kara1a224ad2008-08-20 15:43:36 +0200172/*
173 * Maintain quota information for this filesystem
174 */
175#define OCFS2_FEATURE_RO_COMPAT_USRQUOTA 0x0002
176#define OCFS2_FEATURE_RO_COMPAT_GRPQUOTA 0x0004
177
Mark Fasheh50af94b2007-01-21 14:44:59 -0800178/* The byte offset of the first backup block will be 1G.
179 * The following will be 4G, 16G, 64G, 256G and 1T.
180 */
181#define OCFS2_BACKUP_SB_START 1 << 30
182
183/* the max backup superblock nums */
184#define OCFS2_MAX_BACKUP_SUPERBLOCKS 6
185
186/*
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700187 * Flags on ocfs2_super_block.s_tunefs_flags
188 */
189#define OCFS2_TUNEFS_INPROG_REMOVE_SLOT 0x0001 /* Removing slots */
190
191/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800192 * Flags on ocfs2_dinode.i_flags
193 */
194#define OCFS2_VALID_FL (0x00000001) /* Inode is valid */
195#define OCFS2_UNUSED2_FL (0x00000002)
196#define OCFS2_ORPHANED_FL (0x00000004) /* On the orphan list */
197#define OCFS2_UNUSED3_FL (0x00000008)
198/* System inode flags */
199#define OCFS2_SYSTEM_FL (0x00000010) /* System inode */
200#define OCFS2_SUPER_BLOCK_FL (0x00000020) /* Super block */
201#define OCFS2_LOCAL_ALLOC_FL (0x00000040) /* Slot local alloc bitmap */
202#define OCFS2_BITMAP_FL (0x00000080) /* Allocation bitmap */
203#define OCFS2_JOURNAL_FL (0x00000100) /* Slot local journal */
204#define OCFS2_HEARTBEAT_FL (0x00000200) /* Heartbeat area */
205#define OCFS2_CHAIN_FL (0x00000400) /* Chain allocator */
206#define OCFS2_DEALLOC_FL (0x00000800) /* Truncate log */
Jan Kara1a224ad2008-08-20 15:43:36 +0200207#define OCFS2_QUOTA_FL (0x00001000) /* Quota file */
Mark Fashehccd979b2005-12-15 14:31:24 -0800208
Mark Fasheh15b1e362007-09-07 13:58:15 -0700209/*
210 * Flags on ocfs2_dinode.i_dyn_features
211 *
212 * These can change much more often than i_flags. When adding flags,
213 * keep in mind that i_dyn_features is only 16 bits wide.
214 */
215#define OCFS2_INLINE_DATA_FL (0x0001) /* Data stored in inode block */
216#define OCFS2_HAS_XATTR_FL (0x0002)
217#define OCFS2_INLINE_XATTR_FL (0x0004)
218#define OCFS2_INDEXED_DIR_FL (0x0008)
219
Herbert Poetzlca4d1472006-07-03 17:27:12 -0700220/* Inode attributes, keep in sync with EXT2 */
221#define OCFS2_SECRM_FL (0x00000001) /* Secure deletion */
222#define OCFS2_UNRM_FL (0x00000002) /* Undelete */
223#define OCFS2_COMPR_FL (0x00000004) /* Compress file */
224#define OCFS2_SYNC_FL (0x00000008) /* Synchronous updates */
225#define OCFS2_IMMUTABLE_FL (0x00000010) /* Immutable file */
226#define OCFS2_APPEND_FL (0x00000020) /* writes to file may only append */
227#define OCFS2_NODUMP_FL (0x00000040) /* do not dump file */
228#define OCFS2_NOATIME_FL (0x00000080) /* do not update atime */
229#define OCFS2_DIRSYNC_FL (0x00010000) /* dirsync behaviour (directories only) */
230
231#define OCFS2_FL_VISIBLE (0x000100FF) /* User visible flags */
232#define OCFS2_FL_MODIFIABLE (0x000100FF) /* User modifiable flags */
233
234/*
Mark Fashehe48edee2007-03-07 16:46:57 -0800235 * Extent record flags (e_node.leaf.flags)
236 */
237#define OCFS2_EXT_UNWRITTEN (0x01) /* Extent is allocated but
238 * unwritten */
239
240/*
Herbert Poetzlca4d1472006-07-03 17:27:12 -0700241 * ioctl commands
242 */
243#define OCFS2_IOC_GETFLAGS _IOR('f', 1, long)
244#define OCFS2_IOC_SETFLAGS _IOW('f', 2, long)
Mark Fasheh586d2322007-03-09 15:56:28 -0800245#define OCFS2_IOC32_GETFLAGS _IOR('f', 1, int)
246#define OCFS2_IOC32_SETFLAGS _IOW('f', 2, int)
Herbert Poetzlca4d1472006-07-03 17:27:12 -0700247
Mark Fashehccd979b2005-12-15 14:31:24 -0800248/*
Mark Fashehb2580102007-03-09 16:53:21 -0800249 * Space reservation / allocation / free ioctls and argument structure
250 * are designed to be compatible with XFS.
251 *
252 * ALLOCSP* and FREESP* are not and will never be supported, but are
253 * included here for completeness.
254 */
255struct ocfs2_space_resv {
256 __s16 l_type;
257 __s16 l_whence;
258 __s64 l_start;
259 __s64 l_len; /* len == 0 means until end of file */
260 __s32 l_sysid;
261 __u32 l_pid;
262 __s32 l_pad[4]; /* reserve area */
263};
264
265#define OCFS2_IOC_ALLOCSP _IOW ('X', 10, struct ocfs2_space_resv)
266#define OCFS2_IOC_FREESP _IOW ('X', 11, struct ocfs2_space_resv)
267#define OCFS2_IOC_RESVSP _IOW ('X', 40, struct ocfs2_space_resv)
268#define OCFS2_IOC_UNRESVSP _IOW ('X', 41, struct ocfs2_space_resv)
269#define OCFS2_IOC_ALLOCSP64 _IOW ('X', 36, struct ocfs2_space_resv)
270#define OCFS2_IOC_FREESP64 _IOW ('X', 37, struct ocfs2_space_resv)
271#define OCFS2_IOC_RESVSP64 _IOW ('X', 42, struct ocfs2_space_resv)
272#define OCFS2_IOC_UNRESVSP64 _IOW ('X', 43, struct ocfs2_space_resv)
273
Tao Ma7909f2b2007-12-18 15:47:25 +0800274/* Used to pass group descriptor data when online resize is done */
275struct ocfs2_new_group_input {
276 __u64 group; /* Group descriptor's blkno. */
277 __u32 clusters; /* Total number of clusters in this group */
278 __u32 frees; /* Total free clusters in this group */
279 __u16 chain; /* Chain for this group */
280 __u16 reserved1;
281 __u32 reserved2;
282};
283
Tao Mad6590722007-12-18 15:47:03 +0800284#define OCFS2_IOC_GROUP_EXTEND _IOW('o', 1, int)
Tao Ma7909f2b2007-12-18 15:47:25 +0800285#define OCFS2_IOC_GROUP_ADD _IOW('o', 2,struct ocfs2_new_group_input)
286#define OCFS2_IOC_GROUP_ADD64 _IOW('o', 3,struct ocfs2_new_group_input)
Tao Mad6590722007-12-18 15:47:03 +0800287
Mark Fashehb2580102007-03-09 16:53:21 -0800288/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800289 * Journal Flags (ocfs2_dinode.id1.journal1.i_flags)
290 */
291#define OCFS2_JOURNAL_DIRTY_FL (0x00000001) /* Journal needs recovery */
292
293/*
294 * superblock s_state flags
295 */
296#define OCFS2_ERROR_FS (0x00000001) /* FS saw errors */
297
298/* Limit of space in ocfs2_dir_entry */
299#define OCFS2_MAX_FILENAME_LEN 255
300
301/* Maximum slots on an ocfs2 file system */
302#define OCFS2_MAX_SLOTS 255
303
304/* Slot map indicator for an empty slot */
305#define OCFS2_INVALID_SLOT -1
306
307#define OCFS2_VOL_UUID_LEN 16
308#define OCFS2_MAX_VOL_LABEL_LEN 64
309
Joel Beckerb61817e2008-02-01 15:08:23 -0800310/* The alternate, userspace stack fields */
311#define OCFS2_STACK_LABEL_LEN 4
312#define OCFS2_CLUSTER_NAME_LEN 16
313
Mark Fashehccd979b2005-12-15 14:31:24 -0800314/* Journal limits (in bytes) */
315#define OCFS2_MIN_JOURNAL_SIZE (4 * 1024 * 1024)
Mark Fashehccd979b2005-12-15 14:31:24 -0800316
Sunil Mushran2fbe8d12007-12-20 14:58:11 -0800317/*
318 * Default local alloc size (in megabytes)
319 *
320 * The value chosen should be such that most allocations, including new
321 * block groups, use local alloc.
322 */
323#define OCFS2_DEFAULT_LOCAL_ALLOC_SIZE 8
324
Tiger Yangfdd77702008-08-18 17:08:55 +0800325/*
326 * Inline extended attribute size (in bytes)
327 * The value chosen should be aligned to 16 byte boundaries.
328 */
329#define OCFS2_MIN_XATTR_INLINE_SIZE 256
330
Mark Fashehccd979b2005-12-15 14:31:24 -0800331struct ocfs2_system_inode_info {
332 char *si_name;
333 int si_iflags;
334 int si_mode;
335};
336
337/* System file index */
338enum {
339 BAD_BLOCK_SYSTEM_INODE = 0,
340 GLOBAL_INODE_ALLOC_SYSTEM_INODE,
341 SLOT_MAP_SYSTEM_INODE,
342#define OCFS2_FIRST_ONLINE_SYSTEM_INODE SLOT_MAP_SYSTEM_INODE
343 HEARTBEAT_SYSTEM_INODE,
344 GLOBAL_BITMAP_SYSTEM_INODE,
Jan Kara1a224ad2008-08-20 15:43:36 +0200345 USER_QUOTA_SYSTEM_INODE,
346 GROUP_QUOTA_SYSTEM_INODE,
347#define OCFS2_LAST_GLOBAL_SYSTEM_INODE GROUP_QUOTA_SYSTEM_INODE
Mark Fashehccd979b2005-12-15 14:31:24 -0800348 ORPHAN_DIR_SYSTEM_INODE,
349 EXTENT_ALLOC_SYSTEM_INODE,
350 INODE_ALLOC_SYSTEM_INODE,
351 JOURNAL_SYSTEM_INODE,
352 LOCAL_ALLOC_SYSTEM_INODE,
353 TRUNCATE_LOG_SYSTEM_INODE,
Jan Kara1a224ad2008-08-20 15:43:36 +0200354 LOCAL_USER_QUOTA_SYSTEM_INODE,
355 LOCAL_GROUP_QUOTA_SYSTEM_INODE,
Mark Fashehccd979b2005-12-15 14:31:24 -0800356 NUM_SYSTEM_INODES
357};
358
359static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = {
360 /* Global system inodes (single copy) */
361 /* The first two are only used from userspace mfks/tunefs */
362 [BAD_BLOCK_SYSTEM_INODE] = { "bad_blocks", 0, S_IFREG | 0644 },
363 [GLOBAL_INODE_ALLOC_SYSTEM_INODE] = { "global_inode_alloc", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
364
365 /* These are used by the running filesystem */
366 [SLOT_MAP_SYSTEM_INODE] = { "slot_map", 0, S_IFREG | 0644 },
367 [HEARTBEAT_SYSTEM_INODE] = { "heartbeat", OCFS2_HEARTBEAT_FL, S_IFREG | 0644 },
368 [GLOBAL_BITMAP_SYSTEM_INODE] = { "global_bitmap", 0, S_IFREG | 0644 },
Jan Kara1a224ad2008-08-20 15:43:36 +0200369 [USER_QUOTA_SYSTEM_INODE] = { "aquota.user", OCFS2_QUOTA_FL, S_IFREG | 0644 },
370 [GROUP_QUOTA_SYSTEM_INODE] = { "aquota.group", OCFS2_QUOTA_FL, S_IFREG | 0644 },
Mark Fashehccd979b2005-12-15 14:31:24 -0800371
372 /* Slot-specific system inodes (one copy per slot) */
373 [ORPHAN_DIR_SYSTEM_INODE] = { "orphan_dir:%04d", 0, S_IFDIR | 0755 },
374 [EXTENT_ALLOC_SYSTEM_INODE] = { "extent_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
375 [INODE_ALLOC_SYSTEM_INODE] = { "inode_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
376 [JOURNAL_SYSTEM_INODE] = { "journal:%04d", OCFS2_JOURNAL_FL, S_IFREG | 0644 },
377 [LOCAL_ALLOC_SYSTEM_INODE] = { "local_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_LOCAL_ALLOC_FL, S_IFREG | 0644 },
Jan Kara1a224ad2008-08-20 15:43:36 +0200378 [TRUNCATE_LOG_SYSTEM_INODE] = { "truncate_log:%04d", OCFS2_DEALLOC_FL, S_IFREG | 0644 },
379 [LOCAL_USER_QUOTA_SYSTEM_INODE] = { "aquota.user:%04d", OCFS2_QUOTA_FL, S_IFREG | 0644 },
380 [LOCAL_GROUP_QUOTA_SYSTEM_INODE] = { "aquota.group:%04d", OCFS2_QUOTA_FL, S_IFREG | 0644 },
Mark Fashehccd979b2005-12-15 14:31:24 -0800381};
382
383/* Parameter passed from mount.ocfs2 to module */
384#define OCFS2_HB_NONE "heartbeat=none"
385#define OCFS2_HB_LOCAL "heartbeat=local"
386
387/*
388 * OCFS2 directory file types. Only the low 3 bits are used. The
389 * other bits are reserved for now.
390 */
391#define OCFS2_FT_UNKNOWN 0
392#define OCFS2_FT_REG_FILE 1
393#define OCFS2_FT_DIR 2
394#define OCFS2_FT_CHRDEV 3
395#define OCFS2_FT_BLKDEV 4
396#define OCFS2_FT_FIFO 5
397#define OCFS2_FT_SOCK 6
398#define OCFS2_FT_SYMLINK 7
399
400#define OCFS2_FT_MAX 8
401
402/*
403 * OCFS2_DIR_PAD defines the directory entries boundaries
404 *
405 * NOTE: It must be a multiple of 4
406 */
407#define OCFS2_DIR_PAD 4
408#define OCFS2_DIR_ROUND (OCFS2_DIR_PAD - 1)
409#define OCFS2_DIR_MEMBER_LEN offsetof(struct ocfs2_dir_entry, name)
410#define OCFS2_DIR_REC_LEN(name_len) (((name_len) + OCFS2_DIR_MEMBER_LEN + \
411 OCFS2_DIR_ROUND) & \
412 ~OCFS2_DIR_ROUND)
413
414#define OCFS2_LINK_MAX 32000
415
416#define S_SHIFT 12
417static unsigned char ocfs2_type_by_mode[S_IFMT >> S_SHIFT] = {
418 [S_IFREG >> S_SHIFT] = OCFS2_FT_REG_FILE,
419 [S_IFDIR >> S_SHIFT] = OCFS2_FT_DIR,
420 [S_IFCHR >> S_SHIFT] = OCFS2_FT_CHRDEV,
421 [S_IFBLK >> S_SHIFT] = OCFS2_FT_BLKDEV,
422 [S_IFIFO >> S_SHIFT] = OCFS2_FT_FIFO,
423 [S_IFSOCK >> S_SHIFT] = OCFS2_FT_SOCK,
424 [S_IFLNK >> S_SHIFT] = OCFS2_FT_SYMLINK,
425};
426
427
428/*
429 * Convenience casts
430 */
431#define OCFS2_RAW_SB(dinode) (&((dinode)->id2.i_super))
432
433/*
Joel Beckerab552d52008-10-16 17:50:30 -0700434 * Block checking structure. This is used in metadata to validate the
435 * contents. If OCFS2_FEATURE_INCOMPAT_META_ECC is not set, it is all
436 * zeros.
437 */
438struct ocfs2_block_check {
439/*00*/ __le32 bc_crc32e; /* 802.3 Ethernet II CRC32 */
440 __le16 bc_ecc; /* Single-error-correction parity vector.
441 This is a simple Hamming code dependant
442 on the blocksize. OCFS2's maximum
443 blocksize, 4K, requires 16 parity bits,
444 so we fit in __le16. */
445 __le16 bc_reserved1;
446/*08*/
447};
448
449/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800450 * On disk extent record for OCFS2
451 * It describes a range of clusters on disk.
Mark Fashehe48edee2007-03-07 16:46:57 -0800452 *
453 * Length fields are divided into interior and leaf node versions.
454 * This leaves room for a flags field (OCFS2_EXT_*) in the leaf nodes.
Mark Fashehccd979b2005-12-15 14:31:24 -0800455 */
456struct ocfs2_extent_rec {
457/*00*/ __le32 e_cpos; /* Offset into the file, in clusters */
Mark Fashehe48edee2007-03-07 16:46:57 -0800458 union {
459 __le32 e_int_clusters; /* Clusters covered by all children */
460 struct {
461 __le16 e_leaf_clusters; /* Clusters covered by this
462 extent */
463 __u8 e_reserved1;
464 __u8 e_flags; /* Extent flags */
465 };
466 };
Mark Fashehccd979b2005-12-15 14:31:24 -0800467 __le64 e_blkno; /* Physical disk offset, in blocks */
468/*10*/
469};
470
471struct ocfs2_chain_rec {
472 __le32 c_free; /* Number of free bits in this chain. */
473 __le32 c_total; /* Number of total bits in this chain */
474 __le64 c_blkno; /* Physical disk offset (blocks) of 1st group */
475};
476
477struct ocfs2_truncate_rec {
478 __le32 t_start; /* 1st cluster in this log */
479 __le32 t_clusters; /* Number of total clusters covered */
480};
481
482/*
483 * On disk extent list for OCFS2 (node in the tree). Note that this
484 * is contained inside ocfs2_dinode or ocfs2_extent_block, so the
485 * offsets are relative to ocfs2_dinode.id2.i_list or
486 * ocfs2_extent_block.h_list, respectively.
487 */
488struct ocfs2_extent_list {
489/*00*/ __le16 l_tree_depth; /* Extent tree depth from this
490 point. 0 means data extents
491 hang directly off this
Mark Fashehdcd05382007-01-16 11:32:23 -0800492 header (a leaf)
493 NOTE: The high 8 bits cannot be
494 used - tree_depth is never that big.
495 */
Mark Fashehccd979b2005-12-15 14:31:24 -0800496 __le16 l_count; /* Number of extent records */
497 __le16 l_next_free_rec; /* Next unused extent slot */
498 __le16 l_reserved1;
499 __le64 l_reserved2; /* Pad to
500 sizeof(ocfs2_extent_rec) */
501/*10*/ struct ocfs2_extent_rec l_recs[0]; /* Extent records */
502};
503
504/*
505 * On disk allocation chain list for OCFS2. Note that this is
506 * contained inside ocfs2_dinode, so the offsets are relative to
507 * ocfs2_dinode.id2.i_chain.
508 */
509struct ocfs2_chain_list {
510/*00*/ __le16 cl_cpg; /* Clusters per Block Group */
511 __le16 cl_bpc; /* Bits per cluster */
512 __le16 cl_count; /* Total chains in this list */
513 __le16 cl_next_free_rec; /* Next unused chain slot */
514 __le64 cl_reserved1;
515/*10*/ struct ocfs2_chain_rec cl_recs[0]; /* Chain records */
516};
517
518/*
519 * On disk deallocation log for OCFS2. Note that this is
520 * contained inside ocfs2_dinode, so the offsets are relative to
521 * ocfs2_dinode.id2.i_dealloc.
522 */
523struct ocfs2_truncate_log {
524/*00*/ __le16 tl_count; /* Total records in this log */
525 __le16 tl_used; /* Number of records in use */
526 __le32 tl_reserved1;
527/*08*/ struct ocfs2_truncate_rec tl_recs[0]; /* Truncate records */
528};
529
530/*
531 * On disk extent block (indirect block) for OCFS2
532 */
533struct ocfs2_extent_block
534{
535/*00*/ __u8 h_signature[8]; /* Signature for verification */
Joel Beckerab552d52008-10-16 17:50:30 -0700536 struct ocfs2_block_check h_check; /* Error checking */
Mark Fashehccd979b2005-12-15 14:31:24 -0800537/*10*/ __le16 h_suballoc_slot; /* Slot suballocator this
538 extent_header belongs to */
539 __le16 h_suballoc_bit; /* Bit offset in suballocator
540 block group */
541 __le32 h_fs_generation; /* Must match super block */
542 __le64 h_blkno; /* Offset on disk, in blocks */
543/*20*/ __le64 h_reserved3;
544 __le64 h_next_leaf_blk; /* Offset on disk, in blocks,
545 of next leaf header pointing
546 to data */
547/*30*/ struct ocfs2_extent_list h_list; /* Extent record list */
548/* Actual on-disk size is one block */
549};
550
551/*
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800552 * On disk slot map for OCFS2. This defines the contents of the "slot_map"
Joel Becker386a2ef2008-02-01 12:06:54 -0800553 * system file. A slot is valid if it contains a node number >= 0. The
554 * value -1 (0xFFFF) is OCFS2_INVALID_SLOT. This marks a slot empty.
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800555 */
556struct ocfs2_slot_map {
557/*00*/ __le16 sm_slots[0];
558/*
559 * Actual on-disk size is one block. OCFS2_MAX_SLOTS is 255,
560 * 255 * sizeof(__le16) == 512B, within the 512B block minimum blocksize.
561 */
562};
563
Joel Becker386a2ef2008-02-01 12:06:54 -0800564struct ocfs2_extended_slot {
565/*00*/ __u8 es_valid;
566 __u8 es_reserved1[3];
567 __le32 es_node_num;
568/*10*/
569};
570
571/*
572 * The extended slot map, used when OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP
573 * is set. It separates out the valid marker from the node number, and
574 * has room to grow. Unlike the old slot map, this format is defined by
575 * i_size.
576 */
577struct ocfs2_slot_map_extended {
578/*00*/ struct ocfs2_extended_slot se_slots[0];
579/*
580 * Actual size is i_size of the slot_map system file. It should
581 * match s_max_slots * sizeof(struct ocfs2_extended_slot)
582 */
583};
584
Joel Beckerb61817e2008-02-01 15:08:23 -0800585struct ocfs2_cluster_info {
586/*00*/ __u8 ci_stack[OCFS2_STACK_LABEL_LEN];
587 __le32 ci_reserved;
588/*08*/ __u8 ci_cluster[OCFS2_CLUSTER_NAME_LEN];
589/*18*/
590};
591
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800592/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800593 * On disk superblock for OCFS2
594 * Note that it is contained inside an ocfs2_dinode, so all offsets
595 * are relative to the start of ocfs2_dinode.id2.
596 */
597struct ocfs2_super_block {
598/*00*/ __le16 s_major_rev_level;
599 __le16 s_minor_rev_level;
600 __le16 s_mnt_count;
601 __le16 s_max_mnt_count;
602 __le16 s_state; /* File system state */
603 __le16 s_errors; /* Behaviour when detecting errors */
604 __le32 s_checkinterval; /* Max time between checks */
605/*10*/ __le64 s_lastcheck; /* Time of last check */
606 __le32 s_creator_os; /* OS */
607 __le32 s_feature_compat; /* Compatible feature set */
608/*20*/ __le32 s_feature_incompat; /* Incompatible feature set */
609 __le32 s_feature_ro_compat; /* Readonly-compatible feature set */
610 __le64 s_root_blkno; /* Offset, in blocks, of root directory
611 dinode */
612/*30*/ __le64 s_system_dir_blkno; /* Offset, in blocks, of system
613 directory dinode */
614 __le32 s_blocksize_bits; /* Blocksize for this fs */
615 __le32 s_clustersize_bits; /* Clustersize for this fs */
616/*40*/ __le16 s_max_slots; /* Max number of simultaneous mounts
617 before tunefs required */
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700618 __le16 s_tunefs_flag;
Tiger Yangcf1d6c72008-08-18 17:11:00 +0800619 __le32 s_uuid_hash; /* hash value of uuid */
Mark Fashehccd979b2005-12-15 14:31:24 -0800620 __le64 s_first_cluster_group; /* Block offset of 1st cluster
621 * group header */
622/*50*/ __u8 s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */
623/*90*/ __u8 s_uuid[OCFS2_VOL_UUID_LEN]; /* 128-bit uuid */
Joel Beckerb61817e2008-02-01 15:08:23 -0800624/*A0*/ struct ocfs2_cluster_info s_cluster_info; /* Selected userspace
625 stack. Only valid
626 with INCOMPAT flag. */
Tiger Yang8154da32008-08-18 17:11:46 +0800627/*B8*/ __le16 s_xattr_inline_size; /* extended attribute inline size
628 for this fs*/
629 __le16 s_reserved0;
630 __le32 s_reserved1;
631/*C0*/ __le64 s_reserved2[16]; /* Fill out superblock */
Joel Beckerb61817e2008-02-01 15:08:23 -0800632/*140*/
633
634 /*
635 * NOTE: As stated above, all offsets are relative to
636 * ocfs2_dinode.id2, which is at 0xC0 in the inode.
637 * 0xC0 + 0x140 = 0x200 or 512 bytes. A superblock must fit within
638 * our smallest blocksize, which is 512 bytes. To ensure this,
639 * we reserve the space in s_reserved2. Anything past s_reserved2
640 * will not be available on the smallest blocksize.
641 */
Mark Fashehccd979b2005-12-15 14:31:24 -0800642};
643
644/*
645 * Local allocation bitmap for OCFS2 slots
646 * Note that it exists inside an ocfs2_dinode, so all offsets are
647 * relative to the start of ocfs2_dinode.id2.
648 */
649struct ocfs2_local_alloc
650{
651/*00*/ __le32 la_bm_off; /* Starting bit offset in main bitmap */
652 __le16 la_size; /* Size of included bitmap, in bytes */
653 __le16 la_reserved1;
654 __le64 la_reserved2;
655/*10*/ __u8 la_bitmap[0];
656};
657
658/*
Mark Fasheh15b1e362007-09-07 13:58:15 -0700659 * Data-in-inode header. This is only used if i_dyn_features has
660 * OCFS2_INLINE_DATA_FL set.
661 */
662struct ocfs2_inline_data
663{
664/*00*/ __le16 id_count; /* Number of bytes that can be used
665 * for data, starting at id_data */
666 __le16 id_reserved0;
667 __le32 id_reserved1;
668 __u8 id_data[0]; /* Start of user data */
669};
670
671/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800672 * On disk inode for OCFS2
673 */
674struct ocfs2_dinode {
675/*00*/ __u8 i_signature[8]; /* Signature for validation */
676 __le32 i_generation; /* Generation number */
677 __le16 i_suballoc_slot; /* Slot suballocator this inode
678 belongs to */
679 __le16 i_suballoc_bit; /* Bit offset in suballocator
680 block group */
Tiger Yangfdd77702008-08-18 17:08:55 +0800681/*10*/ __le16 i_reserved0;
682 __le16 i_xattr_inline_size;
Mark Fashehccd979b2005-12-15 14:31:24 -0800683 __le32 i_clusters; /* Cluster count */
684 __le32 i_uid; /* Owner UID */
685 __le32 i_gid; /* Owning GID */
686/*20*/ __le64 i_size; /* Size in bytes */
687 __le16 i_mode; /* File mode */
688 __le16 i_links_count; /* Links count */
689 __le32 i_flags; /* File flags */
690/*30*/ __le64 i_atime; /* Access time */
691 __le64 i_ctime; /* Creation time */
692/*40*/ __le64 i_mtime; /* Modification time */
693 __le64 i_dtime; /* Deletion time */
694/*50*/ __le64 i_blkno; /* Offset on disk, in blocks */
695 __le64 i_last_eb_blk; /* Pointer to last extent
696 block */
697/*60*/ __le32 i_fs_generation; /* Generation per fs-instance */
698 __le32 i_atime_nsec;
699 __le32 i_ctime_nsec;
700 __le32 i_mtime_nsec;
Tiger Yangfdd77702008-08-18 17:08:55 +0800701/*70*/ __le32 i_attr;
Tiger Yang50008632007-03-20 16:01:38 -0700702 __le16 i_orphaned_slot; /* Only valid when OCFS2_ORPHANED_FL
703 was set in i_flags */
Mark Fasheh15b1e362007-09-07 13:58:15 -0700704 __le16 i_dyn_features;
Tiger Yangfdd77702008-08-18 17:08:55 +0800705 __le64 i_xattr_loc;
Joel Beckerab552d52008-10-16 17:50:30 -0700706/*80*/ struct ocfs2_block_check i_check; /* Error checking */
707/*88*/ __le64 i_reserved2[6];
Mark Fashehccd979b2005-12-15 14:31:24 -0800708/*B8*/ union {
709 __le64 i_pad1; /* Generic way to refer to this
710 64bit union */
711 struct {
712 __le64 i_rdev; /* Device number */
713 } dev1;
714 struct { /* Info for bitmap system
715 inodes */
716 __le32 i_used; /* Bits (ie, clusters) used */
717 __le32 i_total; /* Total bits (clusters)
718 available */
719 } bitmap1;
720 struct { /* Info for journal system
721 inodes */
722 __le32 ij_flags; /* Mounted, version, etc. */
Sunil Mushranc69991a2008-07-14 17:31:09 -0700723 __le32 ij_recovery_generation; /* Incremented when the
724 journal is recovered
725 after an unclean
726 shutdown */
Mark Fashehccd979b2005-12-15 14:31:24 -0800727 } journal1;
728 } id1; /* Inode type dependant 1 */
729/*C0*/ union {
730 struct ocfs2_super_block i_super;
731 struct ocfs2_local_alloc i_lab;
732 struct ocfs2_chain_list i_chain;
733 struct ocfs2_extent_list i_list;
734 struct ocfs2_truncate_log i_dealloc;
Mark Fasheh15b1e362007-09-07 13:58:15 -0700735 struct ocfs2_inline_data i_data;
Mark Fashehccd979b2005-12-15 14:31:24 -0800736 __u8 i_symlink[0];
737 } id2;
738/* Actual on-disk size is one block */
739};
740
741/*
742 * On-disk directory entry structure for OCFS2
743 *
744 * Packed as this structure could be accessed unaligned on 64-bit platforms
745 */
746struct ocfs2_dir_entry {
747/*00*/ __le64 inode; /* Inode number */
748 __le16 rec_len; /* Directory entry length */
749 __u8 name_len; /* Name length */
750 __u8 file_type;
751/*0C*/ char name[OCFS2_MAX_FILENAME_LEN]; /* File name */
752/* Actual on-disk length specified by rec_len */
753} __attribute__ ((packed));
754
755/*
Mark Fasheh87d35a72008-12-10 17:36:25 -0800756 * Per-block record for the unindexed directory btree. This is carefully
757 * crafted so that the rec_len and name_len records of an ocfs2_dir_entry are
758 * mirrored. That way, the directory manipulation code needs a minimal amount
759 * of update.
760 *
761 * NOTE: Keep this structure aligned to a multiple of 4 bytes.
762 */
763struct ocfs2_dir_block_trailer {
764/*00*/ __le64 db_compat_inode; /* Always zero. Was inode */
765
766 __le16 db_compat_rec_len; /* Backwards compatible with
767 * ocfs2_dir_entry. */
768 __u8 db_compat_name_len; /* Always zero. Was name_len */
769 __u8 db_reserved0;
770 __le16 db_reserved1;
771 __le16 db_free_rec_len; /* Size of largest empty hole
772 * in this block. (unused) */
773/*10*/ __u8 db_signature[8]; /* Signature for verification */
774 __le64 db_reserved2;
775 __le64 db_free_next; /* Next block in list (unused) */
776/*20*/ __le64 db_blkno; /* Offset on disk, in blocks */
777 __le64 db_parent_dinode; /* dinode which owns me, in
778 blocks */
Joel Beckerc175a512008-12-10 17:58:22 -0800779/*30*/ struct ocfs2_block_check db_check; /* Error checking */
Mark Fasheh87d35a72008-12-10 17:36:25 -0800780/*40*/
781};
782
783/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800784 * On disk allocator group structure for OCFS2
785 */
786struct ocfs2_group_desc
787{
788/*00*/ __u8 bg_signature[8]; /* Signature for validation */
789 __le16 bg_size; /* Size of included bitmap in
790 bytes. */
791 __le16 bg_bits; /* Bits represented by this
792 group. */
793 __le16 bg_free_bits_count; /* Free bits count */
794 __le16 bg_chain; /* What chain I am in. */
795/*10*/ __le32 bg_generation;
796 __le32 bg_reserved1;
797 __le64 bg_next_group; /* Next group in my list, in
798 blocks */
799/*20*/ __le64 bg_parent_dinode; /* dinode which owns me, in
800 blocks */
801 __le64 bg_blkno; /* Offset on disk, in blocks */
Joel Beckerab552d52008-10-16 17:50:30 -0700802/*30*/ struct ocfs2_block_check bg_check; /* Error checking */
803 __le64 bg_reserved2;
Mark Fashehccd979b2005-12-15 14:31:24 -0800804/*40*/ __u8 bg_bitmap[0];
805};
806
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800807/*
808 * On disk extended attribute structure for OCFS2.
809 */
810
811/*
812 * ocfs2_xattr_entry indicates one extend attribute.
813 *
814 * Note that it can be stored in inode, one block or one xattr bucket.
815 */
816struct ocfs2_xattr_entry {
817 __le32 xe_name_hash; /* hash value of xattr prefix+suffix. */
Tao Ma8573f792008-10-24 22:24:17 +0800818 __le16 xe_name_offset; /* byte offset from the 1st entry in the
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800819 local xattr storage(inode, xattr block or
820 xattr bucket). */
821 __u8 xe_name_len; /* xattr name len, does't include prefix. */
Tao Ma8573f792008-10-24 22:24:17 +0800822 __u8 xe_type; /* the low 7 bits indicate the name prefix
823 * type and the highest bit indicates whether
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800824 * the EA is stored in the local storage. */
825 __le64 xe_value_size; /* real xattr value length. */
826};
827
828/*
829 * On disk structure for xattr header.
830 *
831 * One ocfs2_xattr_header describes how many ocfs2_xattr_entry records in
832 * the local xattr storage.
833 */
834struct ocfs2_xattr_header {
835 __le16 xh_count; /* contains the count of how
836 many records are in the
837 local xattr storage. */
Tao Ma0c044f02008-08-18 17:38:50 +0800838 __le16 xh_free_start; /* current offset for storing
839 xattr. */
840 __le16 xh_name_value_len; /* total length of name/value
841 length in this bucket. */
Tao Ma8573f792008-10-24 22:24:17 +0800842 __le16 xh_num_buckets; /* Number of xattr buckets
843 in this extent record,
844 only valid in the first
845 bucket. */
Joel Beckerab552d52008-10-16 17:50:30 -0700846 struct ocfs2_block_check xh_check; /* Error checking
847 (Note, this is only
848 used for xattr
849 buckets. A block uses
850 xb_check and sets
851 this field to zero.) */
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800852 struct ocfs2_xattr_entry xh_entries[0]; /* xattr entry list. */
853};
854
855/*
856 * On disk structure for xattr value root.
857 *
Tao Ma8573f792008-10-24 22:24:17 +0800858 * When an xattr's value is large enough, it is stored in an external
859 * b-tree like file data. The xattr value root points to this structure.
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800860 */
861struct ocfs2_xattr_value_root {
862/*00*/ __le32 xr_clusters; /* clusters covered by xattr value. */
863 __le32 xr_reserved0;
864 __le64 xr_last_eb_blk; /* Pointer to last extent block */
865/*10*/ struct ocfs2_extent_list xr_list; /* Extent record list */
866};
867
868/*
869 * On disk structure for xattr tree root.
870 *
871 * It is used when there are too many extended attributes for one file. These
872 * attributes will be organized and stored in an indexed-btree.
873 */
874struct ocfs2_xattr_tree_root {
875/*00*/ __le32 xt_clusters; /* clusters covered by xattr. */
876 __le32 xt_reserved0;
877 __le64 xt_last_eb_blk; /* Pointer to last extent block */
878/*10*/ struct ocfs2_extent_list xt_list; /* Extent record list */
879};
880
Tiger Yangcf1d6c72008-08-18 17:11:00 +0800881#define OCFS2_XATTR_INDEXED 0x1
882#define OCFS2_HASH_SHIFT 5
883#define OCFS2_XATTR_ROUND 3
884#define OCFS2_XATTR_SIZE(size) (((size) + OCFS2_XATTR_ROUND) & \
885 ~(OCFS2_XATTR_ROUND))
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800886
Tao Ma0c044f02008-08-18 17:38:50 +0800887#define OCFS2_XATTR_BUCKET_SIZE 4096
888#define OCFS2_XATTR_MAX_BLOCKS_PER_BUCKET (OCFS2_XATTR_BUCKET_SIZE \
889 / OCFS2_MIN_BLOCKSIZE)
890
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800891/*
892 * On disk structure for xattr block.
893 */
894struct ocfs2_xattr_block {
895/*00*/ __u8 xb_signature[8]; /* Signature for verification */
896 __le16 xb_suballoc_slot; /* Slot suballocator this
897 block belongs to. */
898 __le16 xb_suballoc_bit; /* Bit offset in suballocator
899 block group */
900 __le32 xb_fs_generation; /* Must match super block */
901/*10*/ __le64 xb_blkno; /* Offset on disk, in blocks */
Joel Beckerab552d52008-10-16 17:50:30 -0700902 struct ocfs2_block_check xb_check; /* Error checking */
Tao Ma5a7bc8e2008-08-18 17:38:46 +0800903/*20*/ __le16 xb_flags; /* Indicates whether this block contains
904 real xattr or a xattr tree. */
905 __le16 xb_reserved0;
906 __le32 xb_reserved1;
907 __le64 xb_reserved2;
908/*30*/ union {
909 struct ocfs2_xattr_header xb_header; /* xattr header if this
910 block contains xattr */
911 struct ocfs2_xattr_tree_root xb_root;/* xattr tree root if this
912 block cotains xattr
913 tree. */
914 } xb_attrs;
915};
916
917#define OCFS2_XATTR_ENTRY_LOCAL 0x80
918#define OCFS2_XATTR_TYPE_MASK 0x7F
919static inline void ocfs2_xattr_set_local(struct ocfs2_xattr_entry *xe,
920 int local)
921{
922 if (local)
923 xe->xe_type |= OCFS2_XATTR_ENTRY_LOCAL;
924 else
925 xe->xe_type &= ~OCFS2_XATTR_ENTRY_LOCAL;
926}
927
928static inline int ocfs2_xattr_is_local(struct ocfs2_xattr_entry *xe)
929{
930 return xe->xe_type & OCFS2_XATTR_ENTRY_LOCAL;
931}
932
933static inline void ocfs2_xattr_set_type(struct ocfs2_xattr_entry *xe, int type)
934{
935 xe->xe_type |= type & OCFS2_XATTR_TYPE_MASK;
936}
937
938static inline int ocfs2_xattr_get_type(struct ocfs2_xattr_entry *xe)
939{
940 return xe->xe_type & OCFS2_XATTR_TYPE_MASK;
941}
942
Jan Kara9e33d692008-08-25 19:56:50 +0200943/*
944 * On disk structures for global quota file
945 */
946
947/* Magic numbers and known versions for global quota files */
948#define OCFS2_GLOBAL_QMAGICS {\
949 0x0cf52470, /* USRQUOTA */ \
950 0x0cf52471 /* GRPQUOTA */ \
951}
952
953#define OCFS2_GLOBAL_QVERSIONS {\
954 0, \
955 0, \
956}
957
958
959/* Each block of each quota file has a certain fixed number of bytes reserved
960 * for OCFS2 internal use at its end. OCFS2 can use it for things like
961 * checksums, etc. */
962#define OCFS2_QBLK_RESERVED_SPACE 8
963
964/* Generic header of all quota files */
965struct ocfs2_disk_dqheader {
966 __le32 dqh_magic; /* Magic number identifying file */
967 __le32 dqh_version; /* Quota format version */
968};
969
970#define OCFS2_GLOBAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
971
972/* Information header of global quota file (immediately follows the generic
973 * header) */
974struct ocfs2_global_disk_dqinfo {
975/*00*/ __le32 dqi_bgrace; /* Grace time for space softlimit excess */
976 __le32 dqi_igrace; /* Grace time for inode softlimit excess */
977 __le32 dqi_syncms; /* Time after which we sync local changes to
978 * global quota file */
979 __le32 dqi_blocks; /* Number of blocks in quota file */
980/*10*/ __le32 dqi_free_blk; /* First free block in quota file */
981 __le32 dqi_free_entry; /* First block with free dquot entry in quota
982 * file */
983};
984
985/* Structure with global user / group information. We reserve some space
986 * for future use. */
987struct ocfs2_global_disk_dqblk {
988/*00*/ __le32 dqb_id; /* ID the structure belongs to */
989 __le32 dqb_use_count; /* Number of nodes having reference to this structure */
990 __le64 dqb_ihardlimit; /* absolute limit on allocated inodes */
991/*10*/ __le64 dqb_isoftlimit; /* preferred inode limit */
992 __le64 dqb_curinodes; /* current # allocated inodes */
993/*20*/ __le64 dqb_bhardlimit; /* absolute limit on disk space */
994 __le64 dqb_bsoftlimit; /* preferred limit on disk space */
995/*30*/ __le64 dqb_curspace; /* current space occupied */
996 __le64 dqb_btime; /* time limit for excessive disk use */
997/*40*/ __le64 dqb_itime; /* time limit for excessive inode use */
998 __le64 dqb_pad1;
999/*50*/ __le64 dqb_pad2;
1000};
1001
1002/*
1003 * On-disk structures for local quota file
1004 */
1005
1006/* Magic numbers and known versions for local quota files */
1007#define OCFS2_LOCAL_QMAGICS {\
1008 0x0cf524c0, /* USRQUOTA */ \
1009 0x0cf524c1 /* GRPQUOTA */ \
1010}
1011
1012#define OCFS2_LOCAL_QVERSIONS {\
1013 0, \
1014 0, \
1015}
1016
1017/* Quota flags in dqinfo header */
1018#define OLQF_CLEAN 0x0001 /* Quota file is empty (this should be after\
1019 * quota has been cleanly turned off) */
1020
1021#define OCFS2_LOCAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
1022
1023/* Information header of local quota file (immediately follows the generic
1024 * header) */
1025struct ocfs2_local_disk_dqinfo {
1026 __le32 dqi_flags; /* Flags for quota file */
1027 __le32 dqi_chunks; /* Number of chunks of quota structures
1028 * with a bitmap */
1029 __le32 dqi_blocks; /* Number of blocks allocated for quota file */
1030};
1031
1032/* Header of one chunk of a quota file */
1033struct ocfs2_local_disk_chunk {
1034 __le32 dqc_free; /* Number of free entries in the bitmap */
1035 u8 dqc_bitmap[0]; /* Bitmap of entries in the corresponding
1036 * chunk of quota file */
1037};
1038
1039/* One entry in local quota file */
1040struct ocfs2_local_disk_dqblk {
1041/*00*/ __le64 dqb_id; /* id this quota applies to */
1042 __le64 dqb_spacemod; /* Change in the amount of used space */
1043/*10*/ __le64 dqb_inodemod; /* Change in the amount of used inodes */
1044};
1045
Joel Beckerab552d52008-10-16 17:50:30 -07001046
1047/*
1048 * The quota trailer lives at the end of each quota block.
1049 */
1050
1051struct ocfs2_disk_dqtrailer {
1052/*00*/ struct ocfs2_block_check dq_check; /* Error checking */
1053/*08*/ /* Cannot be larger than OCFS2_QBLK_RESERVED_SPACE */
1054};
1055
1056static inline struct ocfs2_disk_dqtrailer *ocfs2_block_dqtrailer(int blocksize,
1057 void *buf)
1058{
1059 char *ptr = buf;
1060 ptr += blocksize - OCFS2_QBLK_RESERVED_SPACE;
1061
1062 return (struct ocfs2_disk_dqtrailer *)ptr;
1063}
1064
Mark Fashehccd979b2005-12-15 14:31:24 -08001065#ifdef __KERNEL__
1066static inline int ocfs2_fast_symlink_chars(struct super_block *sb)
1067{
1068 return sb->s_blocksize -
1069 offsetof(struct ocfs2_dinode, id2.i_symlink);
1070}
1071
Mark Fasheh15b1e362007-09-07 13:58:15 -07001072static inline int ocfs2_max_inline_data(struct super_block *sb)
1073{
1074 return sb->s_blocksize -
1075 offsetof(struct ocfs2_dinode, id2.i_data.id_data);
1076}
1077
Tiger Yangfdd77702008-08-18 17:08:55 +08001078static inline int ocfs2_max_inline_data_with_xattr(struct super_block *sb,
1079 struct ocfs2_dinode *di)
1080{
1081 unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
1082
1083 if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
1084 return sb->s_blocksize -
1085 offsetof(struct ocfs2_dinode, id2.i_data.id_data) -
1086 xattrsize;
1087 else
1088 return sb->s_blocksize -
1089 offsetof(struct ocfs2_dinode, id2.i_data.id_data);
1090}
1091
Mark Fashehccd979b2005-12-15 14:31:24 -08001092static inline int ocfs2_extent_recs_per_inode(struct super_block *sb)
1093{
1094 int size;
1095
1096 size = sb->s_blocksize -
1097 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1098
1099 return size / sizeof(struct ocfs2_extent_rec);
1100}
1101
Tiger Yangfdd77702008-08-18 17:08:55 +08001102static inline int ocfs2_extent_recs_per_inode_with_xattr(
1103 struct super_block *sb,
1104 struct ocfs2_dinode *di)
1105{
1106 int size;
1107 unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
1108
1109 if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
1110 size = sb->s_blocksize -
1111 offsetof(struct ocfs2_dinode, id2.i_list.l_recs) -
1112 xattrsize;
1113 else
1114 size = sb->s_blocksize -
1115 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1116
1117 return size / sizeof(struct ocfs2_extent_rec);
1118}
1119
Mark Fashehccd979b2005-12-15 14:31:24 -08001120static inline int ocfs2_chain_recs_per_inode(struct super_block *sb)
1121{
1122 int size;
1123
1124 size = sb->s_blocksize -
1125 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
1126
1127 return size / sizeof(struct ocfs2_chain_rec);
1128}
1129
1130static inline u16 ocfs2_extent_recs_per_eb(struct super_block *sb)
1131{
1132 int size;
1133
1134 size = sb->s_blocksize -
1135 offsetof(struct ocfs2_extent_block, h_list.l_recs);
1136
1137 return size / sizeof(struct ocfs2_extent_rec);
1138}
1139
1140static inline u16 ocfs2_local_alloc_size(struct super_block *sb)
1141{
1142 u16 size;
1143
1144 size = sb->s_blocksize -
1145 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
1146
1147 return size;
1148}
1149
1150static inline int ocfs2_group_bitmap_size(struct super_block *sb)
1151{
1152 int size;
1153
1154 size = sb->s_blocksize -
1155 offsetof(struct ocfs2_group_desc, bg_bitmap);
1156
1157 return size;
1158}
1159
1160static inline int ocfs2_truncate_recs_per_inode(struct super_block *sb)
1161{
1162 int size;
1163
1164 size = sb->s_blocksize -
1165 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
1166
1167 return size / sizeof(struct ocfs2_truncate_rec);
1168}
Mark Fasheh50af94b2007-01-21 14:44:59 -08001169
1170static inline u64 ocfs2_backup_super_blkno(struct super_block *sb, int index)
1171{
1172 u64 offset = OCFS2_BACKUP_SB_START;
1173
1174 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
1175 offset <<= (2 * index);
Mark Fasheha8a75a22007-01-26 10:46:59 -08001176 offset >>= sb->s_blocksize_bits;
Mark Fasheh50af94b2007-01-21 14:44:59 -08001177 return offset;
1178 }
1179
1180 return 0;
1181
1182}
Tao Ma0c044f02008-08-18 17:38:50 +08001183
1184static inline u16 ocfs2_xattr_recs_per_xb(struct super_block *sb)
1185{
1186 int size;
1187
1188 size = sb->s_blocksize -
1189 offsetof(struct ocfs2_xattr_block,
1190 xb_attrs.xb_root.xt_list.l_recs);
1191
1192 return size / sizeof(struct ocfs2_extent_rec);
1193}
Mark Fashehccd979b2005-12-15 14:31:24 -08001194#else
1195static inline int ocfs2_fast_symlink_chars(int blocksize)
1196{
1197 return blocksize - offsetof(struct ocfs2_dinode, id2.i_symlink);
1198}
1199
Mark Fasheh15b1e362007-09-07 13:58:15 -07001200static inline int ocfs2_max_inline_data(int blocksize)
1201{
1202 return blocksize - offsetof(struct ocfs2_dinode, id2.i_data.id_data);
1203}
1204
Mark Fashehccd979b2005-12-15 14:31:24 -08001205static inline int ocfs2_extent_recs_per_inode(int blocksize)
1206{
1207 int size;
1208
1209 size = blocksize -
1210 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1211
1212 return size / sizeof(struct ocfs2_extent_rec);
1213}
1214
1215static inline int ocfs2_chain_recs_per_inode(int blocksize)
1216{
1217 int size;
1218
1219 size = blocksize -
1220 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
1221
1222 return size / sizeof(struct ocfs2_chain_rec);
1223}
1224
1225static inline int ocfs2_extent_recs_per_eb(int blocksize)
1226{
1227 int size;
1228
1229 size = blocksize -
1230 offsetof(struct ocfs2_extent_block, h_list.l_recs);
1231
1232 return size / sizeof(struct ocfs2_extent_rec);
1233}
1234
1235static inline int ocfs2_local_alloc_size(int blocksize)
1236{
1237 int size;
1238
1239 size = blocksize -
1240 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
1241
1242 return size;
1243}
1244
1245static inline int ocfs2_group_bitmap_size(int blocksize)
1246{
1247 int size;
1248
1249 size = blocksize -
1250 offsetof(struct ocfs2_group_desc, bg_bitmap);
1251
1252 return size;
1253}
1254
1255static inline int ocfs2_truncate_recs_per_inode(int blocksize)
1256{
1257 int size;
1258
1259 size = blocksize -
1260 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
1261
1262 return size / sizeof(struct ocfs2_truncate_rec);
1263}
Mark Fasheh50af94b2007-01-21 14:44:59 -08001264
1265static inline uint64_t ocfs2_backup_super_blkno(int blocksize, int index)
1266{
1267 uint64_t offset = OCFS2_BACKUP_SB_START;
1268
1269 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
1270 offset <<= (2 * index);
1271 offset /= blocksize;
1272 return offset;
1273 }
1274
1275 return 0;
1276}
Tao Ma0c044f02008-08-18 17:38:50 +08001277
1278static inline int ocfs2_xattr_recs_per_xb(int blocksize)
1279{
1280 int size;
1281
1282 size = blocksize -
1283 offsetof(struct ocfs2_xattr_block,
1284 xb_attrs.xb_root.xt_list.l_recs);
1285
1286 return size / sizeof(struct ocfs2_extent_rec);
1287}
Mark Fashehccd979b2005-12-15 14:31:24 -08001288#endif /* __KERNEL__ */
1289
1290
1291static inline int ocfs2_system_inode_is_global(int type)
1292{
1293 return ((type >= 0) &&
1294 (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE));
1295}
1296
1297static inline int ocfs2_sprintf_system_inode_name(char *buf, int len,
1298 int type, int slot)
1299{
1300 int chars;
1301
1302 /*
1303 * Global system inodes can only have one copy. Everything
1304 * after OCFS2_LAST_GLOBAL_SYSTEM_INODE in the system inode
1305 * list has a copy per slot.
1306 */
1307 if (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE)
Joel Beckerfe9f3872008-06-12 22:39:18 -07001308 chars = snprintf(buf, len, "%s",
Mark Fashehccd979b2005-12-15 14:31:24 -08001309 ocfs2_system_inodes[type].si_name);
1310 else
1311 chars = snprintf(buf, len,
1312 ocfs2_system_inodes[type].si_name,
1313 slot);
1314
1315 return chars;
1316}
1317
1318static inline void ocfs2_set_de_type(struct ocfs2_dir_entry *de,
1319 umode_t mode)
1320{
1321 de->file_type = ocfs2_type_by_mode[(mode & S_IFMT)>>S_SHIFT];
1322}
1323
1324#endif /* _OCFS2_FS_H */
1325