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