blob: 19ac421b613b2b42801ded28dd5048c9981136c4 [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 \
91 | OCFS2_FEATURE_INCOMPAT_INLINE_DATA)
Mark Fasheh328d5752007-06-18 10:48:04 -070092#define OCFS2_FEATURE_RO_COMPAT_SUPP OCFS2_FEATURE_RO_COMPAT_UNWRITTEN
Mark Fashehccd979b2005-12-15 14:31:24 -080093
94/*
95 * Heartbeat-only devices are missing journals and other files. The
96 * filesystem driver can't load them, but the library can. Never put
97 * this in OCFS2_FEATURE_INCOMPAT_SUPP, *ever*.
98 */
99#define OCFS2_FEATURE_INCOMPAT_HEARTBEAT_DEV 0x0002
100
Mark Fasheh89039012006-12-07 18:05:37 -0800101/*
102 * tunefs sets this incompat flag before starting the resize and clears it
103 * at the end. This flag protects users from inadvertently mounting the fs
104 * after an aborted run without fsck-ing.
105 */
106#define OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG 0x0004
Mark Fashehccd979b2005-12-15 14:31:24 -0800107
Sunil Mushranc271c5c2006-12-05 17:56:35 -0800108/* Used to denote a non-clustered volume */
109#define OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT 0x0008
110
Mark Fasheh89039012006-12-07 18:05:37 -0800111/* Support for sparse allocation in b-trees */
112#define OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC 0x0010
113
Mark Fashehccd979b2005-12-15 14:31:24 -0800114/*
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700115 * Tunefs sets this incompat flag before starting an operation which
116 * would require cleanup on abort. This is done to protect users from
117 * inadvertently mounting the fs after an aborted run without
118 * fsck-ing.
119 *
120 * s_tunefs_flags on the super block describes precisely which
121 * operations were in progress.
122 */
123#define OCFS2_FEATURE_INCOMPAT_TUNEFS_INPROG 0x0020
124
Mark Fasheh15b1e362007-09-07 13:58:15 -0700125/* Support for data packed into inode blocks */
126#define OCFS2_FEATURE_INCOMPAT_INLINE_DATA 0x0040
127
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700128/*
Mark Fasheh50af94b2007-01-21 14:44:59 -0800129 * backup superblock flag is used to indicate that this volume
130 * has backup superblocks.
131 */
132#define OCFS2_FEATURE_COMPAT_BACKUP_SB 0x0001
133
Mark Fasheh328d5752007-06-18 10:48:04 -0700134/*
135 * Unwritten extents support.
136 */
137#define OCFS2_FEATURE_RO_COMPAT_UNWRITTEN 0x0001
138
Mark Fasheh50af94b2007-01-21 14:44:59 -0800139/* The byte offset of the first backup block will be 1G.
140 * The following will be 4G, 16G, 64G, 256G and 1T.
141 */
142#define OCFS2_BACKUP_SB_START 1 << 30
143
144/* the max backup superblock nums */
145#define OCFS2_MAX_BACKUP_SUPERBLOCKS 6
146
147/*
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700148 * Flags on ocfs2_super_block.s_tunefs_flags
149 */
150#define OCFS2_TUNEFS_INPROG_REMOVE_SLOT 0x0001 /* Removing slots */
151
152/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800153 * Flags on ocfs2_dinode.i_flags
154 */
155#define OCFS2_VALID_FL (0x00000001) /* Inode is valid */
156#define OCFS2_UNUSED2_FL (0x00000002)
157#define OCFS2_ORPHANED_FL (0x00000004) /* On the orphan list */
158#define OCFS2_UNUSED3_FL (0x00000008)
159/* System inode flags */
160#define OCFS2_SYSTEM_FL (0x00000010) /* System inode */
161#define OCFS2_SUPER_BLOCK_FL (0x00000020) /* Super block */
162#define OCFS2_LOCAL_ALLOC_FL (0x00000040) /* Slot local alloc bitmap */
163#define OCFS2_BITMAP_FL (0x00000080) /* Allocation bitmap */
164#define OCFS2_JOURNAL_FL (0x00000100) /* Slot local journal */
165#define OCFS2_HEARTBEAT_FL (0x00000200) /* Heartbeat area */
166#define OCFS2_CHAIN_FL (0x00000400) /* Chain allocator */
167#define OCFS2_DEALLOC_FL (0x00000800) /* Truncate log */
168
Mark Fasheh15b1e362007-09-07 13:58:15 -0700169/*
170 * Flags on ocfs2_dinode.i_dyn_features
171 *
172 * These can change much more often than i_flags. When adding flags,
173 * keep in mind that i_dyn_features is only 16 bits wide.
174 */
175#define OCFS2_INLINE_DATA_FL (0x0001) /* Data stored in inode block */
176#define OCFS2_HAS_XATTR_FL (0x0002)
177#define OCFS2_INLINE_XATTR_FL (0x0004)
178#define OCFS2_INDEXED_DIR_FL (0x0008)
179
Herbert Poetzlca4d1472006-07-03 17:27:12 -0700180/* Inode attributes, keep in sync with EXT2 */
181#define OCFS2_SECRM_FL (0x00000001) /* Secure deletion */
182#define OCFS2_UNRM_FL (0x00000002) /* Undelete */
183#define OCFS2_COMPR_FL (0x00000004) /* Compress file */
184#define OCFS2_SYNC_FL (0x00000008) /* Synchronous updates */
185#define OCFS2_IMMUTABLE_FL (0x00000010) /* Immutable file */
186#define OCFS2_APPEND_FL (0x00000020) /* writes to file may only append */
187#define OCFS2_NODUMP_FL (0x00000040) /* do not dump file */
188#define OCFS2_NOATIME_FL (0x00000080) /* do not update atime */
189#define OCFS2_DIRSYNC_FL (0x00010000) /* dirsync behaviour (directories only) */
190
191#define OCFS2_FL_VISIBLE (0x000100FF) /* User visible flags */
192#define OCFS2_FL_MODIFIABLE (0x000100FF) /* User modifiable flags */
193
194/*
Mark Fashehe48edee2007-03-07 16:46:57 -0800195 * Extent record flags (e_node.leaf.flags)
196 */
197#define OCFS2_EXT_UNWRITTEN (0x01) /* Extent is allocated but
198 * unwritten */
199
200/*
Herbert Poetzlca4d1472006-07-03 17:27:12 -0700201 * ioctl commands
202 */
203#define OCFS2_IOC_GETFLAGS _IOR('f', 1, long)
204#define OCFS2_IOC_SETFLAGS _IOW('f', 2, long)
Mark Fasheh586d2322007-03-09 15:56:28 -0800205#define OCFS2_IOC32_GETFLAGS _IOR('f', 1, int)
206#define OCFS2_IOC32_SETFLAGS _IOW('f', 2, int)
Herbert Poetzlca4d1472006-07-03 17:27:12 -0700207
Mark Fashehccd979b2005-12-15 14:31:24 -0800208/*
Mark Fashehb2580102007-03-09 16:53:21 -0800209 * Space reservation / allocation / free ioctls and argument structure
210 * are designed to be compatible with XFS.
211 *
212 * ALLOCSP* and FREESP* are not and will never be supported, but are
213 * included here for completeness.
214 */
215struct ocfs2_space_resv {
216 __s16 l_type;
217 __s16 l_whence;
218 __s64 l_start;
219 __s64 l_len; /* len == 0 means until end of file */
220 __s32 l_sysid;
221 __u32 l_pid;
222 __s32 l_pad[4]; /* reserve area */
223};
224
225#define OCFS2_IOC_ALLOCSP _IOW ('X', 10, struct ocfs2_space_resv)
226#define OCFS2_IOC_FREESP _IOW ('X', 11, struct ocfs2_space_resv)
227#define OCFS2_IOC_RESVSP _IOW ('X', 40, struct ocfs2_space_resv)
228#define OCFS2_IOC_UNRESVSP _IOW ('X', 41, struct ocfs2_space_resv)
229#define OCFS2_IOC_ALLOCSP64 _IOW ('X', 36, struct ocfs2_space_resv)
230#define OCFS2_IOC_FREESP64 _IOW ('X', 37, struct ocfs2_space_resv)
231#define OCFS2_IOC_RESVSP64 _IOW ('X', 42, struct ocfs2_space_resv)
232#define OCFS2_IOC_UNRESVSP64 _IOW ('X', 43, struct ocfs2_space_resv)
233
Tao Mad6590722007-12-18 15:47:03 +0800234#define OCFS2_IOC_GROUP_EXTEND _IOW('o', 1, int)
235
Mark Fashehb2580102007-03-09 16:53:21 -0800236/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800237 * Journal Flags (ocfs2_dinode.id1.journal1.i_flags)
238 */
239#define OCFS2_JOURNAL_DIRTY_FL (0x00000001) /* Journal needs recovery */
240
241/*
242 * superblock s_state flags
243 */
244#define OCFS2_ERROR_FS (0x00000001) /* FS saw errors */
245
246/* Limit of space in ocfs2_dir_entry */
247#define OCFS2_MAX_FILENAME_LEN 255
248
249/* Maximum slots on an ocfs2 file system */
250#define OCFS2_MAX_SLOTS 255
251
252/* Slot map indicator for an empty slot */
253#define OCFS2_INVALID_SLOT -1
254
255#define OCFS2_VOL_UUID_LEN 16
256#define OCFS2_MAX_VOL_LABEL_LEN 64
257
258/* Journal limits (in bytes) */
259#define OCFS2_MIN_JOURNAL_SIZE (4 * 1024 * 1024)
Mark Fashehccd979b2005-12-15 14:31:24 -0800260
261struct ocfs2_system_inode_info {
262 char *si_name;
263 int si_iflags;
264 int si_mode;
265};
266
267/* System file index */
268enum {
269 BAD_BLOCK_SYSTEM_INODE = 0,
270 GLOBAL_INODE_ALLOC_SYSTEM_INODE,
271 SLOT_MAP_SYSTEM_INODE,
272#define OCFS2_FIRST_ONLINE_SYSTEM_INODE SLOT_MAP_SYSTEM_INODE
273 HEARTBEAT_SYSTEM_INODE,
274 GLOBAL_BITMAP_SYSTEM_INODE,
275#define OCFS2_LAST_GLOBAL_SYSTEM_INODE GLOBAL_BITMAP_SYSTEM_INODE
276 ORPHAN_DIR_SYSTEM_INODE,
277 EXTENT_ALLOC_SYSTEM_INODE,
278 INODE_ALLOC_SYSTEM_INODE,
279 JOURNAL_SYSTEM_INODE,
280 LOCAL_ALLOC_SYSTEM_INODE,
281 TRUNCATE_LOG_SYSTEM_INODE,
282 NUM_SYSTEM_INODES
283};
284
285static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = {
286 /* Global system inodes (single copy) */
287 /* The first two are only used from userspace mfks/tunefs */
288 [BAD_BLOCK_SYSTEM_INODE] = { "bad_blocks", 0, S_IFREG | 0644 },
289 [GLOBAL_INODE_ALLOC_SYSTEM_INODE] = { "global_inode_alloc", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
290
291 /* These are used by the running filesystem */
292 [SLOT_MAP_SYSTEM_INODE] = { "slot_map", 0, S_IFREG | 0644 },
293 [HEARTBEAT_SYSTEM_INODE] = { "heartbeat", OCFS2_HEARTBEAT_FL, S_IFREG | 0644 },
294 [GLOBAL_BITMAP_SYSTEM_INODE] = { "global_bitmap", 0, S_IFREG | 0644 },
295
296 /* Slot-specific system inodes (one copy per slot) */
297 [ORPHAN_DIR_SYSTEM_INODE] = { "orphan_dir:%04d", 0, S_IFDIR | 0755 },
298 [EXTENT_ALLOC_SYSTEM_INODE] = { "extent_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
299 [INODE_ALLOC_SYSTEM_INODE] = { "inode_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
300 [JOURNAL_SYSTEM_INODE] = { "journal:%04d", OCFS2_JOURNAL_FL, S_IFREG | 0644 },
301 [LOCAL_ALLOC_SYSTEM_INODE] = { "local_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_LOCAL_ALLOC_FL, S_IFREG | 0644 },
302 [TRUNCATE_LOG_SYSTEM_INODE] = { "truncate_log:%04d", OCFS2_DEALLOC_FL, S_IFREG | 0644 }
303};
304
305/* Parameter passed from mount.ocfs2 to module */
306#define OCFS2_HB_NONE "heartbeat=none"
307#define OCFS2_HB_LOCAL "heartbeat=local"
308
309/*
310 * OCFS2 directory file types. Only the low 3 bits are used. The
311 * other bits are reserved for now.
312 */
313#define OCFS2_FT_UNKNOWN 0
314#define OCFS2_FT_REG_FILE 1
315#define OCFS2_FT_DIR 2
316#define OCFS2_FT_CHRDEV 3
317#define OCFS2_FT_BLKDEV 4
318#define OCFS2_FT_FIFO 5
319#define OCFS2_FT_SOCK 6
320#define OCFS2_FT_SYMLINK 7
321
322#define OCFS2_FT_MAX 8
323
324/*
325 * OCFS2_DIR_PAD defines the directory entries boundaries
326 *
327 * NOTE: It must be a multiple of 4
328 */
329#define OCFS2_DIR_PAD 4
330#define OCFS2_DIR_ROUND (OCFS2_DIR_PAD - 1)
331#define OCFS2_DIR_MEMBER_LEN offsetof(struct ocfs2_dir_entry, name)
332#define OCFS2_DIR_REC_LEN(name_len) (((name_len) + OCFS2_DIR_MEMBER_LEN + \
333 OCFS2_DIR_ROUND) & \
334 ~OCFS2_DIR_ROUND)
335
336#define OCFS2_LINK_MAX 32000
337
338#define S_SHIFT 12
339static unsigned char ocfs2_type_by_mode[S_IFMT >> S_SHIFT] = {
340 [S_IFREG >> S_SHIFT] = OCFS2_FT_REG_FILE,
341 [S_IFDIR >> S_SHIFT] = OCFS2_FT_DIR,
342 [S_IFCHR >> S_SHIFT] = OCFS2_FT_CHRDEV,
343 [S_IFBLK >> S_SHIFT] = OCFS2_FT_BLKDEV,
344 [S_IFIFO >> S_SHIFT] = OCFS2_FT_FIFO,
345 [S_IFSOCK >> S_SHIFT] = OCFS2_FT_SOCK,
346 [S_IFLNK >> S_SHIFT] = OCFS2_FT_SYMLINK,
347};
348
349
350/*
351 * Convenience casts
352 */
353#define OCFS2_RAW_SB(dinode) (&((dinode)->id2.i_super))
354
355/*
356 * On disk extent record for OCFS2
357 * It describes a range of clusters on disk.
Mark Fashehe48edee2007-03-07 16:46:57 -0800358 *
359 * Length fields are divided into interior and leaf node versions.
360 * This leaves room for a flags field (OCFS2_EXT_*) in the leaf nodes.
Mark Fashehccd979b2005-12-15 14:31:24 -0800361 */
362struct ocfs2_extent_rec {
363/*00*/ __le32 e_cpos; /* Offset into the file, in clusters */
Mark Fashehe48edee2007-03-07 16:46:57 -0800364 union {
365 __le32 e_int_clusters; /* Clusters covered by all children */
366 struct {
367 __le16 e_leaf_clusters; /* Clusters covered by this
368 extent */
369 __u8 e_reserved1;
370 __u8 e_flags; /* Extent flags */
371 };
372 };
Mark Fashehccd979b2005-12-15 14:31:24 -0800373 __le64 e_blkno; /* Physical disk offset, in blocks */
374/*10*/
375};
376
377struct ocfs2_chain_rec {
378 __le32 c_free; /* Number of free bits in this chain. */
379 __le32 c_total; /* Number of total bits in this chain */
380 __le64 c_blkno; /* Physical disk offset (blocks) of 1st group */
381};
382
383struct ocfs2_truncate_rec {
384 __le32 t_start; /* 1st cluster in this log */
385 __le32 t_clusters; /* Number of total clusters covered */
386};
387
388/*
389 * On disk extent list for OCFS2 (node in the tree). Note that this
390 * is contained inside ocfs2_dinode or ocfs2_extent_block, so the
391 * offsets are relative to ocfs2_dinode.id2.i_list or
392 * ocfs2_extent_block.h_list, respectively.
393 */
394struct ocfs2_extent_list {
395/*00*/ __le16 l_tree_depth; /* Extent tree depth from this
396 point. 0 means data extents
397 hang directly off this
Mark Fashehdcd05382007-01-16 11:32:23 -0800398 header (a leaf)
399 NOTE: The high 8 bits cannot be
400 used - tree_depth is never that big.
401 */
Mark Fashehccd979b2005-12-15 14:31:24 -0800402 __le16 l_count; /* Number of extent records */
403 __le16 l_next_free_rec; /* Next unused extent slot */
404 __le16 l_reserved1;
405 __le64 l_reserved2; /* Pad to
406 sizeof(ocfs2_extent_rec) */
407/*10*/ struct ocfs2_extent_rec l_recs[0]; /* Extent records */
408};
409
410/*
411 * On disk allocation chain list for OCFS2. Note that this is
412 * contained inside ocfs2_dinode, so the offsets are relative to
413 * ocfs2_dinode.id2.i_chain.
414 */
415struct ocfs2_chain_list {
416/*00*/ __le16 cl_cpg; /* Clusters per Block Group */
417 __le16 cl_bpc; /* Bits per cluster */
418 __le16 cl_count; /* Total chains in this list */
419 __le16 cl_next_free_rec; /* Next unused chain slot */
420 __le64 cl_reserved1;
421/*10*/ struct ocfs2_chain_rec cl_recs[0]; /* Chain records */
422};
423
424/*
425 * On disk deallocation log for OCFS2. Note that this is
426 * contained inside ocfs2_dinode, so the offsets are relative to
427 * ocfs2_dinode.id2.i_dealloc.
428 */
429struct ocfs2_truncate_log {
430/*00*/ __le16 tl_count; /* Total records in this log */
431 __le16 tl_used; /* Number of records in use */
432 __le32 tl_reserved1;
433/*08*/ struct ocfs2_truncate_rec tl_recs[0]; /* Truncate records */
434};
435
436/*
437 * On disk extent block (indirect block) for OCFS2
438 */
439struct ocfs2_extent_block
440{
441/*00*/ __u8 h_signature[8]; /* Signature for verification */
442 __le64 h_reserved1;
443/*10*/ __le16 h_suballoc_slot; /* Slot suballocator this
444 extent_header belongs to */
445 __le16 h_suballoc_bit; /* Bit offset in suballocator
446 block group */
447 __le32 h_fs_generation; /* Must match super block */
448 __le64 h_blkno; /* Offset on disk, in blocks */
449/*20*/ __le64 h_reserved3;
450 __le64 h_next_leaf_blk; /* Offset on disk, in blocks,
451 of next leaf header pointing
452 to data */
453/*30*/ struct ocfs2_extent_list h_list; /* Extent record list */
454/* Actual on-disk size is one block */
455};
456
457/*
458 * On disk superblock for OCFS2
459 * Note that it is contained inside an ocfs2_dinode, so all offsets
460 * are relative to the start of ocfs2_dinode.id2.
461 */
462struct ocfs2_super_block {
463/*00*/ __le16 s_major_rev_level;
464 __le16 s_minor_rev_level;
465 __le16 s_mnt_count;
466 __le16 s_max_mnt_count;
467 __le16 s_state; /* File system state */
468 __le16 s_errors; /* Behaviour when detecting errors */
469 __le32 s_checkinterval; /* Max time between checks */
470/*10*/ __le64 s_lastcheck; /* Time of last check */
471 __le32 s_creator_os; /* OS */
472 __le32 s_feature_compat; /* Compatible feature set */
473/*20*/ __le32 s_feature_incompat; /* Incompatible feature set */
474 __le32 s_feature_ro_compat; /* Readonly-compatible feature set */
475 __le64 s_root_blkno; /* Offset, in blocks, of root directory
476 dinode */
477/*30*/ __le64 s_system_dir_blkno; /* Offset, in blocks, of system
478 directory dinode */
479 __le32 s_blocksize_bits; /* Blocksize for this fs */
480 __le32 s_clustersize_bits; /* Clustersize for this fs */
481/*40*/ __le16 s_max_slots; /* Max number of simultaneous mounts
482 before tunefs required */
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700483 __le16 s_tunefs_flag;
484 __le32 s_reserved1;
Mark Fashehccd979b2005-12-15 14:31:24 -0800485 __le64 s_first_cluster_group; /* Block offset of 1st cluster
486 * group header */
487/*50*/ __u8 s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */
488/*90*/ __u8 s_uuid[OCFS2_VOL_UUID_LEN]; /* 128-bit uuid */
489/*A0*/
490};
491
492/*
493 * Local allocation bitmap for OCFS2 slots
494 * Note that it exists inside an ocfs2_dinode, so all offsets are
495 * relative to the start of ocfs2_dinode.id2.
496 */
497struct ocfs2_local_alloc
498{
499/*00*/ __le32 la_bm_off; /* Starting bit offset in main bitmap */
500 __le16 la_size; /* Size of included bitmap, in bytes */
501 __le16 la_reserved1;
502 __le64 la_reserved2;
503/*10*/ __u8 la_bitmap[0];
504};
505
506/*
Mark Fasheh15b1e362007-09-07 13:58:15 -0700507 * Data-in-inode header. This is only used if i_dyn_features has
508 * OCFS2_INLINE_DATA_FL set.
509 */
510struct ocfs2_inline_data
511{
512/*00*/ __le16 id_count; /* Number of bytes that can be used
513 * for data, starting at id_data */
514 __le16 id_reserved0;
515 __le32 id_reserved1;
516 __u8 id_data[0]; /* Start of user data */
517};
518
519/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800520 * On disk inode for OCFS2
521 */
522struct ocfs2_dinode {
523/*00*/ __u8 i_signature[8]; /* Signature for validation */
524 __le32 i_generation; /* Generation number */
525 __le16 i_suballoc_slot; /* Slot suballocator this inode
526 belongs to */
527 __le16 i_suballoc_bit; /* Bit offset in suballocator
528 block group */
529/*10*/ __le32 i_reserved0;
530 __le32 i_clusters; /* Cluster count */
531 __le32 i_uid; /* Owner UID */
532 __le32 i_gid; /* Owning GID */
533/*20*/ __le64 i_size; /* Size in bytes */
534 __le16 i_mode; /* File mode */
535 __le16 i_links_count; /* Links count */
536 __le32 i_flags; /* File flags */
537/*30*/ __le64 i_atime; /* Access time */
538 __le64 i_ctime; /* Creation time */
539/*40*/ __le64 i_mtime; /* Modification time */
540 __le64 i_dtime; /* Deletion time */
541/*50*/ __le64 i_blkno; /* Offset on disk, in blocks */
542 __le64 i_last_eb_blk; /* Pointer to last extent
543 block */
544/*60*/ __le32 i_fs_generation; /* Generation per fs-instance */
545 __le32 i_atime_nsec;
546 __le32 i_ctime_nsec;
547 __le32 i_mtime_nsec;
Herbert Poetzlca4d1472006-07-03 17:27:12 -0700548 __le32 i_attr;
Tiger Yang50008632007-03-20 16:01:38 -0700549 __le16 i_orphaned_slot; /* Only valid when OCFS2_ORPHANED_FL
550 was set in i_flags */
Mark Fasheh15b1e362007-09-07 13:58:15 -0700551 __le16 i_dyn_features;
Herbert Poetzlca4d1472006-07-03 17:27:12 -0700552/*70*/ __le64 i_reserved2[8];
Mark Fashehccd979b2005-12-15 14:31:24 -0800553/*B8*/ union {
554 __le64 i_pad1; /* Generic way to refer to this
555 64bit union */
556 struct {
557 __le64 i_rdev; /* Device number */
558 } dev1;
559 struct { /* Info for bitmap system
560 inodes */
561 __le32 i_used; /* Bits (ie, clusters) used */
562 __le32 i_total; /* Total bits (clusters)
563 available */
564 } bitmap1;
565 struct { /* Info for journal system
566 inodes */
567 __le32 ij_flags; /* Mounted, version, etc. */
568 __le32 ij_pad;
569 } journal1;
570 } id1; /* Inode type dependant 1 */
571/*C0*/ union {
572 struct ocfs2_super_block i_super;
573 struct ocfs2_local_alloc i_lab;
574 struct ocfs2_chain_list i_chain;
575 struct ocfs2_extent_list i_list;
576 struct ocfs2_truncate_log i_dealloc;
Mark Fasheh15b1e362007-09-07 13:58:15 -0700577 struct ocfs2_inline_data i_data;
Mark Fashehccd979b2005-12-15 14:31:24 -0800578 __u8 i_symlink[0];
579 } id2;
580/* Actual on-disk size is one block */
581};
582
583/*
584 * On-disk directory entry structure for OCFS2
585 *
586 * Packed as this structure could be accessed unaligned on 64-bit platforms
587 */
588struct ocfs2_dir_entry {
589/*00*/ __le64 inode; /* Inode number */
590 __le16 rec_len; /* Directory entry length */
591 __u8 name_len; /* Name length */
592 __u8 file_type;
593/*0C*/ char name[OCFS2_MAX_FILENAME_LEN]; /* File name */
594/* Actual on-disk length specified by rec_len */
595} __attribute__ ((packed));
596
597/*
598 * On disk allocator group structure for OCFS2
599 */
600struct ocfs2_group_desc
601{
602/*00*/ __u8 bg_signature[8]; /* Signature for validation */
603 __le16 bg_size; /* Size of included bitmap in
604 bytes. */
605 __le16 bg_bits; /* Bits represented by this
606 group. */
607 __le16 bg_free_bits_count; /* Free bits count */
608 __le16 bg_chain; /* What chain I am in. */
609/*10*/ __le32 bg_generation;
610 __le32 bg_reserved1;
611 __le64 bg_next_group; /* Next group in my list, in
612 blocks */
613/*20*/ __le64 bg_parent_dinode; /* dinode which owns me, in
614 blocks */
615 __le64 bg_blkno; /* Offset on disk, in blocks */
616/*30*/ __le64 bg_reserved2[2];
617/*40*/ __u8 bg_bitmap[0];
618};
619
620#ifdef __KERNEL__
621static inline int ocfs2_fast_symlink_chars(struct super_block *sb)
622{
623 return sb->s_blocksize -
624 offsetof(struct ocfs2_dinode, id2.i_symlink);
625}
626
Mark Fasheh15b1e362007-09-07 13:58:15 -0700627static inline int ocfs2_max_inline_data(struct super_block *sb)
628{
629 return sb->s_blocksize -
630 offsetof(struct ocfs2_dinode, id2.i_data.id_data);
631}
632
Mark Fashehccd979b2005-12-15 14:31:24 -0800633static inline int ocfs2_extent_recs_per_inode(struct super_block *sb)
634{
635 int size;
636
637 size = sb->s_blocksize -
638 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
639
640 return size / sizeof(struct ocfs2_extent_rec);
641}
642
643static inline int ocfs2_chain_recs_per_inode(struct super_block *sb)
644{
645 int size;
646
647 size = sb->s_blocksize -
648 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
649
650 return size / sizeof(struct ocfs2_chain_rec);
651}
652
653static inline u16 ocfs2_extent_recs_per_eb(struct super_block *sb)
654{
655 int size;
656
657 size = sb->s_blocksize -
658 offsetof(struct ocfs2_extent_block, h_list.l_recs);
659
660 return size / sizeof(struct ocfs2_extent_rec);
661}
662
663static inline u16 ocfs2_local_alloc_size(struct super_block *sb)
664{
665 u16 size;
666
667 size = sb->s_blocksize -
668 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
669
670 return size;
671}
672
673static inline int ocfs2_group_bitmap_size(struct super_block *sb)
674{
675 int size;
676
677 size = sb->s_blocksize -
678 offsetof(struct ocfs2_group_desc, bg_bitmap);
679
680 return size;
681}
682
683static inline int ocfs2_truncate_recs_per_inode(struct super_block *sb)
684{
685 int size;
686
687 size = sb->s_blocksize -
688 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
689
690 return size / sizeof(struct ocfs2_truncate_rec);
691}
Mark Fasheh50af94b2007-01-21 14:44:59 -0800692
693static inline u64 ocfs2_backup_super_blkno(struct super_block *sb, int index)
694{
695 u64 offset = OCFS2_BACKUP_SB_START;
696
697 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
698 offset <<= (2 * index);
Mark Fasheha8a75a22007-01-26 10:46:59 -0800699 offset >>= sb->s_blocksize_bits;
Mark Fasheh50af94b2007-01-21 14:44:59 -0800700 return offset;
701 }
702
703 return 0;
704
705}
Mark Fashehccd979b2005-12-15 14:31:24 -0800706#else
707static inline int ocfs2_fast_symlink_chars(int blocksize)
708{
709 return blocksize - offsetof(struct ocfs2_dinode, id2.i_symlink);
710}
711
Mark Fasheh15b1e362007-09-07 13:58:15 -0700712static inline int ocfs2_max_inline_data(int blocksize)
713{
714 return blocksize - offsetof(struct ocfs2_dinode, id2.i_data.id_data);
715}
716
Mark Fashehccd979b2005-12-15 14:31:24 -0800717static inline int ocfs2_extent_recs_per_inode(int blocksize)
718{
719 int size;
720
721 size = blocksize -
722 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
723
724 return size / sizeof(struct ocfs2_extent_rec);
725}
726
727static inline int ocfs2_chain_recs_per_inode(int blocksize)
728{
729 int size;
730
731 size = blocksize -
732 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
733
734 return size / sizeof(struct ocfs2_chain_rec);
735}
736
737static inline int ocfs2_extent_recs_per_eb(int blocksize)
738{
739 int size;
740
741 size = blocksize -
742 offsetof(struct ocfs2_extent_block, h_list.l_recs);
743
744 return size / sizeof(struct ocfs2_extent_rec);
745}
746
747static inline int ocfs2_local_alloc_size(int blocksize)
748{
749 int size;
750
751 size = blocksize -
752 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
753
754 return size;
755}
756
757static inline int ocfs2_group_bitmap_size(int blocksize)
758{
759 int size;
760
761 size = blocksize -
762 offsetof(struct ocfs2_group_desc, bg_bitmap);
763
764 return size;
765}
766
767static inline int ocfs2_truncate_recs_per_inode(int blocksize)
768{
769 int size;
770
771 size = blocksize -
772 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
773
774 return size / sizeof(struct ocfs2_truncate_rec);
775}
Mark Fasheh50af94b2007-01-21 14:44:59 -0800776
777static inline uint64_t ocfs2_backup_super_blkno(int blocksize, int index)
778{
779 uint64_t offset = OCFS2_BACKUP_SB_START;
780
781 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
782 offset <<= (2 * index);
783 offset /= blocksize;
784 return offset;
785 }
786
787 return 0;
788}
Mark Fashehccd979b2005-12-15 14:31:24 -0800789#endif /* __KERNEL__ */
790
791
792static inline int ocfs2_system_inode_is_global(int type)
793{
794 return ((type >= 0) &&
795 (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE));
796}
797
798static inline int ocfs2_sprintf_system_inode_name(char *buf, int len,
799 int type, int slot)
800{
801 int chars;
802
803 /*
804 * Global system inodes can only have one copy. Everything
805 * after OCFS2_LAST_GLOBAL_SYSTEM_INODE in the system inode
806 * list has a copy per slot.
807 */
808 if (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE)
809 chars = snprintf(buf, len,
810 ocfs2_system_inodes[type].si_name);
811 else
812 chars = snprintf(buf, len,
813 ocfs2_system_inodes[type].si_name,
814 slot);
815
816 return chars;
817}
818
819static inline void ocfs2_set_de_type(struct ocfs2_dir_entry *de,
820 umode_t mode)
821{
822 de->file_type = ocfs2_type_by_mode[(mode & S_IFMT)>>S_SHIFT];
823}
824
825#endif /* _OCFS2_FS_H */
826