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