ocfs2: Add extent tree operation for xattr value btrees
[linux-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
50af94b1 89#define OCFS2_FEATURE_COMPAT_SUPP OCFS2_FEATURE_COMPAT_BACKUP_SB
dcd0538f 90#define OCFS2_FEATURE_INCOMPAT_SUPP (OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT \
15b1e36b 91 | OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC \
386a2ef8 92 | OCFS2_FEATURE_INCOMPAT_INLINE_DATA \
b61817e1
JB
93 | OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP \
94 | OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK)
328d5752 95#define OCFS2_FEATURE_RO_COMPAT_SUPP OCFS2_FEATURE_RO_COMPAT_UNWRITTEN
ccd979bd
MF
96
97/*
98 * Heartbeat-only devices are missing journals and other files. The
99 * filesystem driver can't load them, but the library can. Never put
100 * this in OCFS2_FEATURE_INCOMPAT_SUPP, *ever*.
101 */
102#define OCFS2_FEATURE_INCOMPAT_HEARTBEAT_DEV 0x0002
103
8903901d
MF
104/*
105 * tunefs sets this incompat flag before starting the resize and clears it
106 * at the end. This flag protects users from inadvertently mounting the fs
107 * after an aborted run without fsck-ing.
108 */
109#define OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG 0x0004
ccd979bd 110
c271c5c2
SM
111/* Used to denote a non-clustered volume */
112#define OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT 0x0008
113
8903901d
MF
114/* Support for sparse allocation in b-trees */
115#define OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC 0x0010
116
92e91ce2
MF
117/*
118 * Tunefs sets this incompat flag before starting an operation which
119 * would require cleanup on abort. This is done to protect users from
120 * inadvertently mounting the fs after an aborted run without
121 * fsck-ing.
122 *
123 * s_tunefs_flags on the super block describes precisely which
124 * operations were in progress.
125 */
126#define OCFS2_FEATURE_INCOMPAT_TUNEFS_INPROG 0x0020
127
15b1e36b
MF
128/* Support for data packed into inode blocks */
129#define OCFS2_FEATURE_INCOMPAT_INLINE_DATA 0x0040
130
386a2ef8
JB
131/* Support for the extended slot map */
132#define OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP 0x100
133
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
50af94b1
MF
146/*
147 * backup superblock flag is used to indicate that this volume
148 * has backup superblocks.
149 */
150#define OCFS2_FEATURE_COMPAT_BACKUP_SB 0x0001
151
328d5752
MF
152/*
153 * Unwritten extents support.
154 */
155#define OCFS2_FEATURE_RO_COMPAT_UNWRITTEN 0x0001
156
50af94b1
MF
157/* The byte offset of the first backup block will be 1G.
158 * The following will be 4G, 16G, 64G, 256G and 1T.
159 */
160#define OCFS2_BACKUP_SB_START 1 << 30
161
162/* the max backup superblock nums */
163#define OCFS2_MAX_BACKUP_SUPERBLOCKS 6
164
92e91ce2
MF
165/*
166 * Flags on ocfs2_super_block.s_tunefs_flags
167 */
168#define OCFS2_TUNEFS_INPROG_REMOVE_SLOT 0x0001 /* Removing slots */
169
ccd979bd
MF
170/*
171 * Flags on ocfs2_dinode.i_flags
172 */
173#define OCFS2_VALID_FL (0x00000001) /* Inode is valid */
174#define OCFS2_UNUSED2_FL (0x00000002)
175#define OCFS2_ORPHANED_FL (0x00000004) /* On the orphan list */
176#define OCFS2_UNUSED3_FL (0x00000008)
177/* System inode flags */
178#define OCFS2_SYSTEM_FL (0x00000010) /* System inode */
179#define OCFS2_SUPER_BLOCK_FL (0x00000020) /* Super block */
180#define OCFS2_LOCAL_ALLOC_FL (0x00000040) /* Slot local alloc bitmap */
181#define OCFS2_BITMAP_FL (0x00000080) /* Allocation bitmap */
182#define OCFS2_JOURNAL_FL (0x00000100) /* Slot local journal */
183#define OCFS2_HEARTBEAT_FL (0x00000200) /* Heartbeat area */
184#define OCFS2_CHAIN_FL (0x00000400) /* Chain allocator */
185#define OCFS2_DEALLOC_FL (0x00000800) /* Truncate log */
186
15b1e36b
MF
187/*
188 * Flags on ocfs2_dinode.i_dyn_features
189 *
190 * These can change much more often than i_flags. When adding flags,
191 * keep in mind that i_dyn_features is only 16 bits wide.
192 */
193#define OCFS2_INLINE_DATA_FL (0x0001) /* Data stored in inode block */
194#define OCFS2_HAS_XATTR_FL (0x0002)
195#define OCFS2_INLINE_XATTR_FL (0x0004)
196#define OCFS2_INDEXED_DIR_FL (0x0008)
197
ca4d147e
HP
198/* Inode attributes, keep in sync with EXT2 */
199#define OCFS2_SECRM_FL (0x00000001) /* Secure deletion */
200#define OCFS2_UNRM_FL (0x00000002) /* Undelete */
201#define OCFS2_COMPR_FL (0x00000004) /* Compress file */
202#define OCFS2_SYNC_FL (0x00000008) /* Synchronous updates */
203#define OCFS2_IMMUTABLE_FL (0x00000010) /* Immutable file */
204#define OCFS2_APPEND_FL (0x00000020) /* writes to file may only append */
205#define OCFS2_NODUMP_FL (0x00000040) /* do not dump file */
206#define OCFS2_NOATIME_FL (0x00000080) /* do not update atime */
207#define OCFS2_DIRSYNC_FL (0x00010000) /* dirsync behaviour (directories only) */
208
209#define OCFS2_FL_VISIBLE (0x000100FF) /* User visible flags */
210#define OCFS2_FL_MODIFIABLE (0x000100FF) /* User modifiable flags */
211
e48edee2
MF
212/*
213 * Extent record flags (e_node.leaf.flags)
214 */
215#define OCFS2_EXT_UNWRITTEN (0x01) /* Extent is allocated but
216 * unwritten */
217
ca4d147e
HP
218/*
219 * ioctl commands
220 */
221#define OCFS2_IOC_GETFLAGS _IOR('f', 1, long)
222#define OCFS2_IOC_SETFLAGS _IOW('f', 2, long)
586d232b
MF
223#define OCFS2_IOC32_GETFLAGS _IOR('f', 1, int)
224#define OCFS2_IOC32_SETFLAGS _IOW('f', 2, int)
ca4d147e 225
b2580103
MF
226/*
227 * Space reservation / allocation / free ioctls and argument structure
228 * are designed to be compatible with XFS.
229 *
230 * ALLOCSP* and FREESP* are not and will never be supported, but are
231 * included here for completeness.
232 */
233struct ocfs2_space_resv {
234 __s16 l_type;
235 __s16 l_whence;
236 __s64 l_start;
237 __s64 l_len; /* len == 0 means until end of file */
238 __s32 l_sysid;
239 __u32 l_pid;
240 __s32 l_pad[4]; /* reserve area */
241};
242
243#define OCFS2_IOC_ALLOCSP _IOW ('X', 10, struct ocfs2_space_resv)
244#define OCFS2_IOC_FREESP _IOW ('X', 11, struct ocfs2_space_resv)
245#define OCFS2_IOC_RESVSP _IOW ('X', 40, struct ocfs2_space_resv)
246#define OCFS2_IOC_UNRESVSP _IOW ('X', 41, struct ocfs2_space_resv)
247#define OCFS2_IOC_ALLOCSP64 _IOW ('X', 36, struct ocfs2_space_resv)
248#define OCFS2_IOC_FREESP64 _IOW ('X', 37, struct ocfs2_space_resv)
249#define OCFS2_IOC_RESVSP64 _IOW ('X', 42, struct ocfs2_space_resv)
250#define OCFS2_IOC_UNRESVSP64 _IOW ('X', 43, struct ocfs2_space_resv)
251
7909f2bf
TM
252/* Used to pass group descriptor data when online resize is done */
253struct ocfs2_new_group_input {
254 __u64 group; /* Group descriptor's blkno. */
255 __u32 clusters; /* Total number of clusters in this group */
256 __u32 frees; /* Total free clusters in this group */
257 __u16 chain; /* Chain for this group */
258 __u16 reserved1;
259 __u32 reserved2;
260};
261
d659072f 262#define OCFS2_IOC_GROUP_EXTEND _IOW('o', 1, int)
7909f2bf
TM
263#define OCFS2_IOC_GROUP_ADD _IOW('o', 2,struct ocfs2_new_group_input)
264#define OCFS2_IOC_GROUP_ADD64 _IOW('o', 3,struct ocfs2_new_group_input)
d659072f 265
ccd979bd
MF
266/*
267 * Journal Flags (ocfs2_dinode.id1.journal1.i_flags)
268 */
269#define OCFS2_JOURNAL_DIRTY_FL (0x00000001) /* Journal needs recovery */
270
271/*
272 * superblock s_state flags
273 */
274#define OCFS2_ERROR_FS (0x00000001) /* FS saw errors */
275
276/* Limit of space in ocfs2_dir_entry */
277#define OCFS2_MAX_FILENAME_LEN 255
278
279/* Maximum slots on an ocfs2 file system */
280#define OCFS2_MAX_SLOTS 255
281
282/* Slot map indicator for an empty slot */
283#define OCFS2_INVALID_SLOT -1
284
285#define OCFS2_VOL_UUID_LEN 16
286#define OCFS2_MAX_VOL_LABEL_LEN 64
287
b61817e1
JB
288/* The alternate, userspace stack fields */
289#define OCFS2_STACK_LABEL_LEN 4
290#define OCFS2_CLUSTER_NAME_LEN 16
291
ccd979bd
MF
292/* Journal limits (in bytes) */
293#define OCFS2_MIN_JOURNAL_SIZE (4 * 1024 * 1024)
ccd979bd 294
2fbe8d1e
SM
295/*
296 * Default local alloc size (in megabytes)
297 *
298 * The value chosen should be such that most allocations, including new
299 * block groups, use local alloc.
300 */
301#define OCFS2_DEFAULT_LOCAL_ALLOC_SIZE 8
302
ccd979bd
MF
303struct ocfs2_system_inode_info {
304 char *si_name;
305 int si_iflags;
306 int si_mode;
307};
308
309/* System file index */
310enum {
311 BAD_BLOCK_SYSTEM_INODE = 0,
312 GLOBAL_INODE_ALLOC_SYSTEM_INODE,
313 SLOT_MAP_SYSTEM_INODE,
314#define OCFS2_FIRST_ONLINE_SYSTEM_INODE SLOT_MAP_SYSTEM_INODE
315 HEARTBEAT_SYSTEM_INODE,
316 GLOBAL_BITMAP_SYSTEM_INODE,
317#define OCFS2_LAST_GLOBAL_SYSTEM_INODE GLOBAL_BITMAP_SYSTEM_INODE
318 ORPHAN_DIR_SYSTEM_INODE,
319 EXTENT_ALLOC_SYSTEM_INODE,
320 INODE_ALLOC_SYSTEM_INODE,
321 JOURNAL_SYSTEM_INODE,
322 LOCAL_ALLOC_SYSTEM_INODE,
323 TRUNCATE_LOG_SYSTEM_INODE,
324 NUM_SYSTEM_INODES
325};
326
327static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = {
328 /* Global system inodes (single copy) */
329 /* The first two are only used from userspace mfks/tunefs */
330 [BAD_BLOCK_SYSTEM_INODE] = { "bad_blocks", 0, S_IFREG | 0644 },
331 [GLOBAL_INODE_ALLOC_SYSTEM_INODE] = { "global_inode_alloc", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
332
333 /* These are used by the running filesystem */
334 [SLOT_MAP_SYSTEM_INODE] = { "slot_map", 0, S_IFREG | 0644 },
335 [HEARTBEAT_SYSTEM_INODE] = { "heartbeat", OCFS2_HEARTBEAT_FL, S_IFREG | 0644 },
336 [GLOBAL_BITMAP_SYSTEM_INODE] = { "global_bitmap", 0, S_IFREG | 0644 },
337
338 /* Slot-specific system inodes (one copy per slot) */
339 [ORPHAN_DIR_SYSTEM_INODE] = { "orphan_dir:%04d", 0, S_IFDIR | 0755 },
340 [EXTENT_ALLOC_SYSTEM_INODE] = { "extent_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
341 [INODE_ALLOC_SYSTEM_INODE] = { "inode_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
342 [JOURNAL_SYSTEM_INODE] = { "journal:%04d", OCFS2_JOURNAL_FL, S_IFREG | 0644 },
343 [LOCAL_ALLOC_SYSTEM_INODE] = { "local_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_LOCAL_ALLOC_FL, S_IFREG | 0644 },
344 [TRUNCATE_LOG_SYSTEM_INODE] = { "truncate_log:%04d", OCFS2_DEALLOC_FL, S_IFREG | 0644 }
345};
346
347/* Parameter passed from mount.ocfs2 to module */
348#define OCFS2_HB_NONE "heartbeat=none"
349#define OCFS2_HB_LOCAL "heartbeat=local"
350
351/*
352 * OCFS2 directory file types. Only the low 3 bits are used. The
353 * other bits are reserved for now.
354 */
355#define OCFS2_FT_UNKNOWN 0
356#define OCFS2_FT_REG_FILE 1
357#define OCFS2_FT_DIR 2
358#define OCFS2_FT_CHRDEV 3
359#define OCFS2_FT_BLKDEV 4
360#define OCFS2_FT_FIFO 5
361#define OCFS2_FT_SOCK 6
362#define OCFS2_FT_SYMLINK 7
363
364#define OCFS2_FT_MAX 8
365
366/*
367 * OCFS2_DIR_PAD defines the directory entries boundaries
368 *
369 * NOTE: It must be a multiple of 4
370 */
371#define OCFS2_DIR_PAD 4
372#define OCFS2_DIR_ROUND (OCFS2_DIR_PAD - 1)
373#define OCFS2_DIR_MEMBER_LEN offsetof(struct ocfs2_dir_entry, name)
374#define OCFS2_DIR_REC_LEN(name_len) (((name_len) + OCFS2_DIR_MEMBER_LEN + \
375 OCFS2_DIR_ROUND) & \
376 ~OCFS2_DIR_ROUND)
377
378#define OCFS2_LINK_MAX 32000
379
380#define S_SHIFT 12
381static unsigned char ocfs2_type_by_mode[S_IFMT >> S_SHIFT] = {
382 [S_IFREG >> S_SHIFT] = OCFS2_FT_REG_FILE,
383 [S_IFDIR >> S_SHIFT] = OCFS2_FT_DIR,
384 [S_IFCHR >> S_SHIFT] = OCFS2_FT_CHRDEV,
385 [S_IFBLK >> S_SHIFT] = OCFS2_FT_BLKDEV,
386 [S_IFIFO >> S_SHIFT] = OCFS2_FT_FIFO,
387 [S_IFSOCK >> S_SHIFT] = OCFS2_FT_SOCK,
388 [S_IFLNK >> S_SHIFT] = OCFS2_FT_SYMLINK,
389};
390
391
392/*
393 * Convenience casts
394 */
395#define OCFS2_RAW_SB(dinode) (&((dinode)->id2.i_super))
396
397/*
398 * On disk extent record for OCFS2
399 * It describes a range of clusters on disk.
e48edee2
MF
400 *
401 * Length fields are divided into interior and leaf node versions.
402 * This leaves room for a flags field (OCFS2_EXT_*) in the leaf nodes.
ccd979bd
MF
403 */
404struct ocfs2_extent_rec {
405/*00*/ __le32 e_cpos; /* Offset into the file, in clusters */
e48edee2
MF
406 union {
407 __le32 e_int_clusters; /* Clusters covered by all children */
408 struct {
409 __le16 e_leaf_clusters; /* Clusters covered by this
410 extent */
411 __u8 e_reserved1;
412 __u8 e_flags; /* Extent flags */
413 };
414 };
ccd979bd
MF
415 __le64 e_blkno; /* Physical disk offset, in blocks */
416/*10*/
417};
418
419struct ocfs2_chain_rec {
420 __le32 c_free; /* Number of free bits in this chain. */
421 __le32 c_total; /* Number of total bits in this chain */
422 __le64 c_blkno; /* Physical disk offset (blocks) of 1st group */
423};
424
425struct ocfs2_truncate_rec {
426 __le32 t_start; /* 1st cluster in this log */
427 __le32 t_clusters; /* Number of total clusters covered */
428};
429
430/*
431 * On disk extent list for OCFS2 (node in the tree). Note that this
432 * is contained inside ocfs2_dinode or ocfs2_extent_block, so the
433 * offsets are relative to ocfs2_dinode.id2.i_list or
434 * ocfs2_extent_block.h_list, respectively.
435 */
436struct ocfs2_extent_list {
437/*00*/ __le16 l_tree_depth; /* Extent tree depth from this
438 point. 0 means data extents
439 hang directly off this
dcd0538f
MF
440 header (a leaf)
441 NOTE: The high 8 bits cannot be
442 used - tree_depth is never that big.
443 */
ccd979bd
MF
444 __le16 l_count; /* Number of extent records */
445 __le16 l_next_free_rec; /* Next unused extent slot */
446 __le16 l_reserved1;
447 __le64 l_reserved2; /* Pad to
448 sizeof(ocfs2_extent_rec) */
449/*10*/ struct ocfs2_extent_rec l_recs[0]; /* Extent records */
450};
451
452/*
453 * On disk allocation chain list for OCFS2. Note that this is
454 * contained inside ocfs2_dinode, so the offsets are relative to
455 * ocfs2_dinode.id2.i_chain.
456 */
457struct ocfs2_chain_list {
458/*00*/ __le16 cl_cpg; /* Clusters per Block Group */
459 __le16 cl_bpc; /* Bits per cluster */
460 __le16 cl_count; /* Total chains in this list */
461 __le16 cl_next_free_rec; /* Next unused chain slot */
462 __le64 cl_reserved1;
463/*10*/ struct ocfs2_chain_rec cl_recs[0]; /* Chain records */
464};
465
466/*
467 * On disk deallocation log for OCFS2. Note that this is
468 * contained inside ocfs2_dinode, so the offsets are relative to
469 * ocfs2_dinode.id2.i_dealloc.
470 */
471struct ocfs2_truncate_log {
472/*00*/ __le16 tl_count; /* Total records in this log */
473 __le16 tl_used; /* Number of records in use */
474 __le32 tl_reserved1;
475/*08*/ struct ocfs2_truncate_rec tl_recs[0]; /* Truncate records */
476};
477
478/*
479 * On disk extent block (indirect block) for OCFS2
480 */
481struct ocfs2_extent_block
482{
483/*00*/ __u8 h_signature[8]; /* Signature for verification */
484 __le64 h_reserved1;
485/*10*/ __le16 h_suballoc_slot; /* Slot suballocator this
486 extent_header belongs to */
487 __le16 h_suballoc_bit; /* Bit offset in suballocator
488 block group */
489 __le32 h_fs_generation; /* Must match super block */
490 __le64 h_blkno; /* Offset on disk, in blocks */
491/*20*/ __le64 h_reserved3;
492 __le64 h_next_leaf_blk; /* Offset on disk, in blocks,
493 of next leaf header pointing
494 to data */
495/*30*/ struct ocfs2_extent_list h_list; /* Extent record list */
496/* Actual on-disk size is one block */
497};
498
fb86b1f0
JB
499/*
500 * On disk slot map for OCFS2. This defines the contents of the "slot_map"
386a2ef8
JB
501 * system file. A slot is valid if it contains a node number >= 0. The
502 * value -1 (0xFFFF) is OCFS2_INVALID_SLOT. This marks a slot empty.
fb86b1f0
JB
503 */
504struct ocfs2_slot_map {
505/*00*/ __le16 sm_slots[0];
506/*
507 * Actual on-disk size is one block. OCFS2_MAX_SLOTS is 255,
508 * 255 * sizeof(__le16) == 512B, within the 512B block minimum blocksize.
509 */
510};
511
386a2ef8
JB
512struct ocfs2_extended_slot {
513/*00*/ __u8 es_valid;
514 __u8 es_reserved1[3];
515 __le32 es_node_num;
516/*10*/
517};
518
519/*
520 * The extended slot map, used when OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP
521 * is set. It separates out the valid marker from the node number, and
522 * has room to grow. Unlike the old slot map, this format is defined by
523 * i_size.
524 */
525struct ocfs2_slot_map_extended {
526/*00*/ struct ocfs2_extended_slot se_slots[0];
527/*
528 * Actual size is i_size of the slot_map system file. It should
529 * match s_max_slots * sizeof(struct ocfs2_extended_slot)
530 */
531};
532
b61817e1
JB
533struct ocfs2_cluster_info {
534/*00*/ __u8 ci_stack[OCFS2_STACK_LABEL_LEN];
535 __le32 ci_reserved;
536/*08*/ __u8 ci_cluster[OCFS2_CLUSTER_NAME_LEN];
537/*18*/
538};
539
ccd979bd
MF
540/*
541 * On disk superblock for OCFS2
542 * Note that it is contained inside an ocfs2_dinode, so all offsets
543 * are relative to the start of ocfs2_dinode.id2.
544 */
545struct ocfs2_super_block {
546/*00*/ __le16 s_major_rev_level;
547 __le16 s_minor_rev_level;
548 __le16 s_mnt_count;
549 __le16 s_max_mnt_count;
550 __le16 s_state; /* File system state */
551 __le16 s_errors; /* Behaviour when detecting errors */
552 __le32 s_checkinterval; /* Max time between checks */
553/*10*/ __le64 s_lastcheck; /* Time of last check */
554 __le32 s_creator_os; /* OS */
555 __le32 s_feature_compat; /* Compatible feature set */
556/*20*/ __le32 s_feature_incompat; /* Incompatible feature set */
557 __le32 s_feature_ro_compat; /* Readonly-compatible feature set */
558 __le64 s_root_blkno; /* Offset, in blocks, of root directory
559 dinode */
560/*30*/ __le64 s_system_dir_blkno; /* Offset, in blocks, of system
561 directory dinode */
562 __le32 s_blocksize_bits; /* Blocksize for this fs */
563 __le32 s_clustersize_bits; /* Clustersize for this fs */
564/*40*/ __le16 s_max_slots; /* Max number of simultaneous mounts
565 before tunefs required */
92e91ce2
MF
566 __le16 s_tunefs_flag;
567 __le32 s_reserved1;
ccd979bd
MF
568 __le64 s_first_cluster_group; /* Block offset of 1st cluster
569 * group header */
570/*50*/ __u8 s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */
571/*90*/ __u8 s_uuid[OCFS2_VOL_UUID_LEN]; /* 128-bit uuid */
b61817e1
JB
572/*A0*/ struct ocfs2_cluster_info s_cluster_info; /* Selected userspace
573 stack. Only valid
574 with INCOMPAT flag. */
575/*B8*/ __le64 s_reserved2[17]; /* Fill out superblock */
576/*140*/
577
578 /*
579 * NOTE: As stated above, all offsets are relative to
580 * ocfs2_dinode.id2, which is at 0xC0 in the inode.
581 * 0xC0 + 0x140 = 0x200 or 512 bytes. A superblock must fit within
582 * our smallest blocksize, which is 512 bytes. To ensure this,
583 * we reserve the space in s_reserved2. Anything past s_reserved2
584 * will not be available on the smallest blocksize.
585 */
ccd979bd
MF
586};
587
588/*
589 * Local allocation bitmap for OCFS2 slots
590 * Note that it exists inside an ocfs2_dinode, so all offsets are
591 * relative to the start of ocfs2_dinode.id2.
592 */
593struct ocfs2_local_alloc
594{
595/*00*/ __le32 la_bm_off; /* Starting bit offset in main bitmap */
596 __le16 la_size; /* Size of included bitmap, in bytes */
597 __le16 la_reserved1;
598 __le64 la_reserved2;
599/*10*/ __u8 la_bitmap[0];
600};
601
15b1e36b
MF
602/*
603 * Data-in-inode header. This is only used if i_dyn_features has
604 * OCFS2_INLINE_DATA_FL set.
605 */
606struct ocfs2_inline_data
607{
608/*00*/ __le16 id_count; /* Number of bytes that can be used
609 * for data, starting at id_data */
610 __le16 id_reserved0;
611 __le32 id_reserved1;
612 __u8 id_data[0]; /* Start of user data */
613};
614
ccd979bd
MF
615/*
616 * On disk inode for OCFS2
617 */
618struct ocfs2_dinode {
619/*00*/ __u8 i_signature[8]; /* Signature for validation */
620 __le32 i_generation; /* Generation number */
621 __le16 i_suballoc_slot; /* Slot suballocator this inode
622 belongs to */
623 __le16 i_suballoc_bit; /* Bit offset in suballocator
624 block group */
625/*10*/ __le32 i_reserved0;
626 __le32 i_clusters; /* Cluster count */
627 __le32 i_uid; /* Owner UID */
628 __le32 i_gid; /* Owning GID */
629/*20*/ __le64 i_size; /* Size in bytes */
630 __le16 i_mode; /* File mode */
631 __le16 i_links_count; /* Links count */
632 __le32 i_flags; /* File flags */
633/*30*/ __le64 i_atime; /* Access time */
634 __le64 i_ctime; /* Creation time */
635/*40*/ __le64 i_mtime; /* Modification time */
636 __le64 i_dtime; /* Deletion time */
637/*50*/ __le64 i_blkno; /* Offset on disk, in blocks */
638 __le64 i_last_eb_blk; /* Pointer to last extent
639 block */
640/*60*/ __le32 i_fs_generation; /* Generation per fs-instance */
641 __le32 i_atime_nsec;
642 __le32 i_ctime_nsec;
643 __le32 i_mtime_nsec;
ca4d147e 644 __le32 i_attr;
50008630
TY
645 __le16 i_orphaned_slot; /* Only valid when OCFS2_ORPHANED_FL
646 was set in i_flags */
15b1e36b 647 __le16 i_dyn_features;
ca4d147e 648/*70*/ __le64 i_reserved2[8];
ccd979bd
MF
649/*B8*/ union {
650 __le64 i_pad1; /* Generic way to refer to this
651 64bit union */
652 struct {
653 __le64 i_rdev; /* Device number */
654 } dev1;
655 struct { /* Info for bitmap system
656 inodes */
657 __le32 i_used; /* Bits (ie, clusters) used */
658 __le32 i_total; /* Total bits (clusters)
659 available */
660 } bitmap1;
661 struct { /* Info for journal system
662 inodes */
663 __le32 ij_flags; /* Mounted, version, etc. */
c69991aa
SM
664 __le32 ij_recovery_generation; /* Incremented when the
665 journal is recovered
666 after an unclean
667 shutdown */
ccd979bd
MF
668 } journal1;
669 } id1; /* Inode type dependant 1 */
670/*C0*/ union {
671 struct ocfs2_super_block i_super;
672 struct ocfs2_local_alloc i_lab;
673 struct ocfs2_chain_list i_chain;
674 struct ocfs2_extent_list i_list;
675 struct ocfs2_truncate_log i_dealloc;
15b1e36b 676 struct ocfs2_inline_data i_data;
ccd979bd
MF
677 __u8 i_symlink[0];
678 } id2;
679/* Actual on-disk size is one block */
680};
681
682/*
683 * On-disk directory entry structure for OCFS2
684 *
685 * Packed as this structure could be accessed unaligned on 64-bit platforms
686 */
687struct ocfs2_dir_entry {
688/*00*/ __le64 inode; /* Inode number */
689 __le16 rec_len; /* Directory entry length */
690 __u8 name_len; /* Name length */
691 __u8 file_type;
692/*0C*/ char name[OCFS2_MAX_FILENAME_LEN]; /* File name */
693/* Actual on-disk length specified by rec_len */
694} __attribute__ ((packed));
695
696/*
697 * On disk allocator group structure for OCFS2
698 */
699struct ocfs2_group_desc
700{
701/*00*/ __u8 bg_signature[8]; /* Signature for validation */
702 __le16 bg_size; /* Size of included bitmap in
703 bytes. */
704 __le16 bg_bits; /* Bits represented by this
705 group. */
706 __le16 bg_free_bits_count; /* Free bits count */
707 __le16 bg_chain; /* What chain I am in. */
708/*10*/ __le32 bg_generation;
709 __le32 bg_reserved1;
710 __le64 bg_next_group; /* Next group in my list, in
711 blocks */
712/*20*/ __le64 bg_parent_dinode; /* dinode which owns me, in
713 blocks */
714 __le64 bg_blkno; /* Offset on disk, in blocks */
715/*30*/ __le64 bg_reserved2[2];
716/*40*/ __u8 bg_bitmap[0];
717};
718
5a7bc8eb
TM
719/*
720 * On disk extended attribute structure for OCFS2.
721 */
722
723/*
724 * ocfs2_xattr_entry indicates one extend attribute.
725 *
726 * Note that it can be stored in inode, one block or one xattr bucket.
727 */
728struct ocfs2_xattr_entry {
729 __le32 xe_name_hash; /* hash value of xattr prefix+suffix. */
730 __le16 xe_name_offset; /* byte offset from the 1st etnry in the local
731 local xattr storage(inode, xattr block or
732 xattr bucket). */
733 __u8 xe_name_len; /* xattr name len, does't include prefix. */
734 __u8 xe_type; /* the low 7 bits indicates the name prefix's
735 * type and the highest 1 bits indicate whether
736 * the EA is stored in the local storage. */
737 __le64 xe_value_size; /* real xattr value length. */
738};
739
740/*
741 * On disk structure for xattr header.
742 *
743 * One ocfs2_xattr_header describes how many ocfs2_xattr_entry records in
744 * the local xattr storage.
745 */
746struct ocfs2_xattr_header {
747 __le16 xh_count; /* contains the count of how
748 many records are in the
749 local xattr storage. */
750 __le16 xh_reserved1;
751 __le32 xh_reserved2;
752 __le64 xh_csum;
753 struct ocfs2_xattr_entry xh_entries[0]; /* xattr entry list. */
754};
755
756/*
757 * On disk structure for xattr value root.
758 *
759 * It is used when one extended attribute's size is larger, and we will save it
760 * in an outside cluster. It will stored in a b-tree like file content.
761 */
762struct ocfs2_xattr_value_root {
763/*00*/ __le32 xr_clusters; /* clusters covered by xattr value. */
764 __le32 xr_reserved0;
765 __le64 xr_last_eb_blk; /* Pointer to last extent block */
766/*10*/ struct ocfs2_extent_list xr_list; /* Extent record list */
767};
768
769/*
770 * On disk structure for xattr tree root.
771 *
772 * It is used when there are too many extended attributes for one file. These
773 * attributes will be organized and stored in an indexed-btree.
774 */
775struct ocfs2_xattr_tree_root {
776/*00*/ __le32 xt_clusters; /* clusters covered by xattr. */
777 __le32 xt_reserved0;
778 __le64 xt_last_eb_blk; /* Pointer to last extent block */
779/*10*/ struct ocfs2_extent_list xt_list; /* Extent record list */
780};
781
782#define OCFS2_XATTR_INDEXED 0x1
783
784/*
785 * On disk structure for xattr block.
786 */
787struct ocfs2_xattr_block {
788/*00*/ __u8 xb_signature[8]; /* Signature for verification */
789 __le16 xb_suballoc_slot; /* Slot suballocator this
790 block belongs to. */
791 __le16 xb_suballoc_bit; /* Bit offset in suballocator
792 block group */
793 __le32 xb_fs_generation; /* Must match super block */
794/*10*/ __le64 xb_blkno; /* Offset on disk, in blocks */
795 __le64 xb_csum;
796/*20*/ __le16 xb_flags; /* Indicates whether this block contains
797 real xattr or a xattr tree. */
798 __le16 xb_reserved0;
799 __le32 xb_reserved1;
800 __le64 xb_reserved2;
801/*30*/ union {
802 struct ocfs2_xattr_header xb_header; /* xattr header if this
803 block contains xattr */
804 struct ocfs2_xattr_tree_root xb_root;/* xattr tree root if this
805 block cotains xattr
806 tree. */
807 } xb_attrs;
808};
809
810#define OCFS2_XATTR_ENTRY_LOCAL 0x80
811#define OCFS2_XATTR_TYPE_MASK 0x7F
812static inline void ocfs2_xattr_set_local(struct ocfs2_xattr_entry *xe,
813 int local)
814{
815 if (local)
816 xe->xe_type |= OCFS2_XATTR_ENTRY_LOCAL;
817 else
818 xe->xe_type &= ~OCFS2_XATTR_ENTRY_LOCAL;
819}
820
821static inline int ocfs2_xattr_is_local(struct ocfs2_xattr_entry *xe)
822{
823 return xe->xe_type & OCFS2_XATTR_ENTRY_LOCAL;
824}
825
826static inline void ocfs2_xattr_set_type(struct ocfs2_xattr_entry *xe, int type)
827{
828 xe->xe_type |= type & OCFS2_XATTR_TYPE_MASK;
829}
830
831static inline int ocfs2_xattr_get_type(struct ocfs2_xattr_entry *xe)
832{
833 return xe->xe_type & OCFS2_XATTR_TYPE_MASK;
834}
835
ccd979bd
MF
836#ifdef __KERNEL__
837static inline int ocfs2_fast_symlink_chars(struct super_block *sb)
838{
839 return sb->s_blocksize -
840 offsetof(struct ocfs2_dinode, id2.i_symlink);
841}
842
15b1e36b
MF
843static inline int ocfs2_max_inline_data(struct super_block *sb)
844{
845 return sb->s_blocksize -
846 offsetof(struct ocfs2_dinode, id2.i_data.id_data);
847}
848
ccd979bd
MF
849static inline int ocfs2_extent_recs_per_inode(struct super_block *sb)
850{
851 int size;
852
853 size = sb->s_blocksize -
854 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
855
856 return size / sizeof(struct ocfs2_extent_rec);
857}
858
859static inline int ocfs2_chain_recs_per_inode(struct super_block *sb)
860{
861 int size;
862
863 size = sb->s_blocksize -
864 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
865
866 return size / sizeof(struct ocfs2_chain_rec);
867}
868
869static inline u16 ocfs2_extent_recs_per_eb(struct super_block *sb)
870{
871 int size;
872
873 size = sb->s_blocksize -
874 offsetof(struct ocfs2_extent_block, h_list.l_recs);
875
876 return size / sizeof(struct ocfs2_extent_rec);
877}
878
879static inline u16 ocfs2_local_alloc_size(struct super_block *sb)
880{
881 u16 size;
882
883 size = sb->s_blocksize -
884 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
885
886 return size;
887}
888
889static inline int ocfs2_group_bitmap_size(struct super_block *sb)
890{
891 int size;
892
893 size = sb->s_blocksize -
894 offsetof(struct ocfs2_group_desc, bg_bitmap);
895
896 return size;
897}
898
899static inline int ocfs2_truncate_recs_per_inode(struct super_block *sb)
900{
901 int size;
902
903 size = sb->s_blocksize -
904 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
905
906 return size / sizeof(struct ocfs2_truncate_rec);
907}
50af94b1
MF
908
909static inline u64 ocfs2_backup_super_blkno(struct super_block *sb, int index)
910{
911 u64 offset = OCFS2_BACKUP_SB_START;
912
913 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
914 offset <<= (2 * index);
a8a75a20 915 offset >>= sb->s_blocksize_bits;
50af94b1
MF
916 return offset;
917 }
918
919 return 0;
920
921}
ccd979bd
MF
922#else
923static inline int ocfs2_fast_symlink_chars(int blocksize)
924{
925 return blocksize - offsetof(struct ocfs2_dinode, id2.i_symlink);
926}
927
15b1e36b
MF
928static inline int ocfs2_max_inline_data(int blocksize)
929{
930 return blocksize - offsetof(struct ocfs2_dinode, id2.i_data.id_data);
931}
932
ccd979bd
MF
933static inline int ocfs2_extent_recs_per_inode(int blocksize)
934{
935 int size;
936
937 size = blocksize -
938 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
939
940 return size / sizeof(struct ocfs2_extent_rec);
941}
942
943static inline int ocfs2_chain_recs_per_inode(int blocksize)
944{
945 int size;
946
947 size = blocksize -
948 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
949
950 return size / sizeof(struct ocfs2_chain_rec);
951}
952
953static inline int ocfs2_extent_recs_per_eb(int blocksize)
954{
955 int size;
956
957 size = blocksize -
958 offsetof(struct ocfs2_extent_block, h_list.l_recs);
959
960 return size / sizeof(struct ocfs2_extent_rec);
961}
962
963static inline int ocfs2_local_alloc_size(int blocksize)
964{
965 int size;
966
967 size = blocksize -
968 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
969
970 return size;
971}
972
973static inline int ocfs2_group_bitmap_size(int blocksize)
974{
975 int size;
976
977 size = blocksize -
978 offsetof(struct ocfs2_group_desc, bg_bitmap);
979
980 return size;
981}
982
983static inline int ocfs2_truncate_recs_per_inode(int blocksize)
984{
985 int size;
986
987 size = blocksize -
988 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
989
990 return size / sizeof(struct ocfs2_truncate_rec);
991}
50af94b1
MF
992
993static inline uint64_t ocfs2_backup_super_blkno(int blocksize, int index)
994{
995 uint64_t offset = OCFS2_BACKUP_SB_START;
996
997 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
998 offset <<= (2 * index);
999 offset /= blocksize;
1000 return offset;
1001 }
1002
1003 return 0;
1004}
ccd979bd
MF
1005#endif /* __KERNEL__ */
1006
1007
1008static inline int ocfs2_system_inode_is_global(int type)
1009{
1010 return ((type >= 0) &&
1011 (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE));
1012}
1013
1014static inline int ocfs2_sprintf_system_inode_name(char *buf, int len,
1015 int type, int slot)
1016{
1017 int chars;
1018
1019 /*
1020 * Global system inodes can only have one copy. Everything
1021 * after OCFS2_LAST_GLOBAL_SYSTEM_INODE in the system inode
1022 * list has a copy per slot.
1023 */
1024 if (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE)
fe9f3877 1025 chars = snprintf(buf, len, "%s",
ccd979bd
MF
1026 ocfs2_system_inodes[type].si_name);
1027 else
1028 chars = snprintf(buf, len,
1029 ocfs2_system_inodes[type].si_name,
1030 slot);
1031
1032 return chars;
1033}
1034
1035static inline void ocfs2_set_de_type(struct ocfs2_dir_entry *de,
1036 umode_t mode)
1037{
1038 de->file_type = ocfs2_type_by_mode[(mode & S_IFMT)>>S_SHIFT];
1039}
1040
1041#endif /* _OCFS2_FS_H */
1042