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