blob: 52c426665154312cb0d7c812bed5f0b928a8e62d [file] [log] [blame]
Mark Fashehccd979b2005-12-15 14:31:24 -08001/* -*- 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"
67
68/* Compatibility flags */
69#define OCFS2_HAS_COMPAT_FEATURE(sb,mask) \
70 ( OCFS2_SB(sb)->s_feature_compat & (mask) )
71#define OCFS2_HAS_RO_COMPAT_FEATURE(sb,mask) \
72 ( OCFS2_SB(sb)->s_feature_ro_compat & (mask) )
73#define OCFS2_HAS_INCOMPAT_FEATURE(sb,mask) \
74 ( OCFS2_SB(sb)->s_feature_incompat & (mask) )
75#define OCFS2_SET_COMPAT_FEATURE(sb,mask) \
76 OCFS2_SB(sb)->s_feature_compat |= (mask)
77#define OCFS2_SET_RO_COMPAT_FEATURE(sb,mask) \
78 OCFS2_SB(sb)->s_feature_ro_compat |= (mask)
79#define OCFS2_SET_INCOMPAT_FEATURE(sb,mask) \
80 OCFS2_SB(sb)->s_feature_incompat |= (mask)
81#define OCFS2_CLEAR_COMPAT_FEATURE(sb,mask) \
82 OCFS2_SB(sb)->s_feature_compat &= ~(mask)
83#define OCFS2_CLEAR_RO_COMPAT_FEATURE(sb,mask) \
84 OCFS2_SB(sb)->s_feature_ro_compat &= ~(mask)
85#define OCFS2_CLEAR_INCOMPAT_FEATURE(sb,mask) \
86 OCFS2_SB(sb)->s_feature_incompat &= ~(mask)
87
Mark Fasheh50af94b2007-01-21 14:44:59 -080088#define OCFS2_FEATURE_COMPAT_SUPP OCFS2_FEATURE_COMPAT_BACKUP_SB
Mark Fashehdcd05382007-01-16 11:32:23 -080089#define OCFS2_FEATURE_INCOMPAT_SUPP (OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT \
Mark Fasheh15b1e362007-09-07 13:58:15 -070090 | OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC \
Joel Becker386a2ef2008-02-01 12:06:54 -080091 | OCFS2_FEATURE_INCOMPAT_INLINE_DATA \
Joel Beckerb61817e2008-02-01 15:08:23 -080092 | OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP \
93 | OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK)
Mark Fasheh328d5752007-06-18 10:48:04 -070094#define OCFS2_FEATURE_RO_COMPAT_SUPP OCFS2_FEATURE_RO_COMPAT_UNWRITTEN
Mark Fashehccd979b2005-12-15 14:31:24 -080095
96/*
97 * Heartbeat-only devices are missing journals and other files. The
98 * filesystem driver can't load them, but the library can. Never put
99 * this in OCFS2_FEATURE_INCOMPAT_SUPP, *ever*.
100 */
101#define OCFS2_FEATURE_INCOMPAT_HEARTBEAT_DEV 0x0002
102
Mark Fasheh89039012006-12-07 18:05:37 -0800103/*
104 * tunefs sets this incompat flag before starting the resize and clears it
105 * at the end. This flag protects users from inadvertently mounting the fs
106 * after an aborted run without fsck-ing.
107 */
108#define OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG 0x0004
Mark Fashehccd979b2005-12-15 14:31:24 -0800109
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800110/* Used to denote a non-clustered volume */
111#define OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT 0x0008
112
Mark Fasheh89039012006-12-07 18:05:37 -0800113/* Support for sparse allocation in b-trees */
114#define OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC 0x0010
115
Mark Fashehccd979b2005-12-15 14:31:24 -0800116/*
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700117 * Tunefs sets this incompat flag before starting an operation which
118 * would require cleanup on abort. This is done to protect users from
119 * inadvertently mounting the fs after an aborted run without
120 * fsck-ing.
121 *
122 * s_tunefs_flags on the super block describes precisely which
123 * operations were in progress.
124 */
125#define OCFS2_FEATURE_INCOMPAT_TUNEFS_INPROG 0x0020
126
Mark Fasheh15b1e362007-09-07 13:58:15 -0700127/* Support for data packed into inode blocks */
128#define OCFS2_FEATURE_INCOMPAT_INLINE_DATA 0x0040
129
Joel Becker386a2ef2008-02-01 12:06:54 -0800130/* Support for the extended slot map */
131#define OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP 0x100
132
133
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700134/*
Joel Beckerb61817e2008-02-01 15:08:23 -0800135 * Support for alternate, userspace cluster stacks. If set, the superblock
136 * field s_cluster_info contains a tag for the alternate stack in use as
137 * well as the name of the cluster being joined.
138 * mount.ocfs2 must pass in a matching stack name.
139 *
140 * If not set, the classic stack will be used. This is compatbile with
141 * all older versions.
142 */
143#define OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK 0x0080
144
145/*
Mark Fasheh50af94b2007-01-21 14:44:59 -0800146 * backup superblock flag is used to indicate that this volume
147 * has backup superblocks.
148 */
149#define OCFS2_FEATURE_COMPAT_BACKUP_SB 0x0001
150
Mark Fasheh328d5752007-06-18 10:48:04 -0700151/*
152 * Unwritten extents support.
153 */
154#define OCFS2_FEATURE_RO_COMPAT_UNWRITTEN 0x0001
155
Mark Fasheh50af94b2007-01-21 14:44:59 -0800156/* The byte offset of the first backup block will be 1G.
157 * The following will be 4G, 16G, 64G, 256G and 1T.
158 */
159#define OCFS2_BACKUP_SB_START 1 << 30
160
161/* the max backup superblock nums */
162#define OCFS2_MAX_BACKUP_SUPERBLOCKS 6
163
164/*
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700165 * Flags on ocfs2_super_block.s_tunefs_flags
166 */
167#define OCFS2_TUNEFS_INPROG_REMOVE_SLOT 0x0001 /* Removing slots */
168
169/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800170 * Flags on ocfs2_dinode.i_flags
171 */
172#define OCFS2_VALID_FL (0x00000001) /* Inode is valid */
173#define OCFS2_UNUSED2_FL (0x00000002)
174#define OCFS2_ORPHANED_FL (0x00000004) /* On the orphan list */
175#define OCFS2_UNUSED3_FL (0x00000008)
176/* System inode flags */
177#define OCFS2_SYSTEM_FL (0x00000010) /* System inode */
178#define OCFS2_SUPER_BLOCK_FL (0x00000020) /* Super block */
179#define OCFS2_LOCAL_ALLOC_FL (0x00000040) /* Slot local alloc bitmap */
180#define OCFS2_BITMAP_FL (0x00000080) /* Allocation bitmap */
181#define OCFS2_JOURNAL_FL (0x00000100) /* Slot local journal */
182#define OCFS2_HEARTBEAT_FL (0x00000200) /* Heartbeat area */
183#define OCFS2_CHAIN_FL (0x00000400) /* Chain allocator */
184#define OCFS2_DEALLOC_FL (0x00000800) /* Truncate log */
185
Mark Fasheh15b1e362007-09-07 13:58:15 -0700186/*
187 * Flags on ocfs2_dinode.i_dyn_features
188 *
189 * These can change much more often than i_flags. When adding flags,
190 * keep in mind that i_dyn_features is only 16 bits wide.
191 */
192#define OCFS2_INLINE_DATA_FL (0x0001) /* Data stored in inode block */
193#define OCFS2_HAS_XATTR_FL (0x0002)
194#define OCFS2_INLINE_XATTR_FL (0x0004)
195#define OCFS2_INDEXED_DIR_FL (0x0008)
196
Herbert Poetzlca4d1472006-07-03 17:27:12 -0700197/* Inode attributes, keep in sync with EXT2 */
198#define OCFS2_SECRM_FL (0x00000001) /* Secure deletion */
199#define OCFS2_UNRM_FL (0x00000002) /* Undelete */
200#define OCFS2_COMPR_FL (0x00000004) /* Compress file */
201#define OCFS2_SYNC_FL (0x00000008) /* Synchronous updates */
202#define OCFS2_IMMUTABLE_FL (0x00000010) /* Immutable file */
203#define OCFS2_APPEND_FL (0x00000020) /* writes to file may only append */
204#define OCFS2_NODUMP_FL (0x00000040) /* do not dump file */
205#define OCFS2_NOATIME_FL (0x00000080) /* do not update atime */
206#define OCFS2_DIRSYNC_FL (0x00010000) /* dirsync behaviour (directories only) */
207
208#define OCFS2_FL_VISIBLE (0x000100FF) /* User visible flags */
209#define OCFS2_FL_MODIFIABLE (0x000100FF) /* User modifiable flags */
210
211/*
Mark Fashehe48edee2007-03-07 16:46:57 -0800212 * Extent record flags (e_node.leaf.flags)
213 */
214#define OCFS2_EXT_UNWRITTEN (0x01) /* Extent is allocated but
215 * unwritten */
216
217/*
Herbert Poetzlca4d1472006-07-03 17:27:12 -0700218 * ioctl commands
219 */
220#define OCFS2_IOC_GETFLAGS _IOR('f', 1, long)
221#define OCFS2_IOC_SETFLAGS _IOW('f', 2, long)
Mark Fasheh586d2322007-03-09 15:56:28 -0800222#define OCFS2_IOC32_GETFLAGS _IOR('f', 1, int)
223#define OCFS2_IOC32_SETFLAGS _IOW('f', 2, int)
Herbert Poetzlca4d1472006-07-03 17:27:12 -0700224
Mark Fashehccd979b2005-12-15 14:31:24 -0800225/*
Mark Fashehb2580102007-03-09 16:53:21 -0800226 * Space reservation / allocation / free ioctls and argument structure
227 * are designed to be compatible with XFS.
228 *
229 * ALLOCSP* and FREESP* are not and will never be supported, but are
230 * included here for completeness.
231 */
232struct ocfs2_space_resv {
233 __s16 l_type;
234 __s16 l_whence;
235 __s64 l_start;
236 __s64 l_len; /* len == 0 means until end of file */
237 __s32 l_sysid;
238 __u32 l_pid;
239 __s32 l_pad[4]; /* reserve area */
240};
241
242#define OCFS2_IOC_ALLOCSP _IOW ('X', 10, struct ocfs2_space_resv)
243#define OCFS2_IOC_FREESP _IOW ('X', 11, struct ocfs2_space_resv)
244#define OCFS2_IOC_RESVSP _IOW ('X', 40, struct ocfs2_space_resv)
245#define OCFS2_IOC_UNRESVSP _IOW ('X', 41, struct ocfs2_space_resv)
246#define OCFS2_IOC_ALLOCSP64 _IOW ('X', 36, struct ocfs2_space_resv)
247#define OCFS2_IOC_FREESP64 _IOW ('X', 37, struct ocfs2_space_resv)
248#define OCFS2_IOC_RESVSP64 _IOW ('X', 42, struct ocfs2_space_resv)
249#define OCFS2_IOC_UNRESVSP64 _IOW ('X', 43, struct ocfs2_space_resv)
250
Tao Ma7909f2b2007-12-18 15:47:25 +0800251/* Used to pass group descriptor data when online resize is done */
252struct ocfs2_new_group_input {
253 __u64 group; /* Group descriptor's blkno. */
254 __u32 clusters; /* Total number of clusters in this group */
255 __u32 frees; /* Total free clusters in this group */
256 __u16 chain; /* Chain for this group */
257 __u16 reserved1;
258 __u32 reserved2;
259};
260
Tao Mad6590722007-12-18 15:47:03 +0800261#define OCFS2_IOC_GROUP_EXTEND _IOW('o', 1, int)
Tao Ma7909f2b2007-12-18 15:47:25 +0800262#define OCFS2_IOC_GROUP_ADD _IOW('o', 2,struct ocfs2_new_group_input)
263#define OCFS2_IOC_GROUP_ADD64 _IOW('o', 3,struct ocfs2_new_group_input)
Tao Mad6590722007-12-18 15:47:03 +0800264
Mark Fashehb2580102007-03-09 16:53:21 -0800265/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800266 * Journal Flags (ocfs2_dinode.id1.journal1.i_flags)
267 */
268#define OCFS2_JOURNAL_DIRTY_FL (0x00000001) /* Journal needs recovery */
269
270/*
271 * superblock s_state flags
272 */
273#define OCFS2_ERROR_FS (0x00000001) /* FS saw errors */
274
275/* Limit of space in ocfs2_dir_entry */
276#define OCFS2_MAX_FILENAME_LEN 255
277
278/* Maximum slots on an ocfs2 file system */
279#define OCFS2_MAX_SLOTS 255
280
281/* Slot map indicator for an empty slot */
282#define OCFS2_INVALID_SLOT -1
283
284#define OCFS2_VOL_UUID_LEN 16
285#define OCFS2_MAX_VOL_LABEL_LEN 64
286
Joel Beckerb61817e2008-02-01 15:08:23 -0800287/* The alternate, userspace stack fields */
288#define OCFS2_STACK_LABEL_LEN 4
289#define OCFS2_CLUSTER_NAME_LEN 16
290
Mark Fashehccd979b2005-12-15 14:31:24 -0800291/* Journal limits (in bytes) */
292#define OCFS2_MIN_JOURNAL_SIZE (4 * 1024 * 1024)
Mark Fashehccd979b2005-12-15 14:31:24 -0800293
Sunil Mushran2fbe8d12007-12-20 14:58:11 -0800294/*
295 * Default local alloc size (in megabytes)
296 *
297 * The value chosen should be such that most allocations, including new
298 * block groups, use local alloc.
299 */
300#define OCFS2_DEFAULT_LOCAL_ALLOC_SIZE 8
301
Mark Fashehccd979b2005-12-15 14:31:24 -0800302struct ocfs2_system_inode_info {
303 char *si_name;
304 int si_iflags;
305 int si_mode;
306};
307
308/* System file index */
309enum {
310 BAD_BLOCK_SYSTEM_INODE = 0,
311 GLOBAL_INODE_ALLOC_SYSTEM_INODE,
312 SLOT_MAP_SYSTEM_INODE,
313#define OCFS2_FIRST_ONLINE_SYSTEM_INODE SLOT_MAP_SYSTEM_INODE
314 HEARTBEAT_SYSTEM_INODE,
315 GLOBAL_BITMAP_SYSTEM_INODE,
316#define OCFS2_LAST_GLOBAL_SYSTEM_INODE GLOBAL_BITMAP_SYSTEM_INODE
317 ORPHAN_DIR_SYSTEM_INODE,
318 EXTENT_ALLOC_SYSTEM_INODE,
319 INODE_ALLOC_SYSTEM_INODE,
320 JOURNAL_SYSTEM_INODE,
321 LOCAL_ALLOC_SYSTEM_INODE,
322 TRUNCATE_LOG_SYSTEM_INODE,
323 NUM_SYSTEM_INODES
324};
325
326static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = {
327 /* Global system inodes (single copy) */
328 /* The first two are only used from userspace mfks/tunefs */
329 [BAD_BLOCK_SYSTEM_INODE] = { "bad_blocks", 0, S_IFREG | 0644 },
330 [GLOBAL_INODE_ALLOC_SYSTEM_INODE] = { "global_inode_alloc", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
331
332 /* These are used by the running filesystem */
333 [SLOT_MAP_SYSTEM_INODE] = { "slot_map", 0, S_IFREG | 0644 },
334 [HEARTBEAT_SYSTEM_INODE] = { "heartbeat", OCFS2_HEARTBEAT_FL, S_IFREG | 0644 },
335 [GLOBAL_BITMAP_SYSTEM_INODE] = { "global_bitmap", 0, S_IFREG | 0644 },
336
337 /* Slot-specific system inodes (one copy per slot) */
338 [ORPHAN_DIR_SYSTEM_INODE] = { "orphan_dir:%04d", 0, S_IFDIR | 0755 },
339 [EXTENT_ALLOC_SYSTEM_INODE] = { "extent_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
340 [INODE_ALLOC_SYSTEM_INODE] = { "inode_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
341 [JOURNAL_SYSTEM_INODE] = { "journal:%04d", OCFS2_JOURNAL_FL, S_IFREG | 0644 },
342 [LOCAL_ALLOC_SYSTEM_INODE] = { "local_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_LOCAL_ALLOC_FL, S_IFREG | 0644 },
343 [TRUNCATE_LOG_SYSTEM_INODE] = { "truncate_log:%04d", OCFS2_DEALLOC_FL, S_IFREG | 0644 }
344};
345
346/* Parameter passed from mount.ocfs2 to module */
347#define OCFS2_HB_NONE "heartbeat=none"
348#define OCFS2_HB_LOCAL "heartbeat=local"
349
350/*
351 * OCFS2 directory file types. Only the low 3 bits are used. The
352 * other bits are reserved for now.
353 */
354#define OCFS2_FT_UNKNOWN 0
355#define OCFS2_FT_REG_FILE 1
356#define OCFS2_FT_DIR 2
357#define OCFS2_FT_CHRDEV 3
358#define OCFS2_FT_BLKDEV 4
359#define OCFS2_FT_FIFO 5
360#define OCFS2_FT_SOCK 6
361#define OCFS2_FT_SYMLINK 7
362
363#define OCFS2_FT_MAX 8
364
365/*
366 * OCFS2_DIR_PAD defines the directory entries boundaries
367 *
368 * NOTE: It must be a multiple of 4
369 */
370#define OCFS2_DIR_PAD 4
371#define OCFS2_DIR_ROUND (OCFS2_DIR_PAD - 1)
372#define OCFS2_DIR_MEMBER_LEN offsetof(struct ocfs2_dir_entry, name)
373#define OCFS2_DIR_REC_LEN(name_len) (((name_len) + OCFS2_DIR_MEMBER_LEN + \
374 OCFS2_DIR_ROUND) & \
375 ~OCFS2_DIR_ROUND)
376
377#define OCFS2_LINK_MAX 32000
378
379#define S_SHIFT 12
380static unsigned char ocfs2_type_by_mode[S_IFMT >> S_SHIFT] = {
381 [S_IFREG >> S_SHIFT] = OCFS2_FT_REG_FILE,
382 [S_IFDIR >> S_SHIFT] = OCFS2_FT_DIR,
383 [S_IFCHR >> S_SHIFT] = OCFS2_FT_CHRDEV,
384 [S_IFBLK >> S_SHIFT] = OCFS2_FT_BLKDEV,
385 [S_IFIFO >> S_SHIFT] = OCFS2_FT_FIFO,
386 [S_IFSOCK >> S_SHIFT] = OCFS2_FT_SOCK,
387 [S_IFLNK >> S_SHIFT] = OCFS2_FT_SYMLINK,
388};
389
390
391/*
392 * Convenience casts
393 */
394#define OCFS2_RAW_SB(dinode) (&((dinode)->id2.i_super))
395
396/*
397 * On disk extent record for OCFS2
398 * It describes a range of clusters on disk.
Mark Fashehe48edee2007-03-07 16:46:57 -0800399 *
400 * Length fields are divided into interior and leaf node versions.
401 * This leaves room for a flags field (OCFS2_EXT_*) in the leaf nodes.
Mark Fashehccd979b2005-12-15 14:31:24 -0800402 */
403struct ocfs2_extent_rec {
404/*00*/ __le32 e_cpos; /* Offset into the file, in clusters */
Mark Fashehe48edee2007-03-07 16:46:57 -0800405 union {
406 __le32 e_int_clusters; /* Clusters covered by all children */
407 struct {
408 __le16 e_leaf_clusters; /* Clusters covered by this
409 extent */
410 __u8 e_reserved1;
411 __u8 e_flags; /* Extent flags */
412 };
413 };
Mark Fashehccd979b2005-12-15 14:31:24 -0800414 __le64 e_blkno; /* Physical disk offset, in blocks */
415/*10*/
416};
417
418struct ocfs2_chain_rec {
419 __le32 c_free; /* Number of free bits in this chain. */
420 __le32 c_total; /* Number of total bits in this chain */
421 __le64 c_blkno; /* Physical disk offset (blocks) of 1st group */
422};
423
424struct ocfs2_truncate_rec {
425 __le32 t_start; /* 1st cluster in this log */
426 __le32 t_clusters; /* Number of total clusters covered */
427};
428
429/*
430 * On disk extent list for OCFS2 (node in the tree). Note that this
431 * is contained inside ocfs2_dinode or ocfs2_extent_block, so the
432 * offsets are relative to ocfs2_dinode.id2.i_list or
433 * ocfs2_extent_block.h_list, respectively.
434 */
435struct ocfs2_extent_list {
436/*00*/ __le16 l_tree_depth; /* Extent tree depth from this
437 point. 0 means data extents
438 hang directly off this
Mark Fashehdcd05382007-01-16 11:32:23 -0800439 header (a leaf)
440 NOTE: The high 8 bits cannot be
441 used - tree_depth is never that big.
442 */
Mark Fashehccd979b2005-12-15 14:31:24 -0800443 __le16 l_count; /* Number of extent records */
444 __le16 l_next_free_rec; /* Next unused extent slot */
445 __le16 l_reserved1;
446 __le64 l_reserved2; /* Pad to
447 sizeof(ocfs2_extent_rec) */
448/*10*/ struct ocfs2_extent_rec l_recs[0]; /* Extent records */
449};
450
451/*
452 * On disk allocation chain list for OCFS2. Note that this is
453 * contained inside ocfs2_dinode, so the offsets are relative to
454 * ocfs2_dinode.id2.i_chain.
455 */
456struct ocfs2_chain_list {
457/*00*/ __le16 cl_cpg; /* Clusters per Block Group */
458 __le16 cl_bpc; /* Bits per cluster */
459 __le16 cl_count; /* Total chains in this list */
460 __le16 cl_next_free_rec; /* Next unused chain slot */
461 __le64 cl_reserved1;
462/*10*/ struct ocfs2_chain_rec cl_recs[0]; /* Chain records */
463};
464
465/*
466 * On disk deallocation log for OCFS2. Note that this is
467 * contained inside ocfs2_dinode, so the offsets are relative to
468 * ocfs2_dinode.id2.i_dealloc.
469 */
470struct ocfs2_truncate_log {
471/*00*/ __le16 tl_count; /* Total records in this log */
472 __le16 tl_used; /* Number of records in use */
473 __le32 tl_reserved1;
474/*08*/ struct ocfs2_truncate_rec tl_recs[0]; /* Truncate records */
475};
476
477/*
478 * On disk extent block (indirect block) for OCFS2
479 */
480struct ocfs2_extent_block
481{
482/*00*/ __u8 h_signature[8]; /* Signature for verification */
483 __le64 h_reserved1;
484/*10*/ __le16 h_suballoc_slot; /* Slot suballocator this
485 extent_header belongs to */
486 __le16 h_suballoc_bit; /* Bit offset in suballocator
487 block group */
488 __le32 h_fs_generation; /* Must match super block */
489 __le64 h_blkno; /* Offset on disk, in blocks */
490/*20*/ __le64 h_reserved3;
491 __le64 h_next_leaf_blk; /* Offset on disk, in blocks,
492 of next leaf header pointing
493 to data */
494/*30*/ struct ocfs2_extent_list h_list; /* Extent record list */
495/* Actual on-disk size is one block */
496};
497
498/*
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800499 * On disk slot map for OCFS2. This defines the contents of the "slot_map"
Joel Becker386a2ef2008-02-01 12:06:54 -0800500 * system file. A slot is valid if it contains a node number >= 0. The
501 * value -1 (0xFFFF) is OCFS2_INVALID_SLOT. This marks a slot empty.
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800502 */
503struct ocfs2_slot_map {
504/*00*/ __le16 sm_slots[0];
505/*
506 * Actual on-disk size is one block. OCFS2_MAX_SLOTS is 255,
507 * 255 * sizeof(__le16) == 512B, within the 512B block minimum blocksize.
508 */
509};
510
Joel Becker386a2ef2008-02-01 12:06:54 -0800511struct ocfs2_extended_slot {
512/*00*/ __u8 es_valid;
513 __u8 es_reserved1[3];
514 __le32 es_node_num;
515/*10*/
516};
517
518/*
519 * The extended slot map, used when OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP
520 * is set. It separates out the valid marker from the node number, and
521 * has room to grow. Unlike the old slot map, this format is defined by
522 * i_size.
523 */
524struct ocfs2_slot_map_extended {
525/*00*/ struct ocfs2_extended_slot se_slots[0];
526/*
527 * Actual size is i_size of the slot_map system file. It should
528 * match s_max_slots * sizeof(struct ocfs2_extended_slot)
529 */
530};
531
Joel Beckerb61817e2008-02-01 15:08:23 -0800532struct ocfs2_cluster_info {
533/*00*/ __u8 ci_stack[OCFS2_STACK_LABEL_LEN];
534 __le32 ci_reserved;
535/*08*/ __u8 ci_cluster[OCFS2_CLUSTER_NAME_LEN];
536/*18*/
537};
538
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800539/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800540 * On disk superblock for OCFS2
541 * Note that it is contained inside an ocfs2_dinode, so all offsets
542 * are relative to the start of ocfs2_dinode.id2.
543 */
544struct ocfs2_super_block {
545/*00*/ __le16 s_major_rev_level;
546 __le16 s_minor_rev_level;
547 __le16 s_mnt_count;
548 __le16 s_max_mnt_count;
549 __le16 s_state; /* File system state */
550 __le16 s_errors; /* Behaviour when detecting errors */
551 __le32 s_checkinterval; /* Max time between checks */
552/*10*/ __le64 s_lastcheck; /* Time of last check */
553 __le32 s_creator_os; /* OS */
554 __le32 s_feature_compat; /* Compatible feature set */
555/*20*/ __le32 s_feature_incompat; /* Incompatible feature set */
556 __le32 s_feature_ro_compat; /* Readonly-compatible feature set */
557 __le64 s_root_blkno; /* Offset, in blocks, of root directory
558 dinode */
559/*30*/ __le64 s_system_dir_blkno; /* Offset, in blocks, of system
560 directory dinode */
561 __le32 s_blocksize_bits; /* Blocksize for this fs */
562 __le32 s_clustersize_bits; /* Clustersize for this fs */
563/*40*/ __le16 s_max_slots; /* Max number of simultaneous mounts
564 before tunefs required */
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700565 __le16 s_tunefs_flag;
566 __le32 s_reserved1;
Mark Fashehccd979b2005-12-15 14:31:24 -0800567 __le64 s_first_cluster_group; /* Block offset of 1st cluster
568 * group header */
569/*50*/ __u8 s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */
570/*90*/ __u8 s_uuid[OCFS2_VOL_UUID_LEN]; /* 128-bit uuid */
Joel Beckerb61817e2008-02-01 15:08:23 -0800571/*A0*/ struct ocfs2_cluster_info s_cluster_info; /* Selected userspace
572 stack. Only valid
573 with INCOMPAT flag. */
574/*B8*/ __le64 s_reserved2[17]; /* Fill out superblock */
575/*140*/
576
577 /*
578 * NOTE: As stated above, all offsets are relative to
579 * ocfs2_dinode.id2, which is at 0xC0 in the inode.
580 * 0xC0 + 0x140 = 0x200 or 512 bytes. A superblock must fit within
581 * our smallest blocksize, which is 512 bytes. To ensure this,
582 * we reserve the space in s_reserved2. Anything past s_reserved2
583 * will not be available on the smallest blocksize.
584 */
Mark Fashehccd979b2005-12-15 14:31:24 -0800585};
586
587/*
588 * Local allocation bitmap for OCFS2 slots
589 * Note that it exists inside an ocfs2_dinode, so all offsets are
590 * relative to the start of ocfs2_dinode.id2.
591 */
592struct ocfs2_local_alloc
593{
594/*00*/ __le32 la_bm_off; /* Starting bit offset in main bitmap */
595 __le16 la_size; /* Size of included bitmap, in bytes */
596 __le16 la_reserved1;
597 __le64 la_reserved2;
598/*10*/ __u8 la_bitmap[0];
599};
600
601/*
Mark Fasheh15b1e362007-09-07 13:58:15 -0700602 * Data-in-inode header. This is only used if i_dyn_features has
603 * OCFS2_INLINE_DATA_FL set.
604 */
605struct ocfs2_inline_data
606{
607/*00*/ __le16 id_count; /* Number of bytes that can be used
608 * for data, starting at id_data */
609 __le16 id_reserved0;
610 __le32 id_reserved1;
611 __u8 id_data[0]; /* Start of user data */
612};
613
614/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800615 * On disk inode for OCFS2
616 */
617struct ocfs2_dinode {
618/*00*/ __u8 i_signature[8]; /* Signature for validation */
619 __le32 i_generation; /* Generation number */
620 __le16 i_suballoc_slot; /* Slot suballocator this inode
621 belongs to */
622 __le16 i_suballoc_bit; /* Bit offset in suballocator
623 block group */
624/*10*/ __le32 i_reserved0;
625 __le32 i_clusters; /* Cluster count */
626 __le32 i_uid; /* Owner UID */
627 __le32 i_gid; /* Owning GID */
628/*20*/ __le64 i_size; /* Size in bytes */
629 __le16 i_mode; /* File mode */
630 __le16 i_links_count; /* Links count */
631 __le32 i_flags; /* File flags */
632/*30*/ __le64 i_atime; /* Access time */
633 __le64 i_ctime; /* Creation time */
634/*40*/ __le64 i_mtime; /* Modification time */
635 __le64 i_dtime; /* Deletion time */
636/*50*/ __le64 i_blkno; /* Offset on disk, in blocks */
637 __le64 i_last_eb_blk; /* Pointer to last extent
638 block */
639/*60*/ __le32 i_fs_generation; /* Generation per fs-instance */
640 __le32 i_atime_nsec;
641 __le32 i_ctime_nsec;
642 __le32 i_mtime_nsec;
Herbert Poetzlca4d1472006-07-03 17:27:12 -0700643 __le32 i_attr;
Tiger Yang50008632007-03-20 16:01:38 -0700644 __le16 i_orphaned_slot; /* Only valid when OCFS2_ORPHANED_FL
645 was set in i_flags */
Mark Fasheh15b1e362007-09-07 13:58:15 -0700646 __le16 i_dyn_features;
Herbert Poetzlca4d1472006-07-03 17:27:12 -0700647/*70*/ __le64 i_reserved2[8];
Mark Fashehccd979b2005-12-15 14:31:24 -0800648/*B8*/ union {
649 __le64 i_pad1; /* Generic way to refer to this
650 64bit union */
651 struct {
652 __le64 i_rdev; /* Device number */
653 } dev1;
654 struct { /* Info for bitmap system
655 inodes */
656 __le32 i_used; /* Bits (ie, clusters) used */
657 __le32 i_total; /* Total bits (clusters)
658 available */
659 } bitmap1;
660 struct { /* Info for journal system
661 inodes */
662 __le32 ij_flags; /* Mounted, version, etc. */
663 __le32 ij_pad;
664 } journal1;
665 } id1; /* Inode type dependant 1 */
666/*C0*/ union {
667 struct ocfs2_super_block i_super;
668 struct ocfs2_local_alloc i_lab;
669 struct ocfs2_chain_list i_chain;
670 struct ocfs2_extent_list i_list;
671 struct ocfs2_truncate_log i_dealloc;
Mark Fasheh15b1e362007-09-07 13:58:15 -0700672 struct ocfs2_inline_data i_data;
Mark Fashehccd979b2005-12-15 14:31:24 -0800673 __u8 i_symlink[0];
674 } id2;
675/* Actual on-disk size is one block */
676};
677
678/*
679 * On-disk directory entry structure for OCFS2
680 *
681 * Packed as this structure could be accessed unaligned on 64-bit platforms
682 */
683struct ocfs2_dir_entry {
684/*00*/ __le64 inode; /* Inode number */
685 __le16 rec_len; /* Directory entry length */
686 __u8 name_len; /* Name length */
687 __u8 file_type;
688/*0C*/ char name[OCFS2_MAX_FILENAME_LEN]; /* File name */
689/* Actual on-disk length specified by rec_len */
690} __attribute__ ((packed));
691
692/*
693 * On disk allocator group structure for OCFS2
694 */
695struct ocfs2_group_desc
696{
697/*00*/ __u8 bg_signature[8]; /* Signature for validation */
698 __le16 bg_size; /* Size of included bitmap in
699 bytes. */
700 __le16 bg_bits; /* Bits represented by this
701 group. */
702 __le16 bg_free_bits_count; /* Free bits count */
703 __le16 bg_chain; /* What chain I am in. */
704/*10*/ __le32 bg_generation;
705 __le32 bg_reserved1;
706 __le64 bg_next_group; /* Next group in my list, in
707 blocks */
708/*20*/ __le64 bg_parent_dinode; /* dinode which owns me, in
709 blocks */
710 __le64 bg_blkno; /* Offset on disk, in blocks */
711/*30*/ __le64 bg_reserved2[2];
712/*40*/ __u8 bg_bitmap[0];
713};
714
715#ifdef __KERNEL__
716static inline int ocfs2_fast_symlink_chars(struct super_block *sb)
717{
718 return sb->s_blocksize -
719 offsetof(struct ocfs2_dinode, id2.i_symlink);
720}
721
Mark Fasheh15b1e362007-09-07 13:58:15 -0700722static inline int ocfs2_max_inline_data(struct super_block *sb)
723{
724 return sb->s_blocksize -
725 offsetof(struct ocfs2_dinode, id2.i_data.id_data);
726}
727
Mark Fashehccd979b2005-12-15 14:31:24 -0800728static inline int ocfs2_extent_recs_per_inode(struct super_block *sb)
729{
730 int size;
731
732 size = sb->s_blocksize -
733 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
734
735 return size / sizeof(struct ocfs2_extent_rec);
736}
737
738static inline int ocfs2_chain_recs_per_inode(struct super_block *sb)
739{
740 int size;
741
742 size = sb->s_blocksize -
743 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
744
745 return size / sizeof(struct ocfs2_chain_rec);
746}
747
748static inline u16 ocfs2_extent_recs_per_eb(struct super_block *sb)
749{
750 int size;
751
752 size = sb->s_blocksize -
753 offsetof(struct ocfs2_extent_block, h_list.l_recs);
754
755 return size / sizeof(struct ocfs2_extent_rec);
756}
757
758static inline u16 ocfs2_local_alloc_size(struct super_block *sb)
759{
760 u16 size;
761
762 size = sb->s_blocksize -
763 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
764
765 return size;
766}
767
768static inline int ocfs2_group_bitmap_size(struct super_block *sb)
769{
770 int size;
771
772 size = sb->s_blocksize -
773 offsetof(struct ocfs2_group_desc, bg_bitmap);
774
775 return size;
776}
777
778static inline int ocfs2_truncate_recs_per_inode(struct super_block *sb)
779{
780 int size;
781
782 size = sb->s_blocksize -
783 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
784
785 return size / sizeof(struct ocfs2_truncate_rec);
786}
Mark Fasheh50af94b2007-01-21 14:44:59 -0800787
788static inline u64 ocfs2_backup_super_blkno(struct super_block *sb, int index)
789{
790 u64 offset = OCFS2_BACKUP_SB_START;
791
792 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
793 offset <<= (2 * index);
Mark Fasheha8a75a22007-01-26 10:46:59 -0800794 offset >>= sb->s_blocksize_bits;
Mark Fasheh50af94b2007-01-21 14:44:59 -0800795 return offset;
796 }
797
798 return 0;
799
800}
Mark Fashehccd979b2005-12-15 14:31:24 -0800801#else
802static inline int ocfs2_fast_symlink_chars(int blocksize)
803{
804 return blocksize - offsetof(struct ocfs2_dinode, id2.i_symlink);
805}
806
Mark Fasheh15b1e362007-09-07 13:58:15 -0700807static inline int ocfs2_max_inline_data(int blocksize)
808{
809 return blocksize - offsetof(struct ocfs2_dinode, id2.i_data.id_data);
810}
811
Mark Fashehccd979b2005-12-15 14:31:24 -0800812static inline int ocfs2_extent_recs_per_inode(int blocksize)
813{
814 int size;
815
816 size = blocksize -
817 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
818
819 return size / sizeof(struct ocfs2_extent_rec);
820}
821
822static inline int ocfs2_chain_recs_per_inode(int blocksize)
823{
824 int size;
825
826 size = blocksize -
827 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
828
829 return size / sizeof(struct ocfs2_chain_rec);
830}
831
832static inline int ocfs2_extent_recs_per_eb(int blocksize)
833{
834 int size;
835
836 size = blocksize -
837 offsetof(struct ocfs2_extent_block, h_list.l_recs);
838
839 return size / sizeof(struct ocfs2_extent_rec);
840}
841
842static inline int ocfs2_local_alloc_size(int blocksize)
843{
844 int size;
845
846 size = blocksize -
847 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
848
849 return size;
850}
851
852static inline int ocfs2_group_bitmap_size(int blocksize)
853{
854 int size;
855
856 size = blocksize -
857 offsetof(struct ocfs2_group_desc, bg_bitmap);
858
859 return size;
860}
861
862static inline int ocfs2_truncate_recs_per_inode(int blocksize)
863{
864 int size;
865
866 size = blocksize -
867 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
868
869 return size / sizeof(struct ocfs2_truncate_rec);
870}
Mark Fasheh50af94b2007-01-21 14:44:59 -0800871
872static inline uint64_t ocfs2_backup_super_blkno(int blocksize, int index)
873{
874 uint64_t offset = OCFS2_BACKUP_SB_START;
875
876 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
877 offset <<= (2 * index);
878 offset /= blocksize;
879 return offset;
880 }
881
882 return 0;
883}
Mark Fashehccd979b2005-12-15 14:31:24 -0800884#endif /* __KERNEL__ */
885
886
887static inline int ocfs2_system_inode_is_global(int type)
888{
889 return ((type >= 0) &&
890 (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE));
891}
892
893static inline int ocfs2_sprintf_system_inode_name(char *buf, int len,
894 int type, int slot)
895{
896 int chars;
897
898 /*
899 * Global system inodes can only have one copy. Everything
900 * after OCFS2_LAST_GLOBAL_SYSTEM_INODE in the system inode
901 * list has a copy per slot.
902 */
903 if (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE)
904 chars = snprintf(buf, len,
905 ocfs2_system_inodes[type].si_name);
906 else
907 chars = snprintf(buf, len,
908 ocfs2_system_inodes[type].si_name,
909 slot);
910
911 return chars;
912}
913
914static inline void ocfs2_set_de_type(struct ocfs2_dir_entry *de,
915 umode_t mode)
916{
917 de->file_type = ocfs2_type_by_mode[(mode & S_IFMT)>>S_SHIFT];
918}
919
920#endif /* _OCFS2_FS_H */
921