blob: 3299116b8021050722dde323b320d018565c3c7e [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 Ma7909f2b2007-12-18 15:47:25 +0800234/* Used to pass group descriptor data when online resize is done */
235struct ocfs2_new_group_input {
236 __u64 group; /* Group descriptor's blkno. */
237 __u32 clusters; /* Total number of clusters in this group */
238 __u32 frees; /* Total free clusters in this group */
239 __u16 chain; /* Chain for this group */
240 __u16 reserved1;
241 __u32 reserved2;
242};
243
Tao Mad6590722007-12-18 15:47:03 +0800244#define OCFS2_IOC_GROUP_EXTEND _IOW('o', 1, int)
Tao Ma7909f2b2007-12-18 15:47:25 +0800245#define OCFS2_IOC_GROUP_ADD _IOW('o', 2,struct ocfs2_new_group_input)
246#define OCFS2_IOC_GROUP_ADD64 _IOW('o', 3,struct ocfs2_new_group_input)
Tao Mad6590722007-12-18 15:47:03 +0800247
Mark Fashehb2580102007-03-09 16:53:21 -0800248/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800249 * Journal Flags (ocfs2_dinode.id1.journal1.i_flags)
250 */
251#define OCFS2_JOURNAL_DIRTY_FL (0x00000001) /* Journal needs recovery */
252
253/*
254 * superblock s_state flags
255 */
256#define OCFS2_ERROR_FS (0x00000001) /* FS saw errors */
257
258/* Limit of space in ocfs2_dir_entry */
259#define OCFS2_MAX_FILENAME_LEN 255
260
261/* Maximum slots on an ocfs2 file system */
262#define OCFS2_MAX_SLOTS 255
263
264/* Slot map indicator for an empty slot */
265#define OCFS2_INVALID_SLOT -1
266
267#define OCFS2_VOL_UUID_LEN 16
268#define OCFS2_MAX_VOL_LABEL_LEN 64
269
270/* Journal limits (in bytes) */
271#define OCFS2_MIN_JOURNAL_SIZE (4 * 1024 * 1024)
Mark Fashehccd979b2005-12-15 14:31:24 -0800272
Sunil Mushran2fbe8d12007-12-20 14:58:11 -0800273/*
274 * Default local alloc size (in megabytes)
275 *
276 * The value chosen should be such that most allocations, including new
277 * block groups, use local alloc.
278 */
279#define OCFS2_DEFAULT_LOCAL_ALLOC_SIZE 8
280
Mark Fashehccd979b2005-12-15 14:31:24 -0800281struct ocfs2_system_inode_info {
282 char *si_name;
283 int si_iflags;
284 int si_mode;
285};
286
287/* System file index */
288enum {
289 BAD_BLOCK_SYSTEM_INODE = 0,
290 GLOBAL_INODE_ALLOC_SYSTEM_INODE,
291 SLOT_MAP_SYSTEM_INODE,
292#define OCFS2_FIRST_ONLINE_SYSTEM_INODE SLOT_MAP_SYSTEM_INODE
293 HEARTBEAT_SYSTEM_INODE,
294 GLOBAL_BITMAP_SYSTEM_INODE,
295#define OCFS2_LAST_GLOBAL_SYSTEM_INODE GLOBAL_BITMAP_SYSTEM_INODE
296 ORPHAN_DIR_SYSTEM_INODE,
297 EXTENT_ALLOC_SYSTEM_INODE,
298 INODE_ALLOC_SYSTEM_INODE,
299 JOURNAL_SYSTEM_INODE,
300 LOCAL_ALLOC_SYSTEM_INODE,
301 TRUNCATE_LOG_SYSTEM_INODE,
302 NUM_SYSTEM_INODES
303};
304
305static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = {
306 /* Global system inodes (single copy) */
307 /* The first two are only used from userspace mfks/tunefs */
308 [BAD_BLOCK_SYSTEM_INODE] = { "bad_blocks", 0, S_IFREG | 0644 },
309 [GLOBAL_INODE_ALLOC_SYSTEM_INODE] = { "global_inode_alloc", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
310
311 /* These are used by the running filesystem */
312 [SLOT_MAP_SYSTEM_INODE] = { "slot_map", 0, S_IFREG | 0644 },
313 [HEARTBEAT_SYSTEM_INODE] = { "heartbeat", OCFS2_HEARTBEAT_FL, S_IFREG | 0644 },
314 [GLOBAL_BITMAP_SYSTEM_INODE] = { "global_bitmap", 0, S_IFREG | 0644 },
315
316 /* Slot-specific system inodes (one copy per slot) */
317 [ORPHAN_DIR_SYSTEM_INODE] = { "orphan_dir:%04d", 0, S_IFDIR | 0755 },
318 [EXTENT_ALLOC_SYSTEM_INODE] = { "extent_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
319 [INODE_ALLOC_SYSTEM_INODE] = { "inode_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
320 [JOURNAL_SYSTEM_INODE] = { "journal:%04d", OCFS2_JOURNAL_FL, S_IFREG | 0644 },
321 [LOCAL_ALLOC_SYSTEM_INODE] = { "local_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_LOCAL_ALLOC_FL, S_IFREG | 0644 },
322 [TRUNCATE_LOG_SYSTEM_INODE] = { "truncate_log:%04d", OCFS2_DEALLOC_FL, S_IFREG | 0644 }
323};
324
325/* Parameter passed from mount.ocfs2 to module */
326#define OCFS2_HB_NONE "heartbeat=none"
327#define OCFS2_HB_LOCAL "heartbeat=local"
328
329/*
330 * OCFS2 directory file types. Only the low 3 bits are used. The
331 * other bits are reserved for now.
332 */
333#define OCFS2_FT_UNKNOWN 0
334#define OCFS2_FT_REG_FILE 1
335#define OCFS2_FT_DIR 2
336#define OCFS2_FT_CHRDEV 3
337#define OCFS2_FT_BLKDEV 4
338#define OCFS2_FT_FIFO 5
339#define OCFS2_FT_SOCK 6
340#define OCFS2_FT_SYMLINK 7
341
342#define OCFS2_FT_MAX 8
343
344/*
345 * OCFS2_DIR_PAD defines the directory entries boundaries
346 *
347 * NOTE: It must be a multiple of 4
348 */
349#define OCFS2_DIR_PAD 4
350#define OCFS2_DIR_ROUND (OCFS2_DIR_PAD - 1)
351#define OCFS2_DIR_MEMBER_LEN offsetof(struct ocfs2_dir_entry, name)
352#define OCFS2_DIR_REC_LEN(name_len) (((name_len) + OCFS2_DIR_MEMBER_LEN + \
353 OCFS2_DIR_ROUND) & \
354 ~OCFS2_DIR_ROUND)
355
356#define OCFS2_LINK_MAX 32000
357
358#define S_SHIFT 12
359static unsigned char ocfs2_type_by_mode[S_IFMT >> S_SHIFT] = {
360 [S_IFREG >> S_SHIFT] = OCFS2_FT_REG_FILE,
361 [S_IFDIR >> S_SHIFT] = OCFS2_FT_DIR,
362 [S_IFCHR >> S_SHIFT] = OCFS2_FT_CHRDEV,
363 [S_IFBLK >> S_SHIFT] = OCFS2_FT_BLKDEV,
364 [S_IFIFO >> S_SHIFT] = OCFS2_FT_FIFO,
365 [S_IFSOCK >> S_SHIFT] = OCFS2_FT_SOCK,
366 [S_IFLNK >> S_SHIFT] = OCFS2_FT_SYMLINK,
367};
368
369
370/*
371 * Convenience casts
372 */
373#define OCFS2_RAW_SB(dinode) (&((dinode)->id2.i_super))
374
375/*
376 * On disk extent record for OCFS2
377 * It describes a range of clusters on disk.
Mark Fashehe48edee2007-03-07 16:46:57 -0800378 *
379 * Length fields are divided into interior and leaf node versions.
380 * This leaves room for a flags field (OCFS2_EXT_*) in the leaf nodes.
Mark Fashehccd979b2005-12-15 14:31:24 -0800381 */
382struct ocfs2_extent_rec {
383/*00*/ __le32 e_cpos; /* Offset into the file, in clusters */
Mark Fashehe48edee2007-03-07 16:46:57 -0800384 union {
385 __le32 e_int_clusters; /* Clusters covered by all children */
386 struct {
387 __le16 e_leaf_clusters; /* Clusters covered by this
388 extent */
389 __u8 e_reserved1;
390 __u8 e_flags; /* Extent flags */
391 };
392 };
Mark Fashehccd979b2005-12-15 14:31:24 -0800393 __le64 e_blkno; /* Physical disk offset, in blocks */
394/*10*/
395};
396
397struct ocfs2_chain_rec {
398 __le32 c_free; /* Number of free bits in this chain. */
399 __le32 c_total; /* Number of total bits in this chain */
400 __le64 c_blkno; /* Physical disk offset (blocks) of 1st group */
401};
402
403struct ocfs2_truncate_rec {
404 __le32 t_start; /* 1st cluster in this log */
405 __le32 t_clusters; /* Number of total clusters covered */
406};
407
408/*
409 * On disk extent list for OCFS2 (node in the tree). Note that this
410 * is contained inside ocfs2_dinode or ocfs2_extent_block, so the
411 * offsets are relative to ocfs2_dinode.id2.i_list or
412 * ocfs2_extent_block.h_list, respectively.
413 */
414struct ocfs2_extent_list {
415/*00*/ __le16 l_tree_depth; /* Extent tree depth from this
416 point. 0 means data extents
417 hang directly off this
Mark Fashehdcd05382007-01-16 11:32:23 -0800418 header (a leaf)
419 NOTE: The high 8 bits cannot be
420 used - tree_depth is never that big.
421 */
Mark Fashehccd979b2005-12-15 14:31:24 -0800422 __le16 l_count; /* Number of extent records */
423 __le16 l_next_free_rec; /* Next unused extent slot */
424 __le16 l_reserved1;
425 __le64 l_reserved2; /* Pad to
426 sizeof(ocfs2_extent_rec) */
427/*10*/ struct ocfs2_extent_rec l_recs[0]; /* Extent records */
428};
429
430/*
431 * On disk allocation chain list for OCFS2. Note that this is
432 * contained inside ocfs2_dinode, so the offsets are relative to
433 * ocfs2_dinode.id2.i_chain.
434 */
435struct ocfs2_chain_list {
436/*00*/ __le16 cl_cpg; /* Clusters per Block Group */
437 __le16 cl_bpc; /* Bits per cluster */
438 __le16 cl_count; /* Total chains in this list */
439 __le16 cl_next_free_rec; /* Next unused chain slot */
440 __le64 cl_reserved1;
441/*10*/ struct ocfs2_chain_rec cl_recs[0]; /* Chain records */
442};
443
444/*
445 * On disk deallocation log for OCFS2. Note that this is
446 * contained inside ocfs2_dinode, so the offsets are relative to
447 * ocfs2_dinode.id2.i_dealloc.
448 */
449struct ocfs2_truncate_log {
450/*00*/ __le16 tl_count; /* Total records in this log */
451 __le16 tl_used; /* Number of records in use */
452 __le32 tl_reserved1;
453/*08*/ struct ocfs2_truncate_rec tl_recs[0]; /* Truncate records */
454};
455
456/*
457 * On disk extent block (indirect block) for OCFS2
458 */
459struct ocfs2_extent_block
460{
461/*00*/ __u8 h_signature[8]; /* Signature for verification */
462 __le64 h_reserved1;
463/*10*/ __le16 h_suballoc_slot; /* Slot suballocator this
464 extent_header belongs to */
465 __le16 h_suballoc_bit; /* Bit offset in suballocator
466 block group */
467 __le32 h_fs_generation; /* Must match super block */
468 __le64 h_blkno; /* Offset on disk, in blocks */
469/*20*/ __le64 h_reserved3;
470 __le64 h_next_leaf_blk; /* Offset on disk, in blocks,
471 of next leaf header pointing
472 to data */
473/*30*/ struct ocfs2_extent_list h_list; /* Extent record list */
474/* Actual on-disk size is one block */
475};
476
477/*
Joel Beckerfb86b1f2008-02-01 11:59:05 -0800478 * On disk slot map for OCFS2. This defines the contents of the "slot_map"
479 * system file.
480 */
481struct ocfs2_slot_map {
482/*00*/ __le16 sm_slots[0];
483/*
484 * Actual on-disk size is one block. OCFS2_MAX_SLOTS is 255,
485 * 255 * sizeof(__le16) == 512B, within the 512B block minimum blocksize.
486 */
487};
488
489/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800490 * On disk superblock for OCFS2
491 * Note that it is contained inside an ocfs2_dinode, so all offsets
492 * are relative to the start of ocfs2_dinode.id2.
493 */
494struct ocfs2_super_block {
495/*00*/ __le16 s_major_rev_level;
496 __le16 s_minor_rev_level;
497 __le16 s_mnt_count;
498 __le16 s_max_mnt_count;
499 __le16 s_state; /* File system state */
500 __le16 s_errors; /* Behaviour when detecting errors */
501 __le32 s_checkinterval; /* Max time between checks */
502/*10*/ __le64 s_lastcheck; /* Time of last check */
503 __le32 s_creator_os; /* OS */
504 __le32 s_feature_compat; /* Compatible feature set */
505/*20*/ __le32 s_feature_incompat; /* Incompatible feature set */
506 __le32 s_feature_ro_compat; /* Readonly-compatible feature set */
507 __le64 s_root_blkno; /* Offset, in blocks, of root directory
508 dinode */
509/*30*/ __le64 s_system_dir_blkno; /* Offset, in blocks, of system
510 directory dinode */
511 __le32 s_blocksize_bits; /* Blocksize for this fs */
512 __le32 s_clustersize_bits; /* Clustersize for this fs */
513/*40*/ __le16 s_max_slots; /* Max number of simultaneous mounts
514 before tunefs required */
Mark Fasheh92e91ce2007-09-20 11:19:20 -0700515 __le16 s_tunefs_flag;
516 __le32 s_reserved1;
Mark Fashehccd979b2005-12-15 14:31:24 -0800517 __le64 s_first_cluster_group; /* Block offset of 1st cluster
518 * group header */
519/*50*/ __u8 s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */
520/*90*/ __u8 s_uuid[OCFS2_VOL_UUID_LEN]; /* 128-bit uuid */
521/*A0*/
522};
523
524/*
525 * Local allocation bitmap for OCFS2 slots
526 * Note that it exists inside an ocfs2_dinode, so all offsets are
527 * relative to the start of ocfs2_dinode.id2.
528 */
529struct ocfs2_local_alloc
530{
531/*00*/ __le32 la_bm_off; /* Starting bit offset in main bitmap */
532 __le16 la_size; /* Size of included bitmap, in bytes */
533 __le16 la_reserved1;
534 __le64 la_reserved2;
535/*10*/ __u8 la_bitmap[0];
536};
537
538/*
Mark Fasheh15b1e362007-09-07 13:58:15 -0700539 * Data-in-inode header. This is only used if i_dyn_features has
540 * OCFS2_INLINE_DATA_FL set.
541 */
542struct ocfs2_inline_data
543{
544/*00*/ __le16 id_count; /* Number of bytes that can be used
545 * for data, starting at id_data */
546 __le16 id_reserved0;
547 __le32 id_reserved1;
548 __u8 id_data[0]; /* Start of user data */
549};
550
551/*
Mark Fashehccd979b2005-12-15 14:31:24 -0800552 * On disk inode for OCFS2
553 */
554struct ocfs2_dinode {
555/*00*/ __u8 i_signature[8]; /* Signature for validation */
556 __le32 i_generation; /* Generation number */
557 __le16 i_suballoc_slot; /* Slot suballocator this inode
558 belongs to */
559 __le16 i_suballoc_bit; /* Bit offset in suballocator
560 block group */
561/*10*/ __le32 i_reserved0;
562 __le32 i_clusters; /* Cluster count */
563 __le32 i_uid; /* Owner UID */
564 __le32 i_gid; /* Owning GID */
565/*20*/ __le64 i_size; /* Size in bytes */
566 __le16 i_mode; /* File mode */
567 __le16 i_links_count; /* Links count */
568 __le32 i_flags; /* File flags */
569/*30*/ __le64 i_atime; /* Access time */
570 __le64 i_ctime; /* Creation time */
571/*40*/ __le64 i_mtime; /* Modification time */
572 __le64 i_dtime; /* Deletion time */
573/*50*/ __le64 i_blkno; /* Offset on disk, in blocks */
574 __le64 i_last_eb_blk; /* Pointer to last extent
575 block */
576/*60*/ __le32 i_fs_generation; /* Generation per fs-instance */
577 __le32 i_atime_nsec;
578 __le32 i_ctime_nsec;
579 __le32 i_mtime_nsec;
Herbert Poetzlca4d1472006-07-03 17:27:12 -0700580 __le32 i_attr;
Tiger Yang50008632007-03-20 16:01:38 -0700581 __le16 i_orphaned_slot; /* Only valid when OCFS2_ORPHANED_FL
582 was set in i_flags */
Mark Fasheh15b1e362007-09-07 13:58:15 -0700583 __le16 i_dyn_features;
Herbert Poetzlca4d1472006-07-03 17:27:12 -0700584/*70*/ __le64 i_reserved2[8];
Mark Fashehccd979b2005-12-15 14:31:24 -0800585/*B8*/ union {
586 __le64 i_pad1; /* Generic way to refer to this
587 64bit union */
588 struct {
589 __le64 i_rdev; /* Device number */
590 } dev1;
591 struct { /* Info for bitmap system
592 inodes */
593 __le32 i_used; /* Bits (ie, clusters) used */
594 __le32 i_total; /* Total bits (clusters)
595 available */
596 } bitmap1;
597 struct { /* Info for journal system
598 inodes */
599 __le32 ij_flags; /* Mounted, version, etc. */
600 __le32 ij_pad;
601 } journal1;
602 } id1; /* Inode type dependant 1 */
603/*C0*/ union {
604 struct ocfs2_super_block i_super;
605 struct ocfs2_local_alloc i_lab;
606 struct ocfs2_chain_list i_chain;
607 struct ocfs2_extent_list i_list;
608 struct ocfs2_truncate_log i_dealloc;
Mark Fasheh15b1e362007-09-07 13:58:15 -0700609 struct ocfs2_inline_data i_data;
Mark Fashehccd979b2005-12-15 14:31:24 -0800610 __u8 i_symlink[0];
611 } id2;
612/* Actual on-disk size is one block */
613};
614
615/*
616 * On-disk directory entry structure for OCFS2
617 *
618 * Packed as this structure could be accessed unaligned on 64-bit platforms
619 */
620struct ocfs2_dir_entry {
621/*00*/ __le64 inode; /* Inode number */
622 __le16 rec_len; /* Directory entry length */
623 __u8 name_len; /* Name length */
624 __u8 file_type;
625/*0C*/ char name[OCFS2_MAX_FILENAME_LEN]; /* File name */
626/* Actual on-disk length specified by rec_len */
627} __attribute__ ((packed));
628
629/*
630 * On disk allocator group structure for OCFS2
631 */
632struct ocfs2_group_desc
633{
634/*00*/ __u8 bg_signature[8]; /* Signature for validation */
635 __le16 bg_size; /* Size of included bitmap in
636 bytes. */
637 __le16 bg_bits; /* Bits represented by this
638 group. */
639 __le16 bg_free_bits_count; /* Free bits count */
640 __le16 bg_chain; /* What chain I am in. */
641/*10*/ __le32 bg_generation;
642 __le32 bg_reserved1;
643 __le64 bg_next_group; /* Next group in my list, in
644 blocks */
645/*20*/ __le64 bg_parent_dinode; /* dinode which owns me, in
646 blocks */
647 __le64 bg_blkno; /* Offset on disk, in blocks */
648/*30*/ __le64 bg_reserved2[2];
649/*40*/ __u8 bg_bitmap[0];
650};
651
652#ifdef __KERNEL__
653static inline int ocfs2_fast_symlink_chars(struct super_block *sb)
654{
655 return sb->s_blocksize -
656 offsetof(struct ocfs2_dinode, id2.i_symlink);
657}
658
Mark Fasheh15b1e362007-09-07 13:58:15 -0700659static inline int ocfs2_max_inline_data(struct super_block *sb)
660{
661 return sb->s_blocksize -
662 offsetof(struct ocfs2_dinode, id2.i_data.id_data);
663}
664
Mark Fashehccd979b2005-12-15 14:31:24 -0800665static inline int ocfs2_extent_recs_per_inode(struct super_block *sb)
666{
667 int size;
668
669 size = sb->s_blocksize -
670 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
671
672 return size / sizeof(struct ocfs2_extent_rec);
673}
674
675static inline int ocfs2_chain_recs_per_inode(struct super_block *sb)
676{
677 int size;
678
679 size = sb->s_blocksize -
680 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
681
682 return size / sizeof(struct ocfs2_chain_rec);
683}
684
685static inline u16 ocfs2_extent_recs_per_eb(struct super_block *sb)
686{
687 int size;
688
689 size = sb->s_blocksize -
690 offsetof(struct ocfs2_extent_block, h_list.l_recs);
691
692 return size / sizeof(struct ocfs2_extent_rec);
693}
694
695static inline u16 ocfs2_local_alloc_size(struct super_block *sb)
696{
697 u16 size;
698
699 size = sb->s_blocksize -
700 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
701
702 return size;
703}
704
705static inline int ocfs2_group_bitmap_size(struct super_block *sb)
706{
707 int size;
708
709 size = sb->s_blocksize -
710 offsetof(struct ocfs2_group_desc, bg_bitmap);
711
712 return size;
713}
714
715static inline int ocfs2_truncate_recs_per_inode(struct super_block *sb)
716{
717 int size;
718
719 size = sb->s_blocksize -
720 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
721
722 return size / sizeof(struct ocfs2_truncate_rec);
723}
Mark Fasheh50af94b2007-01-21 14:44:59 -0800724
725static inline u64 ocfs2_backup_super_blkno(struct super_block *sb, int index)
726{
727 u64 offset = OCFS2_BACKUP_SB_START;
728
729 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
730 offset <<= (2 * index);
Mark Fasheha8a75a22007-01-26 10:46:59 -0800731 offset >>= sb->s_blocksize_bits;
Mark Fasheh50af94b2007-01-21 14:44:59 -0800732 return offset;
733 }
734
735 return 0;
736
737}
Mark Fashehccd979b2005-12-15 14:31:24 -0800738#else
739static inline int ocfs2_fast_symlink_chars(int blocksize)
740{
741 return blocksize - offsetof(struct ocfs2_dinode, id2.i_symlink);
742}
743
Mark Fasheh15b1e362007-09-07 13:58:15 -0700744static inline int ocfs2_max_inline_data(int blocksize)
745{
746 return blocksize - offsetof(struct ocfs2_dinode, id2.i_data.id_data);
747}
748
Mark Fashehccd979b2005-12-15 14:31:24 -0800749static inline int ocfs2_extent_recs_per_inode(int blocksize)
750{
751 int size;
752
753 size = blocksize -
754 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
755
756 return size / sizeof(struct ocfs2_extent_rec);
757}
758
759static inline int ocfs2_chain_recs_per_inode(int blocksize)
760{
761 int size;
762
763 size = blocksize -
764 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
765
766 return size / sizeof(struct ocfs2_chain_rec);
767}
768
769static inline int ocfs2_extent_recs_per_eb(int blocksize)
770{
771 int size;
772
773 size = blocksize -
774 offsetof(struct ocfs2_extent_block, h_list.l_recs);
775
776 return size / sizeof(struct ocfs2_extent_rec);
777}
778
779static inline int ocfs2_local_alloc_size(int blocksize)
780{
781 int size;
782
783 size = blocksize -
784 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
785
786 return size;
787}
788
789static inline int ocfs2_group_bitmap_size(int blocksize)
790{
791 int size;
792
793 size = blocksize -
794 offsetof(struct ocfs2_group_desc, bg_bitmap);
795
796 return size;
797}
798
799static inline int ocfs2_truncate_recs_per_inode(int blocksize)
800{
801 int size;
802
803 size = blocksize -
804 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
805
806 return size / sizeof(struct ocfs2_truncate_rec);
807}
Mark Fasheh50af94b2007-01-21 14:44:59 -0800808
809static inline uint64_t ocfs2_backup_super_blkno(int blocksize, int index)
810{
811 uint64_t offset = OCFS2_BACKUP_SB_START;
812
813 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
814 offset <<= (2 * index);
815 offset /= blocksize;
816 return offset;
817 }
818
819 return 0;
820}
Mark Fashehccd979b2005-12-15 14:31:24 -0800821#endif /* __KERNEL__ */
822
823
824static inline int ocfs2_system_inode_is_global(int type)
825{
826 return ((type >= 0) &&
827 (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE));
828}
829
830static inline int ocfs2_sprintf_system_inode_name(char *buf, int len,
831 int type, int slot)
832{
833 int chars;
834
835 /*
836 * Global system inodes can only have one copy. Everything
837 * after OCFS2_LAST_GLOBAL_SYSTEM_INODE in the system inode
838 * list has a copy per slot.
839 */
840 if (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE)
841 chars = snprintf(buf, len,
842 ocfs2_system_inodes[type].si_name);
843 else
844 chars = snprintf(buf, len,
845 ocfs2_system_inodes[type].si_name,
846 slot);
847
848 return chars;
849}
850
851static inline void ocfs2_set_de_type(struct ocfs2_dir_entry *de,
852 umode_t mode)
853{
854 de->file_type = ocfs2_type_by_mode[(mode & S_IFMT)>>S_SHIFT];
855}
856
857#endif /* _OCFS2_FS_H */
858