1 /* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
6 * On-disk structures for OCFS2.
8 * Copyright (C) 2002, 2004 Oracle. All rights reserved.
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.
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.
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.
29 #define OCFS2_MAJOR_REV_LEVEL 0
30 #define OCFS2_MINOR_REV_LEVEL 90
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.
38 * All other structures are found from the superblock information.
40 * OCFS2_SUPER_BLOCK_BLKNO is in blocks, not sectors. eg, for a
41 * blocksize of 2K, it is 4096 bytes into disk.
43 #define OCFS2_SUPER_BLOCK_BLKNO 2
46 * Cluster size limits. The maximum is kept arbitrarily at 1 MB, and could
49 #define OCFS2_MIN_CLUSTERSIZE 4096
50 #define OCFS2_MAX_CLUSTERSIZE 1048576
53 * Blocks cannot be bigger than clusters, so the maximum blocksize is the
54 * minimum cluster size.
56 #define OCFS2_MIN_BLOCKSIZE 512
57 #define OCFS2_MAX_BLOCKSIZE OCFS2_MIN_CLUSTERSIZE
59 /* Filesystem magic number */
60 #define OCFS2_SUPER_MAGIC 0x7461636f
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 #define OCFS2_XATTR_BLOCK_SIGNATURE "XATTR01"
69 /* Compatibility flags */
70 #define OCFS2_HAS_COMPAT_FEATURE(sb,mask) \
71 ( OCFS2_SB(sb)->s_feature_compat & (mask) )
72 #define OCFS2_HAS_RO_COMPAT_FEATURE(sb,mask) \
73 ( OCFS2_SB(sb)->s_feature_ro_compat & (mask) )
74 #define OCFS2_HAS_INCOMPAT_FEATURE(sb,mask) \
75 ( OCFS2_SB(sb)->s_feature_incompat & (mask) )
76 #define OCFS2_SET_COMPAT_FEATURE(sb,mask) \
77 OCFS2_SB(sb)->s_feature_compat |= (mask)
78 #define OCFS2_SET_RO_COMPAT_FEATURE(sb,mask) \
79 OCFS2_SB(sb)->s_feature_ro_compat |= (mask)
80 #define OCFS2_SET_INCOMPAT_FEATURE(sb,mask) \
81 OCFS2_SB(sb)->s_feature_incompat |= (mask)
82 #define OCFS2_CLEAR_COMPAT_FEATURE(sb,mask) \
83 OCFS2_SB(sb)->s_feature_compat &= ~(mask)
84 #define OCFS2_CLEAR_RO_COMPAT_FEATURE(sb,mask) \
85 OCFS2_SB(sb)->s_feature_ro_compat &= ~(mask)
86 #define OCFS2_CLEAR_INCOMPAT_FEATURE(sb,mask) \
87 OCFS2_SB(sb)->s_feature_incompat &= ~(mask)
89 #define OCFS2_FEATURE_COMPAT_SUPP (OCFS2_FEATURE_COMPAT_BACKUP_SB \
90 | OCFS2_FEATURE_COMPAT_JBD2_SB)
91 #define OCFS2_FEATURE_INCOMPAT_SUPP (OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT \
92 | OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC \
93 | OCFS2_FEATURE_INCOMPAT_INLINE_DATA \
94 | OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP \
95 | OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK \
96 | OCFS2_FEATURE_INCOMPAT_XATTR)
97 #define OCFS2_FEATURE_RO_COMPAT_SUPP (OCFS2_FEATURE_RO_COMPAT_UNWRITTEN)
100 * Heartbeat-only devices are missing journals and other files. The
101 * filesystem driver can't load them, but the library can. Never put
102 * this in OCFS2_FEATURE_INCOMPAT_SUPP, *ever*.
104 #define OCFS2_FEATURE_INCOMPAT_HEARTBEAT_DEV 0x0002
107 * tunefs sets this incompat flag before starting the resize and clears it
108 * at the end. This flag protects users from inadvertently mounting the fs
109 * after an aborted run without fsck-ing.
111 #define OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG 0x0004
113 /* Used to denote a non-clustered volume */
114 #define OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT 0x0008
116 /* Support for sparse allocation in b-trees */
117 #define OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC 0x0010
120 * Tunefs sets this incompat flag before starting an operation which
121 * would require cleanup on abort. This is done to protect users from
122 * inadvertently mounting the fs after an aborted run without
125 * s_tunefs_flags on the super block describes precisely which
126 * operations were in progress.
128 #define OCFS2_FEATURE_INCOMPAT_TUNEFS_INPROG 0x0020
130 /* Support for data packed into inode blocks */
131 #define OCFS2_FEATURE_INCOMPAT_INLINE_DATA 0x0040
134 * Support for alternate, userspace cluster stacks. If set, the superblock
135 * field s_cluster_info contains a tag for the alternate stack in use as
136 * well as the name of the cluster being joined.
137 * mount.ocfs2 must pass in a matching stack name.
139 * If not set, the classic stack will be used. This is compatbile with
140 * all older versions.
142 #define OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK 0x0080
144 /* Support for the extended slot map */
145 #define OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP 0x100
147 /* Support for extended attributes */
148 #define OCFS2_FEATURE_INCOMPAT_XATTR 0x0200
151 * backup superblock flag is used to indicate that this volume
152 * has backup superblocks.
154 #define OCFS2_FEATURE_COMPAT_BACKUP_SB 0x0001
157 * The filesystem will correctly handle journal feature bits.
159 #define OCFS2_FEATURE_COMPAT_JBD2_SB 0x0002
162 * Unwritten extents support.
164 #define OCFS2_FEATURE_RO_COMPAT_UNWRITTEN 0x0001
167 * Maintain quota information for this filesystem
169 #define OCFS2_FEATURE_RO_COMPAT_USRQUOTA 0x0002
170 #define OCFS2_FEATURE_RO_COMPAT_GRPQUOTA 0x0004
172 /* The byte offset of the first backup block will be 1G.
173 * The following will be 4G, 16G, 64G, 256G and 1T.
175 #define OCFS2_BACKUP_SB_START 1 << 30
177 /* the max backup superblock nums */
178 #define OCFS2_MAX_BACKUP_SUPERBLOCKS 6
181 * Flags on ocfs2_super_block.s_tunefs_flags
183 #define OCFS2_TUNEFS_INPROG_REMOVE_SLOT 0x0001 /* Removing slots */
186 * Flags on ocfs2_dinode.i_flags
188 #define OCFS2_VALID_FL (0x00000001) /* Inode is valid */
189 #define OCFS2_UNUSED2_FL (0x00000002)
190 #define OCFS2_ORPHANED_FL (0x00000004) /* On the orphan list */
191 #define OCFS2_UNUSED3_FL (0x00000008)
192 /* System inode flags */
193 #define OCFS2_SYSTEM_FL (0x00000010) /* System inode */
194 #define OCFS2_SUPER_BLOCK_FL (0x00000020) /* Super block */
195 #define OCFS2_LOCAL_ALLOC_FL (0x00000040) /* Slot local alloc bitmap */
196 #define OCFS2_BITMAP_FL (0x00000080) /* Allocation bitmap */
197 #define OCFS2_JOURNAL_FL (0x00000100) /* Slot local journal */
198 #define OCFS2_HEARTBEAT_FL (0x00000200) /* Heartbeat area */
199 #define OCFS2_CHAIN_FL (0x00000400) /* Chain allocator */
200 #define OCFS2_DEALLOC_FL (0x00000800) /* Truncate log */
201 #define OCFS2_QUOTA_FL (0x00001000) /* Quota file */
204 * Flags on ocfs2_dinode.i_dyn_features
206 * These can change much more often than i_flags. When adding flags,
207 * keep in mind that i_dyn_features is only 16 bits wide.
209 #define OCFS2_INLINE_DATA_FL (0x0001) /* Data stored in inode block */
210 #define OCFS2_HAS_XATTR_FL (0x0002)
211 #define OCFS2_INLINE_XATTR_FL (0x0004)
212 #define OCFS2_INDEXED_DIR_FL (0x0008)
214 /* Inode attributes, keep in sync with EXT2 */
215 #define OCFS2_SECRM_FL (0x00000001) /* Secure deletion */
216 #define OCFS2_UNRM_FL (0x00000002) /* Undelete */
217 #define OCFS2_COMPR_FL (0x00000004) /* Compress file */
218 #define OCFS2_SYNC_FL (0x00000008) /* Synchronous updates */
219 #define OCFS2_IMMUTABLE_FL (0x00000010) /* Immutable file */
220 #define OCFS2_APPEND_FL (0x00000020) /* writes to file may only append */
221 #define OCFS2_NODUMP_FL (0x00000040) /* do not dump file */
222 #define OCFS2_NOATIME_FL (0x00000080) /* do not update atime */
223 #define OCFS2_DIRSYNC_FL (0x00010000) /* dirsync behaviour (directories only) */
225 #define OCFS2_FL_VISIBLE (0x000100FF) /* User visible flags */
226 #define OCFS2_FL_MODIFIABLE (0x000100FF) /* User modifiable flags */
229 * Extent record flags (e_node.leaf.flags)
231 #define OCFS2_EXT_UNWRITTEN (0x01) /* Extent is allocated but
237 #define OCFS2_IOC_GETFLAGS _IOR('f', 1, long)
238 #define OCFS2_IOC_SETFLAGS _IOW('f', 2, long)
239 #define OCFS2_IOC32_GETFLAGS _IOR('f', 1, int)
240 #define OCFS2_IOC32_SETFLAGS _IOW('f', 2, int)
243 * Space reservation / allocation / free ioctls and argument structure
244 * are designed to be compatible with XFS.
246 * ALLOCSP* and FREESP* are not and will never be supported, but are
247 * included here for completeness.
249 struct ocfs2_space_resv
{
253 __s64 l_len
; /* len == 0 means until end of file */
256 __s32 l_pad
[4]; /* reserve area */
259 #define OCFS2_IOC_ALLOCSP _IOW ('X', 10, struct ocfs2_space_resv)
260 #define OCFS2_IOC_FREESP _IOW ('X', 11, struct ocfs2_space_resv)
261 #define OCFS2_IOC_RESVSP _IOW ('X', 40, struct ocfs2_space_resv)
262 #define OCFS2_IOC_UNRESVSP _IOW ('X', 41, struct ocfs2_space_resv)
263 #define OCFS2_IOC_ALLOCSP64 _IOW ('X', 36, struct ocfs2_space_resv)
264 #define OCFS2_IOC_FREESP64 _IOW ('X', 37, struct ocfs2_space_resv)
265 #define OCFS2_IOC_RESVSP64 _IOW ('X', 42, struct ocfs2_space_resv)
266 #define OCFS2_IOC_UNRESVSP64 _IOW ('X', 43, struct ocfs2_space_resv)
268 /* Used to pass group descriptor data when online resize is done */
269 struct ocfs2_new_group_input
{
270 __u64 group
; /* Group descriptor's blkno. */
271 __u32 clusters
; /* Total number of clusters in this group */
272 __u32 frees
; /* Total free clusters in this group */
273 __u16 chain
; /* Chain for this group */
278 #define OCFS2_IOC_GROUP_EXTEND _IOW('o', 1, int)
279 #define OCFS2_IOC_GROUP_ADD _IOW('o', 2,struct ocfs2_new_group_input)
280 #define OCFS2_IOC_GROUP_ADD64 _IOW('o', 3,struct ocfs2_new_group_input)
283 * Journal Flags (ocfs2_dinode.id1.journal1.i_flags)
285 #define OCFS2_JOURNAL_DIRTY_FL (0x00000001) /* Journal needs recovery */
288 * superblock s_state flags
290 #define OCFS2_ERROR_FS (0x00000001) /* FS saw errors */
292 /* Limit of space in ocfs2_dir_entry */
293 #define OCFS2_MAX_FILENAME_LEN 255
295 /* Maximum slots on an ocfs2 file system */
296 #define OCFS2_MAX_SLOTS 255
298 /* Slot map indicator for an empty slot */
299 #define OCFS2_INVALID_SLOT -1
301 #define OCFS2_VOL_UUID_LEN 16
302 #define OCFS2_MAX_VOL_LABEL_LEN 64
304 /* The alternate, userspace stack fields */
305 #define OCFS2_STACK_LABEL_LEN 4
306 #define OCFS2_CLUSTER_NAME_LEN 16
308 /* Journal limits (in bytes) */
309 #define OCFS2_MIN_JOURNAL_SIZE (4 * 1024 * 1024)
312 * Default local alloc size (in megabytes)
314 * The value chosen should be such that most allocations, including new
315 * block groups, use local alloc.
317 #define OCFS2_DEFAULT_LOCAL_ALLOC_SIZE 8
320 * Inline extended attribute size (in bytes)
321 * The value chosen should be aligned to 16 byte boundaries.
323 #define OCFS2_MIN_XATTR_INLINE_SIZE 256
325 struct ocfs2_system_inode_info
{
331 /* System file index */
333 BAD_BLOCK_SYSTEM_INODE
= 0,
334 GLOBAL_INODE_ALLOC_SYSTEM_INODE
,
335 SLOT_MAP_SYSTEM_INODE
,
336 #define OCFS2_FIRST_ONLINE_SYSTEM_INODE SLOT_MAP_SYSTEM_INODE
337 HEARTBEAT_SYSTEM_INODE
,
338 GLOBAL_BITMAP_SYSTEM_INODE
,
339 USER_QUOTA_SYSTEM_INODE
,
340 GROUP_QUOTA_SYSTEM_INODE
,
341 #define OCFS2_LAST_GLOBAL_SYSTEM_INODE GROUP_QUOTA_SYSTEM_INODE
342 ORPHAN_DIR_SYSTEM_INODE
,
343 EXTENT_ALLOC_SYSTEM_INODE
,
344 INODE_ALLOC_SYSTEM_INODE
,
345 JOURNAL_SYSTEM_INODE
,
346 LOCAL_ALLOC_SYSTEM_INODE
,
347 TRUNCATE_LOG_SYSTEM_INODE
,
348 LOCAL_USER_QUOTA_SYSTEM_INODE
,
349 LOCAL_GROUP_QUOTA_SYSTEM_INODE
,
353 static struct ocfs2_system_inode_info ocfs2_system_inodes
[NUM_SYSTEM_INODES
] = {
354 /* Global system inodes (single copy) */
355 /* The first two are only used from userspace mfks/tunefs */
356 [BAD_BLOCK_SYSTEM_INODE
] = { "bad_blocks", 0, S_IFREG
| 0644 },
357 [GLOBAL_INODE_ALLOC_SYSTEM_INODE
] = { "global_inode_alloc", OCFS2_BITMAP_FL
| OCFS2_CHAIN_FL
, S_IFREG
| 0644 },
359 /* These are used by the running filesystem */
360 [SLOT_MAP_SYSTEM_INODE
] = { "slot_map", 0, S_IFREG
| 0644 },
361 [HEARTBEAT_SYSTEM_INODE
] = { "heartbeat", OCFS2_HEARTBEAT_FL
, S_IFREG
| 0644 },
362 [GLOBAL_BITMAP_SYSTEM_INODE
] = { "global_bitmap", 0, S_IFREG
| 0644 },
363 [USER_QUOTA_SYSTEM_INODE
] = { "aquota.user", OCFS2_QUOTA_FL
, S_IFREG
| 0644 },
364 [GROUP_QUOTA_SYSTEM_INODE
] = { "aquota.group", OCFS2_QUOTA_FL
, S_IFREG
| 0644 },
366 /* Slot-specific system inodes (one copy per slot) */
367 [ORPHAN_DIR_SYSTEM_INODE
] = { "orphan_dir:%04d", 0, S_IFDIR
| 0755 },
368 [EXTENT_ALLOC_SYSTEM_INODE
] = { "extent_alloc:%04d", OCFS2_BITMAP_FL
| OCFS2_CHAIN_FL
, S_IFREG
| 0644 },
369 [INODE_ALLOC_SYSTEM_INODE
] = { "inode_alloc:%04d", OCFS2_BITMAP_FL
| OCFS2_CHAIN_FL
, S_IFREG
| 0644 },
370 [JOURNAL_SYSTEM_INODE
] = { "journal:%04d", OCFS2_JOURNAL_FL
, S_IFREG
| 0644 },
371 [LOCAL_ALLOC_SYSTEM_INODE
] = { "local_alloc:%04d", OCFS2_BITMAP_FL
| OCFS2_LOCAL_ALLOC_FL
, S_IFREG
| 0644 },
372 [TRUNCATE_LOG_SYSTEM_INODE
] = { "truncate_log:%04d", OCFS2_DEALLOC_FL
, S_IFREG
| 0644 },
373 [LOCAL_USER_QUOTA_SYSTEM_INODE
] = { "aquota.user:%04d", OCFS2_QUOTA_FL
, S_IFREG
| 0644 },
374 [LOCAL_GROUP_QUOTA_SYSTEM_INODE
] = { "aquota.group:%04d", OCFS2_QUOTA_FL
, S_IFREG
| 0644 },
377 /* Parameter passed from mount.ocfs2 to module */
378 #define OCFS2_HB_NONE "heartbeat=none"
379 #define OCFS2_HB_LOCAL "heartbeat=local"
382 * OCFS2 directory file types. Only the low 3 bits are used. The
383 * other bits are reserved for now.
385 #define OCFS2_FT_UNKNOWN 0
386 #define OCFS2_FT_REG_FILE 1
387 #define OCFS2_FT_DIR 2
388 #define OCFS2_FT_CHRDEV 3
389 #define OCFS2_FT_BLKDEV 4
390 #define OCFS2_FT_FIFO 5
391 #define OCFS2_FT_SOCK 6
392 #define OCFS2_FT_SYMLINK 7
394 #define OCFS2_FT_MAX 8
397 * OCFS2_DIR_PAD defines the directory entries boundaries
399 * NOTE: It must be a multiple of 4
401 #define OCFS2_DIR_PAD 4
402 #define OCFS2_DIR_ROUND (OCFS2_DIR_PAD - 1)
403 #define OCFS2_DIR_MEMBER_LEN offsetof(struct ocfs2_dir_entry, name)
404 #define OCFS2_DIR_REC_LEN(name_len) (((name_len) + OCFS2_DIR_MEMBER_LEN + \
408 #define OCFS2_LINK_MAX 32000
411 static unsigned char ocfs2_type_by_mode
[S_IFMT
>> S_SHIFT
] = {
412 [S_IFREG
>> S_SHIFT
] = OCFS2_FT_REG_FILE
,
413 [S_IFDIR
>> S_SHIFT
] = OCFS2_FT_DIR
,
414 [S_IFCHR
>> S_SHIFT
] = OCFS2_FT_CHRDEV
,
415 [S_IFBLK
>> S_SHIFT
] = OCFS2_FT_BLKDEV
,
416 [S_IFIFO
>> S_SHIFT
] = OCFS2_FT_FIFO
,
417 [S_IFSOCK
>> S_SHIFT
] = OCFS2_FT_SOCK
,
418 [S_IFLNK
>> S_SHIFT
] = OCFS2_FT_SYMLINK
,
425 #define OCFS2_RAW_SB(dinode) (&((dinode)->id2.i_super))
428 * On disk extent record for OCFS2
429 * It describes a range of clusters on disk.
431 * Length fields are divided into interior and leaf node versions.
432 * This leaves room for a flags field (OCFS2_EXT_*) in the leaf nodes.
434 struct ocfs2_extent_rec
{
435 /*00*/ __le32 e_cpos
; /* Offset into the file, in clusters */
437 __le32 e_int_clusters
; /* Clusters covered by all children */
439 __le16 e_leaf_clusters
; /* Clusters covered by this
442 __u8 e_flags
; /* Extent flags */
445 __le64 e_blkno
; /* Physical disk offset, in blocks */
449 struct ocfs2_chain_rec
{
450 __le32 c_free
; /* Number of free bits in this chain. */
451 __le32 c_total
; /* Number of total bits in this chain */
452 __le64 c_blkno
; /* Physical disk offset (blocks) of 1st group */
455 struct ocfs2_truncate_rec
{
456 __le32 t_start
; /* 1st cluster in this log */
457 __le32 t_clusters
; /* Number of total clusters covered */
461 * On disk extent list for OCFS2 (node in the tree). Note that this
462 * is contained inside ocfs2_dinode or ocfs2_extent_block, so the
463 * offsets are relative to ocfs2_dinode.id2.i_list or
464 * ocfs2_extent_block.h_list, respectively.
466 struct ocfs2_extent_list
{
467 /*00*/ __le16 l_tree_depth
; /* Extent tree depth from this
468 point. 0 means data extents
469 hang directly off this
471 NOTE: The high 8 bits cannot be
472 used - tree_depth is never that big.
474 __le16 l_count
; /* Number of extent records */
475 __le16 l_next_free_rec
; /* Next unused extent slot */
477 __le64 l_reserved2
; /* Pad to
478 sizeof(ocfs2_extent_rec) */
479 /*10*/ struct ocfs2_extent_rec l_recs
[0]; /* Extent records */
483 * On disk allocation chain list for OCFS2. Note that this is
484 * contained inside ocfs2_dinode, so the offsets are relative to
485 * ocfs2_dinode.id2.i_chain.
487 struct ocfs2_chain_list
{
488 /*00*/ __le16 cl_cpg
; /* Clusters per Block Group */
489 __le16 cl_bpc
; /* Bits per cluster */
490 __le16 cl_count
; /* Total chains in this list */
491 __le16 cl_next_free_rec
; /* Next unused chain slot */
493 /*10*/ struct ocfs2_chain_rec cl_recs
[0]; /* Chain records */
497 * On disk deallocation log for OCFS2. Note that this is
498 * contained inside ocfs2_dinode, so the offsets are relative to
499 * ocfs2_dinode.id2.i_dealloc.
501 struct ocfs2_truncate_log
{
502 /*00*/ __le16 tl_count
; /* Total records in this log */
503 __le16 tl_used
; /* Number of records in use */
505 /*08*/ struct ocfs2_truncate_rec tl_recs
[0]; /* Truncate records */
509 * On disk extent block (indirect block) for OCFS2
511 struct ocfs2_extent_block
513 /*00*/ __u8 h_signature
[8]; /* Signature for verification */
515 /*10*/ __le16 h_suballoc_slot
; /* Slot suballocator this
516 extent_header belongs to */
517 __le16 h_suballoc_bit
; /* Bit offset in suballocator
519 __le32 h_fs_generation
; /* Must match super block */
520 __le64 h_blkno
; /* Offset on disk, in blocks */
521 /*20*/ __le64 h_reserved3
;
522 __le64 h_next_leaf_blk
; /* Offset on disk, in blocks,
523 of next leaf header pointing
525 /*30*/ struct ocfs2_extent_list h_list
; /* Extent record list */
526 /* Actual on-disk size is one block */
530 * On disk slot map for OCFS2. This defines the contents of the "slot_map"
531 * system file. A slot is valid if it contains a node number >= 0. The
532 * value -1 (0xFFFF) is OCFS2_INVALID_SLOT. This marks a slot empty.
534 struct ocfs2_slot_map
{
535 /*00*/ __le16 sm_slots
[0];
537 * Actual on-disk size is one block. OCFS2_MAX_SLOTS is 255,
538 * 255 * sizeof(__le16) == 512B, within the 512B block minimum blocksize.
542 struct ocfs2_extended_slot
{
543 /*00*/ __u8 es_valid
;
544 __u8 es_reserved1
[3];
550 * The extended slot map, used when OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP
551 * is set. It separates out the valid marker from the node number, and
552 * has room to grow. Unlike the old slot map, this format is defined by
555 struct ocfs2_slot_map_extended
{
556 /*00*/ struct ocfs2_extended_slot se_slots
[0];
558 * Actual size is i_size of the slot_map system file. It should
559 * match s_max_slots * sizeof(struct ocfs2_extended_slot)
563 struct ocfs2_cluster_info
{
564 /*00*/ __u8 ci_stack
[OCFS2_STACK_LABEL_LEN
];
566 /*08*/ __u8 ci_cluster
[OCFS2_CLUSTER_NAME_LEN
];
571 * On disk superblock for OCFS2
572 * Note that it is contained inside an ocfs2_dinode, so all offsets
573 * are relative to the start of ocfs2_dinode.id2.
575 struct ocfs2_super_block
{
576 /*00*/ __le16 s_major_rev_level
;
577 __le16 s_minor_rev_level
;
579 __le16 s_max_mnt_count
;
580 __le16 s_state
; /* File system state */
581 __le16 s_errors
; /* Behaviour when detecting errors */
582 __le32 s_checkinterval
; /* Max time between checks */
583 /*10*/ __le64 s_lastcheck
; /* Time of last check */
584 __le32 s_creator_os
; /* OS */
585 __le32 s_feature_compat
; /* Compatible feature set */
586 /*20*/ __le32 s_feature_incompat
; /* Incompatible feature set */
587 __le32 s_feature_ro_compat
; /* Readonly-compatible feature set */
588 __le64 s_root_blkno
; /* Offset, in blocks, of root directory
590 /*30*/ __le64 s_system_dir_blkno
; /* Offset, in blocks, of system
592 __le32 s_blocksize_bits
; /* Blocksize for this fs */
593 __le32 s_clustersize_bits
; /* Clustersize for this fs */
594 /*40*/ __le16 s_max_slots
; /* Max number of simultaneous mounts
595 before tunefs required */
596 __le16 s_tunefs_flag
;
597 __le32 s_uuid_hash
; /* hash value of uuid */
598 __le64 s_first_cluster_group
; /* Block offset of 1st cluster
600 /*50*/ __u8 s_label
[OCFS2_MAX_VOL_LABEL_LEN
]; /* Label for mounting, etc. */
601 /*90*/ __u8 s_uuid
[OCFS2_VOL_UUID_LEN
]; /* 128-bit uuid */
602 /*A0*/ struct ocfs2_cluster_info s_cluster_info
; /* Selected userspace
604 with INCOMPAT flag. */
605 /*B8*/ __le16 s_xattr_inline_size
; /* extended attribute inline size
609 /*C0*/ __le64 s_reserved2
[16]; /* Fill out superblock */
613 * NOTE: As stated above, all offsets are relative to
614 * ocfs2_dinode.id2, which is at 0xC0 in the inode.
615 * 0xC0 + 0x140 = 0x200 or 512 bytes. A superblock must fit within
616 * our smallest blocksize, which is 512 bytes. To ensure this,
617 * we reserve the space in s_reserved2. Anything past s_reserved2
618 * will not be available on the smallest blocksize.
623 * Local allocation bitmap for OCFS2 slots
624 * Note that it exists inside an ocfs2_dinode, so all offsets are
625 * relative to the start of ocfs2_dinode.id2.
627 struct ocfs2_local_alloc
629 /*00*/ __le32 la_bm_off
; /* Starting bit offset in main bitmap */
630 __le16 la_size
; /* Size of included bitmap, in bytes */
633 /*10*/ __u8 la_bitmap
[0];
637 * Data-in-inode header. This is only used if i_dyn_features has
638 * OCFS2_INLINE_DATA_FL set.
640 struct ocfs2_inline_data
642 /*00*/ __le16 id_count
; /* Number of bytes that can be used
643 * for data, starting at id_data */
646 __u8 id_data
[0]; /* Start of user data */
650 * On disk inode for OCFS2
652 struct ocfs2_dinode
{
653 /*00*/ __u8 i_signature
[8]; /* Signature for validation */
654 __le32 i_generation
; /* Generation number */
655 __le16 i_suballoc_slot
; /* Slot suballocator this inode
657 __le16 i_suballoc_bit
; /* Bit offset in suballocator
659 /*10*/ __le16 i_reserved0
;
660 __le16 i_xattr_inline_size
;
661 __le32 i_clusters
; /* Cluster count */
662 __le32 i_uid
; /* Owner UID */
663 __le32 i_gid
; /* Owning GID */
664 /*20*/ __le64 i_size
; /* Size in bytes */
665 __le16 i_mode
; /* File mode */
666 __le16 i_links_count
; /* Links count */
667 __le32 i_flags
; /* File flags */
668 /*30*/ __le64 i_atime
; /* Access time */
669 __le64 i_ctime
; /* Creation time */
670 /*40*/ __le64 i_mtime
; /* Modification time */
671 __le64 i_dtime
; /* Deletion time */
672 /*50*/ __le64 i_blkno
; /* Offset on disk, in blocks */
673 __le64 i_last_eb_blk
; /* Pointer to last extent
675 /*60*/ __le32 i_fs_generation
; /* Generation per fs-instance */
679 /*70*/ __le32 i_attr
;
680 __le16 i_orphaned_slot
; /* Only valid when OCFS2_ORPHANED_FL
681 was set in i_flags */
682 __le16 i_dyn_features
;
684 /*80*/ __le64 i_reserved2
[7];
686 __le64 i_pad1
; /* Generic way to refer to this
689 __le64 i_rdev
; /* Device number */
691 struct { /* Info for bitmap system
693 __le32 i_used
; /* Bits (ie, clusters) used */
694 __le32 i_total
; /* Total bits (clusters)
697 struct { /* Info for journal system
699 __le32 ij_flags
; /* Mounted, version, etc. */
700 __le32 ij_recovery_generation
; /* Incremented when the
705 } id1
; /* Inode type dependant 1 */
707 struct ocfs2_super_block i_super
;
708 struct ocfs2_local_alloc i_lab
;
709 struct ocfs2_chain_list i_chain
;
710 struct ocfs2_extent_list i_list
;
711 struct ocfs2_truncate_log i_dealloc
;
712 struct ocfs2_inline_data i_data
;
715 /* Actual on-disk size is one block */
719 * On-disk directory entry structure for OCFS2
721 * Packed as this structure could be accessed unaligned on 64-bit platforms
723 struct ocfs2_dir_entry
{
724 /*00*/ __le64 inode
; /* Inode number */
725 __le16 rec_len
; /* Directory entry length */
726 __u8 name_len
; /* Name length */
728 /*0C*/ char name
[OCFS2_MAX_FILENAME_LEN
]; /* File name */
729 /* Actual on-disk length specified by rec_len */
730 } __attribute__ ((packed
));
733 * On disk allocator group structure for OCFS2
735 struct ocfs2_group_desc
737 /*00*/ __u8 bg_signature
[8]; /* Signature for validation */
738 __le16 bg_size
; /* Size of included bitmap in
740 __le16 bg_bits
; /* Bits represented by this
742 __le16 bg_free_bits_count
; /* Free bits count */
743 __le16 bg_chain
; /* What chain I am in. */
744 /*10*/ __le32 bg_generation
;
746 __le64 bg_next_group
; /* Next group in my list, in
748 /*20*/ __le64 bg_parent_dinode
; /* dinode which owns me, in
750 __le64 bg_blkno
; /* Offset on disk, in blocks */
751 /*30*/ __le64 bg_reserved2
[2];
752 /*40*/ __u8 bg_bitmap
[0];
756 * On disk extended attribute structure for OCFS2.
760 * ocfs2_xattr_entry indicates one extend attribute.
762 * Note that it can be stored in inode, one block or one xattr bucket.
764 struct ocfs2_xattr_entry
{
765 __le32 xe_name_hash
; /* hash value of xattr prefix+suffix. */
766 __le16 xe_name_offset
; /* byte offset from the 1st entry in the
767 local xattr storage(inode, xattr block or
769 __u8 xe_name_len
; /* xattr name len, does't include prefix. */
770 __u8 xe_type
; /* the low 7 bits indicate the name prefix
771 * type and the highest bit indicates whether
772 * the EA is stored in the local storage. */
773 __le64 xe_value_size
; /* real xattr value length. */
777 * On disk structure for xattr header.
779 * One ocfs2_xattr_header describes how many ocfs2_xattr_entry records in
780 * the local xattr storage.
782 struct ocfs2_xattr_header
{
783 __le16 xh_count
; /* contains the count of how
784 many records are in the
785 local xattr storage. */
786 __le16 xh_free_start
; /* current offset for storing
788 __le16 xh_name_value_len
; /* total length of name/value
789 length in this bucket. */
790 __le16 xh_num_buckets
; /* Number of xattr buckets
791 in this extent record,
792 only valid in the first
795 struct ocfs2_xattr_entry xh_entries
[0]; /* xattr entry list. */
799 * On disk structure for xattr value root.
801 * When an xattr's value is large enough, it is stored in an external
802 * b-tree like file data. The xattr value root points to this structure.
804 struct ocfs2_xattr_value_root
{
805 /*00*/ __le32 xr_clusters
; /* clusters covered by xattr value. */
807 __le64 xr_last_eb_blk
; /* Pointer to last extent block */
808 /*10*/ struct ocfs2_extent_list xr_list
; /* Extent record list */
812 * On disk structure for xattr tree root.
814 * It is used when there are too many extended attributes for one file. These
815 * attributes will be organized and stored in an indexed-btree.
817 struct ocfs2_xattr_tree_root
{
818 /*00*/ __le32 xt_clusters
; /* clusters covered by xattr. */
820 __le64 xt_last_eb_blk
; /* Pointer to last extent block */
821 /*10*/ struct ocfs2_extent_list xt_list
; /* Extent record list */
824 #define OCFS2_XATTR_INDEXED 0x1
825 #define OCFS2_HASH_SHIFT 5
826 #define OCFS2_XATTR_ROUND 3
827 #define OCFS2_XATTR_SIZE(size) (((size) + OCFS2_XATTR_ROUND) & \
828 ~(OCFS2_XATTR_ROUND))
830 #define OCFS2_XATTR_BUCKET_SIZE 4096
831 #define OCFS2_XATTR_MAX_BLOCKS_PER_BUCKET (OCFS2_XATTR_BUCKET_SIZE \
832 / OCFS2_MIN_BLOCKSIZE)
835 * On disk structure for xattr block.
837 struct ocfs2_xattr_block
{
838 /*00*/ __u8 xb_signature
[8]; /* Signature for verification */
839 __le16 xb_suballoc_slot
; /* Slot suballocator this
841 __le16 xb_suballoc_bit
; /* Bit offset in suballocator
843 __le32 xb_fs_generation
; /* Must match super block */
844 /*10*/ __le64 xb_blkno
; /* Offset on disk, in blocks */
846 /*20*/ __le16 xb_flags
; /* Indicates whether this block contains
847 real xattr or a xattr tree. */
852 struct ocfs2_xattr_header xb_header
; /* xattr header if this
853 block contains xattr */
854 struct ocfs2_xattr_tree_root xb_root
;/* xattr tree root if this
860 #define OCFS2_XATTR_ENTRY_LOCAL 0x80
861 #define OCFS2_XATTR_TYPE_MASK 0x7F
862 static inline void ocfs2_xattr_set_local(struct ocfs2_xattr_entry
*xe
,
866 xe
->xe_type
|= OCFS2_XATTR_ENTRY_LOCAL
;
868 xe
->xe_type
&= ~OCFS2_XATTR_ENTRY_LOCAL
;
871 static inline int ocfs2_xattr_is_local(struct ocfs2_xattr_entry
*xe
)
873 return xe
->xe_type
& OCFS2_XATTR_ENTRY_LOCAL
;
876 static inline void ocfs2_xattr_set_type(struct ocfs2_xattr_entry
*xe
, int type
)
878 xe
->xe_type
|= type
& OCFS2_XATTR_TYPE_MASK
;
881 static inline int ocfs2_xattr_get_type(struct ocfs2_xattr_entry
*xe
)
883 return xe
->xe_type
& OCFS2_XATTR_TYPE_MASK
;
887 static inline int ocfs2_fast_symlink_chars(struct super_block
*sb
)
889 return sb
->s_blocksize
-
890 offsetof(struct ocfs2_dinode
, id2
.i_symlink
);
893 static inline int ocfs2_max_inline_data(struct super_block
*sb
)
895 return sb
->s_blocksize
-
896 offsetof(struct ocfs2_dinode
, id2
.i_data
.id_data
);
899 static inline int ocfs2_max_inline_data_with_xattr(struct super_block
*sb
,
900 struct ocfs2_dinode
*di
)
902 unsigned int xattrsize
= le16_to_cpu(di
->i_xattr_inline_size
);
904 if (le16_to_cpu(di
->i_dyn_features
) & OCFS2_INLINE_XATTR_FL
)
905 return sb
->s_blocksize
-
906 offsetof(struct ocfs2_dinode
, id2
.i_data
.id_data
) -
909 return sb
->s_blocksize
-
910 offsetof(struct ocfs2_dinode
, id2
.i_data
.id_data
);
913 static inline int ocfs2_extent_recs_per_inode(struct super_block
*sb
)
917 size
= sb
->s_blocksize
-
918 offsetof(struct ocfs2_dinode
, id2
.i_list
.l_recs
);
920 return size
/ sizeof(struct ocfs2_extent_rec
);
923 static inline int ocfs2_extent_recs_per_inode_with_xattr(
924 struct super_block
*sb
,
925 struct ocfs2_dinode
*di
)
928 unsigned int xattrsize
= le16_to_cpu(di
->i_xattr_inline_size
);
930 if (le16_to_cpu(di
->i_dyn_features
) & OCFS2_INLINE_XATTR_FL
)
931 size
= sb
->s_blocksize
-
932 offsetof(struct ocfs2_dinode
, id2
.i_list
.l_recs
) -
935 size
= sb
->s_blocksize
-
936 offsetof(struct ocfs2_dinode
, id2
.i_list
.l_recs
);
938 return size
/ sizeof(struct ocfs2_extent_rec
);
941 static inline int ocfs2_chain_recs_per_inode(struct super_block
*sb
)
945 size
= sb
->s_blocksize
-
946 offsetof(struct ocfs2_dinode
, id2
.i_chain
.cl_recs
);
948 return size
/ sizeof(struct ocfs2_chain_rec
);
951 static inline u16
ocfs2_extent_recs_per_eb(struct super_block
*sb
)
955 size
= sb
->s_blocksize
-
956 offsetof(struct ocfs2_extent_block
, h_list
.l_recs
);
958 return size
/ sizeof(struct ocfs2_extent_rec
);
961 static inline u16
ocfs2_local_alloc_size(struct super_block
*sb
)
965 size
= sb
->s_blocksize
-
966 offsetof(struct ocfs2_dinode
, id2
.i_lab
.la_bitmap
);
971 static inline int ocfs2_group_bitmap_size(struct super_block
*sb
)
975 size
= sb
->s_blocksize
-
976 offsetof(struct ocfs2_group_desc
, bg_bitmap
);
981 static inline int ocfs2_truncate_recs_per_inode(struct super_block
*sb
)
985 size
= sb
->s_blocksize
-
986 offsetof(struct ocfs2_dinode
, id2
.i_dealloc
.tl_recs
);
988 return size
/ sizeof(struct ocfs2_truncate_rec
);
991 static inline u64
ocfs2_backup_super_blkno(struct super_block
*sb
, int index
)
993 u64 offset
= OCFS2_BACKUP_SB_START
;
995 if (index
>= 0 && index
< OCFS2_MAX_BACKUP_SUPERBLOCKS
) {
996 offset
<<= (2 * index
);
997 offset
>>= sb
->s_blocksize_bits
;
1005 static inline u16
ocfs2_xattr_recs_per_xb(struct super_block
*sb
)
1009 size
= sb
->s_blocksize
-
1010 offsetof(struct ocfs2_xattr_block
,
1011 xb_attrs
.xb_root
.xt_list
.l_recs
);
1013 return size
/ sizeof(struct ocfs2_extent_rec
);
1016 static inline int ocfs2_fast_symlink_chars(int blocksize
)
1018 return blocksize
- offsetof(struct ocfs2_dinode
, id2
.i_symlink
);
1021 static inline int ocfs2_max_inline_data(int blocksize
)
1023 return blocksize
- offsetof(struct ocfs2_dinode
, id2
.i_data
.id_data
);
1026 static inline int ocfs2_extent_recs_per_inode(int blocksize
)
1031 offsetof(struct ocfs2_dinode
, id2
.i_list
.l_recs
);
1033 return size
/ sizeof(struct ocfs2_extent_rec
);
1036 static inline int ocfs2_chain_recs_per_inode(int blocksize
)
1041 offsetof(struct ocfs2_dinode
, id2
.i_chain
.cl_recs
);
1043 return size
/ sizeof(struct ocfs2_chain_rec
);
1046 static inline int ocfs2_extent_recs_per_eb(int blocksize
)
1051 offsetof(struct ocfs2_extent_block
, h_list
.l_recs
);
1053 return size
/ sizeof(struct ocfs2_extent_rec
);
1056 static inline int ocfs2_local_alloc_size(int blocksize
)
1061 offsetof(struct ocfs2_dinode
, id2
.i_lab
.la_bitmap
);
1066 static inline int ocfs2_group_bitmap_size(int blocksize
)
1071 offsetof(struct ocfs2_group_desc
, bg_bitmap
);
1076 static inline int ocfs2_truncate_recs_per_inode(int blocksize
)
1081 offsetof(struct ocfs2_dinode
, id2
.i_dealloc
.tl_recs
);
1083 return size
/ sizeof(struct ocfs2_truncate_rec
);
1086 static inline uint64_t ocfs2_backup_super_blkno(int blocksize
, int index
)
1088 uint64_t offset
= OCFS2_BACKUP_SB_START
;
1090 if (index
>= 0 && index
< OCFS2_MAX_BACKUP_SUPERBLOCKS
) {
1091 offset
<<= (2 * index
);
1092 offset
/= blocksize
;
1099 static inline int ocfs2_xattr_recs_per_xb(int blocksize
)
1104 offsetof(struct ocfs2_xattr_block
,
1105 xb_attrs
.xb_root
.xt_list
.l_recs
);
1107 return size
/ sizeof(struct ocfs2_extent_rec
);
1109 #endif /* __KERNEL__ */
1112 static inline int ocfs2_system_inode_is_global(int type
)
1114 return ((type
>= 0) &&
1115 (type
<= OCFS2_LAST_GLOBAL_SYSTEM_INODE
));
1118 static inline int ocfs2_sprintf_system_inode_name(char *buf
, int len
,
1124 * Global system inodes can only have one copy. Everything
1125 * after OCFS2_LAST_GLOBAL_SYSTEM_INODE in the system inode
1126 * list has a copy per slot.
1128 if (type
<= OCFS2_LAST_GLOBAL_SYSTEM_INODE
)
1129 chars
= snprintf(buf
, len
, "%s",
1130 ocfs2_system_inodes
[type
].si_name
);
1132 chars
= snprintf(buf
, len
,
1133 ocfs2_system_inodes
[type
].si_name
,
1139 static inline void ocfs2_set_de_type(struct ocfs2_dir_entry
*de
,
1142 de
->file_type
= ocfs2_type_by_mode
[(mode
& S_IFMT
)>>S_SHIFT
];
1145 #endif /* _OCFS2_FS_H */