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