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 69 /* Compatibility flags */ 70 #define OCFS2_HAS_COMPAT_FEATURE(sb,mask) \ 71 ( OCFS2_SB(sb)->s_feature_compat & (mask) ) 72 #define OCFS2_HAS_RO_COMPAT_FEATURE(sb,mask) \ 73 ( OCFS2_SB(sb)->s_feature_ro_compat & (mask) ) 74 #define OCFS2_HAS_INCOMPAT_FEATURE(sb,mask) \ 75 ( OCFS2_SB(sb)->s_feature_incompat & (mask) ) 76 #define OCFS2_SET_COMPAT_FEATURE(sb,mask) \ 77 OCFS2_SB(sb)->s_feature_compat |= (mask) 78 #define OCFS2_SET_RO_COMPAT_FEATURE(sb,mask) \ 79 OCFS2_SB(sb)->s_feature_ro_compat |= (mask) 80 #define OCFS2_SET_INCOMPAT_FEATURE(sb,mask) \ 81 OCFS2_SB(sb)->s_feature_incompat |= (mask) 82 #define OCFS2_CLEAR_COMPAT_FEATURE(sb,mask) \ 83 OCFS2_SB(sb)->s_feature_compat &= ~(mask) 84 #define OCFS2_CLEAR_RO_COMPAT_FEATURE(sb,mask) \ 85 OCFS2_SB(sb)->s_feature_ro_compat &= ~(mask) 86 #define OCFS2_CLEAR_INCOMPAT_FEATURE(sb,mask) \ 87 OCFS2_SB(sb)->s_feature_incompat &= ~(mask) 88 89 #define OCFS2_FEATURE_COMPAT_SUPP OCFS2_FEATURE_COMPAT_BACKUP_SB 90 #define OCFS2_FEATURE_INCOMPAT_SUPP (OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT \ 91 | OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC \ 92 | OCFS2_FEATURE_INCOMPAT_INLINE_DATA \ 93 | OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP \ 94 | OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK \ 95 | OCFS2_FEATURE_INCOMPAT_XATTR) 96 #define OCFS2_FEATURE_RO_COMPAT_SUPP OCFS2_FEATURE_RO_COMPAT_UNWRITTEN 97 98 /* 99 * Heartbeat-only devices are missing journals and other files. The 100 * filesystem driver can't load them, but the library can. Never put 101 * this in OCFS2_FEATURE_INCOMPAT_SUPP, *ever*. 102 */ 103 #define OCFS2_FEATURE_INCOMPAT_HEARTBEAT_DEV 0x0002 104 105 /* 106 * tunefs sets this incompat flag before starting the resize and clears it 107 * at the end. This flag protects users from inadvertently mounting the fs 108 * after an aborted run without fsck-ing. 109 */ 110 #define OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG 0x0004 111 112 /* Used to denote a non-clustered volume */ 113 #define OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT 0x0008 114 115 /* Support for sparse allocation in b-trees */ 116 #define OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC 0x0010 117 118 /* 119 * Tunefs sets this incompat flag before starting an operation which 120 * would require cleanup on abort. This is done to protect users from 121 * inadvertently mounting the fs after an aborted run without 122 * fsck-ing. 123 * 124 * s_tunefs_flags on the super block describes precisely which 125 * operations were in progress. 126 */ 127 #define OCFS2_FEATURE_INCOMPAT_TUNEFS_INPROG 0x0020 128 129 /* Support for data packed into inode blocks */ 130 #define OCFS2_FEATURE_INCOMPAT_INLINE_DATA 0x0040 131 132 /* 133 * Support for alternate, userspace cluster stacks. If set, the superblock 134 * field s_cluster_info contains a tag for the alternate stack in use as 135 * well as the name of the cluster being joined. 136 * mount.ocfs2 must pass in a matching stack name. 137 * 138 * If not set, the classic stack will be used. This is compatbile with 139 * all older versions. 140 */ 141 #define OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK 0x0080 142 143 /* Support for the extended slot map */ 144 #define OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP 0x100 145 146 /* Support for extended attributes */ 147 #define OCFS2_FEATURE_INCOMPAT_XATTR 0x0200 148 149 /* 150 * backup superblock flag is used to indicate that this volume 151 * has backup superblocks. 152 */ 153 #define OCFS2_FEATURE_COMPAT_BACKUP_SB 0x0001 154 155 /* 156 * Unwritten extents support. 157 */ 158 #define OCFS2_FEATURE_RO_COMPAT_UNWRITTEN 0x0001 159 160 /* The byte offset of the first backup block will be 1G. 161 * The following will be 4G, 16G, 64G, 256G and 1T. 162 */ 163 #define OCFS2_BACKUP_SB_START 1 << 30 164 165 /* the max backup superblock nums */ 166 #define OCFS2_MAX_BACKUP_SUPERBLOCKS 6 167 168 /* 169 * Flags on ocfs2_super_block.s_tunefs_flags 170 */ 171 #define OCFS2_TUNEFS_INPROG_REMOVE_SLOT 0x0001 /* Removing slots */ 172 173 /* 174 * Flags on ocfs2_dinode.i_flags 175 */ 176 #define OCFS2_VALID_FL (0x00000001) /* Inode is valid */ 177 #define OCFS2_UNUSED2_FL (0x00000002) 178 #define OCFS2_ORPHANED_FL (0x00000004) /* On the orphan list */ 179 #define OCFS2_UNUSED3_FL (0x00000008) 180 /* System inode flags */ 181 #define OCFS2_SYSTEM_FL (0x00000010) /* System inode */ 182 #define OCFS2_SUPER_BLOCK_FL (0x00000020) /* Super block */ 183 #define OCFS2_LOCAL_ALLOC_FL (0x00000040) /* Slot local alloc bitmap */ 184 #define OCFS2_BITMAP_FL (0x00000080) /* Allocation bitmap */ 185 #define OCFS2_JOURNAL_FL (0x00000100) /* Slot local journal */ 186 #define OCFS2_HEARTBEAT_FL (0x00000200) /* Heartbeat area */ 187 #define OCFS2_CHAIN_FL (0x00000400) /* Chain allocator */ 188 #define OCFS2_DEALLOC_FL (0x00000800) /* Truncate log */ 189 190 /* 191 * Flags on ocfs2_dinode.i_dyn_features 192 * 193 * These can change much more often than i_flags. When adding flags, 194 * keep in mind that i_dyn_features is only 16 bits wide. 195 */ 196 #define OCFS2_INLINE_DATA_FL (0x0001) /* Data stored in inode block */ 197 #define OCFS2_HAS_XATTR_FL (0x0002) 198 #define OCFS2_INLINE_XATTR_FL (0x0004) 199 #define OCFS2_INDEXED_DIR_FL (0x0008) 200 201 /* Inode attributes, keep in sync with EXT2 */ 202 #define OCFS2_SECRM_FL (0x00000001) /* Secure deletion */ 203 #define OCFS2_UNRM_FL (0x00000002) /* Undelete */ 204 #define OCFS2_COMPR_FL (0x00000004) /* Compress file */ 205 #define OCFS2_SYNC_FL (0x00000008) /* Synchronous updates */ 206 #define OCFS2_IMMUTABLE_FL (0x00000010) /* Immutable file */ 207 #define OCFS2_APPEND_FL (0x00000020) /* writes to file may only append */ 208 #define OCFS2_NODUMP_FL (0x00000040) /* do not dump file */ 209 #define OCFS2_NOATIME_FL (0x00000080) /* do not update atime */ 210 #define OCFS2_DIRSYNC_FL (0x00010000) /* dirsync behaviour (directories only) */ 211 212 #define OCFS2_FL_VISIBLE (0x000100FF) /* User visible flags */ 213 #define OCFS2_FL_MODIFIABLE (0x000100FF) /* User modifiable flags */ 214 215 /* 216 * Extent record flags (e_node.leaf.flags) 217 */ 218 #define OCFS2_EXT_UNWRITTEN (0x01) /* Extent is allocated but 219 * unwritten */ 220 221 /* 222 * ioctl commands 223 */ 224 #define OCFS2_IOC_GETFLAGS _IOR('f', 1, long) 225 #define OCFS2_IOC_SETFLAGS _IOW('f', 2, long) 226 #define OCFS2_IOC32_GETFLAGS _IOR('f', 1, int) 227 #define OCFS2_IOC32_SETFLAGS _IOW('f', 2, int) 228 229 /* 230 * Space reservation / allocation / free ioctls and argument structure 231 * are designed to be compatible with XFS. 232 * 233 * ALLOCSP* and FREESP* are not and will never be supported, but are 234 * included here for completeness. 235 */ 236 struct ocfs2_space_resv { 237 __s16 l_type; 238 __s16 l_whence; 239 __s64 l_start; 240 __s64 l_len; /* len == 0 means until end of file */ 241 __s32 l_sysid; 242 __u32 l_pid; 243 __s32 l_pad[4]; /* reserve area */ 244 }; 245 246 #define OCFS2_IOC_ALLOCSP _IOW ('X', 10, struct ocfs2_space_resv) 247 #define OCFS2_IOC_FREESP _IOW ('X', 11, struct ocfs2_space_resv) 248 #define OCFS2_IOC_RESVSP _IOW ('X', 40, struct ocfs2_space_resv) 249 #define OCFS2_IOC_UNRESVSP _IOW ('X', 41, struct ocfs2_space_resv) 250 #define OCFS2_IOC_ALLOCSP64 _IOW ('X', 36, struct ocfs2_space_resv) 251 #define OCFS2_IOC_FREESP64 _IOW ('X', 37, struct ocfs2_space_resv) 252 #define OCFS2_IOC_RESVSP64 _IOW ('X', 42, struct ocfs2_space_resv) 253 #define OCFS2_IOC_UNRESVSP64 _IOW ('X', 43, struct ocfs2_space_resv) 254 255 /* Used to pass group descriptor data when online resize is done */ 256 struct ocfs2_new_group_input { 257 __u64 group; /* Group descriptor's blkno. */ 258 __u32 clusters; /* Total number of clusters in this group */ 259 __u32 frees; /* Total free clusters in this group */ 260 __u16 chain; /* Chain for this group */ 261 __u16 reserved1; 262 __u32 reserved2; 263 }; 264 265 #define OCFS2_IOC_GROUP_EXTEND _IOW('o', 1, int) 266 #define OCFS2_IOC_GROUP_ADD _IOW('o', 2,struct ocfs2_new_group_input) 267 #define OCFS2_IOC_GROUP_ADD64 _IOW('o', 3,struct ocfs2_new_group_input) 268 269 /* 270 * Journal Flags (ocfs2_dinode.id1.journal1.i_flags) 271 */ 272 #define OCFS2_JOURNAL_DIRTY_FL (0x00000001) /* Journal needs recovery */ 273 274 /* 275 * superblock s_state flags 276 */ 277 #define OCFS2_ERROR_FS (0x00000001) /* FS saw errors */ 278 279 /* Limit of space in ocfs2_dir_entry */ 280 #define OCFS2_MAX_FILENAME_LEN 255 281 282 /* Maximum slots on an ocfs2 file system */ 283 #define OCFS2_MAX_SLOTS 255 284 285 /* Slot map indicator for an empty slot */ 286 #define OCFS2_INVALID_SLOT -1 287 288 #define OCFS2_VOL_UUID_LEN 16 289 #define OCFS2_MAX_VOL_LABEL_LEN 64 290 291 /* The alternate, userspace stack fields */ 292 #define OCFS2_STACK_LABEL_LEN 4 293 #define OCFS2_CLUSTER_NAME_LEN 16 294 295 /* Journal limits (in bytes) */ 296 #define OCFS2_MIN_JOURNAL_SIZE (4 * 1024 * 1024) 297 298 /* 299 * Default local alloc size (in megabytes) 300 * 301 * The value chosen should be such that most allocations, including new 302 * block groups, use local alloc. 303 */ 304 #define OCFS2_DEFAULT_LOCAL_ALLOC_SIZE 8 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 struct ocfs2_system_inode_info { 313 char *si_name; 314 int si_iflags; 315 int si_mode; 316 }; 317 318 /* System file index */ 319 enum { 320 BAD_BLOCK_SYSTEM_INODE = 0, 321 GLOBAL_INODE_ALLOC_SYSTEM_INODE, 322 SLOT_MAP_SYSTEM_INODE, 323 #define OCFS2_FIRST_ONLINE_SYSTEM_INODE SLOT_MAP_SYSTEM_INODE 324 HEARTBEAT_SYSTEM_INODE, 325 GLOBAL_BITMAP_SYSTEM_INODE, 326 #define OCFS2_LAST_GLOBAL_SYSTEM_INODE GLOBAL_BITMAP_SYSTEM_INODE 327 ORPHAN_DIR_SYSTEM_INODE, 328 EXTENT_ALLOC_SYSTEM_INODE, 329 INODE_ALLOC_SYSTEM_INODE, 330 JOURNAL_SYSTEM_INODE, 331 LOCAL_ALLOC_SYSTEM_INODE, 332 TRUNCATE_LOG_SYSTEM_INODE, 333 NUM_SYSTEM_INODES 334 }; 335 336 static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = { 337 /* Global system inodes (single copy) */ 338 /* The first two are only used from userspace mfks/tunefs */ 339 [BAD_BLOCK_SYSTEM_INODE] = { "bad_blocks", 0, S_IFREG | 0644 }, 340 [GLOBAL_INODE_ALLOC_SYSTEM_INODE] = { "global_inode_alloc", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 }, 341 342 /* These are used by the running filesystem */ 343 [SLOT_MAP_SYSTEM_INODE] = { "slot_map", 0, S_IFREG | 0644 }, 344 [HEARTBEAT_SYSTEM_INODE] = { "heartbeat", OCFS2_HEARTBEAT_FL, S_IFREG | 0644 }, 345 [GLOBAL_BITMAP_SYSTEM_INODE] = { "global_bitmap", 0, S_IFREG | 0644 }, 346 347 /* Slot-specific system inodes (one copy per slot) */ 348 [ORPHAN_DIR_SYSTEM_INODE] = { "orphan_dir:%04d", 0, S_IFDIR | 0755 }, 349 [EXTENT_ALLOC_SYSTEM_INODE] = { "extent_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 }, 350 [INODE_ALLOC_SYSTEM_INODE] = { "inode_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 }, 351 [JOURNAL_SYSTEM_INODE] = { "journal:%04d", OCFS2_JOURNAL_FL, S_IFREG | 0644 }, 352 [LOCAL_ALLOC_SYSTEM_INODE] = { "local_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_LOCAL_ALLOC_FL, S_IFREG | 0644 }, 353 [TRUNCATE_LOG_SYSTEM_INODE] = { "truncate_log:%04d", OCFS2_DEALLOC_FL, S_IFREG | 0644 } 354 }; 355 356 /* Parameter passed from mount.ocfs2 to module */ 357 #define OCFS2_HB_NONE "heartbeat=none" 358 #define OCFS2_HB_LOCAL "heartbeat=local" 359 360 /* 361 * OCFS2 directory file types. Only the low 3 bits are used. The 362 * other bits are reserved for now. 363 */ 364 #define OCFS2_FT_UNKNOWN 0 365 #define OCFS2_FT_REG_FILE 1 366 #define OCFS2_FT_DIR 2 367 #define OCFS2_FT_CHRDEV 3 368 #define OCFS2_FT_BLKDEV 4 369 #define OCFS2_FT_FIFO 5 370 #define OCFS2_FT_SOCK 6 371 #define OCFS2_FT_SYMLINK 7 372 373 #define OCFS2_FT_MAX 8 374 375 /* 376 * OCFS2_DIR_PAD defines the directory entries boundaries 377 * 378 * NOTE: It must be a multiple of 4 379 */ 380 #define OCFS2_DIR_PAD 4 381 #define OCFS2_DIR_ROUND (OCFS2_DIR_PAD - 1) 382 #define OCFS2_DIR_MEMBER_LEN offsetof(struct ocfs2_dir_entry, name) 383 #define OCFS2_DIR_REC_LEN(name_len) (((name_len) + OCFS2_DIR_MEMBER_LEN + \ 384 OCFS2_DIR_ROUND) & \ 385 ~OCFS2_DIR_ROUND) 386 387 #define OCFS2_LINK_MAX 32000 388 389 #define S_SHIFT 12 390 static unsigned char ocfs2_type_by_mode[S_IFMT >> S_SHIFT] = { 391 [S_IFREG >> S_SHIFT] = OCFS2_FT_REG_FILE, 392 [S_IFDIR >> S_SHIFT] = OCFS2_FT_DIR, 393 [S_IFCHR >> S_SHIFT] = OCFS2_FT_CHRDEV, 394 [S_IFBLK >> S_SHIFT] = OCFS2_FT_BLKDEV, 395 [S_IFIFO >> S_SHIFT] = OCFS2_FT_FIFO, 396 [S_IFSOCK >> S_SHIFT] = OCFS2_FT_SOCK, 397 [S_IFLNK >> S_SHIFT] = OCFS2_FT_SYMLINK, 398 }; 399 400 401 /* 402 * Convenience casts 403 */ 404 #define OCFS2_RAW_SB(dinode) (&((dinode)->id2.i_super)) 405 406 /* 407 * On disk extent record for OCFS2 408 * It describes a range of clusters on disk. 409 * 410 * Length fields are divided into interior and leaf node versions. 411 * This leaves room for a flags field (OCFS2_EXT_*) in the leaf nodes. 412 */ 413 struct ocfs2_extent_rec { 414 /*00*/ __le32 e_cpos; /* Offset into the file, in clusters */ 415 union { 416 __le32 e_int_clusters; /* Clusters covered by all children */ 417 struct { 418 __le16 e_leaf_clusters; /* Clusters covered by this 419 extent */ 420 __u8 e_reserved1; 421 __u8 e_flags; /* Extent flags */ 422 }; 423 }; 424 __le64 e_blkno; /* Physical disk offset, in blocks */ 425 /*10*/ 426 }; 427 428 struct ocfs2_chain_rec { 429 __le32 c_free; /* Number of free bits in this chain. */ 430 __le32 c_total; /* Number of total bits in this chain */ 431 __le64 c_blkno; /* Physical disk offset (blocks) of 1st group */ 432 }; 433 434 struct ocfs2_truncate_rec { 435 __le32 t_start; /* 1st cluster in this log */ 436 __le32 t_clusters; /* Number of total clusters covered */ 437 }; 438 439 /* 440 * On disk extent list for OCFS2 (node in the tree). Note that this 441 * is contained inside ocfs2_dinode or ocfs2_extent_block, so the 442 * offsets are relative to ocfs2_dinode.id2.i_list or 443 * ocfs2_extent_block.h_list, respectively. 444 */ 445 struct ocfs2_extent_list { 446 /*00*/ __le16 l_tree_depth; /* Extent tree depth from this 447 point. 0 means data extents 448 hang directly off this 449 header (a leaf) 450 NOTE: The high 8 bits cannot be 451 used - tree_depth is never that big. 452 */ 453 __le16 l_count; /* Number of extent records */ 454 __le16 l_next_free_rec; /* Next unused extent slot */ 455 __le16 l_reserved1; 456 __le64 l_reserved2; /* Pad to 457 sizeof(ocfs2_extent_rec) */ 458 /*10*/ struct ocfs2_extent_rec l_recs[0]; /* Extent records */ 459 }; 460 461 /* 462 * On disk allocation chain list for OCFS2. Note that this is 463 * contained inside ocfs2_dinode, so the offsets are relative to 464 * ocfs2_dinode.id2.i_chain. 465 */ 466 struct ocfs2_chain_list { 467 /*00*/ __le16 cl_cpg; /* Clusters per Block Group */ 468 __le16 cl_bpc; /* Bits per cluster */ 469 __le16 cl_count; /* Total chains in this list */ 470 __le16 cl_next_free_rec; /* Next unused chain slot */ 471 __le64 cl_reserved1; 472 /*10*/ struct ocfs2_chain_rec cl_recs[0]; /* Chain records */ 473 }; 474 475 /* 476 * On disk deallocation log for OCFS2. Note that this is 477 * contained inside ocfs2_dinode, so the offsets are relative to 478 * ocfs2_dinode.id2.i_dealloc. 479 */ 480 struct ocfs2_truncate_log { 481 /*00*/ __le16 tl_count; /* Total records in this log */ 482 __le16 tl_used; /* Number of records in use */ 483 __le32 tl_reserved1; 484 /*08*/ struct ocfs2_truncate_rec tl_recs[0]; /* Truncate records */ 485 }; 486 487 /* 488 * On disk extent block (indirect block) for OCFS2 489 */ 490 struct ocfs2_extent_block 491 { 492 /*00*/ __u8 h_signature[8]; /* Signature for verification */ 493 __le64 h_reserved1; 494 /*10*/ __le16 h_suballoc_slot; /* Slot suballocator this 495 extent_header belongs to */ 496 __le16 h_suballoc_bit; /* Bit offset in suballocator 497 block group */ 498 __le32 h_fs_generation; /* Must match super block */ 499 __le64 h_blkno; /* Offset on disk, in blocks */ 500 /*20*/ __le64 h_reserved3; 501 __le64 h_next_leaf_blk; /* Offset on disk, in blocks, 502 of next leaf header pointing 503 to data */ 504 /*30*/ struct ocfs2_extent_list h_list; /* Extent record list */ 505 /* Actual on-disk size is one block */ 506 }; 507 508 /* 509 * On disk slot map for OCFS2. This defines the contents of the "slot_map" 510 * system file. A slot is valid if it contains a node number >= 0. The 511 * value -1 (0xFFFF) is OCFS2_INVALID_SLOT. This marks a slot empty. 512 */ 513 struct ocfs2_slot_map { 514 /*00*/ __le16 sm_slots[0]; 515 /* 516 * Actual on-disk size is one block. OCFS2_MAX_SLOTS is 255, 517 * 255 * sizeof(__le16) == 512B, within the 512B block minimum blocksize. 518 */ 519 }; 520 521 struct ocfs2_extended_slot { 522 /*00*/ __u8 es_valid; 523 __u8 es_reserved1[3]; 524 __le32 es_node_num; 525 /*10*/ 526 }; 527 528 /* 529 * The extended slot map, used when OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP 530 * is set. It separates out the valid marker from the node number, and 531 * has room to grow. Unlike the old slot map, this format is defined by 532 * i_size. 533 */ 534 struct ocfs2_slot_map_extended { 535 /*00*/ struct ocfs2_extended_slot se_slots[0]; 536 /* 537 * Actual size is i_size of the slot_map system file. It should 538 * match s_max_slots * sizeof(struct ocfs2_extended_slot) 539 */ 540 }; 541 542 struct ocfs2_cluster_info { 543 /*00*/ __u8 ci_stack[OCFS2_STACK_LABEL_LEN]; 544 __le32 ci_reserved; 545 /*08*/ __u8 ci_cluster[OCFS2_CLUSTER_NAME_LEN]; 546 /*18*/ 547 }; 548 549 /* 550 * On disk superblock for OCFS2 551 * Note that it is contained inside an ocfs2_dinode, so all offsets 552 * are relative to the start of ocfs2_dinode.id2. 553 */ 554 struct ocfs2_super_block { 555 /*00*/ __le16 s_major_rev_level; 556 __le16 s_minor_rev_level; 557 __le16 s_mnt_count; 558 __le16 s_max_mnt_count; 559 __le16 s_state; /* File system state */ 560 __le16 s_errors; /* Behaviour when detecting errors */ 561 __le32 s_checkinterval; /* Max time between checks */ 562 /*10*/ __le64 s_lastcheck; /* Time of last check */ 563 __le32 s_creator_os; /* OS */ 564 __le32 s_feature_compat; /* Compatible feature set */ 565 /*20*/ __le32 s_feature_incompat; /* Incompatible feature set */ 566 __le32 s_feature_ro_compat; /* Readonly-compatible feature set */ 567 __le64 s_root_blkno; /* Offset, in blocks, of root directory 568 dinode */ 569 /*30*/ __le64 s_system_dir_blkno; /* Offset, in blocks, of system 570 directory dinode */ 571 __le32 s_blocksize_bits; /* Blocksize for this fs */ 572 __le32 s_clustersize_bits; /* Clustersize for this fs */ 573 /*40*/ __le16 s_max_slots; /* Max number of simultaneous mounts 574 before tunefs required */ 575 __le16 s_tunefs_flag; 576 __le32 s_uuid_hash; /* hash value of uuid */ 577 __le64 s_first_cluster_group; /* Block offset of 1st cluster 578 * group header */ 579 /*50*/ __u8 s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */ 580 /*90*/ __u8 s_uuid[OCFS2_VOL_UUID_LEN]; /* 128-bit uuid */ 581 /*A0*/ struct ocfs2_cluster_info s_cluster_info; /* Selected userspace 582 stack. Only valid 583 with INCOMPAT flag. */ 584 /*B8*/ __le16 s_xattr_inline_size; /* extended attribute inline size 585 for this fs*/ 586 __le16 s_reserved0; 587 __le32 s_reserved1; 588 /*C0*/ __le64 s_reserved2[16]; /* Fill out superblock */ 589 /*140*/ 590 591 /* 592 * NOTE: As stated above, all offsets are relative to 593 * ocfs2_dinode.id2, which is at 0xC0 in the inode. 594 * 0xC0 + 0x140 = 0x200 or 512 bytes. A superblock must fit within 595 * our smallest blocksize, which is 512 bytes. To ensure this, 596 * we reserve the space in s_reserved2. Anything past s_reserved2 597 * will not be available on the smallest blocksize. 598 */ 599 }; 600 601 /* 602 * Local allocation bitmap for OCFS2 slots 603 * Note that it exists inside an ocfs2_dinode, so all offsets are 604 * relative to the start of ocfs2_dinode.id2. 605 */ 606 struct ocfs2_local_alloc 607 { 608 /*00*/ __le32 la_bm_off; /* Starting bit offset in main bitmap */ 609 __le16 la_size; /* Size of included bitmap, in bytes */ 610 __le16 la_reserved1; 611 __le64 la_reserved2; 612 /*10*/ __u8 la_bitmap[0]; 613 }; 614 615 /* 616 * Data-in-inode header. This is only used if i_dyn_features has 617 * OCFS2_INLINE_DATA_FL set. 618 */ 619 struct ocfs2_inline_data 620 { 621 /*00*/ __le16 id_count; /* Number of bytes that can be used 622 * for data, starting at id_data */ 623 __le16 id_reserved0; 624 __le32 id_reserved1; 625 __u8 id_data[0]; /* Start of user data */ 626 }; 627 628 /* 629 * On disk inode for OCFS2 630 */ 631 struct ocfs2_dinode { 632 /*00*/ __u8 i_signature[8]; /* Signature for validation */ 633 __le32 i_generation; /* Generation number */ 634 __le16 i_suballoc_slot; /* Slot suballocator this inode 635 belongs to */ 636 __le16 i_suballoc_bit; /* Bit offset in suballocator 637 block group */ 638 /*10*/ __le16 i_reserved0; 639 __le16 i_xattr_inline_size; 640 __le32 i_clusters; /* Cluster count */ 641 __le32 i_uid; /* Owner UID */ 642 __le32 i_gid; /* Owning GID */ 643 /*20*/ __le64 i_size; /* Size in bytes */ 644 __le16 i_mode; /* File mode */ 645 __le16 i_links_count; /* Links count */ 646 __le32 i_flags; /* File flags */ 647 /*30*/ __le64 i_atime; /* Access time */ 648 __le64 i_ctime; /* Creation time */ 649 /*40*/ __le64 i_mtime; /* Modification time */ 650 __le64 i_dtime; /* Deletion time */ 651 /*50*/ __le64 i_blkno; /* Offset on disk, in blocks */ 652 __le64 i_last_eb_blk; /* Pointer to last extent 653 block */ 654 /*60*/ __le32 i_fs_generation; /* Generation per fs-instance */ 655 __le32 i_atime_nsec; 656 __le32 i_ctime_nsec; 657 __le32 i_mtime_nsec; 658 /*70*/ __le32 i_attr; 659 __le16 i_orphaned_slot; /* Only valid when OCFS2_ORPHANED_FL 660 was set in i_flags */ 661 __le16 i_dyn_features; 662 __le64 i_xattr_loc; 663 /*80*/ __le64 i_reserved2[7]; 664 /*B8*/ union { 665 __le64 i_pad1; /* Generic way to refer to this 666 64bit union */ 667 struct { 668 __le64 i_rdev; /* Device number */ 669 } dev1; 670 struct { /* Info for bitmap system 671 inodes */ 672 __le32 i_used; /* Bits (ie, clusters) used */ 673 __le32 i_total; /* Total bits (clusters) 674 available */ 675 } bitmap1; 676 struct { /* Info for journal system 677 inodes */ 678 __le32 ij_flags; /* Mounted, version, etc. */ 679 __le32 ij_recovery_generation; /* Incremented when the 680 journal is recovered 681 after an unclean 682 shutdown */ 683 } journal1; 684 } id1; /* Inode type dependant 1 */ 685 /*C0*/ union { 686 struct ocfs2_super_block i_super; 687 struct ocfs2_local_alloc i_lab; 688 struct ocfs2_chain_list i_chain; 689 struct ocfs2_extent_list i_list; 690 struct ocfs2_truncate_log i_dealloc; 691 struct ocfs2_inline_data i_data; 692 __u8 i_symlink[0]; 693 } id2; 694 /* Actual on-disk size is one block */ 695 }; 696 697 /* 698 * On-disk directory entry structure for OCFS2 699 * 700 * Packed as this structure could be accessed unaligned on 64-bit platforms 701 */ 702 struct ocfs2_dir_entry { 703 /*00*/ __le64 inode; /* Inode number */ 704 __le16 rec_len; /* Directory entry length */ 705 __u8 name_len; /* Name length */ 706 __u8 file_type; 707 /*0C*/ char name[OCFS2_MAX_FILENAME_LEN]; /* File name */ 708 /* Actual on-disk length specified by rec_len */ 709 } __attribute__ ((packed)); 710 711 /* 712 * On disk allocator group structure for OCFS2 713 */ 714 struct ocfs2_group_desc 715 { 716 /*00*/ __u8 bg_signature[8]; /* Signature for validation */ 717 __le16 bg_size; /* Size of included bitmap in 718 bytes. */ 719 __le16 bg_bits; /* Bits represented by this 720 group. */ 721 __le16 bg_free_bits_count; /* Free bits count */ 722 __le16 bg_chain; /* What chain I am in. */ 723 /*10*/ __le32 bg_generation; 724 __le32 bg_reserved1; 725 __le64 bg_next_group; /* Next group in my list, in 726 blocks */ 727 /*20*/ __le64 bg_parent_dinode; /* dinode which owns me, in 728 blocks */ 729 __le64 bg_blkno; /* Offset on disk, in blocks */ 730 /*30*/ __le64 bg_reserved2[2]; 731 /*40*/ __u8 bg_bitmap[0]; 732 }; 733 734 /* 735 * On disk extended attribute structure for OCFS2. 736 */ 737 738 /* 739 * ocfs2_xattr_entry indicates one extend attribute. 740 * 741 * Note that it can be stored in inode, one block or one xattr bucket. 742 */ 743 struct ocfs2_xattr_entry { 744 __le32 xe_name_hash; /* hash value of xattr prefix+suffix. */ 745 __le16 xe_name_offset; /* byte offset from the 1st etnry in the local 746 local xattr storage(inode, xattr block or 747 xattr bucket). */ 748 __u8 xe_name_len; /* xattr name len, does't include prefix. */ 749 __u8 xe_type; /* the low 7 bits indicates the name prefix's 750 * type and the highest 1 bits indicate whether 751 * the EA is stored in the local storage. */ 752 __le64 xe_value_size; /* real xattr value length. */ 753 }; 754 755 /* 756 * On disk structure for xattr header. 757 * 758 * One ocfs2_xattr_header describes how many ocfs2_xattr_entry records in 759 * the local xattr storage. 760 */ 761 struct ocfs2_xattr_header { 762 __le16 xh_count; /* contains the count of how 763 many records are in the 764 local xattr storage. */ 765 __le16 xh_free_start; /* current offset for storing 766 xattr. */ 767 __le16 xh_name_value_len; /* total length of name/value 768 length in this bucket. */ 769 __le16 xh_num_buckets; /* bucket nums in one extent 770 record, only valid in the 771 first bucket. */ 772 __le64 xh_csum; 773 struct ocfs2_xattr_entry xh_entries[0]; /* xattr entry list. */ 774 }; 775 776 /* 777 * On disk structure for xattr value root. 778 * 779 * It is used when one extended attribute's size is larger, and we will save it 780 * in an outside cluster. It will stored in a b-tree like file content. 781 */ 782 struct ocfs2_xattr_value_root { 783 /*00*/ __le32 xr_clusters; /* clusters covered by xattr value. */ 784 __le32 xr_reserved0; 785 __le64 xr_last_eb_blk; /* Pointer to last extent block */ 786 /*10*/ struct ocfs2_extent_list xr_list; /* Extent record list */ 787 }; 788 789 /* 790 * On disk structure for xattr tree root. 791 * 792 * It is used when there are too many extended attributes for one file. These 793 * attributes will be organized and stored in an indexed-btree. 794 */ 795 struct ocfs2_xattr_tree_root { 796 /*00*/ __le32 xt_clusters; /* clusters covered by xattr. */ 797 __le32 xt_reserved0; 798 __le64 xt_last_eb_blk; /* Pointer to last extent block */ 799 /*10*/ struct ocfs2_extent_list xt_list; /* Extent record list */ 800 }; 801 802 #define OCFS2_XATTR_INDEXED 0x1 803 #define OCFS2_HASH_SHIFT 5 804 #define OCFS2_XATTR_ROUND 3 805 #define OCFS2_XATTR_SIZE(size) (((size) + OCFS2_XATTR_ROUND) & \ 806 ~(OCFS2_XATTR_ROUND)) 807 808 #define OCFS2_XATTR_BUCKET_SIZE 4096 809 #define OCFS2_XATTR_MAX_BLOCKS_PER_BUCKET (OCFS2_XATTR_BUCKET_SIZE \ 810 / OCFS2_MIN_BLOCKSIZE) 811 812 /* 813 * On disk structure for xattr block. 814 */ 815 struct ocfs2_xattr_block { 816 /*00*/ __u8 xb_signature[8]; /* Signature for verification */ 817 __le16 xb_suballoc_slot; /* Slot suballocator this 818 block belongs to. */ 819 __le16 xb_suballoc_bit; /* Bit offset in suballocator 820 block group */ 821 __le32 xb_fs_generation; /* Must match super block */ 822 /*10*/ __le64 xb_blkno; /* Offset on disk, in blocks */ 823 __le64 xb_csum; 824 /*20*/ __le16 xb_flags; /* Indicates whether this block contains 825 real xattr or a xattr tree. */ 826 __le16 xb_reserved0; 827 __le32 xb_reserved1; 828 __le64 xb_reserved2; 829 /*30*/ union { 830 struct ocfs2_xattr_header xb_header; /* xattr header if this 831 block contains xattr */ 832 struct ocfs2_xattr_tree_root xb_root;/* xattr tree root if this 833 block cotains xattr 834 tree. */ 835 } xb_attrs; 836 }; 837 838 #define OCFS2_XATTR_ENTRY_LOCAL 0x80 839 #define OCFS2_XATTR_TYPE_MASK 0x7F 840 static inline void ocfs2_xattr_set_local(struct ocfs2_xattr_entry *xe, 841 int local) 842 { 843 if (local) 844 xe->xe_type |= OCFS2_XATTR_ENTRY_LOCAL; 845 else 846 xe->xe_type &= ~OCFS2_XATTR_ENTRY_LOCAL; 847 } 848 849 static inline int ocfs2_xattr_is_local(struct ocfs2_xattr_entry *xe) 850 { 851 return xe->xe_type & OCFS2_XATTR_ENTRY_LOCAL; 852 } 853 854 static inline void ocfs2_xattr_set_type(struct ocfs2_xattr_entry *xe, int type) 855 { 856 xe->xe_type |= type & OCFS2_XATTR_TYPE_MASK; 857 } 858 859 static inline int ocfs2_xattr_get_type(struct ocfs2_xattr_entry *xe) 860 { 861 return xe->xe_type & OCFS2_XATTR_TYPE_MASK; 862 } 863 864 #ifdef __KERNEL__ 865 static inline int ocfs2_fast_symlink_chars(struct super_block *sb) 866 { 867 return sb->s_blocksize - 868 offsetof(struct ocfs2_dinode, id2.i_symlink); 869 } 870 871 static inline int ocfs2_max_inline_data(struct super_block *sb) 872 { 873 return sb->s_blocksize - 874 offsetof(struct ocfs2_dinode, id2.i_data.id_data); 875 } 876 877 static inline int ocfs2_max_inline_data_with_xattr(struct super_block *sb, 878 struct ocfs2_dinode *di) 879 { 880 unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size); 881 882 if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL) 883 return sb->s_blocksize - 884 offsetof(struct ocfs2_dinode, id2.i_data.id_data) - 885 xattrsize; 886 else 887 return sb->s_blocksize - 888 offsetof(struct ocfs2_dinode, id2.i_data.id_data); 889 } 890 891 static inline int ocfs2_extent_recs_per_inode(struct super_block *sb) 892 { 893 int size; 894 895 size = sb->s_blocksize - 896 offsetof(struct ocfs2_dinode, id2.i_list.l_recs); 897 898 return size / sizeof(struct ocfs2_extent_rec); 899 } 900 901 static inline int ocfs2_extent_recs_per_inode_with_xattr( 902 struct super_block *sb, 903 struct ocfs2_dinode *di) 904 { 905 int size; 906 unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size); 907 908 if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL) 909 size = sb->s_blocksize - 910 offsetof(struct ocfs2_dinode, id2.i_list.l_recs) - 911 xattrsize; 912 else 913 size = sb->s_blocksize - 914 offsetof(struct ocfs2_dinode, id2.i_list.l_recs); 915 916 return size / sizeof(struct ocfs2_extent_rec); 917 } 918 919 static inline int ocfs2_chain_recs_per_inode(struct super_block *sb) 920 { 921 int size; 922 923 size = sb->s_blocksize - 924 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs); 925 926 return size / sizeof(struct ocfs2_chain_rec); 927 } 928 929 static inline u16 ocfs2_extent_recs_per_eb(struct super_block *sb) 930 { 931 int size; 932 933 size = sb->s_blocksize - 934 offsetof(struct ocfs2_extent_block, h_list.l_recs); 935 936 return size / sizeof(struct ocfs2_extent_rec); 937 } 938 939 static inline u16 ocfs2_local_alloc_size(struct super_block *sb) 940 { 941 u16 size; 942 943 size = sb->s_blocksize - 944 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap); 945 946 return size; 947 } 948 949 static inline int ocfs2_group_bitmap_size(struct super_block *sb) 950 { 951 int size; 952 953 size = sb->s_blocksize - 954 offsetof(struct ocfs2_group_desc, bg_bitmap); 955 956 return size; 957 } 958 959 static inline int ocfs2_truncate_recs_per_inode(struct super_block *sb) 960 { 961 int size; 962 963 size = sb->s_blocksize - 964 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs); 965 966 return size / sizeof(struct ocfs2_truncate_rec); 967 } 968 969 static inline u64 ocfs2_backup_super_blkno(struct super_block *sb, int index) 970 { 971 u64 offset = OCFS2_BACKUP_SB_START; 972 973 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) { 974 offset <<= (2 * index); 975 offset >>= sb->s_blocksize_bits; 976 return offset; 977 } 978 979 return 0; 980 981 } 982 983 static inline u16 ocfs2_xattr_recs_per_xb(struct super_block *sb) 984 { 985 int size; 986 987 size = sb->s_blocksize - 988 offsetof(struct ocfs2_xattr_block, 989 xb_attrs.xb_root.xt_list.l_recs); 990 991 return size / sizeof(struct ocfs2_extent_rec); 992 } 993 #else 994 static inline int ocfs2_fast_symlink_chars(int blocksize) 995 { 996 return blocksize - offsetof(struct ocfs2_dinode, id2.i_symlink); 997 } 998 999 static inline int ocfs2_max_inline_data(int blocksize) 1000 { 1001 return blocksize - offsetof(struct ocfs2_dinode, id2.i_data.id_data); 1002 } 1003 1004 static inline int ocfs2_extent_recs_per_inode(int blocksize) 1005 { 1006 int size; 1007 1008 size = blocksize - 1009 offsetof(struct ocfs2_dinode, id2.i_list.l_recs); 1010 1011 return size / sizeof(struct ocfs2_extent_rec); 1012 } 1013 1014 static inline int ocfs2_chain_recs_per_inode(int blocksize) 1015 { 1016 int size; 1017 1018 size = blocksize - 1019 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs); 1020 1021 return size / sizeof(struct ocfs2_chain_rec); 1022 } 1023 1024 static inline int ocfs2_extent_recs_per_eb(int blocksize) 1025 { 1026 int size; 1027 1028 size = blocksize - 1029 offsetof(struct ocfs2_extent_block, h_list.l_recs); 1030 1031 return size / sizeof(struct ocfs2_extent_rec); 1032 } 1033 1034 static inline int ocfs2_local_alloc_size(int blocksize) 1035 { 1036 int size; 1037 1038 size = blocksize - 1039 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap); 1040 1041 return size; 1042 } 1043 1044 static inline int ocfs2_group_bitmap_size(int blocksize) 1045 { 1046 int size; 1047 1048 size = blocksize - 1049 offsetof(struct ocfs2_group_desc, bg_bitmap); 1050 1051 return size; 1052 } 1053 1054 static inline int ocfs2_truncate_recs_per_inode(int blocksize) 1055 { 1056 int size; 1057 1058 size = blocksize - 1059 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs); 1060 1061 return size / sizeof(struct ocfs2_truncate_rec); 1062 } 1063 1064 static inline uint64_t ocfs2_backup_super_blkno(int blocksize, int index) 1065 { 1066 uint64_t offset = OCFS2_BACKUP_SB_START; 1067 1068 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) { 1069 offset <<= (2 * index); 1070 offset /= blocksize; 1071 return offset; 1072 } 1073 1074 return 0; 1075 } 1076 1077 static inline int ocfs2_xattr_recs_per_xb(int blocksize) 1078 { 1079 int size; 1080 1081 size = blocksize - 1082 offsetof(struct ocfs2_xattr_block, 1083 xb_attrs.xb_root.xt_list.l_recs); 1084 1085 return size / sizeof(struct ocfs2_extent_rec); 1086 } 1087 #endif /* __KERNEL__ */ 1088 1089 1090 static inline int ocfs2_system_inode_is_global(int type) 1091 { 1092 return ((type >= 0) && 1093 (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE)); 1094 } 1095 1096 static inline int ocfs2_sprintf_system_inode_name(char *buf, int len, 1097 int type, int slot) 1098 { 1099 int chars; 1100 1101 /* 1102 * Global system inodes can only have one copy. Everything 1103 * after OCFS2_LAST_GLOBAL_SYSTEM_INODE in the system inode 1104 * list has a copy per slot. 1105 */ 1106 if (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE) 1107 chars = snprintf(buf, len, "%s", 1108 ocfs2_system_inodes[type].si_name); 1109 else 1110 chars = snprintf(buf, len, 1111 ocfs2_system_inodes[type].si_name, 1112 slot); 1113 1114 return chars; 1115 } 1116 1117 static inline void ocfs2_set_de_type(struct ocfs2_dir_entry *de, 1118 umode_t mode) 1119 { 1120 de->file_type = ocfs2_type_by_mode[(mode & S_IFMT)>>S_SHIFT]; 1121 } 1122 1123 #endif /* _OCFS2_FS_H */ 1124 1125