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