]> bbs.cooldavid.org Git - net-next-2.6.git/blame - fs/ocfs2/ocfs2_fs.h
Merge branch 'perf-fixes-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[net-next-2.6.git] / fs / ocfs2 / ocfs2_fs.h
CommitLineData
ccd979bd
MF
1/* -*- 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"
5a7bc8eb 67#define OCFS2_XATTR_BLOCK_SIGNATURE "XATTR01"
87d35a74 68#define OCFS2_DIR_TRAILER_SIGNATURE "DIRTRL1"
9b7895ef
MF
69#define OCFS2_DX_ROOT_SIGNATURE "DXDIR01"
70#define OCFS2_DX_LEAF_SIGNATURE "DXLEAF1"
721f69c4 71#define OCFS2_REFCOUNT_BLOCK_SIGNATURE "REFCNT1"
ccd979bd
MF
72
73/* Compatibility flags */
74#define OCFS2_HAS_COMPAT_FEATURE(sb,mask) \
75 ( OCFS2_SB(sb)->s_feature_compat & (mask) )
76#define OCFS2_HAS_RO_COMPAT_FEATURE(sb,mask) \
77 ( OCFS2_SB(sb)->s_feature_ro_compat & (mask) )
78#define OCFS2_HAS_INCOMPAT_FEATURE(sb,mask) \
79 ( OCFS2_SB(sb)->s_feature_incompat & (mask) )
80#define OCFS2_SET_COMPAT_FEATURE(sb,mask) \
81 OCFS2_SB(sb)->s_feature_compat |= (mask)
82#define OCFS2_SET_RO_COMPAT_FEATURE(sb,mask) \
83 OCFS2_SB(sb)->s_feature_ro_compat |= (mask)
84#define OCFS2_SET_INCOMPAT_FEATURE(sb,mask) \
85 OCFS2_SB(sb)->s_feature_incompat |= (mask)
86#define OCFS2_CLEAR_COMPAT_FEATURE(sb,mask) \
87 OCFS2_SB(sb)->s_feature_compat &= ~(mask)
88#define OCFS2_CLEAR_RO_COMPAT_FEATURE(sb,mask) \
89 OCFS2_SB(sb)->s_feature_ro_compat &= ~(mask)
90#define OCFS2_CLEAR_INCOMPAT_FEATURE(sb,mask) \
91 OCFS2_SB(sb)->s_feature_incompat &= ~(mask)
92
a9772189
JB
93#define OCFS2_FEATURE_COMPAT_SUPP (OCFS2_FEATURE_COMPAT_BACKUP_SB \
94 | OCFS2_FEATURE_COMPAT_JBD2_SB)
dcd0538f 95#define OCFS2_FEATURE_INCOMPAT_SUPP (OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT \
15b1e36b 96 | OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC \
386a2ef8 97 | OCFS2_FEATURE_INCOMPAT_INLINE_DATA \
b61817e1 98 | OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP \
8154da3d 99 | OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK \
9d28cfb7 100 | OCFS2_FEATURE_INCOMPAT_XATTR \
3a8df2b9 101 | OCFS2_FEATURE_INCOMPAT_META_ECC \
64871b8d 102 | OCFS2_FEATURE_INCOMPAT_INDEXED_DIRS \
1a934c3e
TM
103 | OCFS2_FEATURE_INCOMPAT_REFCOUNT_TREE \
104 | OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG)
19ece546
JK
105#define OCFS2_FEATURE_RO_COMPAT_SUPP (OCFS2_FEATURE_RO_COMPAT_UNWRITTEN \
106 | OCFS2_FEATURE_RO_COMPAT_USRQUOTA \
107 | OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)
ccd979bd
MF
108
109/*
110 * Heartbeat-only devices are missing journals and other files. The
111 * filesystem driver can't load them, but the library can. Never put
112 * this in OCFS2_FEATURE_INCOMPAT_SUPP, *ever*.
113 */
114#define OCFS2_FEATURE_INCOMPAT_HEARTBEAT_DEV 0x0002
115
8903901d
MF
116/*
117 * tunefs sets this incompat flag before starting the resize and clears it
118 * at the end. This flag protects users from inadvertently mounting the fs
119 * after an aborted run without fsck-ing.
120 */
121#define OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG 0x0004
ccd979bd 122
c271c5c2
SM
123/* Used to denote a non-clustered volume */
124#define OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT 0x0008
125
8903901d
MF
126/* Support for sparse allocation in b-trees */
127#define OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC 0x0010
128
92e91ce2
MF
129/*
130 * Tunefs sets this incompat flag before starting an operation which
131 * would require cleanup on abort. This is done to protect users from
132 * inadvertently mounting the fs after an aborted run without
133 * fsck-ing.
134 *
135 * s_tunefs_flags on the super block describes precisely which
136 * operations were in progress.
137 */
138#define OCFS2_FEATURE_INCOMPAT_TUNEFS_INPROG 0x0020
139
15b1e36b
MF
140/* Support for data packed into inode blocks */
141#define OCFS2_FEATURE_INCOMPAT_INLINE_DATA 0x0040
142
b61817e1
JB
143/*
144 * Support for alternate, userspace cluster stacks. If set, the superblock
145 * field s_cluster_info contains a tag for the alternate stack in use as
146 * well as the name of the cluster being joined.
147 * mount.ocfs2 must pass in a matching stack name.
148 *
149 * If not set, the classic stack will be used. This is compatbile with
150 * all older versions.
151 */
152#define OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK 0x0080
153
8154da3d
TY
154/* Support for the extended slot map */
155#define OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP 0x100
156
157/* Support for extended attributes */
158#define OCFS2_FEATURE_INCOMPAT_XATTR 0x0200
159
9b7895ef
MF
160/* Support for indexed directores */
161#define OCFS2_FEATURE_INCOMPAT_INDEXED_DIRS 0x0400
162
ab552d54
JB
163/* Metadata checksum and error correction */
164#define OCFS2_FEATURE_INCOMPAT_META_ECC 0x0800
165
721f69c4
TM
166/* Refcount tree support */
167#define OCFS2_FEATURE_INCOMPAT_REFCOUNT_TREE 0x1000
168
4cbe4249
JB
169/* Discontigous block groups */
170#define OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG 0x2000
171
50af94b1
MF
172/*
173 * backup superblock flag is used to indicate that this volume
174 * has backup superblocks.
175 */
176#define OCFS2_FEATURE_COMPAT_BACKUP_SB 0x0001
177
a9772189
JB
178/*
179 * The filesystem will correctly handle journal feature bits.
180 */
181#define OCFS2_FEATURE_COMPAT_JBD2_SB 0x0002
182
328d5752
MF
183/*
184 * Unwritten extents support.
185 */
186#define OCFS2_FEATURE_RO_COMPAT_UNWRITTEN 0x0001
187
1a224ad1
JK
188/*
189 * Maintain quota information for this filesystem
190 */
191#define OCFS2_FEATURE_RO_COMPAT_USRQUOTA 0x0002
192#define OCFS2_FEATURE_RO_COMPAT_GRPQUOTA 0x0004
193
50af94b1
MF
194/* The byte offset of the first backup block will be 1G.
195 * The following will be 4G, 16G, 64G, 256G and 1T.
196 */
197#define OCFS2_BACKUP_SB_START 1 << 30
198
199/* the max backup superblock nums */
200#define OCFS2_MAX_BACKUP_SUPERBLOCKS 6
201
92e91ce2
MF
202/*
203 * Flags on ocfs2_super_block.s_tunefs_flags
204 */
205#define OCFS2_TUNEFS_INPROG_REMOVE_SLOT 0x0001 /* Removing slots */
206
ccd979bd
MF
207/*
208 * Flags on ocfs2_dinode.i_flags
209 */
210#define OCFS2_VALID_FL (0x00000001) /* Inode is valid */
211#define OCFS2_UNUSED2_FL (0x00000002)
212#define OCFS2_ORPHANED_FL (0x00000004) /* On the orphan list */
213#define OCFS2_UNUSED3_FL (0x00000008)
214/* System inode flags */
215#define OCFS2_SYSTEM_FL (0x00000010) /* System inode */
216#define OCFS2_SUPER_BLOCK_FL (0x00000020) /* Super block */
217#define OCFS2_LOCAL_ALLOC_FL (0x00000040) /* Slot local alloc bitmap */
218#define OCFS2_BITMAP_FL (0x00000080) /* Allocation bitmap */
219#define OCFS2_JOURNAL_FL (0x00000100) /* Slot local journal */
220#define OCFS2_HEARTBEAT_FL (0x00000200) /* Heartbeat area */
221#define OCFS2_CHAIN_FL (0x00000400) /* Chain allocator */
222#define OCFS2_DEALLOC_FL (0x00000800) /* Truncate log */
1a224ad1 223#define OCFS2_QUOTA_FL (0x00001000) /* Quota file */
ccd979bd 224
15b1e36b
MF
225/*
226 * Flags on ocfs2_dinode.i_dyn_features
227 *
228 * These can change much more often than i_flags. When adding flags,
229 * keep in mind that i_dyn_features is only 16 bits wide.
230 */
231#define OCFS2_INLINE_DATA_FL (0x0001) /* Data stored in inode block */
232#define OCFS2_HAS_XATTR_FL (0x0002)
233#define OCFS2_INLINE_XATTR_FL (0x0004)
234#define OCFS2_INDEXED_DIR_FL (0x0008)
721f69c4 235#define OCFS2_HAS_REFCOUNT_FL (0x0010)
15b1e36b 236
ca4d147e 237/* Inode attributes, keep in sync with EXT2 */
0000b862
TM
238#define OCFS2_SECRM_FL FS_SECRM_FL /* Secure deletion */
239#define OCFS2_UNRM_FL FS_UNRM_FL /* Undelete */
240#define OCFS2_COMPR_FL FS_COMPR_FL /* Compress file */
241#define OCFS2_SYNC_FL FS_SYNC_FL /* Synchronous updates */
242#define OCFS2_IMMUTABLE_FL FS_IMMUTABLE_FL /* Immutable file */
243#define OCFS2_APPEND_FL FS_APPEND_FL /* writes to file may only append */
244#define OCFS2_NODUMP_FL FS_NODUMP_FL /* do not dump file */
245#define OCFS2_NOATIME_FL FS_NOATIME_FL /* do not update atime */
246/* Reserved for compression usage... */
247#define OCFS2_DIRTY_FL FS_DIRTY_FL
248#define OCFS2_COMPRBLK_FL FS_COMPRBLK_FL /* One or more compressed clusters */
249#define OCFS2_NOCOMP_FL FS_NOCOMP_FL /* Don't compress */
250#define OCFS2_ECOMPR_FL FS_ECOMPR_FL /* Compression error */
251/* End compression flags --- maybe not all used */
252#define OCFS2_BTREE_FL FS_BTREE_FL /* btree format dir */
253#define OCFS2_INDEX_FL FS_INDEX_FL /* hash-indexed directory */
254#define OCFS2_IMAGIC_FL FS_IMAGIC_FL /* AFS directory */
255#define OCFS2_JOURNAL_DATA_FL FS_JOURNAL_DATA_FL /* Reserved for ext3 */
256#define OCFS2_NOTAIL_FL FS_NOTAIL_FL /* file tail should not be merged */
257#define OCFS2_DIRSYNC_FL FS_DIRSYNC_FL /* dirsync behaviour (directories only) */
258#define OCFS2_TOPDIR_FL FS_TOPDIR_FL /* Top of directory hierarchies*/
259#define OCFS2_RESERVED_FL FS_RESERVED_FL /* reserved for ext2 lib */
260
261#define OCFS2_FL_VISIBLE FS_FL_USER_VISIBLE /* User visible flags */
262#define OCFS2_FL_MODIFIABLE FS_FL_USER_MODIFIABLE /* User modifiable flags */
ca4d147e 263
e48edee2
MF
264/*
265 * Extent record flags (e_node.leaf.flags)
266 */
721f69c4
TM
267#define OCFS2_EXT_UNWRITTEN (0x01) /* Extent is allocated but
268 * unwritten */
269#define OCFS2_EXT_REFCOUNTED (0x02) /* Extent is reference
270 * counted in an associated
271 * refcount tree */
e48edee2 272
ccd979bd
MF
273/*
274 * Journal Flags (ocfs2_dinode.id1.journal1.i_flags)
275 */
276#define OCFS2_JOURNAL_DIRTY_FL (0x00000001) /* Journal needs recovery */
277
278/*
279 * superblock s_state flags
280 */
281#define OCFS2_ERROR_FS (0x00000001) /* FS saw errors */
282
283/* Limit of space in ocfs2_dir_entry */
284#define OCFS2_MAX_FILENAME_LEN 255
285
286/* Maximum slots on an ocfs2 file system */
287#define OCFS2_MAX_SLOTS 255
288
289/* Slot map indicator for an empty slot */
290#define OCFS2_INVALID_SLOT -1
291
292#define OCFS2_VOL_UUID_LEN 16
293#define OCFS2_MAX_VOL_LABEL_LEN 64
294
b61817e1
JB
295/* The alternate, userspace stack fields */
296#define OCFS2_STACK_LABEL_LEN 4
297#define OCFS2_CLUSTER_NAME_LEN 16
298
ccd979bd
MF
299/* Journal limits (in bytes) */
300#define OCFS2_MIN_JOURNAL_SIZE (4 * 1024 * 1024)
ccd979bd 301
fdd77704
TY
302/*
303 * Inline extended attribute size (in bytes)
304 * The value chosen should be aligned to 16 byte boundaries.
305 */
306#define OCFS2_MIN_XATTR_INLINE_SIZE 256
307
ccd979bd
MF
308struct ocfs2_system_inode_info {
309 char *si_name;
310 int si_iflags;
311 int si_mode;
312};
313
314/* System file index */
315enum {
316 BAD_BLOCK_SYSTEM_INODE = 0,
317 GLOBAL_INODE_ALLOC_SYSTEM_INODE,
318 SLOT_MAP_SYSTEM_INODE,
319#define OCFS2_FIRST_ONLINE_SYSTEM_INODE SLOT_MAP_SYSTEM_INODE
320 HEARTBEAT_SYSTEM_INODE,
321 GLOBAL_BITMAP_SYSTEM_INODE,
1a224ad1
JK
322 USER_QUOTA_SYSTEM_INODE,
323 GROUP_QUOTA_SYSTEM_INODE,
324#define OCFS2_LAST_GLOBAL_SYSTEM_INODE GROUP_QUOTA_SYSTEM_INODE
ccd979bd
MF
325 ORPHAN_DIR_SYSTEM_INODE,
326 EXTENT_ALLOC_SYSTEM_INODE,
327 INODE_ALLOC_SYSTEM_INODE,
328 JOURNAL_SYSTEM_INODE,
329 LOCAL_ALLOC_SYSTEM_INODE,
330 TRUNCATE_LOG_SYSTEM_INODE,
1a224ad1
JK
331 LOCAL_USER_QUOTA_SYSTEM_INODE,
332 LOCAL_GROUP_QUOTA_SYSTEM_INODE,
ccd979bd
MF
333 NUM_SYSTEM_INODES
334};
335
336static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = {
337 /* Global system inodes (single copy) */
338 /* The first two are only used from userspace mfks/tunefs */
339 [BAD_BLOCK_SYSTEM_INODE] = { "bad_blocks", 0, S_IFREG | 0644 },
340 [GLOBAL_INODE_ALLOC_SYSTEM_INODE] = { "global_inode_alloc", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
341
342 /* These are used by the running filesystem */
343 [SLOT_MAP_SYSTEM_INODE] = { "slot_map", 0, S_IFREG | 0644 },
344 [HEARTBEAT_SYSTEM_INODE] = { "heartbeat", OCFS2_HEARTBEAT_FL, S_IFREG | 0644 },
345 [GLOBAL_BITMAP_SYSTEM_INODE] = { "global_bitmap", 0, S_IFREG | 0644 },
1a224ad1
JK
346 [USER_QUOTA_SYSTEM_INODE] = { "aquota.user", OCFS2_QUOTA_FL, S_IFREG | 0644 },
347 [GROUP_QUOTA_SYSTEM_INODE] = { "aquota.group", OCFS2_QUOTA_FL, S_IFREG | 0644 },
ccd979bd
MF
348
349 /* Slot-specific system inodes (one copy per slot) */
350 [ORPHAN_DIR_SYSTEM_INODE] = { "orphan_dir:%04d", 0, S_IFDIR | 0755 },
351 [EXTENT_ALLOC_SYSTEM_INODE] = { "extent_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
352 [INODE_ALLOC_SYSTEM_INODE] = { "inode_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
353 [JOURNAL_SYSTEM_INODE] = { "journal:%04d", OCFS2_JOURNAL_FL, S_IFREG | 0644 },
354 [LOCAL_ALLOC_SYSTEM_INODE] = { "local_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_LOCAL_ALLOC_FL, S_IFREG | 0644 },
1a224ad1
JK
355 [TRUNCATE_LOG_SYSTEM_INODE] = { "truncate_log:%04d", OCFS2_DEALLOC_FL, S_IFREG | 0644 },
356 [LOCAL_USER_QUOTA_SYSTEM_INODE] = { "aquota.user:%04d", OCFS2_QUOTA_FL, S_IFREG | 0644 },
357 [LOCAL_GROUP_QUOTA_SYSTEM_INODE] = { "aquota.group:%04d", OCFS2_QUOTA_FL, S_IFREG | 0644 },
ccd979bd
MF
358};
359
360/* Parameter passed from mount.ocfs2 to module */
361#define OCFS2_HB_NONE "heartbeat=none"
362#define OCFS2_HB_LOCAL "heartbeat=local"
363
364/*
365 * OCFS2 directory file types. Only the low 3 bits are used. The
366 * other bits are reserved for now.
367 */
368#define OCFS2_FT_UNKNOWN 0
369#define OCFS2_FT_REG_FILE 1
370#define OCFS2_FT_DIR 2
371#define OCFS2_FT_CHRDEV 3
372#define OCFS2_FT_BLKDEV 4
373#define OCFS2_FT_FIFO 5
374#define OCFS2_FT_SOCK 6
375#define OCFS2_FT_SYMLINK 7
376
377#define OCFS2_FT_MAX 8
378
379/*
380 * OCFS2_DIR_PAD defines the directory entries boundaries
381 *
382 * NOTE: It must be a multiple of 4
383 */
384#define OCFS2_DIR_PAD 4
385#define OCFS2_DIR_ROUND (OCFS2_DIR_PAD - 1)
386#define OCFS2_DIR_MEMBER_LEN offsetof(struct ocfs2_dir_entry, name)
387#define OCFS2_DIR_REC_LEN(name_len) (((name_len) + OCFS2_DIR_MEMBER_LEN + \
388 OCFS2_DIR_ROUND) & \
389 ~OCFS2_DIR_ROUND)
e7c17e43 390#define OCFS2_DIR_MIN_REC_LEN OCFS2_DIR_REC_LEN(1)
ccd979bd
MF
391
392#define OCFS2_LINK_MAX 32000
198a1ca3
MF
393#define OCFS2_DX_LINK_MAX ((1U << 31) - 1U)
394#define OCFS2_LINKS_HI_SHIFT 16
e3a93c2d 395#define OCFS2_DX_ENTRIES_MAX (0xffffffffU)
ccd979bd
MF
396
397#define S_SHIFT 12
398static unsigned char ocfs2_type_by_mode[S_IFMT >> S_SHIFT] = {
399 [S_IFREG >> S_SHIFT] = OCFS2_FT_REG_FILE,
400 [S_IFDIR >> S_SHIFT] = OCFS2_FT_DIR,
401 [S_IFCHR >> S_SHIFT] = OCFS2_FT_CHRDEV,
402 [S_IFBLK >> S_SHIFT] = OCFS2_FT_BLKDEV,
403 [S_IFIFO >> S_SHIFT] = OCFS2_FT_FIFO,
404 [S_IFSOCK >> S_SHIFT] = OCFS2_FT_SOCK,
405 [S_IFLNK >> S_SHIFT] = OCFS2_FT_SYMLINK,
406};
407
408
409/*
410 * Convenience casts
411 */
412#define OCFS2_RAW_SB(dinode) (&((dinode)->id2.i_super))
413
ab552d54
JB
414/*
415 * Block checking structure. This is used in metadata to validate the
416 * contents. If OCFS2_FEATURE_INCOMPAT_META_ECC is not set, it is all
417 * zeros.
418 */
419struct ocfs2_block_check {
420/*00*/ __le32 bc_crc32e; /* 802.3 Ethernet II CRC32 */
421 __le16 bc_ecc; /* Single-error-correction parity vector.
422 This is a simple Hamming code dependant
423 on the blocksize. OCFS2's maximum
424 blocksize, 4K, requires 16 parity bits,
425 so we fit in __le16. */
426 __le16 bc_reserved1;
427/*08*/
428};
429
ccd979bd
MF
430/*
431 * On disk extent record for OCFS2
432 * It describes a range of clusters on disk.
e48edee2
MF
433 *
434 * Length fields are divided into interior and leaf node versions.
435 * This leaves room for a flags field (OCFS2_EXT_*) in the leaf nodes.
ccd979bd
MF
436 */
437struct ocfs2_extent_rec {
438/*00*/ __le32 e_cpos; /* Offset into the file, in clusters */
e48edee2
MF
439 union {
440 __le32 e_int_clusters; /* Clusters covered by all children */
441 struct {
442 __le16 e_leaf_clusters; /* Clusters covered by this
443 extent */
444 __u8 e_reserved1;
445 __u8 e_flags; /* Extent flags */
446 };
447 };
ccd979bd
MF
448 __le64 e_blkno; /* Physical disk offset, in blocks */
449/*10*/
450};
451
452struct ocfs2_chain_rec {
453 __le32 c_free; /* Number of free bits in this chain. */
454 __le32 c_total; /* Number of total bits in this chain */
455 __le64 c_blkno; /* Physical disk offset (blocks) of 1st group */
456};
457
458struct ocfs2_truncate_rec {
459 __le32 t_start; /* 1st cluster in this log */
460 __le32 t_clusters; /* Number of total clusters covered */
461};
462
463/*
464 * On disk extent list for OCFS2 (node in the tree). Note that this
465 * is contained inside ocfs2_dinode or ocfs2_extent_block, so the
466 * offsets are relative to ocfs2_dinode.id2.i_list or
467 * ocfs2_extent_block.h_list, respectively.
468 */
469struct ocfs2_extent_list {
470/*00*/ __le16 l_tree_depth; /* Extent tree depth from this
471 point. 0 means data extents
472 hang directly off this
dcd0538f
MF
473 header (a leaf)
474 NOTE: The high 8 bits cannot be
475 used - tree_depth is never that big.
476 */
ccd979bd
MF
477 __le16 l_count; /* Number of extent records */
478 __le16 l_next_free_rec; /* Next unused extent slot */
479 __le16 l_reserved1;
480 __le64 l_reserved2; /* Pad to
481 sizeof(ocfs2_extent_rec) */
482/*10*/ struct ocfs2_extent_rec l_recs[0]; /* Extent records */
483};
484
485/*
486 * On disk allocation chain list for OCFS2. Note that this is
487 * contained inside ocfs2_dinode, so the offsets are relative to
488 * ocfs2_dinode.id2.i_chain.
489 */
490struct ocfs2_chain_list {
491/*00*/ __le16 cl_cpg; /* Clusters per Block Group */
492 __le16 cl_bpc; /* Bits per cluster */
493 __le16 cl_count; /* Total chains in this list */
494 __le16 cl_next_free_rec; /* Next unused chain slot */
495 __le64 cl_reserved1;
496/*10*/ struct ocfs2_chain_rec cl_recs[0]; /* Chain records */
497};
498
499/*
500 * On disk deallocation log for OCFS2. Note that this is
501 * contained inside ocfs2_dinode, so the offsets are relative to
502 * ocfs2_dinode.id2.i_dealloc.
503 */
504struct ocfs2_truncate_log {
505/*00*/ __le16 tl_count; /* Total records in this log */
506 __le16 tl_used; /* Number of records in use */
507 __le32 tl_reserved1;
508/*08*/ struct ocfs2_truncate_rec tl_recs[0]; /* Truncate records */
509};
510
511/*
512 * On disk extent block (indirect block) for OCFS2
513 */
514struct ocfs2_extent_block
515{
516/*00*/ __u8 h_signature[8]; /* Signature for verification */
ab552d54 517 struct ocfs2_block_check h_check; /* Error checking */
ccd979bd
MF
518/*10*/ __le16 h_suballoc_slot; /* Slot suballocator this
519 extent_header belongs to */
520 __le16 h_suballoc_bit; /* Bit offset in suballocator
521 block group */
522 __le32 h_fs_generation; /* Must match super block */
523 __le64 h_blkno; /* Offset on disk, in blocks */
9cbc0123
JB
524/*20*/ __le64 h_suballoc_loc; /* Suballocator block group this
525 eb belongs to. Only valid
526 if allocated from a
527 discontiguous block group */
ccd979bd
MF
528 __le64 h_next_leaf_blk; /* Offset on disk, in blocks,
529 of next leaf header pointing
530 to data */
531/*30*/ struct ocfs2_extent_list h_list; /* Extent record list */
532/* Actual on-disk size is one block */
533};
534
fb86b1f0
JB
535/*
536 * On disk slot map for OCFS2. This defines the contents of the "slot_map"
386a2ef8
JB
537 * system file. A slot is valid if it contains a node number >= 0. The
538 * value -1 (0xFFFF) is OCFS2_INVALID_SLOT. This marks a slot empty.
fb86b1f0
JB
539 */
540struct ocfs2_slot_map {
541/*00*/ __le16 sm_slots[0];
542/*
543 * Actual on-disk size is one block. OCFS2_MAX_SLOTS is 255,
544 * 255 * sizeof(__le16) == 512B, within the 512B block minimum blocksize.
545 */
546};
547
386a2ef8
JB
548struct ocfs2_extended_slot {
549/*00*/ __u8 es_valid;
550 __u8 es_reserved1[3];
551 __le32 es_node_num;
552/*10*/
553};
554
555/*
556 * The extended slot map, used when OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP
557 * is set. It separates out the valid marker from the node number, and
558 * has room to grow. Unlike the old slot map, this format is defined by
559 * i_size.
560 */
561struct ocfs2_slot_map_extended {
562/*00*/ struct ocfs2_extended_slot se_slots[0];
563/*
564 * Actual size is i_size of the slot_map system file. It should
565 * match s_max_slots * sizeof(struct ocfs2_extended_slot)
566 */
567};
568
b61817e1
JB
569struct ocfs2_cluster_info {
570/*00*/ __u8 ci_stack[OCFS2_STACK_LABEL_LEN];
571 __le32 ci_reserved;
572/*08*/ __u8 ci_cluster[OCFS2_CLUSTER_NAME_LEN];
573/*18*/
574};
575
ccd979bd
MF
576/*
577 * On disk superblock for OCFS2
578 * Note that it is contained inside an ocfs2_dinode, so all offsets
579 * are relative to the start of ocfs2_dinode.id2.
580 */
581struct ocfs2_super_block {
582/*00*/ __le16 s_major_rev_level;
583 __le16 s_minor_rev_level;
584 __le16 s_mnt_count;
585 __le16 s_max_mnt_count;
586 __le16 s_state; /* File system state */
587 __le16 s_errors; /* Behaviour when detecting errors */
588 __le32 s_checkinterval; /* Max time between checks */
589/*10*/ __le64 s_lastcheck; /* Time of last check */
590 __le32 s_creator_os; /* OS */
591 __le32 s_feature_compat; /* Compatible feature set */
592/*20*/ __le32 s_feature_incompat; /* Incompatible feature set */
593 __le32 s_feature_ro_compat; /* Readonly-compatible feature set */
594 __le64 s_root_blkno; /* Offset, in blocks, of root directory
595 dinode */
596/*30*/ __le64 s_system_dir_blkno; /* Offset, in blocks, of system
597 directory dinode */
598 __le32 s_blocksize_bits; /* Blocksize for this fs */
599 __le32 s_clustersize_bits; /* Clustersize for this fs */
600/*40*/ __le16 s_max_slots; /* Max number of simultaneous mounts
601 before tunefs required */
92e91ce2 602 __le16 s_tunefs_flag;
cf1d6c76 603 __le32 s_uuid_hash; /* hash value of uuid */
ccd979bd
MF
604 __le64 s_first_cluster_group; /* Block offset of 1st cluster
605 * group header */
606/*50*/ __u8 s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */
607/*90*/ __u8 s_uuid[OCFS2_VOL_UUID_LEN]; /* 128-bit uuid */
b61817e1
JB
608/*A0*/ struct ocfs2_cluster_info s_cluster_info; /* Selected userspace
609 stack. Only valid
610 with INCOMPAT flag. */
8154da3d
TY
611/*B8*/ __le16 s_xattr_inline_size; /* extended attribute inline size
612 for this fs*/
613 __le16 s_reserved0;
9b7895ef
MF
614 __le32 s_dx_seed[3]; /* seed[0-2] for dx dir hash.
615 * s_uuid_hash serves as seed[3]. */
616/*C0*/ __le64 s_reserved2[15]; /* Fill out superblock */
b61817e1
JB
617/*140*/
618
619 /*
620 * NOTE: As stated above, all offsets are relative to
621 * ocfs2_dinode.id2, which is at 0xC0 in the inode.
622 * 0xC0 + 0x140 = 0x200 or 512 bytes. A superblock must fit within
623 * our smallest blocksize, which is 512 bytes. To ensure this,
624 * we reserve the space in s_reserved2. Anything past s_reserved2
625 * will not be available on the smallest blocksize.
626 */
ccd979bd
MF
627};
628
629/*
630 * Local allocation bitmap for OCFS2 slots
631 * Note that it exists inside an ocfs2_dinode, so all offsets are
632 * relative to the start of ocfs2_dinode.id2.
633 */
634struct ocfs2_local_alloc
635{
636/*00*/ __le32 la_bm_off; /* Starting bit offset in main bitmap */
637 __le16 la_size; /* Size of included bitmap, in bytes */
638 __le16 la_reserved1;
639 __le64 la_reserved2;
640/*10*/ __u8 la_bitmap[0];
641};
642
15b1e36b
MF
643/*
644 * Data-in-inode header. This is only used if i_dyn_features has
645 * OCFS2_INLINE_DATA_FL set.
646 */
647struct ocfs2_inline_data
648{
649/*00*/ __le16 id_count; /* Number of bytes that can be used
650 * for data, starting at id_data */
651 __le16 id_reserved0;
652 __le32 id_reserved1;
653 __u8 id_data[0]; /* Start of user data */
654};
655
ccd979bd
MF
656/*
657 * On disk inode for OCFS2
658 */
659struct ocfs2_dinode {
660/*00*/ __u8 i_signature[8]; /* Signature for validation */
661 __le32 i_generation; /* Generation number */
662 __le16 i_suballoc_slot; /* Slot suballocator this inode
663 belongs to */
664 __le16 i_suballoc_bit; /* Bit offset in suballocator
665 block group */
198a1ca3 666/*10*/ __le16 i_links_count_hi; /* High 16 bits of links count */
fdd77704 667 __le16 i_xattr_inline_size;
ccd979bd
MF
668 __le32 i_clusters; /* Cluster count */
669 __le32 i_uid; /* Owner UID */
670 __le32 i_gid; /* Owning GID */
671/*20*/ __le64 i_size; /* Size in bytes */
672 __le16 i_mode; /* File mode */
673 __le16 i_links_count; /* Links count */
674 __le32 i_flags; /* File flags */
675/*30*/ __le64 i_atime; /* Access time */
676 __le64 i_ctime; /* Creation time */
677/*40*/ __le64 i_mtime; /* Modification time */
678 __le64 i_dtime; /* Deletion time */
679/*50*/ __le64 i_blkno; /* Offset on disk, in blocks */
680 __le64 i_last_eb_blk; /* Pointer to last extent
681 block */
682/*60*/ __le32 i_fs_generation; /* Generation per fs-instance */
683 __le32 i_atime_nsec;
684 __le32 i_ctime_nsec;
685 __le32 i_mtime_nsec;
fdd77704 686/*70*/ __le32 i_attr;
50008630
TY
687 __le16 i_orphaned_slot; /* Only valid when OCFS2_ORPHANED_FL
688 was set in i_flags */
15b1e36b 689 __le16 i_dyn_features;
fdd77704 690 __le64 i_xattr_loc;
ab552d54 691/*80*/ struct ocfs2_block_check i_check; /* Error checking */
9b7895ef 692/*88*/ __le64 i_dx_root; /* Pointer to dir index root block */
721f69c4 693/*90*/ __le64 i_refcount_loc;
9cbc0123
JB
694 __le64 i_suballoc_loc; /* Suballocator block group this
695 inode belongs to. Only valid
696 if allocated from a
697 discontiguous block group */
698/*A0*/ __le64 i_reserved2[3];
ccd979bd
MF
699/*B8*/ union {
700 __le64 i_pad1; /* Generic way to refer to this
701 64bit union */
702 struct {
703 __le64 i_rdev; /* Device number */
704 } dev1;
705 struct { /* Info for bitmap system
706 inodes */
707 __le32 i_used; /* Bits (ie, clusters) used */
708 __le32 i_total; /* Total bits (clusters)
709 available */
710 } bitmap1;
711 struct { /* Info for journal system
712 inodes */
713 __le32 ij_flags; /* Mounted, version, etc. */
c69991aa
SM
714 __le32 ij_recovery_generation; /* Incremented when the
715 journal is recovered
716 after an unclean
717 shutdown */
ccd979bd
MF
718 } journal1;
719 } id1; /* Inode type dependant 1 */
720/*C0*/ union {
721 struct ocfs2_super_block i_super;
722 struct ocfs2_local_alloc i_lab;
723 struct ocfs2_chain_list i_chain;
724 struct ocfs2_extent_list i_list;
725 struct ocfs2_truncate_log i_dealloc;
15b1e36b 726 struct ocfs2_inline_data i_data;
ccd979bd
MF
727 __u8 i_symlink[0];
728 } id2;
729/* Actual on-disk size is one block */
730};
731
732/*
733 * On-disk directory entry structure for OCFS2
734 *
735 * Packed as this structure could be accessed unaligned on 64-bit platforms
736 */
737struct ocfs2_dir_entry {
738/*00*/ __le64 inode; /* Inode number */
739 __le16 rec_len; /* Directory entry length */
740 __u8 name_len; /* Name length */
741 __u8 file_type;
742/*0C*/ char name[OCFS2_MAX_FILENAME_LEN]; /* File name */
743/* Actual on-disk length specified by rec_len */
744} __attribute__ ((packed));
745
87d35a74
MF
746/*
747 * Per-block record for the unindexed directory btree. This is carefully
748 * crafted so that the rec_len and name_len records of an ocfs2_dir_entry are
749 * mirrored. That way, the directory manipulation code needs a minimal amount
750 * of update.
751 *
752 * NOTE: Keep this structure aligned to a multiple of 4 bytes.
753 */
754struct ocfs2_dir_block_trailer {
755/*00*/ __le64 db_compat_inode; /* Always zero. Was inode */
756
757 __le16 db_compat_rec_len; /* Backwards compatible with
758 * ocfs2_dir_entry. */
759 __u8 db_compat_name_len; /* Always zero. Was name_len */
760 __u8 db_reserved0;
761 __le16 db_reserved1;
762 __le16 db_free_rec_len; /* Size of largest empty hole
763 * in this block. (unused) */
764/*10*/ __u8 db_signature[8]; /* Signature for verification */
765 __le64 db_reserved2;
766 __le64 db_free_next; /* Next block in list (unused) */
767/*20*/ __le64 db_blkno; /* Offset on disk, in blocks */
768 __le64 db_parent_dinode; /* dinode which owns me, in
769 blocks */
c175a518 770/*30*/ struct ocfs2_block_check db_check; /* Error checking */
87d35a74
MF
771/*40*/
772};
773
9b7895ef
MF
774 /*
775 * A directory entry in the indexed tree. We don't store the full name here,
776 * but instead provide a pointer to the full dirent in the unindexed tree.
777 *
778 * We also store name_len here so as to reduce the number of leaf blocks we
779 * need to search in case of collisions.
780 */
781struct ocfs2_dx_entry {
782 __le32 dx_major_hash; /* Used to find logical
783 * cluster in index */
784 __le32 dx_minor_hash; /* Lower bits used to find
785 * block in cluster */
786 __le64 dx_dirent_blk; /* Physical block in unindexed
787 * tree holding this dirent. */
788};
789
790struct ocfs2_dx_entry_list {
791 __le32 de_reserved;
792 __le16 de_count; /* Maximum number of entries
793 * possible in de_entries */
794 __le16 de_num_used; /* Current number of
795 * de_entries entries */
796 struct ocfs2_dx_entry de_entries[0]; /* Indexed dir entries
797 * in a packed array of
798 * length de_num_used */
799};
800
4ed8a6bb
MF
801#define OCFS2_DX_FLAG_INLINE 0x01
802
9b7895ef
MF
803/*
804 * A directory indexing block. Each indexed directory has one of these,
805 * pointed to by ocfs2_dinode.
806 *
807 * This block stores an indexed btree root, and a set of free space
808 * start-of-list pointers.
809 */
810struct ocfs2_dx_root_block {
811 __u8 dr_signature[8]; /* Signature for verification */
812 struct ocfs2_block_check dr_check; /* Error checking */
813 __le16 dr_suballoc_slot; /* Slot suballocator this
814 * block belongs to. */
815 __le16 dr_suballoc_bit; /* Bit offset in suballocator
816 * block group */
817 __le32 dr_fs_generation; /* Must match super block */
818 __le64 dr_blkno; /* Offset on disk, in blocks */
819 __le64 dr_last_eb_blk; /* Pointer to last
820 * extent block */
821 __le32 dr_clusters; /* Clusters allocated
822 * to the indexed tree. */
4ed8a6bb
MF
823 __u8 dr_flags; /* OCFS2_DX_FLAG_* flags */
824 __u8 dr_reserved0;
825 __le16 dr_reserved1;
9b7895ef 826 __le64 dr_dir_blkno; /* Pointer to parent inode */
e3a93c2d
MF
827 __le32 dr_num_entries; /* Total number of
828 * names stored in
829 * this directory.*/
830 __le32 dr_reserved2;
e7c17e43
MF
831 __le64 dr_free_blk; /* Pointer to head of free
832 * unindexed block list. */
9cbc0123
JB
833 __le64 dr_suballoc_loc; /* Suballocator block group
834 this root belongs to.
835 Only valid if allocated
836 from a discontiguous
837 block group */
838 __le64 dr_reserved3[14];
4ed8a6bb
MF
839 union {
840 struct ocfs2_extent_list dr_list; /* Keep this aligned to 128
841 * bits for maximum space
842 * efficiency. */
843 struct ocfs2_dx_entry_list dr_entries; /* In-root-block list of
844 * entries. We grow out
845 * to extents if this
846 * gets too big. */
847 };
9b7895ef
MF
848};
849
850/*
851 * The header of a leaf block in the indexed tree.
852 */
853struct ocfs2_dx_leaf {
854 __u8 dl_signature[8];/* Signature for verification */
855 struct ocfs2_block_check dl_check; /* Error checking */
856 __le64 dl_blkno; /* Offset on disk, in blocks */
857 __le32 dl_fs_generation;/* Must match super block */
858 __le32 dl_reserved0;
859 __le64 dl_reserved1;
860 struct ocfs2_dx_entry_list dl_list;
861};
862
4cbe4249
JB
863/*
864 * Largest bitmap for a block (suballocator) group in bytes. This limit
865 * does not affect cluster groups (global allocator). Cluster group
866 * bitmaps run to the end of the block.
867 */
868#define OCFS2_MAX_BG_BITMAP_SIZE 256
869
ccd979bd
MF
870/*
871 * On disk allocator group structure for OCFS2
872 */
873struct ocfs2_group_desc
874{
875/*00*/ __u8 bg_signature[8]; /* Signature for validation */
876 __le16 bg_size; /* Size of included bitmap in
877 bytes. */
878 __le16 bg_bits; /* Bits represented by this
879 group. */
880 __le16 bg_free_bits_count; /* Free bits count */
881 __le16 bg_chain; /* What chain I am in. */
882/*10*/ __le32 bg_generation;
883 __le32 bg_reserved1;
884 __le64 bg_next_group; /* Next group in my list, in
885 blocks */
886/*20*/ __le64 bg_parent_dinode; /* dinode which owns me, in
887 blocks */
888 __le64 bg_blkno; /* Offset on disk, in blocks */
ab552d54
JB
889/*30*/ struct ocfs2_block_check bg_check; /* Error checking */
890 __le64 bg_reserved2;
4cbe4249
JB
891/*40*/ union {
892 __u8 bg_bitmap[0];
893 struct {
894 /*
895 * Block groups may be discontiguous when
896 * OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG is set.
897 * The extents of a discontigous block group are
898 * stored in bg_list. It is a flat list.
899 * l_tree_depth must always be zero. A
900 * discontiguous group is signified by a non-zero
901 * bg_list->l_next_free_rec. Only block groups
902 * can be discontiguous; Cluster groups cannot.
903 * We've never made a block group with more than
904 * 2048 blocks (256 bytes of bg_bitmap). This
905 * codifies that limit so that we can fit bg_list.
906 * bg_size of a discontiguous block group will
907 * be 256 to match bg_bitmap_filler.
908 */
909 __u8 bg_bitmap_filler[OCFS2_MAX_BG_BITMAP_SIZE];
910/*140*/ struct ocfs2_extent_list bg_list;
911 };
912 };
913/* Actual on-disk size is one block */
ccd979bd
MF
914};
915
721f69c4
TM
916struct ocfs2_refcount_rec {
917/*00*/ __le64 r_cpos; /* Physical offset, in clusters */
918 __le32 r_clusters; /* Clusters covered by this extent */
919 __le32 r_refcount; /* Reference count of this extent */
920/*10*/
921};
e73a819d 922#define OCFS2_32BIT_POS_MASK (0xffffffffULL)
721f69c4
TM
923
924#define OCFS2_REFCOUNT_LEAF_FL (0x00000001)
925#define OCFS2_REFCOUNT_TREE_FL (0x00000002)
926
927struct ocfs2_refcount_list {
928/*00*/ __le16 rl_count; /* Maximum number of entries possible
929 in rl_records */
930 __le16 rl_used; /* Current number of used records */
931 __le32 rl_reserved2;
932 __le64 rl_reserved1; /* Pad to sizeof(ocfs2_refcount_record) */
933/*10*/ struct ocfs2_refcount_rec rl_recs[0]; /* Refcount records */
934};
935
936
937struct ocfs2_refcount_block {
938/*00*/ __u8 rf_signature[8]; /* Signature for verification */
939 __le16 rf_suballoc_slot; /* Slot suballocator this block
940 belongs to */
941 __le16 rf_suballoc_bit; /* Bit offset in suballocator
942 block group */
943 __le32 rf_fs_generation; /* Must match superblock */
944/*10*/ __le64 rf_blkno; /* Offset on disk, in blocks */
945 __le64 rf_parent; /* Parent block, only valid if
946 OCFS2_REFCOUNT_LEAF_FL is set in
947 rf_flags */
948/*20*/ struct ocfs2_block_check rf_check; /* Error checking */
949 __le64 rf_last_eb_blk; /* Pointer to last extent block */
950/*30*/ __le32 rf_count; /* Number of inodes sharing this
951 refcount tree */
952 __le32 rf_flags; /* See the flags above */
953 __le32 rf_clusters; /* clusters covered by refcount tree. */
954 __le32 rf_cpos; /* cluster offset in refcount tree.*/
955/*40*/ __le32 rf_generation; /* generation number. all be the same
956 * for the same refcount tree. */
957 __le32 rf_reserved0;
9cbc0123
JB
958 __le64 rf_suballoc_loc; /* Suballocator block group this
959 refcount block belongs to. Only
960 valid if allocated from a
961 discontiguous block group */
962/*50*/ __le64 rf_reserved1[6];
721f69c4
TM
963/*80*/ union {
964 struct ocfs2_refcount_list rf_records; /* List of refcount
965 records */
966 struct ocfs2_extent_list rf_list; /* Extent record list,
967 only valid if
968 OCFS2_REFCOUNT_TREE_FL
969 is set in rf_flags */
970 };
971/* Actual on-disk size is one block */
972};
973
5a7bc8eb
TM
974/*
975 * On disk extended attribute structure for OCFS2.
976 */
977
978/*
979 * ocfs2_xattr_entry indicates one extend attribute.
980 *
981 * Note that it can be stored in inode, one block or one xattr bucket.
982 */
983struct ocfs2_xattr_entry {
984 __le32 xe_name_hash; /* hash value of xattr prefix+suffix. */
8573f79d 985 __le16 xe_name_offset; /* byte offset from the 1st entry in the
5a7bc8eb
TM
986 local xattr storage(inode, xattr block or
987 xattr bucket). */
988 __u8 xe_name_len; /* xattr name len, does't include prefix. */
8573f79d
TM
989 __u8 xe_type; /* the low 7 bits indicate the name prefix
990 * type and the highest bit indicates whether
5a7bc8eb
TM
991 * the EA is stored in the local storage. */
992 __le64 xe_value_size; /* real xattr value length. */
993};
994
995/*
996 * On disk structure for xattr header.
997 *
998 * One ocfs2_xattr_header describes how many ocfs2_xattr_entry records in
999 * the local xattr storage.
1000 */
1001struct ocfs2_xattr_header {
1002 __le16 xh_count; /* contains the count of how
1003 many records are in the
1004 local xattr storage. */
0c044f0b
TM
1005 __le16 xh_free_start; /* current offset for storing
1006 xattr. */
1007 __le16 xh_name_value_len; /* total length of name/value
1008 length in this bucket. */
8573f79d
TM
1009 __le16 xh_num_buckets; /* Number of xattr buckets
1010 in this extent record,
1011 only valid in the first
1012 bucket. */
ab552d54
JB
1013 struct ocfs2_block_check xh_check; /* Error checking
1014 (Note, this is only
1015 used for xattr
1016 buckets. A block uses
1017 xb_check and sets
1018 this field to zero.) */
5a7bc8eb
TM
1019 struct ocfs2_xattr_entry xh_entries[0]; /* xattr entry list. */
1020};
1021
1022/*
1023 * On disk structure for xattr value root.
1024 *
8573f79d
TM
1025 * When an xattr's value is large enough, it is stored in an external
1026 * b-tree like file data. The xattr value root points to this structure.
5a7bc8eb
TM
1027 */
1028struct ocfs2_xattr_value_root {
1029/*00*/ __le32 xr_clusters; /* clusters covered by xattr value. */
1030 __le32 xr_reserved0;
1031 __le64 xr_last_eb_blk; /* Pointer to last extent block */
1032/*10*/ struct ocfs2_extent_list xr_list; /* Extent record list */
1033};
1034
1035/*
1036 * On disk structure for xattr tree root.
1037 *
1038 * It is used when there are too many extended attributes for one file. These
1039 * attributes will be organized and stored in an indexed-btree.
1040 */
1041struct ocfs2_xattr_tree_root {
1042/*00*/ __le32 xt_clusters; /* clusters covered by xattr. */
1043 __le32 xt_reserved0;
1044 __le64 xt_last_eb_blk; /* Pointer to last extent block */
1045/*10*/ struct ocfs2_extent_list xt_list; /* Extent record list */
1046};
1047
cf1d6c76
TY
1048#define OCFS2_XATTR_INDEXED 0x1
1049#define OCFS2_HASH_SHIFT 5
1050#define OCFS2_XATTR_ROUND 3
1051#define OCFS2_XATTR_SIZE(size) (((size) + OCFS2_XATTR_ROUND) & \
1052 ~(OCFS2_XATTR_ROUND))
5a7bc8eb 1053
0c044f0b
TM
1054#define OCFS2_XATTR_BUCKET_SIZE 4096
1055#define OCFS2_XATTR_MAX_BLOCKS_PER_BUCKET (OCFS2_XATTR_BUCKET_SIZE \
1056 / OCFS2_MIN_BLOCKSIZE)
1057
5a7bc8eb
TM
1058/*
1059 * On disk structure for xattr block.
1060 */
1061struct ocfs2_xattr_block {
1062/*00*/ __u8 xb_signature[8]; /* Signature for verification */
1063 __le16 xb_suballoc_slot; /* Slot suballocator this
1064 block belongs to. */
1065 __le16 xb_suballoc_bit; /* Bit offset in suballocator
1066 block group */
1067 __le32 xb_fs_generation; /* Must match super block */
1068/*10*/ __le64 xb_blkno; /* Offset on disk, in blocks */
ab552d54 1069 struct ocfs2_block_check xb_check; /* Error checking */
5a7bc8eb
TM
1070/*20*/ __le16 xb_flags; /* Indicates whether this block contains
1071 real xattr or a xattr tree. */
1072 __le16 xb_reserved0;
1073 __le32 xb_reserved1;
9cbc0123
JB
1074 __le64 xb_suballoc_loc; /* Suballocator block group this
1075 xattr block belongs to. Only
1076 valid if allocated from a
1077 discontiguous block group */
5a7bc8eb
TM
1078/*30*/ union {
1079 struct ocfs2_xattr_header xb_header; /* xattr header if this
1080 block contains xattr */
1081 struct ocfs2_xattr_tree_root xb_root;/* xattr tree root if this
1082 block cotains xattr
1083 tree. */
1084 } xb_attrs;
1085};
1086
1087#define OCFS2_XATTR_ENTRY_LOCAL 0x80
1088#define OCFS2_XATTR_TYPE_MASK 0x7F
1089static inline void ocfs2_xattr_set_local(struct ocfs2_xattr_entry *xe,
1090 int local)
1091{
1092 if (local)
1093 xe->xe_type |= OCFS2_XATTR_ENTRY_LOCAL;
1094 else
1095 xe->xe_type &= ~OCFS2_XATTR_ENTRY_LOCAL;
1096}
1097
1098static inline int ocfs2_xattr_is_local(struct ocfs2_xattr_entry *xe)
1099{
1100 return xe->xe_type & OCFS2_XATTR_ENTRY_LOCAL;
1101}
1102
1103static inline void ocfs2_xattr_set_type(struct ocfs2_xattr_entry *xe, int type)
1104{
1105 xe->xe_type |= type & OCFS2_XATTR_TYPE_MASK;
1106}
1107
1108static inline int ocfs2_xattr_get_type(struct ocfs2_xattr_entry *xe)
1109{
1110 return xe->xe_type & OCFS2_XATTR_TYPE_MASK;
1111}
1112
9e33d69f
JK
1113/*
1114 * On disk structures for global quota file
1115 */
1116
1117/* Magic numbers and known versions for global quota files */
1118#define OCFS2_GLOBAL_QMAGICS {\
1119 0x0cf52470, /* USRQUOTA */ \
1120 0x0cf52471 /* GRPQUOTA */ \
1121}
1122
1123#define OCFS2_GLOBAL_QVERSIONS {\
1124 0, \
1125 0, \
1126}
1127
1128
1129/* Each block of each quota file has a certain fixed number of bytes reserved
1130 * for OCFS2 internal use at its end. OCFS2 can use it for things like
1131 * checksums, etc. */
1132#define OCFS2_QBLK_RESERVED_SPACE 8
1133
1134/* Generic header of all quota files */
1135struct ocfs2_disk_dqheader {
1136 __le32 dqh_magic; /* Magic number identifying file */
1137 __le32 dqh_version; /* Quota format version */
1138};
1139
1140#define OCFS2_GLOBAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
1141
1142/* Information header of global quota file (immediately follows the generic
1143 * header) */
1144struct ocfs2_global_disk_dqinfo {
1145/*00*/ __le32 dqi_bgrace; /* Grace time for space softlimit excess */
1146 __le32 dqi_igrace; /* Grace time for inode softlimit excess */
1147 __le32 dqi_syncms; /* Time after which we sync local changes to
1148 * global quota file */
1149 __le32 dqi_blocks; /* Number of blocks in quota file */
1150/*10*/ __le32 dqi_free_blk; /* First free block in quota file */
1151 __le32 dqi_free_entry; /* First block with free dquot entry in quota
1152 * file */
1153};
1154
1155/* Structure with global user / group information. We reserve some space
1156 * for future use. */
1157struct ocfs2_global_disk_dqblk {
1158/*00*/ __le32 dqb_id; /* ID the structure belongs to */
1159 __le32 dqb_use_count; /* Number of nodes having reference to this structure */
1160 __le64 dqb_ihardlimit; /* absolute limit on allocated inodes */
1161/*10*/ __le64 dqb_isoftlimit; /* preferred inode limit */
1162 __le64 dqb_curinodes; /* current # allocated inodes */
1163/*20*/ __le64 dqb_bhardlimit; /* absolute limit on disk space */
1164 __le64 dqb_bsoftlimit; /* preferred limit on disk space */
1165/*30*/ __le64 dqb_curspace; /* current space occupied */
1166 __le64 dqb_btime; /* time limit for excessive disk use */
1167/*40*/ __le64 dqb_itime; /* time limit for excessive inode use */
1168 __le64 dqb_pad1;
1169/*50*/ __le64 dqb_pad2;
1170};
1171
1172/*
1173 * On-disk structures for local quota file
1174 */
1175
1176/* Magic numbers and known versions for local quota files */
1177#define OCFS2_LOCAL_QMAGICS {\
1178 0x0cf524c0, /* USRQUOTA */ \
1179 0x0cf524c1 /* GRPQUOTA */ \
1180}
1181
1182#define OCFS2_LOCAL_QVERSIONS {\
1183 0, \
1184 0, \
1185}
1186
1187/* Quota flags in dqinfo header */
1188#define OLQF_CLEAN 0x0001 /* Quota file is empty (this should be after\
1189 * quota has been cleanly turned off) */
1190
1191#define OCFS2_LOCAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
1192
1193/* Information header of local quota file (immediately follows the generic
1194 * header) */
1195struct ocfs2_local_disk_dqinfo {
1196 __le32 dqi_flags; /* Flags for quota file */
1197 __le32 dqi_chunks; /* Number of chunks of quota structures
1198 * with a bitmap */
1199 __le32 dqi_blocks; /* Number of blocks allocated for quota file */
1200};
1201
1202/* Header of one chunk of a quota file */
1203struct ocfs2_local_disk_chunk {
1204 __le32 dqc_free; /* Number of free entries in the bitmap */
93654540 1205 __u8 dqc_bitmap[0]; /* Bitmap of entries in the corresponding
9e33d69f
JK
1206 * chunk of quota file */
1207};
1208
1209/* One entry in local quota file */
1210struct ocfs2_local_disk_dqblk {
1211/*00*/ __le64 dqb_id; /* id this quota applies to */
1212 __le64 dqb_spacemod; /* Change in the amount of used space */
1213/*10*/ __le64 dqb_inodemod; /* Change in the amount of used inodes */
1214};
1215
ab552d54
JB
1216
1217/*
1218 * The quota trailer lives at the end of each quota block.
1219 */
1220
1221struct ocfs2_disk_dqtrailer {
1222/*00*/ struct ocfs2_block_check dq_check; /* Error checking */
1223/*08*/ /* Cannot be larger than OCFS2_QBLK_RESERVED_SPACE */
1224};
1225
1226static inline struct ocfs2_disk_dqtrailer *ocfs2_block_dqtrailer(int blocksize,
1227 void *buf)
1228{
1229 char *ptr = buf;
1230 ptr += blocksize - OCFS2_QBLK_RESERVED_SPACE;
1231
1232 return (struct ocfs2_disk_dqtrailer *)ptr;
1233}
1234
ccd979bd
MF
1235#ifdef __KERNEL__
1236static inline int ocfs2_fast_symlink_chars(struct super_block *sb)
1237{
1238 return sb->s_blocksize -
1239 offsetof(struct ocfs2_dinode, id2.i_symlink);
1240}
1241
fdd77704
TY
1242static inline int ocfs2_max_inline_data_with_xattr(struct super_block *sb,
1243 struct ocfs2_dinode *di)
1244{
1245 unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
1246
1247 if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
1248 return sb->s_blocksize -
1249 offsetof(struct ocfs2_dinode, id2.i_data.id_data) -
1250 xattrsize;
1251 else
1252 return sb->s_blocksize -
1253 offsetof(struct ocfs2_dinode, id2.i_data.id_data);
1254}
1255
ccd979bd
MF
1256static inline int ocfs2_extent_recs_per_inode(struct super_block *sb)
1257{
1258 int size;
1259
1260 size = sb->s_blocksize -
1261 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1262
1263 return size / sizeof(struct ocfs2_extent_rec);
1264}
1265
fdd77704
TY
1266static inline int ocfs2_extent_recs_per_inode_with_xattr(
1267 struct super_block *sb,
1268 struct ocfs2_dinode *di)
1269{
1270 int size;
1271 unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
1272
1273 if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
1274 size = sb->s_blocksize -
1275 offsetof(struct ocfs2_dinode, id2.i_list.l_recs) -
1276 xattrsize;
1277 else
1278 size = sb->s_blocksize -
1279 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1280
1281 return size / sizeof(struct ocfs2_extent_rec);
1282}
1283
9b7895ef
MF
1284static inline int ocfs2_extent_recs_per_dx_root(struct super_block *sb)
1285{
1286 int size;
1287
1288 size = sb->s_blocksize -
1289 offsetof(struct ocfs2_dx_root_block, dr_list.l_recs);
1290
1291 return size / sizeof(struct ocfs2_extent_rec);
1292}
1293
ccd979bd
MF
1294static inline int ocfs2_chain_recs_per_inode(struct super_block *sb)
1295{
1296 int size;
1297
1298 size = sb->s_blocksize -
1299 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
1300
1301 return size / sizeof(struct ocfs2_chain_rec);
1302}
1303
1304static inline u16 ocfs2_extent_recs_per_eb(struct super_block *sb)
1305{
1306 int size;
1307
1308 size = sb->s_blocksize -
1309 offsetof(struct ocfs2_extent_block, h_list.l_recs);
1310
1311 return size / sizeof(struct ocfs2_extent_rec);
1312}
1313
798db35f
JB
1314static inline u16 ocfs2_extent_recs_per_gd(struct super_block *sb)
1315{
1316 int size;
1317
1318 size = sb->s_blocksize -
1319 offsetof(struct ocfs2_group_desc, bg_list.l_recs);
1320
1321 return size / sizeof(struct ocfs2_extent_rec);
1322}
1323
9b7895ef
MF
1324static inline int ocfs2_dx_entries_per_leaf(struct super_block *sb)
1325{
1326 int size;
1327
1328 size = sb->s_blocksize -
1329 offsetof(struct ocfs2_dx_leaf, dl_list.de_entries);
1330
1331 return size / sizeof(struct ocfs2_dx_entry);
1332}
1333
4ed8a6bb
MF
1334static inline int ocfs2_dx_entries_per_root(struct super_block *sb)
1335{
1336 int size;
1337
1338 size = sb->s_blocksize -
1339 offsetof(struct ocfs2_dx_root_block, dr_entries.de_entries);
1340
1341 return size / sizeof(struct ocfs2_dx_entry);
1342}
1343
ccd979bd
MF
1344static inline u16 ocfs2_local_alloc_size(struct super_block *sb)
1345{
1346 u16 size;
1347
1348 size = sb->s_blocksize -
1349 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
1350
1351 return size;
1352}
1353
4cbe4249 1354static inline int ocfs2_group_bitmap_size(struct super_block *sb,
8571882c
TM
1355 int suballocator,
1356 u32 feature_incompat)
ccd979bd 1357{
8571882c
TM
1358 int size = sb->s_blocksize -
1359 offsetof(struct ocfs2_group_desc, bg_bitmap);
ccd979bd 1360
8571882c
TM
1361 /*
1362 * The cluster allocator uses the entire block. Suballocators have
1363 * never used more than OCFS2_MAX_BG_BITMAP_SIZE. Unfortunately, older
1364 * code expects bg_size set to the maximum. Thus we must keep
1365 * bg_size as-is unless discontig_bg is enabled.
1366 */
1367 if (suballocator &&
1368 (feature_incompat & OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG))
4cbe4249 1369 size = OCFS2_MAX_BG_BITMAP_SIZE;
ccd979bd
MF
1370
1371 return size;
1372}
1373
1374static inline int ocfs2_truncate_recs_per_inode(struct super_block *sb)
1375{
1376 int size;
1377
1378 size = sb->s_blocksize -
1379 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
1380
1381 return size / sizeof(struct ocfs2_truncate_rec);
1382}
50af94b1
MF
1383
1384static inline u64 ocfs2_backup_super_blkno(struct super_block *sb, int index)
1385{
1386 u64 offset = OCFS2_BACKUP_SB_START;
1387
1388 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
1389 offset <<= (2 * index);
a8a75a20 1390 offset >>= sb->s_blocksize_bits;
50af94b1
MF
1391 return offset;
1392 }
1393
1394 return 0;
1395
1396}
0c044f0b
TM
1397
1398static inline u16 ocfs2_xattr_recs_per_xb(struct super_block *sb)
1399{
1400 int size;
1401
1402 size = sb->s_blocksize -
1403 offsetof(struct ocfs2_xattr_block,
1404 xb_attrs.xb_root.xt_list.l_recs);
1405
1406 return size / sizeof(struct ocfs2_extent_rec);
1407}
721f69c4
TM
1408
1409static inline u16 ocfs2_extent_recs_per_rb(struct super_block *sb)
1410{
1411 int size;
1412
1413 size = sb->s_blocksize -
1414 offsetof(struct ocfs2_refcount_block, rf_list.l_recs);
1415
1416 return size / sizeof(struct ocfs2_extent_rec);
1417}
1418
1419static inline u16 ocfs2_refcount_recs_per_rb(struct super_block *sb)
1420{
1421 int size;
1422
1423 size = sb->s_blocksize -
1424 offsetof(struct ocfs2_refcount_block, rf_records.rl_recs);
1425
1426 return size / sizeof(struct ocfs2_refcount_rec);
1427}
e73a819d
TM
1428
1429static inline u32
1430ocfs2_get_ref_rec_low_cpos(const struct ocfs2_refcount_rec *rec)
1431{
1432 return le64_to_cpu(rec->r_cpos) & OCFS2_32BIT_POS_MASK;
1433}
ccd979bd
MF
1434#else
1435static inline int ocfs2_fast_symlink_chars(int blocksize)
1436{
1437 return blocksize - offsetof(struct ocfs2_dinode, id2.i_symlink);
1438}
1439
1097df3f
TM
1440static inline int ocfs2_max_inline_data_with_xattr(int blocksize,
1441 struct ocfs2_dinode *di)
15b1e36b 1442{
1097df3f
TM
1443 if (di && (di->i_dyn_features & OCFS2_INLINE_XATTR_FL))
1444 return blocksize -
1445 offsetof(struct ocfs2_dinode, id2.i_data.id_data) -
1446 di->i_xattr_inline_size;
1447 else
1448 return blocksize -
1449 offsetof(struct ocfs2_dinode, id2.i_data.id_data);
15b1e36b
MF
1450}
1451
ccd979bd
MF
1452static inline int ocfs2_extent_recs_per_inode(int blocksize)
1453{
1454 int size;
1455
1456 size = blocksize -
1457 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1458
1459 return size / sizeof(struct ocfs2_extent_rec);
1460}
1461
1462static inline int ocfs2_chain_recs_per_inode(int blocksize)
1463{
1464 int size;
1465
1466 size = blocksize -
1467 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
1468
1469 return size / sizeof(struct ocfs2_chain_rec);
1470}
1471
1472static inline int ocfs2_extent_recs_per_eb(int blocksize)
1473{
1474 int size;
1475
1476 size = blocksize -
1477 offsetof(struct ocfs2_extent_block, h_list.l_recs);
1478
1479 return size / sizeof(struct ocfs2_extent_rec);
1480}
1481
798db35f
JB
1482static inline int ocfs2_extent_recs_per_gd(int blocksize)
1483{
1484 int size;
1485
1486 size = blocksize -
1487 offsetof(struct ocfs2_group_desc, bg_list.l_recs);
1488
1489 return size / sizeof(struct ocfs2_extent_rec);
1490}
1491
ccd979bd
MF
1492static inline int ocfs2_local_alloc_size(int blocksize)
1493{
1494 int size;
1495
1496 size = blocksize -
1497 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
1498
1499 return size;
1500}
1501
8571882c
TM
1502static inline int ocfs2_group_bitmap_size(int blocksize,
1503 int suballocator,
1504 uint32_t feature_incompat)
ccd979bd 1505{
8571882c
TM
1506 int size = sb->s_blocksize -
1507 offsetof(struct ocfs2_group_desc, bg_bitmap);
ccd979bd 1508
8571882c
TM
1509 /*
1510 * The cluster allocator uses the entire block. Suballocators have
1511 * never used more than OCFS2_MAX_BG_BITMAP_SIZE. Unfortunately, older
1512 * code expects bg_size set to the maximum. Thus we must keep
1513 * bg_size as-is unless discontig_bg is enabled.
1514 */
1515 if (suballocator &&
1516 (feature_incompat & OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG))
4cbe4249 1517 size = OCFS2_MAX_BG_BITMAP_SIZE;
ccd979bd
MF
1518
1519 return size;
1520}
1521
1522static inline int ocfs2_truncate_recs_per_inode(int blocksize)
1523{
1524 int size;
1525
1526 size = blocksize -
1527 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
1528
1529 return size / sizeof(struct ocfs2_truncate_rec);
1530}
50af94b1
MF
1531
1532static inline uint64_t ocfs2_backup_super_blkno(int blocksize, int index)
1533{
1534 uint64_t offset = OCFS2_BACKUP_SB_START;
1535
1536 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
1537 offset <<= (2 * index);
1538 offset /= blocksize;
1539 return offset;
1540 }
1541
1542 return 0;
1543}
0c044f0b
TM
1544
1545static inline int ocfs2_xattr_recs_per_xb(int blocksize)
1546{
1547 int size;
1548
1549 size = blocksize -
1550 offsetof(struct ocfs2_xattr_block,
1551 xb_attrs.xb_root.xt_list.l_recs);
1552
1553 return size / sizeof(struct ocfs2_extent_rec);
1554}
ccd979bd
MF
1555#endif /* __KERNEL__ */
1556
1557
1558static inline int ocfs2_system_inode_is_global(int type)
1559{
1560 return ((type >= 0) &&
1561 (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE));
1562}
1563
1564static inline int ocfs2_sprintf_system_inode_name(char *buf, int len,
1565 int type, int slot)
1566{
1567 int chars;
1568
1569 /*
1570 * Global system inodes can only have one copy. Everything
1571 * after OCFS2_LAST_GLOBAL_SYSTEM_INODE in the system inode
1572 * list has a copy per slot.
1573 */
1574 if (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE)
fe9f3877 1575 chars = snprintf(buf, len, "%s",
ccd979bd
MF
1576 ocfs2_system_inodes[type].si_name);
1577 else
1578 chars = snprintf(buf, len,
1579 ocfs2_system_inodes[type].si_name,
1580 slot);
1581
1582 return chars;
1583}
1584
1585static inline void ocfs2_set_de_type(struct ocfs2_dir_entry *de,
1586 umode_t mode)
1587{
1588 de->file_type = ocfs2_type_by_mode[(mode & S_IFMT)>>S_SHIFT];
1589}
1590
af2bf0d8
TM
1591static inline int ocfs2_gd_is_discontig(struct ocfs2_group_desc *gd)
1592{
1593 if ((offsetof(struct ocfs2_group_desc, bg_bitmap) +
1594 le16_to_cpu(gd->bg_size)) !=
1595 offsetof(struct ocfs2_group_desc, bg_list))
1596 return 0;
1597 /*
1598 * Only valid to check l_next_free_rec if
1599 * bg_bitmap + bg_size == bg_list.
1600 */
1601 if (!gd->bg_list.l_next_free_rec)
1602 return 0;
1603 return 1;
1604}
ccd979bd
MF
1605#endif /* _OCFS2_FS_H */
1606