1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * ocfs2_fs.h
4 *
5 * On-disk structures for OCFS2.
6 *
7 * Copyright (C) 2002, 2004 Oracle. All rights reserved.
8 */
9
10 #ifndef _OCFS2_FS_H
11 #define _OCFS2_FS_H
12
13 #include <linux/magic.h>
14
15 /* Version */
16 #define OCFS2_MAJOR_REV_LEVEL 0
17 #define OCFS2_MINOR_REV_LEVEL 90
18
19 /*
20 * An OCFS2 volume starts this way:
21 * Sector 0: Valid ocfs1_vol_disk_hdr that cleanly fails to mount OCFS.
22 * Sector 1: Valid ocfs1_vol_label that cleanly fails to mount OCFS.
23 * Block OCFS2_SUPER_BLOCK_BLKNO: OCFS2 superblock.
24 *
25 * All other structures are found from the superblock information.
26 *
27 * OCFS2_SUPER_BLOCK_BLKNO is in blocks, not sectors. eg, for a
28 * blocksize of 2K, it is 4096 bytes into disk.
29 */
30 #define OCFS2_SUPER_BLOCK_BLKNO 2
31
32 /*
33 * Cluster size limits. The maximum is kept arbitrarily at 1 MB, and could
34 * grow if needed.
35 */
36 #define OCFS2_MIN_CLUSTERSIZE 4096
37 #define OCFS2_MAX_CLUSTERSIZE 1048576
38
39 /*
40 * Blocks cannot be bigger than clusters, so the maximum blocksize is the
41 * minimum cluster size.
42 */
43 #define OCFS2_MIN_BLOCKSIZE 512
44 #define OCFS2_MAX_BLOCKSIZE OCFS2_MIN_CLUSTERSIZE
45
46 /* Object signatures */
47 #define OCFS2_SUPER_BLOCK_SIGNATURE "OCFSV2"
48 #define OCFS2_INODE_SIGNATURE "INODE01"
49 #define OCFS2_EXTENT_BLOCK_SIGNATURE "EXBLK01"
50 #define OCFS2_GROUP_DESC_SIGNATURE "GROUP01"
51 #define OCFS2_XATTR_BLOCK_SIGNATURE "XATTR01"
52 #define OCFS2_DIR_TRAILER_SIGNATURE "DIRTRL1"
53 #define OCFS2_DX_ROOT_SIGNATURE "DXDIR01"
54 #define OCFS2_DX_LEAF_SIGNATURE "DXLEAF1"
55 #define OCFS2_REFCOUNT_BLOCK_SIGNATURE "REFCNT1"
56
57 /* Compatibility flags */
58 #define OCFS2_HAS_COMPAT_FEATURE(sb,mask) \
59 ( OCFS2_SB(sb)->s_feature_compat & (mask) )
60 #define OCFS2_HAS_RO_COMPAT_FEATURE(sb,mask) \
61 ( OCFS2_SB(sb)->s_feature_ro_compat & (mask) )
62 #define OCFS2_HAS_INCOMPAT_FEATURE(sb,mask) \
63 ( OCFS2_SB(sb)->s_feature_incompat & (mask) )
64 #define OCFS2_SET_COMPAT_FEATURE(sb,mask) \
65 OCFS2_SB(sb)->s_feature_compat |= (mask)
66 #define OCFS2_SET_RO_COMPAT_FEATURE(sb,mask) \
67 OCFS2_SB(sb)->s_feature_ro_compat |= (mask)
68 #define OCFS2_SET_INCOMPAT_FEATURE(sb,mask) \
69 OCFS2_SB(sb)->s_feature_incompat |= (mask)
70 #define OCFS2_CLEAR_COMPAT_FEATURE(sb,mask) \
71 OCFS2_SB(sb)->s_feature_compat &= ~(mask)
72 #define OCFS2_CLEAR_RO_COMPAT_FEATURE(sb,mask) \
73 OCFS2_SB(sb)->s_feature_ro_compat &= ~(mask)
74 #define OCFS2_CLEAR_INCOMPAT_FEATURE(sb,mask) \
75 OCFS2_SB(sb)->s_feature_incompat &= ~(mask)
76
77 #define OCFS2_FEATURE_COMPAT_SUPP (OCFS2_FEATURE_COMPAT_BACKUP_SB \
78 | OCFS2_FEATURE_COMPAT_JBD2_SB)
79 #define OCFS2_FEATURE_INCOMPAT_SUPP (OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT \
80 | OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC \
81 | OCFS2_FEATURE_INCOMPAT_INLINE_DATA \
82 | OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP \
83 | OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK \
84 | OCFS2_FEATURE_INCOMPAT_XATTR \
85 | OCFS2_FEATURE_INCOMPAT_META_ECC \
86 | OCFS2_FEATURE_INCOMPAT_INDEXED_DIRS \
87 | OCFS2_FEATURE_INCOMPAT_REFCOUNT_TREE \
88 | OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG \
89 | OCFS2_FEATURE_INCOMPAT_CLUSTERINFO \
90 | OCFS2_FEATURE_INCOMPAT_APPEND_DIO)
91 #define OCFS2_FEATURE_RO_COMPAT_SUPP (OCFS2_FEATURE_RO_COMPAT_UNWRITTEN \
92 | OCFS2_FEATURE_RO_COMPAT_USRQUOTA \
93 | OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)
94
95 /*
96 * Heartbeat-only devices are missing journals and other files. The
97 * filesystem driver can't load them, but the library can. Never put
98 * this in OCFS2_FEATURE_INCOMPAT_SUPP, *ever*.
99 */
100 #define OCFS2_FEATURE_INCOMPAT_HEARTBEAT_DEV 0x0002
101
102 /*
103 * tunefs sets this incompat flag before starting the resize and clears it
104 * at the end. This flag protects users from inadvertently mounting the fs
105 * after an aborted run without fsck-ing.
106 */
107 #define OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG 0x0004
108
109 /* Used to denote a non-clustered volume */
110 #define OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT 0x0008
111
112 /* Support for sparse allocation in b-trees */
113 #define OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC 0x0010
114
115 /*
116 * Tunefs sets this incompat flag before starting an operation which
117 * would require cleanup on abort. This is done to protect users from
118 * inadvertently mounting the fs after an aborted run without
119 * fsck-ing.
120 *
121 * s_tunefs_flags on the super block describes precisely which
122 * operations were in progress.
123 */
124 #define OCFS2_FEATURE_INCOMPAT_TUNEFS_INPROG 0x0020
125
126 /* Support for data packed into inode blocks */
127 #define OCFS2_FEATURE_INCOMPAT_INLINE_DATA 0x0040
128
129 /*
130 * Support for alternate, userspace cluster stacks. If set, the superblock
131 * field s_cluster_info contains a tag for the alternate stack in use as
132 * well as the name of the cluster being joined.
133 * mount.ocfs2 must pass in a matching stack name.
134 *
135 * If not set, the classic stack will be used. This is compatible with
136 * all older versions.
137 */
138 #define OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK 0x0080
139
140 /* Support for the extended slot map */
141 #define OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP 0x100
142
143 /* Support for extended attributes */
144 #define OCFS2_FEATURE_INCOMPAT_XATTR 0x0200
145
146 /* Support for indexed directories */
147 #define OCFS2_FEATURE_INCOMPAT_INDEXED_DIRS 0x0400
148
149 /* Metadata checksum and error correction */
150 #define OCFS2_FEATURE_INCOMPAT_META_ECC 0x0800
151
152 /* Refcount tree support */
153 #define OCFS2_FEATURE_INCOMPAT_REFCOUNT_TREE 0x1000
154
155 /* Discontiguous block groups */
156 #define OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG 0x2000
157
158 /*
159 * Incompat bit to indicate usable clusterinfo with stackflags for all
160 * cluster stacks (userspace adnd o2cb). If this bit is set,
161 * INCOMPAT_USERSPACE_STACK becomes superfluous and thus should not be set.
162 */
163 #define OCFS2_FEATURE_INCOMPAT_CLUSTERINFO 0x4000
164
165 /*
166 * Append Direct IO support
167 */
168 #define OCFS2_FEATURE_INCOMPAT_APPEND_DIO 0x8000
169
170 /*
171 * backup superblock flag is used to indicate that this volume
172 * has backup superblocks.
173 */
174 #define OCFS2_FEATURE_COMPAT_BACKUP_SB 0x0001
175
176 /*
177 * The filesystem will correctly handle journal feature bits.
178 */
179 #define OCFS2_FEATURE_COMPAT_JBD2_SB 0x0002
180
181 /*
182 * Unwritten extents support.
183 */
184 #define OCFS2_FEATURE_RO_COMPAT_UNWRITTEN 0x0001
185
186 /*
187 * Maintain quota information for this filesystem
188 */
189 #define OCFS2_FEATURE_RO_COMPAT_USRQUOTA 0x0002
190 #define OCFS2_FEATURE_RO_COMPAT_GRPQUOTA 0x0004
191
192
193 /* The byte offset of the first backup block will be 1G.
194 * The following will be 4G, 16G, 64G, 256G and 1T.
195 */
196 #define OCFS2_BACKUP_SB_START 1 << 30
197
198 /* the max backup superblock nums */
199 #define OCFS2_MAX_BACKUP_SUPERBLOCKS 6
200
201 /*
202 * Flags on ocfs2_super_block.s_tunefs_flags
203 */
204 #define OCFS2_TUNEFS_INPROG_REMOVE_SLOT 0x0001 /* Removing slots */
205
206 /*
207 * Flags on ocfs2_dinode.i_flags
208 */
209 #define OCFS2_VALID_FL (0x00000001) /* Inode is valid */
210 #define OCFS2_UNUSED2_FL (0x00000002)
211 #define OCFS2_ORPHANED_FL (0x00000004) /* On the orphan list */
212 #define OCFS2_UNUSED3_FL (0x00000008)
213 /* System inode flags */
214 #define OCFS2_SYSTEM_FL (0x00000010) /* System inode */
215 #define OCFS2_SUPER_BLOCK_FL (0x00000020) /* Super block */
216 #define OCFS2_LOCAL_ALLOC_FL (0x00000040) /* Slot local alloc bitmap */
217 #define OCFS2_BITMAP_FL (0x00000080) /* Allocation bitmap */
218 #define OCFS2_JOURNAL_FL (0x00000100) /* Slot local journal */
219 #define OCFS2_HEARTBEAT_FL (0x00000200) /* Heartbeat area */
220 #define OCFS2_CHAIN_FL (0x00000400) /* Chain allocator */
221 #define OCFS2_DEALLOC_FL (0x00000800) /* Truncate log */
222 #define OCFS2_QUOTA_FL (0x00001000) /* Quota file */
223 #define OCFS2_DIO_ORPHANED_FL (0X00002000) /* On the orphan list especially
224 * for dio */
225
226 /*
227 * Flags on ocfs2_dinode.i_dyn_features
228 *
229 * These can change much more often than i_flags. When adding flags,
230 * keep in mind that i_dyn_features is only 16 bits wide.
231 */
232 #define OCFS2_INLINE_DATA_FL (0x0001) /* Data stored in inode block */
233 #define OCFS2_HAS_XATTR_FL (0x0002)
234 #define OCFS2_INLINE_XATTR_FL (0x0004)
235 #define OCFS2_INDEXED_DIR_FL (0x0008)
236 #define OCFS2_HAS_REFCOUNT_FL (0x0010)
237
238 /* Inode attributes, keep in sync with EXT2 */
239 #define OCFS2_SECRM_FL FS_SECRM_FL /* Secure deletion */
240 #define OCFS2_UNRM_FL FS_UNRM_FL /* Undelete */
241 #define OCFS2_COMPR_FL FS_COMPR_FL /* Compress file */
242 #define OCFS2_SYNC_FL FS_SYNC_FL /* Synchronous updates */
243 #define OCFS2_IMMUTABLE_FL FS_IMMUTABLE_FL /* Immutable file */
244 #define OCFS2_APPEND_FL FS_APPEND_FL /* writes to file may only append */
245 #define OCFS2_NODUMP_FL FS_NODUMP_FL /* do not dump file */
246 #define OCFS2_NOATIME_FL FS_NOATIME_FL /* do not update atime */
247 /* Reserved for compression usage... */
248 #define OCFS2_DIRTY_FL FS_DIRTY_FL
249 #define OCFS2_COMPRBLK_FL FS_COMPRBLK_FL /* One or more compressed clusters */
250 #define OCFS2_NOCOMP_FL FS_NOCOMP_FL /* Don't compress */
251 #define OCFS2_ECOMPR_FL FS_ECOMPR_FL /* Compression error */
252 /* End compression flags --- maybe not all used */
253 #define OCFS2_BTREE_FL FS_BTREE_FL /* btree format dir */
254 #define OCFS2_INDEX_FL FS_INDEX_FL /* hash-indexed directory */
255 #define OCFS2_IMAGIC_FL FS_IMAGIC_FL /* AFS directory */
256 #define OCFS2_JOURNAL_DATA_FL FS_JOURNAL_DATA_FL /* Reserved for ext3 */
257 #define OCFS2_NOTAIL_FL FS_NOTAIL_FL /* file tail should not be merged */
258 #define OCFS2_DIRSYNC_FL FS_DIRSYNC_FL /* dirsync behaviour (directories only) */
259 #define OCFS2_TOPDIR_FL FS_TOPDIR_FL /* Top of directory hierarchies*/
260 #define OCFS2_RESERVED_FL FS_RESERVED_FL /* reserved for ext2 lib */
261
262 #define OCFS2_FL_VISIBLE FS_FL_USER_VISIBLE /* User visible flags */
263 #define OCFS2_FL_MODIFIABLE FS_FL_USER_MODIFIABLE /* User modifiable flags */
264
265 /*
266 * Extent record flags (e_node.leaf.flags)
267 */
268 #define OCFS2_EXT_UNWRITTEN (0x01) /* Extent is allocated but
269 * unwritten */
270 #define OCFS2_EXT_REFCOUNTED (0x02) /* Extent is reference
271 * counted in an associated
272 * refcount tree */
273
274 /*
275 * Journal Flags (ocfs2_dinode.id1.journal1.i_flags)
276 */
277 #define OCFS2_JOURNAL_DIRTY_FL (0x00000001) /* Journal needs recovery */
278
279 /*
280 * superblock s_state flags
281 */
282 #define OCFS2_ERROR_FS (0x00000001) /* FS saw errors */
283
284 /* Limit of space in ocfs2_dir_entry */
285 #define OCFS2_MAX_FILENAME_LEN 255
286
287 /* Maximum slots on an ocfs2 file system */
288 #define OCFS2_MAX_SLOTS 255
289
290 /* Slot map indicator for an empty slot */
291 #define OCFS2_INVALID_SLOT ((u16)-1)
292
293 #define OCFS2_VOL_UUID_LEN 16
294 #define OCFS2_MAX_VOL_LABEL_LEN 64
295
296 /* The cluster stack fields */
297 #define OCFS2_STACK_LABEL_LEN 4
298 #define OCFS2_CLUSTER_NAME_LEN 16
299
300 /* Classic (historically speaking) cluster stack */
301 #define OCFS2_CLASSIC_CLUSTER_STACK "o2cb"
302
303 /* Journal limits (in bytes) */
304 #define OCFS2_MIN_JOURNAL_SIZE (4 * 1024 * 1024)
305
306 /*
307 * Inline extended attribute size (in bytes)
308 * The value chosen should be aligned to 16 byte boundaries.
309 */
310 #define OCFS2_MIN_XATTR_INLINE_SIZE 256
311
312 /*
313 * Cluster info flags (ocfs2_cluster_info.ci_stackflags)
314 */
315 #define OCFS2_CLUSTER_O2CB_GLOBAL_HEARTBEAT (0x01)
316
317 struct ocfs2_system_inode_info {
318 char *si_name;
319 int si_iflags;
320 int si_mode;
321 };
322
323 /* System file index */
324 enum {
325 BAD_BLOCK_SYSTEM_INODE = 0,
326 GLOBAL_INODE_ALLOC_SYSTEM_INODE,
327 #define OCFS2_FIRST_ONLINE_SYSTEM_INODE GLOBAL_INODE_ALLOC_SYSTEM_INODE
328 SLOT_MAP_SYSTEM_INODE,
329 HEARTBEAT_SYSTEM_INODE,
330 GLOBAL_BITMAP_SYSTEM_INODE,
331 USER_QUOTA_SYSTEM_INODE,
332 GROUP_QUOTA_SYSTEM_INODE,
333 #define OCFS2_LAST_GLOBAL_SYSTEM_INODE GROUP_QUOTA_SYSTEM_INODE
334 #define OCFS2_FIRST_LOCAL_SYSTEM_INODE ORPHAN_DIR_SYSTEM_INODE
335 ORPHAN_DIR_SYSTEM_INODE,
336 EXTENT_ALLOC_SYSTEM_INODE,
337 INODE_ALLOC_SYSTEM_INODE,
338 JOURNAL_SYSTEM_INODE,
339 LOCAL_ALLOC_SYSTEM_INODE,
340 TRUNCATE_LOG_SYSTEM_INODE,
341 LOCAL_USER_QUOTA_SYSTEM_INODE,
342 LOCAL_GROUP_QUOTA_SYSTEM_INODE,
343 #define OCFS2_LAST_LOCAL_SYSTEM_INODE LOCAL_GROUP_QUOTA_SYSTEM_INODE
344 NUM_SYSTEM_INODES
345 };
346 #define NUM_GLOBAL_SYSTEM_INODES OCFS2_FIRST_LOCAL_SYSTEM_INODE
347 #define NUM_LOCAL_SYSTEM_INODES \
348 (NUM_SYSTEM_INODES - OCFS2_FIRST_LOCAL_SYSTEM_INODE)
349
350 static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = {
351 /* Global system inodes (single copy) */
352 /* The first two are only used from userspace mfks/tunefs */
353 [BAD_BLOCK_SYSTEM_INODE] = { "bad_blocks", 0, S_IFREG | 0644 },
354 [GLOBAL_INODE_ALLOC_SYSTEM_INODE] = { "global_inode_alloc", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
355
356 /* These are used by the running filesystem */
357 [SLOT_MAP_SYSTEM_INODE] = { "slot_map", 0, S_IFREG | 0644 },
358 [HEARTBEAT_SYSTEM_INODE] = { "heartbeat", OCFS2_HEARTBEAT_FL, S_IFREG | 0644 },
359 [GLOBAL_BITMAP_SYSTEM_INODE] = { "global_bitmap", 0, S_IFREG | 0644 },
360 [USER_QUOTA_SYSTEM_INODE] = { "aquota.user", OCFS2_QUOTA_FL, S_IFREG | 0644 },
361 [GROUP_QUOTA_SYSTEM_INODE] = { "aquota.group", OCFS2_QUOTA_FL, S_IFREG | 0644 },
362
363 /* Slot-specific system inodes (one copy per slot) */
364 [ORPHAN_DIR_SYSTEM_INODE] = { "orphan_dir:%04d", 0, S_IFDIR | 0755 },
365 [EXTENT_ALLOC_SYSTEM_INODE] = { "extent_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
366 [INODE_ALLOC_SYSTEM_INODE] = { "inode_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
367 [JOURNAL_SYSTEM_INODE] = { "journal:%04d", OCFS2_JOURNAL_FL, S_IFREG | 0644 },
368 [LOCAL_ALLOC_SYSTEM_INODE] = { "local_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_LOCAL_ALLOC_FL, S_IFREG | 0644 },
369 [TRUNCATE_LOG_SYSTEM_INODE] = { "truncate_log:%04d", OCFS2_DEALLOC_FL, S_IFREG | 0644 },
370 [LOCAL_USER_QUOTA_SYSTEM_INODE] = { "aquota.user:%04d", OCFS2_QUOTA_FL, S_IFREG | 0644 },
371 [LOCAL_GROUP_QUOTA_SYSTEM_INODE] = { "aquota.group:%04d", OCFS2_QUOTA_FL, S_IFREG | 0644 },
372 };
373
374 /* Parameter passed from mount.ocfs2 to module */
375 #define OCFS2_HB_NONE "heartbeat=none"
376 #define OCFS2_HB_LOCAL "heartbeat=local"
377 #define OCFS2_HB_GLOBAL "heartbeat=global"
378
379 /*
380 * OCFS2_DIR_PAD defines the directory entries boundaries
381 *
382 * NOTE: It must be a multiple of 4
383 */
384 #define OCFS2_DIR_PAD 4
385 #define OCFS2_DIR_ROUND (OCFS2_DIR_PAD - 1)
386 #define OCFS2_DIR_MEMBER_LEN offsetof(struct ocfs2_dir_entry, name)
387 #define OCFS2_DIR_REC_LEN(name_len) (((name_len) + OCFS2_DIR_MEMBER_LEN + \
388 OCFS2_DIR_ROUND) & \
389 ~OCFS2_DIR_ROUND)
390 #define OCFS2_DIR_MIN_REC_LEN OCFS2_DIR_REC_LEN(1)
391
392 #define OCFS2_LINK_MAX 32000
393 #define OCFS2_DX_LINK_MAX ((1U << 31) - 1U)
394 #define OCFS2_LINKS_HI_SHIFT 16
395 #define OCFS2_DX_ENTRIES_MAX (0xffffffffU)
396
397
398 /*
399 * Convenience casts
400 */
401 #define OCFS2_RAW_SB(dinode) (&((dinode)->id2.i_super))
402
403 /*
404 * Block checking structure. This is used in metadata to validate the
405 * contents. If OCFS2_FEATURE_INCOMPAT_META_ECC is not set, it is all
406 * zeros.
407 */
408 struct ocfs2_block_check {
409 /*00*/ __le32 bc_crc32e; /* 802.3 Ethernet II CRC32 */
410 __le16 bc_ecc; /* Single-error-correction parity vector.
411 This is a simple Hamming code dependent
412 on the blocksize. OCFS2's maximum
413 blocksize, 4K, requires 16 parity bits,
414 so we fit in __le16. */
415 __le16 bc_reserved1;
416 /*08*/
417 };
418
419 /*
420 * On disk extent record for OCFS2
421 * It describes a range of clusters on disk.
422 *
423 * Length fields are divided into interior and leaf node versions.
424 * This leaves room for a flags field (OCFS2_EXT_*) in the leaf nodes.
425 */
426 struct ocfs2_extent_rec {
427 /*00*/ __le32 e_cpos; /* Offset into the file, in clusters */
428 union {
429 __le32 e_int_clusters; /* Clusters covered by all children */
430 struct {
431 __le16 e_leaf_clusters; /* Clusters covered by this
432 extent */
433 __u8 e_reserved1;
434 __u8 e_flags; /* Extent flags */
435 };
436 };
437 __le64 e_blkno; /* Physical disk offset, in blocks */
438 /*10*/
439 };
440
441 struct ocfs2_chain_rec {
442 __le32 c_free; /* Number of free bits in this chain. */
443 __le32 c_total; /* Number of total bits in this chain */
444 __le64 c_blkno; /* Physical disk offset (blocks) of 1st group */
445 };
446
447 struct ocfs2_truncate_rec {
448 __le32 t_start; /* 1st cluster in this log */
449 __le32 t_clusters; /* Number of total clusters covered */
450 };
451
452 /*
453 * On disk extent list for OCFS2 (node in the tree). Note that this
454 * is contained inside ocfs2_dinode or ocfs2_extent_block, so the
455 * offsets are relative to ocfs2_dinode.id2.i_list or
456 * ocfs2_extent_block.h_list, respectively.
457 */
458 struct ocfs2_extent_list {
459 /*00*/ __le16 l_tree_depth; /* Extent tree depth from this
460 point. 0 means data extents
461 hang directly off this
462 header (a leaf)
463 NOTE: The high 8 bits cannot be
464 used - tree_depth is never that big.
465 */
466 __le16 l_count; /* Number of extent records */
467 __le16 l_next_free_rec; /* Next unused extent slot */
468 __le16 l_reserved1;
469 __le64 l_reserved2; /* Pad to
470 sizeof(ocfs2_extent_rec) */
471 /* Extent records */
472 /*10*/ struct ocfs2_extent_rec l_recs[] __counted_by_le(l_count);
473 };
474
475 /*
476 * On disk allocation chain list for OCFS2. Note that this is
477 * contained inside ocfs2_dinode, so the offsets are relative to
478 * ocfs2_dinode.id2.i_chain.
479 */
480 struct ocfs2_chain_list {
481 /*00*/ __le16 cl_cpg; /* Clusters per Block Group */
482 __le16 cl_bpc; /* Bits per cluster */
483 __le16 cl_count; /* Total chains in this list */
484 __le16 cl_next_free_rec; /* Next unused chain slot */
485 __le64 cl_reserved1;
486 /* Chain records */
487 /*10*/ struct ocfs2_chain_rec cl_recs[] __counted_by_le(cl_count);
488 };
489
490 /*
491 * On disk deallocation log for OCFS2. Note that this is
492 * contained inside ocfs2_dinode, so the offsets are relative to
493 * ocfs2_dinode.id2.i_dealloc.
494 */
495 struct ocfs2_truncate_log {
496 /*00*/ __le16 tl_count; /* Total records in this log */
497 __le16 tl_used; /* Number of records in use */
498 __le32 tl_reserved1;
499 /* Truncate records */
500 /*08*/ struct ocfs2_truncate_rec tl_recs[] __counted_by_le(tl_count);
501 };
502
503 /*
504 * On disk extent block (indirect block) for OCFS2
505 */
506 struct ocfs2_extent_block
507 {
508 /*00*/ __u8 h_signature[8]; /* Signature for verification */
509 struct ocfs2_block_check h_check; /* Error checking */
510 /*10*/ __le16 h_suballoc_slot; /* Slot suballocator this
511 extent_header belongs to */
512 __le16 h_suballoc_bit; /* Bit offset in suballocator
513 block group */
514 __le32 h_fs_generation; /* Must match super block */
515 __le64 h_blkno; /* Offset on disk, in blocks */
516 /*20*/ __le64 h_suballoc_loc; /* Suballocator block group this
517 eb belongs to. Only valid
518 if allocated from a
519 discontiguous block group */
520 __le64 h_next_leaf_blk; /* Offset on disk, in blocks,
521 of next leaf header pointing
522 to data */
523 /*30*/ struct ocfs2_extent_list h_list; /* Extent record list */
524 /* Actual on-disk size is one block */
525 };
526
527 /*
528 * On disk slot map for OCFS2. This defines the contents of the "slot_map"
529 * system file. A slot is valid if it contains a node number >= 0. The
530 * value -1 (0xFFFF) is OCFS2_INVALID_SLOT. This marks a slot empty.
531 */
532 struct ocfs2_slot_map {
533 /*00*/ DECLARE_FLEX_ARRAY(__le16, sm_slots);
534 /*
535 * Actual on-disk size is one block. OCFS2_MAX_SLOTS is 255,
536 * 255 * sizeof(__le16) == 512B, within the 512B block minimum blocksize.
537 */
538 };
539
540 struct ocfs2_extended_slot {
541 /*00*/ __u8 es_valid;
542 __u8 es_reserved1[3];
543 __le32 es_node_num;
544 /*08*/
545 };
546
547 /*
548 * The extended slot map, used when OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP
549 * is set. It separates out the valid marker from the node number, and
550 * has room to grow. Unlike the old slot map, this format is defined by
551 * i_size.
552 */
553 struct ocfs2_slot_map_extended {
554 /*00*/ DECLARE_FLEX_ARRAY(struct ocfs2_extended_slot, se_slots);
555 /*
556 * Actual size is i_size of the slot_map system file. It should
557 * match s_max_slots * sizeof(struct ocfs2_extended_slot)
558 */
559 };
560
561 /*
562 * ci_stackflags is only valid if the incompat bit
563 * OCFS2_FEATURE_INCOMPAT_CLUSTERINFO is set.
564 */
565 struct ocfs2_cluster_info {
566 /*00*/ __u8 ci_stack[OCFS2_STACK_LABEL_LEN];
567 union {
568 __le32 ci_reserved;
569 struct {
570 __u8 ci_stackflags;
571 __u8 ci_reserved1;
572 __u8 ci_reserved2;
573 __u8 ci_reserved3;
574 };
575 };
576 /*08*/ __u8 ci_cluster[OCFS2_CLUSTER_NAME_LEN];
577 /*18*/
578 };
579
580 /*
581 * On disk superblock for OCFS2
582 * Note that it is contained inside an ocfs2_dinode, so all offsets
583 * are relative to the start of ocfs2_dinode.id2.
584 */
585 struct ocfs2_super_block {
586 /*00*/ __le16 s_major_rev_level;
587 __le16 s_minor_rev_level;
588 __le16 s_mnt_count;
589 __le16 s_max_mnt_count;
590 __le16 s_state; /* File system state */
591 __le16 s_errors; /* Behaviour when detecting errors */
592 __le32 s_checkinterval; /* Max time between checks */
593 /*10*/ __le64 s_lastcheck; /* Time of last check */
594 __le32 s_creator_os; /* OS */
595 __le32 s_feature_compat; /* Compatible feature set */
596 /*20*/ __le32 s_feature_incompat; /* Incompatible feature set */
597 __le32 s_feature_ro_compat; /* Readonly-compatible feature set */
598 __le64 s_root_blkno; /* Offset, in blocks, of root directory
599 dinode */
600 /*30*/ __le64 s_system_dir_blkno; /* Offset, in blocks, of system
601 directory dinode */
602 __le32 s_blocksize_bits; /* Blocksize for this fs */
603 __le32 s_clustersize_bits; /* Clustersize for this fs */
604 /*40*/ __le16 s_max_slots; /* Max number of simultaneous mounts
605 before tunefs required */
606 __le16 s_tunefs_flag;
607 __le32 s_uuid_hash; /* hash value of uuid */
608 __le64 s_first_cluster_group; /* Block offset of 1st cluster
609 * group header */
610 /*50*/ __u8 s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */
611 /*90*/ __u8 s_uuid[OCFS2_VOL_UUID_LEN]; /* 128-bit uuid */
612 /*A0*/ struct ocfs2_cluster_info s_cluster_info; /* Only valid if either
613 userspace or clusterinfo
614 INCOMPAT flag set. */
615 /*B8*/ __le16 s_xattr_inline_size; /* extended attribute inline size
616 for this fs*/
617 __le16 s_reserved0;
618 __le32 s_dx_seed[3]; /* seed[0-2] for dx dir hash.
619 * s_uuid_hash serves as seed[3]. */
620 /*C8*/ __le64 s_reserved2[15]; /* Fill out superblock */
621 /*140*/
622
623 /*
624 * NOTE: As stated above, all offsets are relative to
625 * ocfs2_dinode.id2, which is at 0xC0 in the inode.
626 * 0xC0 + 0x140 = 0x200 or 512 bytes. A superblock must fit within
627 * our smallest blocksize, which is 512 bytes. To ensure this,
628 * we reserve the space in s_reserved2. Anything past s_reserved2
629 * will not be available on the smallest blocksize.
630 */
631 };
632
633 /*
634 * Local allocation bitmap for OCFS2 slots
635 * Note that it exists inside an ocfs2_dinode, so all offsets are
636 * relative to the start of ocfs2_dinode.id2.
637 */
638 struct ocfs2_local_alloc
639 {
640 /*00*/ __le32 la_bm_off; /* Starting bit offset in main bitmap */
641 __le16 la_size; /* Size of included bitmap, in bytes */
642 __le16 la_reserved1;
643 __le64 la_reserved2;
644 /*10*/ __u8 la_bitmap[];
645 };
646
647 /*
648 * Data-in-inode header. This is only used if i_dyn_features has
649 * OCFS2_INLINE_DATA_FL set.
650 */
651 struct ocfs2_inline_data
652 {
653 /*00*/ __le16 id_count; /* Number of bytes that can be used
654 * for data, starting at id_data */
655 __le16 id_reserved0;
656 __le32 id_reserved1;
657 __u8 id_data[]; /* Start of user data */
658 };
659
660 /*
661 * On disk inode for OCFS2
662 */
663 struct ocfs2_dinode {
664 /*00*/ __u8 i_signature[8]; /* Signature for validation */
665 __le32 i_generation; /* Generation number */
666 __le16 i_suballoc_slot; /* Slot suballocator this inode
667 belongs to */
668 __le16 i_suballoc_bit; /* Bit offset in suballocator
669 block group */
670 /*10*/ __le16 i_links_count_hi; /* High 16 bits of links count */
671 __le16 i_xattr_inline_size;
672 __le32 i_clusters; /* Cluster count */
673 __le32 i_uid; /* Owner UID */
674 __le32 i_gid; /* Owning GID */
675 /*20*/ __le64 i_size; /* Size in bytes */
676 __le16 i_mode; /* File mode */
677 __le16 i_links_count; /* Links count */
678 __le32 i_flags; /* File flags */
679 /*30*/ __le64 i_atime; /* Access time */
680 __le64 i_ctime; /* Creation time */
681 /*40*/ __le64 i_mtime; /* Modification time */
682 __le64 i_dtime; /* Deletion time */
683 /*50*/ __le64 i_blkno; /* Offset on disk, in blocks */
684 __le64 i_last_eb_blk; /* Pointer to last extent
685 block */
686 /*60*/ __le32 i_fs_generation; /* Generation per fs-instance */
687 __le32 i_atime_nsec;
688 __le32 i_ctime_nsec;
689 __le32 i_mtime_nsec;
690 /*70*/ __le32 i_attr;
691 __le16 i_orphaned_slot; /* Only valid when OCFS2_ORPHANED_FL
692 was set in i_flags */
693 __le16 i_dyn_features;
694 __le64 i_xattr_loc;
695 /*80*/ struct ocfs2_block_check i_check; /* Error checking */
696 /*88*/ __le64 i_dx_root; /* Pointer to dir index root block */
697 /*90*/ __le64 i_refcount_loc;
698 __le64 i_suballoc_loc; /* Suballocator block group this
699 inode belongs to. Only valid
700 if allocated from a
701 discontiguous block group */
702 /*A0*/ __le16 i_dio_orphaned_slot; /* only used for append dio write */
703 __le16 i_reserved1[3];
704 __le64 i_reserved2[2];
705 /*B8*/ union {
706 __le64 i_pad1; /* Generic way to refer to this
707 64bit union */
708 struct {
709 __le64 i_rdev; /* Device number */
710 } dev1;
711 struct { /* Info for bitmap system
712 inodes */
713 __le32 i_used; /* Bits (ie, clusters) used */
714 __le32 i_total; /* Total bits (clusters)
715 available */
716 } bitmap1;
717 struct { /* Info for journal system
718 inodes */
719 __le32 ij_flags; /* Mounted, version, etc. */
720 __le32 ij_recovery_generation; /* Incremented when the
721 journal is recovered
722 after an unclean
723 shutdown */
724 } journal1;
725 } id1; /* Inode type dependent 1 */
726 /*C0*/ union {
727 struct ocfs2_super_block i_super;
728 struct ocfs2_local_alloc i_lab;
729 struct ocfs2_chain_list i_chain;
730 struct ocfs2_extent_list i_list;
731 struct ocfs2_truncate_log i_dealloc;
732 struct ocfs2_inline_data i_data;
733 DECLARE_FLEX_ARRAY(__u8, i_symlink);
734 } id2;
735 /* Actual on-disk size is one block */
736 };
737
738 /*
739 * On-disk directory entry structure for OCFS2
740 *
741 * Packed as this structure could be accessed unaligned on 64-bit platforms
742 */
743 struct ocfs2_dir_entry {
744 /*00*/ __le64 inode; /* Inode number */
745 __le16 rec_len; /* Directory entry length */
746 __u8 name_len; /* Name length */
747 __u8 file_type;
748 /*0C*/ char name[OCFS2_MAX_FILENAME_LEN]; /* File name */
749 /* Actual on-disk length specified by rec_len */
750 } __attribute__ ((packed));
751
752 /*
753 * Per-block record for the unindexed directory btree. This is carefully
754 * crafted so that the rec_len and name_len records of an ocfs2_dir_entry are
755 * mirrored. That way, the directory manipulation code needs a minimal amount
756 * of update.
757 *
758 * NOTE: Keep this structure aligned to a multiple of 4 bytes.
759 */
760 struct ocfs2_dir_block_trailer {
761 /*00*/ __le64 db_compat_inode; /* Always zero. Was inode */
762
763 __le16 db_compat_rec_len; /* Backwards compatible with
764 * ocfs2_dir_entry. */
765 __u8 db_compat_name_len; /* Always zero. Was name_len */
766 __u8 db_reserved0;
767 __le16 db_reserved1;
768 __le16 db_free_rec_len; /* Size of largest empty hole
769 * in this block. (unused) */
770 /*10*/ __u8 db_signature[8]; /* Signature for verification */
771 __le64 db_reserved2;
772 /*20*/ __le64 db_free_next; /* Next block in list (unused) */
773 __le64 db_blkno; /* Offset on disk, in blocks */
774 /*30*/ __le64 db_parent_dinode; /* dinode which owns me, in
775 blocks */
776 struct ocfs2_block_check db_check; /* Error checking */
777 /*40*/
778 };
779
780 /*
781 * A directory entry in the indexed tree. We don't store the full name here,
782 * but instead provide a pointer to the full dirent in the unindexed tree.
783 *
784 * We also store name_len here so as to reduce the number of leaf blocks we
785 * need to search in case of collisions.
786 */
787 struct ocfs2_dx_entry {
788 __le32 dx_major_hash; /* Used to find logical
789 * cluster in index */
790 __le32 dx_minor_hash; /* Lower bits used to find
791 * block in cluster */
792 __le64 dx_dirent_blk; /* Physical block in unindexed
793 * tree holding this dirent. */
794 };
795
796 struct ocfs2_dx_entry_list {
797 __le32 de_reserved;
798 __le16 de_count; /* Maximum number of entries
799 * possible in de_entries */
800 __le16 de_num_used; /* Current number of
801 * de_entries entries */
802 /* Indexed dir entries in a packed
803 * array of length de_num_used.
804 */
805 struct ocfs2_dx_entry de_entries[] __counted_by_le(de_count);
806 };
807
808 #define OCFS2_DX_FLAG_INLINE 0x01
809
810 /*
811 * A directory indexing block. Each indexed directory has one of these,
812 * pointed to by ocfs2_dinode.
813 *
814 * This block stores an indexed btree root, and a set of free space
815 * start-of-list pointers.
816 */
817 struct ocfs2_dx_root_block {
818 __u8 dr_signature[8]; /* Signature for verification */
819 struct ocfs2_block_check dr_check; /* Error checking */
820 __le16 dr_suballoc_slot; /* Slot suballocator this
821 * block belongs to. */
822 __le16 dr_suballoc_bit; /* Bit offset in suballocator
823 * block group */
824 __le32 dr_fs_generation; /* Must match super block */
825 __le64 dr_blkno; /* Offset on disk, in blocks */
826 __le64 dr_last_eb_blk; /* Pointer to last
827 * extent block */
828 __le32 dr_clusters; /* Clusters allocated
829 * to the indexed tree. */
830 __u8 dr_flags; /* OCFS2_DX_FLAG_* flags */
831 __u8 dr_reserved0;
832 __le16 dr_reserved1;
833 __le64 dr_dir_blkno; /* Pointer to parent inode */
834 __le32 dr_num_entries; /* Total number of
835 * names stored in
836 * this directory.*/
837 __le32 dr_reserved2;
838 __le64 dr_free_blk; /* Pointer to head of free
839 * unindexed block list. */
840 __le64 dr_suballoc_loc; /* Suballocator block group
841 this root belongs to.
842 Only valid if allocated
843 from a discontiguous
844 block group */
845 __le64 dr_reserved3[14];
846 union {
847 struct ocfs2_extent_list dr_list; /* Keep this aligned to 128
848 * bits for maximum space
849 * efficiency. */
850 struct ocfs2_dx_entry_list dr_entries; /* In-root-block list of
851 * entries. We grow out
852 * to extents if this
853 * gets too big. */
854 };
855 };
856
857 /*
858 * The header of a leaf block in the indexed tree.
859 */
860 struct ocfs2_dx_leaf {
861 __u8 dl_signature[8];/* Signature for verification */
862 struct ocfs2_block_check dl_check; /* Error checking */
863 __le64 dl_blkno; /* Offset on disk, in blocks */
864 __le32 dl_fs_generation;/* Must match super block */
865 __le32 dl_reserved0;
866 __le64 dl_reserved1;
867 struct ocfs2_dx_entry_list dl_list;
868 };
869
870 /*
871 * Largest bitmap for a block (suballocator) group in bytes. This limit
872 * does not affect cluster groups (global allocator). Cluster group
873 * bitmaps run to the end of the block.
874 */
875 #define OCFS2_MAX_BG_BITMAP_SIZE 256
876
877 /*
878 * On disk allocator group structure for OCFS2
879 */
880 struct ocfs2_group_desc
881 {
882 /*00*/ __u8 bg_signature[8]; /* Signature for validation */
883 __le16 bg_size; /* Size of included bitmap in
884 bytes. */
885 __le16 bg_bits; /* Bits represented by this
886 group. */
887 __le16 bg_free_bits_count; /* Free bits count */
888 __le16 bg_chain; /* What chain I am in. */
889 /*10*/ __le32 bg_generation;
890 __le16 bg_contig_free_bits; /* max contig free bits length */
891 __le16 bg_reserved1;
892 __le64 bg_next_group; /* Next group in my list, in
893 blocks */
894 /*20*/ __le64 bg_parent_dinode; /* dinode which owns me, in
895 blocks */
896 __le64 bg_blkno; /* Offset on disk, in blocks */
897 /*30*/ struct ocfs2_block_check bg_check; /* Error checking */
898 __le64 bg_reserved2;
899 /*40*/ union {
900 DECLARE_FLEX_ARRAY(__u8, bg_bitmap);
901 struct {
902 /*
903 * Block groups may be discontiguous when
904 * OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG is set.
905 * The extents of a discontiguous block group are
906 * stored in bg_list. It is a flat list.
907 * l_tree_depth must always be zero. A
908 * discontiguous group is signified by a non-zero
909 * bg_list->l_next_free_rec. Only block groups
910 * can be discontiguous; Cluster groups cannot.
911 * We've never made a block group with more than
912 * 2048 blocks (256 bytes of bg_bitmap). This
913 * codifies that limit so that we can fit bg_list.
914 * bg_size of a discontiguous block group will
915 * be 256 to match bg_bitmap_filler.
916 */
917 __u8 bg_bitmap_filler[OCFS2_MAX_BG_BITMAP_SIZE];
918 /*140*/ struct ocfs2_extent_list bg_list;
919 };
920 };
921 /* Actual on-disk size is one block */
922 };
923
924 struct ocfs2_refcount_rec {
925 /*00*/ __le64 r_cpos; /* Physical offset, in clusters */
926 __le32 r_clusters; /* Clusters covered by this extent */
927 __le32 r_refcount; /* Reference count of this extent */
928 /*10*/
929 };
930 #define OCFS2_32BIT_POS_MASK (0xffffffffULL)
931
932 #define OCFS2_REFCOUNT_LEAF_FL (0x00000001)
933 #define OCFS2_REFCOUNT_TREE_FL (0x00000002)
934
935 struct ocfs2_refcount_list {
936 /*00*/ __le16 rl_count; /* Maximum number of entries possible
937 in rl_records */
938 __le16 rl_used; /* Current number of used records */
939 __le32 rl_reserved2;
940 __le64 rl_reserved1; /* Pad to sizeof(ocfs2_refcount_record) */
941 /* Refcount records */
942 /*10*/ struct ocfs2_refcount_rec rl_recs[] __counted_by_le(rl_count);
943 };
944
945
946 struct ocfs2_refcount_block {
947 /*00*/ __u8 rf_signature[8]; /* Signature for verification */
948 __le16 rf_suballoc_slot; /* Slot suballocator this block
949 belongs to */
950 __le16 rf_suballoc_bit; /* Bit offset in suballocator
951 block group */
952 __le32 rf_fs_generation; /* Must match superblock */
953 /*10*/ __le64 rf_blkno; /* Offset on disk, in blocks */
954 __le64 rf_parent; /* Parent block, only valid if
955 OCFS2_REFCOUNT_LEAF_FL is set in
956 rf_flags */
957 /*20*/ struct ocfs2_block_check rf_check; /* Error checking */
958 __le64 rf_last_eb_blk; /* Pointer to last extent block */
959 /*30*/ __le32 rf_count; /* Number of inodes sharing this
960 refcount tree */
961 __le32 rf_flags; /* See the flags above */
962 __le32 rf_clusters; /* clusters covered by refcount tree. */
963 __le32 rf_cpos; /* cluster offset in refcount tree.*/
964 /*40*/ __le32 rf_generation; /* generation number. all be the same
965 * for the same refcount tree. */
966 __le32 rf_reserved0;
967 __le64 rf_suballoc_loc; /* Suballocator block group this
968 refcount block belongs to. Only
969 valid if allocated from a
970 discontiguous block group */
971 /*50*/ __le64 rf_reserved1[6];
972 /*80*/ union {
973 struct ocfs2_refcount_list rf_records; /* List of refcount
974 records */
975 struct ocfs2_extent_list rf_list; /* Extent record list,
976 only valid if
977 OCFS2_REFCOUNT_TREE_FL
978 is set in rf_flags */
979 };
980 /* Actual on-disk size is one block */
981 };
982
983 /*
984 * On disk extended attribute structure for OCFS2.
985 */
986
987 /*
988 * ocfs2_xattr_entry indicates one extend attribute.
989 *
990 * Note that it can be stored in inode, one block or one xattr bucket.
991 */
992 struct ocfs2_xattr_entry {
993 __le32 xe_name_hash; /* hash value of xattr prefix+suffix. */
994 __le16 xe_name_offset; /* byte offset from the 1st entry in the
995 local xattr storage(inode, xattr block or
996 xattr bucket). */
997 __u8 xe_name_len; /* xattr name len, doesn't include prefix. */
998 __u8 xe_type; /* the low 7 bits indicate the name prefix
999 * type and the highest bit indicates whether
1000 * the EA is stored in the local storage. */
1001 __le64 xe_value_size; /* real xattr value length. */
1002 };
1003
1004 /*
1005 * On disk structure for xattr header.
1006 *
1007 * One ocfs2_xattr_header describes how many ocfs2_xattr_entry records in
1008 * the local xattr storage.
1009 */
1010 struct ocfs2_xattr_header {
1011 __le16 xh_count; /* contains the count of how
1012 many records are in the
1013 local xattr storage. */
1014 __le16 xh_free_start; /* current offset for storing
1015 xattr. */
1016 __le16 xh_name_value_len; /* total length of name/value
1017 length in this bucket. */
1018 __le16 xh_num_buckets; /* Number of xattr buckets
1019 in this extent record,
1020 only valid in the first
1021 bucket. */
1022 struct ocfs2_block_check xh_check; /* Error checking
1023 (Note, this is only
1024 used for xattr
1025 buckets. A block uses
1026 xb_check and sets
1027 this field to zero.) */
1028 /* xattr entry list. */
1029 struct ocfs2_xattr_entry xh_entries[] __counted_by_le(xh_count);
1030 };
1031
1032 /*
1033 * On disk structure for xattr value root.
1034 *
1035 * When an xattr's value is large enough, it is stored in an external
1036 * b-tree like file data. The xattr value root points to this structure.
1037 */
1038 struct ocfs2_xattr_value_root {
1039 /*00*/ __le32 xr_clusters; /* clusters covered by xattr value. */
1040 __le32 xr_reserved0;
1041 __le64 xr_last_eb_blk; /* Pointer to last extent block */
1042 /*10*/ struct ocfs2_extent_list xr_list; /* Extent record list */
1043 };
1044
1045 /*
1046 * On disk structure for xattr tree root.
1047 *
1048 * It is used when there are too many extended attributes for one file. These
1049 * attributes will be organized and stored in an indexed-btree.
1050 */
1051 struct ocfs2_xattr_tree_root {
1052 /*00*/ __le32 xt_clusters; /* clusters covered by xattr. */
1053 __le32 xt_reserved0;
1054 __le64 xt_last_eb_blk; /* Pointer to last extent block */
1055 /*10*/ struct ocfs2_extent_list xt_list; /* Extent record list */
1056 };
1057
1058 #define OCFS2_XATTR_INDEXED 0x1
1059 #define OCFS2_HASH_SHIFT 5
1060 #define OCFS2_XATTR_ROUND 3
1061 #define OCFS2_XATTR_SIZE(size) (((size) + OCFS2_XATTR_ROUND) & \
1062 ~(OCFS2_XATTR_ROUND))
1063
1064 #define OCFS2_XATTR_BUCKET_SIZE 4096
1065 #define OCFS2_XATTR_MAX_BLOCKS_PER_BUCKET (OCFS2_XATTR_BUCKET_SIZE \
1066 / OCFS2_MIN_BLOCKSIZE)
1067
1068 /*
1069 * On disk structure for xattr block.
1070 */
1071 struct ocfs2_xattr_block {
1072 /*00*/ __u8 xb_signature[8]; /* Signature for verification */
1073 __le16 xb_suballoc_slot; /* Slot suballocator this
1074 block belongs to. */
1075 __le16 xb_suballoc_bit; /* Bit offset in suballocator
1076 block group */
1077 __le32 xb_fs_generation; /* Must match super block */
1078 /*10*/ __le64 xb_blkno; /* Offset on disk, in blocks */
1079 struct ocfs2_block_check xb_check; /* Error checking */
1080 /*20*/ __le16 xb_flags; /* Indicates whether this block contains
1081 real xattr or a xattr tree. */
1082 __le16 xb_reserved0;
1083 __le32 xb_reserved1;
1084 __le64 xb_suballoc_loc; /* Suballocator block group this
1085 xattr block belongs to. Only
1086 valid if allocated from a
1087 discontiguous block group */
1088 /*30*/ union {
1089 struct ocfs2_xattr_header xb_header; /* xattr header if this
1090 block contains xattr */
1091 struct ocfs2_xattr_tree_root xb_root;/* xattr tree root if this
1092 block contains xattr
1093 tree. */
1094 } xb_attrs;
1095 };
1096
1097 #define OCFS2_XATTR_ENTRY_LOCAL 0x80
1098 #define OCFS2_XATTR_TYPE_MASK 0x7F
ocfs2_xattr_set_local(struct ocfs2_xattr_entry * xe,int local)1099 static inline void ocfs2_xattr_set_local(struct ocfs2_xattr_entry *xe,
1100 int local)
1101 {
1102 if (local)
1103 xe->xe_type |= OCFS2_XATTR_ENTRY_LOCAL;
1104 else
1105 xe->xe_type &= ~OCFS2_XATTR_ENTRY_LOCAL;
1106 }
1107
ocfs2_xattr_is_local(struct ocfs2_xattr_entry * xe)1108 static inline int ocfs2_xattr_is_local(struct ocfs2_xattr_entry *xe)
1109 {
1110 return xe->xe_type & OCFS2_XATTR_ENTRY_LOCAL;
1111 }
1112
ocfs2_xattr_set_type(struct ocfs2_xattr_entry * xe,int type)1113 static inline void ocfs2_xattr_set_type(struct ocfs2_xattr_entry *xe, int type)
1114 {
1115 xe->xe_type |= type & OCFS2_XATTR_TYPE_MASK;
1116 }
1117
ocfs2_xattr_get_type(struct ocfs2_xattr_entry * xe)1118 static inline int ocfs2_xattr_get_type(struct ocfs2_xattr_entry *xe)
1119 {
1120 return xe->xe_type & OCFS2_XATTR_TYPE_MASK;
1121 }
1122
1123 /*
1124 * On disk structures for global quota file
1125 */
1126
1127 /* Magic numbers and known versions for global quota files */
1128 #define OCFS2_GLOBAL_QMAGICS {\
1129 0x0cf52470, /* USRQUOTA */ \
1130 0x0cf52471 /* GRPQUOTA */ \
1131 }
1132
1133 #define OCFS2_GLOBAL_QVERSIONS {\
1134 0, \
1135 0, \
1136 }
1137
1138
1139 /* Each block of each quota file has a certain fixed number of bytes reserved
1140 * for OCFS2 internal use at its end. OCFS2 can use it for things like
1141 * checksums, etc. */
1142 #define OCFS2_QBLK_RESERVED_SPACE 8
1143
1144 /* Generic header of all quota files */
1145 struct ocfs2_disk_dqheader {
1146 __le32 dqh_magic; /* Magic number identifying file */
1147 __le32 dqh_version; /* Quota format version */
1148 };
1149
1150 #define OCFS2_GLOBAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
1151
1152 /* Information header of global quota file (immediately follows the generic
1153 * header) */
1154 struct ocfs2_global_disk_dqinfo {
1155 /*00*/ __le32 dqi_bgrace; /* Grace time for space softlimit excess */
1156 __le32 dqi_igrace; /* Grace time for inode softlimit excess */
1157 __le32 dqi_syncms; /* Time after which we sync local changes to
1158 * global quota file */
1159 __le32 dqi_blocks; /* Number of blocks in quota file */
1160 /*10*/ __le32 dqi_free_blk; /* First free block in quota file */
1161 __le32 dqi_free_entry; /* First block with free dquot entry in quota
1162 * file */
1163 };
1164
1165 /* Structure with global user / group information. We reserve some space
1166 * for future use. */
1167 struct ocfs2_global_disk_dqblk {
1168 /*00*/ __le32 dqb_id; /* ID the structure belongs to */
1169 __le32 dqb_use_count; /* Number of nodes having reference to this structure */
1170 __le64 dqb_ihardlimit; /* absolute limit on allocated inodes */
1171 /*10*/ __le64 dqb_isoftlimit; /* preferred inode limit */
1172 __le64 dqb_curinodes; /* current # allocated inodes */
1173 /*20*/ __le64 dqb_bhardlimit; /* absolute limit on disk space */
1174 __le64 dqb_bsoftlimit; /* preferred limit on disk space */
1175 /*30*/ __le64 dqb_curspace; /* current space occupied */
1176 __le64 dqb_btime; /* time limit for excessive disk use */
1177 /*40*/ __le64 dqb_itime; /* time limit for excessive inode use */
1178 __le64 dqb_pad1;
1179 /*50*/ __le64 dqb_pad2;
1180 };
1181
1182 /*
1183 * On-disk structures for local quota file
1184 */
1185
1186 /* Magic numbers and known versions for local quota files */
1187 #define OCFS2_LOCAL_QMAGICS {\
1188 0x0cf524c0, /* USRQUOTA */ \
1189 0x0cf524c1 /* GRPQUOTA */ \
1190 }
1191
1192 #define OCFS2_LOCAL_QVERSIONS {\
1193 0, \
1194 0, \
1195 }
1196
1197 /* Quota flags in dqinfo header */
1198 #define OLQF_CLEAN 0x0001 /* Quota file is empty (this should be after\
1199 * quota has been cleanly turned off) */
1200
1201 #define OCFS2_LOCAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
1202
1203 /* Information header of local quota file (immediately follows the generic
1204 * header) */
1205 struct ocfs2_local_disk_dqinfo {
1206 __le32 dqi_flags; /* Flags for quota file */
1207 __le32 dqi_chunks; /* Number of chunks of quota structures
1208 * with a bitmap */
1209 __le32 dqi_blocks; /* Number of blocks allocated for quota file */
1210 };
1211
1212 /* Header of one chunk of a quota file */
1213 struct ocfs2_local_disk_chunk {
1214 __le32 dqc_free; /* Number of free entries in the bitmap */
1215 __u8 dqc_bitmap[]; /* Bitmap of entries in the corresponding
1216 * chunk of quota file */
1217 };
1218
1219 /* One entry in local quota file */
1220 struct ocfs2_local_disk_dqblk {
1221 /*00*/ __le64 dqb_id; /* id this quota applies to */
1222 __le64 dqb_spacemod; /* Change in the amount of used space */
1223 /*10*/ __le64 dqb_inodemod; /* Change in the amount of used inodes */
1224 };
1225
1226
1227 /*
1228 * The quota trailer lives at the end of each quota block.
1229 */
1230
1231 struct ocfs2_disk_dqtrailer {
1232 /*00*/ struct ocfs2_block_check dq_check; /* Error checking */
1233 /*08*/ /* Cannot be larger than OCFS2_QBLK_RESERVED_SPACE */
1234 };
1235
ocfs2_block_dqtrailer(int blocksize,void * buf)1236 static inline struct ocfs2_disk_dqtrailer *ocfs2_block_dqtrailer(int blocksize,
1237 void *buf)
1238 {
1239 char *ptr = buf;
1240 ptr += blocksize - OCFS2_QBLK_RESERVED_SPACE;
1241
1242 return (struct ocfs2_disk_dqtrailer *)ptr;
1243 }
1244
1245 #ifdef __KERNEL__
ocfs2_fast_symlink_chars(struct super_block * sb)1246 static inline int ocfs2_fast_symlink_chars(struct super_block *sb)
1247 {
1248 return sb->s_blocksize -
1249 offsetof(struct ocfs2_dinode, id2.i_symlink);
1250 }
1251
ocfs2_max_inline_data_with_xattr(struct super_block * sb,struct ocfs2_dinode * di)1252 static inline int ocfs2_max_inline_data_with_xattr(struct super_block *sb,
1253 struct ocfs2_dinode *di)
1254 {
1255 unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
1256
1257 if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
1258 return sb->s_blocksize -
1259 offsetof(struct ocfs2_dinode, id2.i_data.id_data) -
1260 xattrsize;
1261 else
1262 return sb->s_blocksize -
1263 offsetof(struct ocfs2_dinode, id2.i_data.id_data);
1264 }
1265
ocfs2_extent_recs_per_inode(struct super_block * sb)1266 static inline int ocfs2_extent_recs_per_inode(struct super_block *sb)
1267 {
1268 int size;
1269
1270 size = sb->s_blocksize -
1271 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1272
1273 return size / sizeof(struct ocfs2_extent_rec);
1274 }
1275
ocfs2_extent_recs_per_inode_with_xattr(struct super_block * sb,struct ocfs2_dinode * di)1276 static inline int ocfs2_extent_recs_per_inode_with_xattr(
1277 struct super_block *sb,
1278 struct ocfs2_dinode *di)
1279 {
1280 int size;
1281 unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size);
1282
1283 if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL)
1284 size = sb->s_blocksize -
1285 offsetof(struct ocfs2_dinode, id2.i_list.l_recs) -
1286 xattrsize;
1287 else
1288 size = sb->s_blocksize -
1289 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1290
1291 return size / sizeof(struct ocfs2_extent_rec);
1292 }
1293
ocfs2_extent_recs_per_dx_root(struct super_block * sb)1294 static inline int ocfs2_extent_recs_per_dx_root(struct super_block *sb)
1295 {
1296 int size;
1297
1298 size = sb->s_blocksize -
1299 offsetof(struct ocfs2_dx_root_block, dr_list.l_recs);
1300
1301 return size / sizeof(struct ocfs2_extent_rec);
1302 }
1303
ocfs2_chain_recs_per_inode(struct super_block * sb)1304 static inline int ocfs2_chain_recs_per_inode(struct super_block *sb)
1305 {
1306 int size;
1307
1308 size = sb->s_blocksize -
1309 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
1310
1311 return size / sizeof(struct ocfs2_chain_rec);
1312 }
1313
ocfs2_extent_recs_per_eb(struct super_block * sb)1314 static inline u16 ocfs2_extent_recs_per_eb(struct super_block *sb)
1315 {
1316 int size;
1317
1318 size = sb->s_blocksize -
1319 offsetof(struct ocfs2_extent_block, h_list.l_recs);
1320
1321 return size / sizeof(struct ocfs2_extent_rec);
1322 }
1323
ocfs2_extent_recs_per_gd(struct super_block * sb)1324 static inline u16 ocfs2_extent_recs_per_gd(struct super_block *sb)
1325 {
1326 int size;
1327
1328 size = sb->s_blocksize -
1329 offsetof(struct ocfs2_group_desc, bg_list.l_recs);
1330
1331 return size / sizeof(struct ocfs2_extent_rec);
1332 }
1333
ocfs2_dx_entries_per_leaf(struct super_block * sb)1334 static inline int ocfs2_dx_entries_per_leaf(struct super_block *sb)
1335 {
1336 int size;
1337
1338 size = sb->s_blocksize -
1339 offsetof(struct ocfs2_dx_leaf, dl_list.de_entries);
1340
1341 return size / sizeof(struct ocfs2_dx_entry);
1342 }
1343
ocfs2_dx_entries_per_root(struct super_block * sb)1344 static inline int ocfs2_dx_entries_per_root(struct super_block *sb)
1345 {
1346 int size;
1347
1348 size = sb->s_blocksize -
1349 offsetof(struct ocfs2_dx_root_block, dr_entries.de_entries);
1350
1351 return size / sizeof(struct ocfs2_dx_entry);
1352 }
1353
ocfs2_local_alloc_size(struct super_block * sb)1354 static inline u16 ocfs2_local_alloc_size(struct super_block *sb)
1355 {
1356 u16 size;
1357
1358 size = sb->s_blocksize -
1359 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
1360
1361 return size;
1362 }
1363
ocfs2_group_bitmap_size(struct super_block * sb,int suballocator,u32 feature_incompat)1364 static inline int ocfs2_group_bitmap_size(struct super_block *sb,
1365 int suballocator,
1366 u32 feature_incompat)
1367 {
1368 int size = sb->s_blocksize -
1369 offsetof(struct ocfs2_group_desc, bg_bitmap);
1370
1371 /*
1372 * The cluster allocator uses the entire block. Suballocators have
1373 * never used more than OCFS2_MAX_BG_BITMAP_SIZE. Unfortunately, older
1374 * code expects bg_size set to the maximum. Thus we must keep
1375 * bg_size as-is unless discontig_bg is enabled.
1376 */
1377 if (suballocator &&
1378 (feature_incompat & OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG))
1379 size = OCFS2_MAX_BG_BITMAP_SIZE;
1380
1381 return size;
1382 }
1383
ocfs2_truncate_recs_per_inode(struct super_block * sb)1384 static inline int ocfs2_truncate_recs_per_inode(struct super_block *sb)
1385 {
1386 int size;
1387
1388 size = sb->s_blocksize -
1389 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
1390
1391 return size / sizeof(struct ocfs2_truncate_rec);
1392 }
1393
ocfs2_backup_super_blkno(struct super_block * sb,int index)1394 static inline u64 ocfs2_backup_super_blkno(struct super_block *sb, int index)
1395 {
1396 u64 offset = OCFS2_BACKUP_SB_START;
1397
1398 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
1399 offset <<= (2 * index);
1400 offset >>= sb->s_blocksize_bits;
1401 return offset;
1402 }
1403
1404 return 0;
1405
1406 }
1407
ocfs2_xattr_recs_per_xb(struct super_block * sb)1408 static inline u16 ocfs2_xattr_recs_per_xb(struct super_block *sb)
1409 {
1410 int size;
1411
1412 size = sb->s_blocksize -
1413 offsetof(struct ocfs2_xattr_block,
1414 xb_attrs.xb_root.xt_list.l_recs);
1415
1416 return size / sizeof(struct ocfs2_extent_rec);
1417 }
1418
ocfs2_extent_recs_per_rb(struct super_block * sb)1419 static inline u16 ocfs2_extent_recs_per_rb(struct super_block *sb)
1420 {
1421 int size;
1422
1423 size = sb->s_blocksize -
1424 offsetof(struct ocfs2_refcount_block, rf_list.l_recs);
1425
1426 return size / sizeof(struct ocfs2_extent_rec);
1427 }
1428
ocfs2_refcount_recs_per_rb(struct super_block * sb)1429 static inline u16 ocfs2_refcount_recs_per_rb(struct super_block *sb)
1430 {
1431 int size;
1432
1433 size = sb->s_blocksize -
1434 offsetof(struct ocfs2_refcount_block, rf_records.rl_recs);
1435
1436 return size / sizeof(struct ocfs2_refcount_rec);
1437 }
1438
1439 static inline u32
ocfs2_get_ref_rec_low_cpos(const struct ocfs2_refcount_rec * rec)1440 ocfs2_get_ref_rec_low_cpos(const struct ocfs2_refcount_rec *rec)
1441 {
1442 return le64_to_cpu(rec->r_cpos) & OCFS2_32BIT_POS_MASK;
1443 }
1444 #else
ocfs2_fast_symlink_chars(int blocksize)1445 static inline int ocfs2_fast_symlink_chars(int blocksize)
1446 {
1447 return blocksize - offsetof(struct ocfs2_dinode, id2.i_symlink);
1448 }
1449
ocfs2_max_inline_data_with_xattr(int blocksize,struct ocfs2_dinode * di)1450 static inline int ocfs2_max_inline_data_with_xattr(int blocksize,
1451 struct ocfs2_dinode *di)
1452 {
1453 if (di && (di->i_dyn_features & OCFS2_INLINE_XATTR_FL))
1454 return blocksize -
1455 offsetof(struct ocfs2_dinode, id2.i_data.id_data) -
1456 di->i_xattr_inline_size;
1457 else
1458 return blocksize -
1459 offsetof(struct ocfs2_dinode, id2.i_data.id_data);
1460 }
1461
ocfs2_extent_recs_per_inode(int blocksize)1462 static inline int ocfs2_extent_recs_per_inode(int blocksize)
1463 {
1464 int size;
1465
1466 size = blocksize -
1467 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
1468
1469 return size / sizeof(struct ocfs2_extent_rec);
1470 }
1471
ocfs2_chain_recs_per_inode(int blocksize)1472 static inline int ocfs2_chain_recs_per_inode(int blocksize)
1473 {
1474 int size;
1475
1476 size = blocksize -
1477 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
1478
1479 return size / sizeof(struct ocfs2_chain_rec);
1480 }
1481
ocfs2_extent_recs_per_eb(int blocksize)1482 static inline int ocfs2_extent_recs_per_eb(int blocksize)
1483 {
1484 int size;
1485
1486 size = blocksize -
1487 offsetof(struct ocfs2_extent_block, h_list.l_recs);
1488
1489 return size / sizeof(struct ocfs2_extent_rec);
1490 }
1491
ocfs2_extent_recs_per_gd(int blocksize)1492 static inline int ocfs2_extent_recs_per_gd(int blocksize)
1493 {
1494 int size;
1495
1496 size = blocksize -
1497 offsetof(struct ocfs2_group_desc, bg_list.l_recs);
1498
1499 return size / sizeof(struct ocfs2_extent_rec);
1500 }
1501
ocfs2_local_alloc_size(int blocksize)1502 static inline int ocfs2_local_alloc_size(int blocksize)
1503 {
1504 int size;
1505
1506 size = blocksize -
1507 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
1508
1509 return size;
1510 }
1511
ocfs2_group_bitmap_size(int blocksize,int suballocator,uint32_t feature_incompat)1512 static inline int ocfs2_group_bitmap_size(int blocksize,
1513 int suballocator,
1514 uint32_t feature_incompat)
1515 {
1516 int size = sb->s_blocksize -
1517 offsetof(struct ocfs2_group_desc, bg_bitmap);
1518
1519 /*
1520 * The cluster allocator uses the entire block. Suballocators have
1521 * never used more than OCFS2_MAX_BG_BITMAP_SIZE. Unfortunately, older
1522 * code expects bg_size set to the maximum. Thus we must keep
1523 * bg_size as-is unless discontig_bg is enabled.
1524 */
1525 if (suballocator &&
1526 (feature_incompat & OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG))
1527 size = OCFS2_MAX_BG_BITMAP_SIZE;
1528
1529 return size;
1530 }
1531
ocfs2_truncate_recs_per_inode(int blocksize)1532 static inline int ocfs2_truncate_recs_per_inode(int blocksize)
1533 {
1534 int size;
1535
1536 size = blocksize -
1537 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
1538
1539 return size / sizeof(struct ocfs2_truncate_rec);
1540 }
1541
ocfs2_backup_super_blkno(int blocksize,int index)1542 static inline uint64_t ocfs2_backup_super_blkno(int blocksize, int index)
1543 {
1544 uint64_t offset = OCFS2_BACKUP_SB_START;
1545
1546 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
1547 offset <<= (2 * index);
1548 offset /= blocksize;
1549 return offset;
1550 }
1551
1552 return 0;
1553 }
1554
ocfs2_xattr_recs_per_xb(int blocksize)1555 static inline int ocfs2_xattr_recs_per_xb(int blocksize)
1556 {
1557 int size;
1558
1559 size = blocksize -
1560 offsetof(struct ocfs2_xattr_block,
1561 xb_attrs.xb_root.xt_list.l_recs);
1562
1563 return size / sizeof(struct ocfs2_extent_rec);
1564 }
1565 #endif /* __KERNEL__ */
1566
1567
ocfs2_system_inode_is_global(int type)1568 static inline int ocfs2_system_inode_is_global(int type)
1569 {
1570 return ((type >= 0) &&
1571 (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE));
1572 }
1573
ocfs2_sprintf_system_inode_name(char * buf,int len,int type,int slot)1574 static inline int ocfs2_sprintf_system_inode_name(char *buf, int len,
1575 int type, int slot)
1576 {
1577 int chars;
1578
1579 /*
1580 * Global system inodes can only have one copy. Everything
1581 * after OCFS2_LAST_GLOBAL_SYSTEM_INODE in the system inode
1582 * list has a copy per slot.
1583 */
1584 if (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE)
1585 chars = snprintf(buf, len, "%s",
1586 ocfs2_system_inodes[type].si_name);
1587 else
1588 chars = snprintf(buf, len,
1589 ocfs2_system_inodes[type].si_name,
1590 slot);
1591
1592 return chars;
1593 }
1594
ocfs2_set_de_type(struct ocfs2_dir_entry * de,umode_t mode)1595 static inline void ocfs2_set_de_type(struct ocfs2_dir_entry *de,
1596 umode_t mode)
1597 {
1598 de->file_type = fs_umode_to_ftype(mode);
1599 }
1600
ocfs2_gd_is_discontig(struct ocfs2_group_desc * gd)1601 static inline int ocfs2_gd_is_discontig(struct ocfs2_group_desc *gd)
1602 {
1603 if ((offsetof(struct ocfs2_group_desc, bg_bitmap) +
1604 le16_to_cpu(gd->bg_size)) !=
1605 offsetof(struct ocfs2_group_desc, bg_list))
1606 return 0;
1607 /*
1608 * Only valid to check l_next_free_rec if
1609 * bg_bitmap + bg_size == bg_list.
1610 */
1611 if (!gd->bg_list.l_next_free_rec)
1612 return 0;
1613 return 1;
1614 }
1615 #endif /* _OCFS2_FS_H */
1616
1617