1 /* xfs.h - an extraction from xfsprogs-1.3.5/include/xfs* into one file */ 2 /* 3 * GRUB -- GRand Unified Bootloader 4 * Copyright (C) 2000 Silicon Graphics, Inc. All Rights Reserved. 5 * Copyright (C) 2001,2004 Free Software Foundation, Inc. 6 * 7 * This program is free software; you can redistribute it and/or modify it 8 * under the terms of version 2 of the GNU General Public License as 9 * published by the Free Software Foundation. 10 * 11 * This program is distributed in the hope that it would be useful, but 12 * WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 14 * 15 * Further, this software is distributed without any warranty that it is 16 * free of the rightful claim of any third person regarding infringement 17 * or the like. Any license provided herein, whether implied or 18 * otherwise, applies only to this software file. Patent licenses, if 19 * any, provided herein do not apply to combinations of this program with 20 * other software, or any other product whatsoever. 21 * 22 * You should have received a copy of the GNU General Public License along 23 * with this program; if not, write the Free Software Foundation, Inc., 59 24 * Temple Place - Suite 330, Boston MA 02111-1307, USA. 25 * 26 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, 27 * Mountain View, CA 94043, or: 28 * 29 * http://www.sgi.com 30 * 31 * For further information regarding this notice, see: 32 * 33 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/ 34 */ 35 36 typedef signed char xfs_int8_t; 37 typedef unsigned char xfs_uint8_t; 38 typedef short xfs_int16_t; 39 typedef unsigned short xfs_uint16_t; 40 typedef int xfs_int32_t; 41 typedef unsigned int xfs_uint32_t; 42 typedef long long xfs_int64_t; 43 typedef unsigned long long xfs_uint64_t; 44 45 typedef xfs_uint64_t xfs_ino_t; 46 typedef xfs_uint32_t xfs_agino_t; 47 typedef xfs_int64_t xfs_daddr_t; 48 typedef xfs_int64_t xfs_off_t; 49 typedef xfs_uint8_t uuid_t[16]; 50 51 52 /* those are from xfs_types.h */ 53 54 typedef xfs_uint32_t xfs_agblock_t; /* blockno in alloc. group */ 55 typedef xfs_uint32_t xfs_extlen_t; /* extent length in blocks */ 56 typedef xfs_uint32_t xfs_agnumber_t; /* allocation group number */ 57 typedef xfs_int32_t xfs_extnum_t; /* # of extents in a file */ 58 typedef xfs_int16_t xfs_aextnum_t; /* # extents in an attribute fork */ 59 typedef xfs_int64_t xfs_fsize_t; /* bytes in a file */ 60 61 typedef xfs_uint32_t xfs_dablk_t; /* dir/attr block number (in file) */ 62 typedef xfs_uint32_t xfs_dahash_t; /* dir/attr hash value */ 63 64 /* 65 * Disk based types: 66 */ 67 typedef xfs_uint64_t xfs_dfsbno_t; /* blockno in filesystem (agno|agbno) */ 68 typedef xfs_uint64_t xfs_drfsbno_t; /* blockno in filesystem (raw) */ 69 typedef xfs_uint64_t xfs_drtbno_t; /* extent (block) in realtime area */ 70 typedef xfs_uint64_t xfs_dfiloff_t; /* block number in a file */ 71 72 typedef xfs_uint64_t xfs_fsblock_t; /* blockno in filesystem (agno|agbno) */ 73 typedef xfs_uint64_t xfs_fileoff_t; /* block number in a file */ 74 typedef xfs_uint64_t xfs_filblks_t; /* number of blocks in a file */ 75 76 77 /* those are from xfs_sb.h */ 78 79 #define XFS_SB_MAGIC 0x58465342 /* 'XFSB'*/ 80 #define XFS_SB_VERSION_4 4 /* 6.2+ - bitmask version */ 81 #define XFS_SB_VERSION_NUMBITS 0x000f 82 83 typedef struct xfs_sb 84 { 85 xfs_uint32_t sb_magicnum; /* magic number == XFS_SB_MAGIC */ 86 xfs_uint32_t sb_blocksize; /* logical block size, bytes */ 87 xfs_drfsbno_t sb_dblocks; /* number of data blocks */ 88 xfs_drfsbno_t sb_rblocks; /* number of realtime blocks */ 89 xfs_drtbno_t sb_rextents; /* number of realtime extents */ 90 uuid_t sb_uuid; /* file system unique id */ 91 xfs_dfsbno_t sb_logstart; /* starting block of log if internal */ 92 xfs_ino_t sb_rootino; /* root inode number */ 93 xfs_ino_t sb_rbmino; /* bitmap inode for realtime extents */ 94 xfs_ino_t sb_rsumino; /* summary inode for rt bitmap */ 95 xfs_agblock_t sb_rextsize; /* realtime extent size, blocks */ 96 xfs_agblock_t sb_agblocks; /* size of an allocation group */ 97 xfs_agnumber_t sb_agcount; /* number of allocation groups */ 98 xfs_extlen_t sb_rbmblocks; /* number of rt bitmap blocks */ 99 xfs_extlen_t sb_logblocks; /* number of log blocks */ 100 xfs_uint16_t sb_versionnum; /* header version == XFS_SB_VERSION */ 101 xfs_uint16_t sb_sectsize; /* volume sector size, bytes */ 102 xfs_uint16_t sb_inodesize; /* inode size, bytes */ 103 xfs_uint16_t sb_inopblock; /* inodes per block */ 104 char sb_fname[12]; /* file system name */ 105 xfs_uint8_t sb_blocklog; /* log2 of sb_blocksize */ 106 xfs_uint8_t sb_sectlog; /* log2 of sb_sectsize */ 107 xfs_uint8_t sb_inodelog; /* log2 of sb_inodesize */ 108 xfs_uint8_t sb_inopblog; /* log2 of sb_inopblock */ 109 xfs_uint8_t sb_agblklog; /* log2 of sb_agblocks (rounded up) */ 110 xfs_uint8_t sb_rextslog; /* log2 of sb_rextents */ 111 xfs_uint8_t sb_inprogress; /* mkfs is in progress, don't mount */ 112 xfs_uint8_t sb_imax_pct; /* max % of fs for inode space */ 113 /* statistics */ 114 /* 115 * These fields must remain contiguous. If you really 116 * want to change their layout, make sure you fix the 117 * code in xfs_trans_apply_sb_deltas(). 118 */ 119 xfs_uint64_t sb_icount; /* allocated inodes */ 120 xfs_uint64_t sb_ifree; /* free inodes */ 121 xfs_uint64_t sb_fdblocks; /* free data blocks */ 122 xfs_uint64_t sb_frextents; /* free realtime extents */ 123 /* 124 * End contiguous fields. 125 */ 126 xfs_ino_t sb_uquotino; /* user quota inode */ 127 xfs_ino_t sb_gquotino; /* group quota inode */ 128 xfs_uint16_t sb_qflags; /* quota flags */ 129 xfs_uint8_t sb_flags; /* misc. flags */ 130 xfs_uint8_t sb_shared_vn; /* shared version number */ 131 xfs_extlen_t sb_inoalignmt; /* inode chunk alignment, fsblocks */ 132 xfs_uint32_t sb_unit; /* stripe or raid unit */ 133 xfs_uint32_t sb_width; /* stripe or raid width */ 134 xfs_uint8_t sb_dirblklog; /* log2 of dir block size (fsbs) */ 135 xfs_uint8_t sb_dummy[7]; /* padding */ 136 } xfs_sb_t; 137 138 139 /* those are from xfs_btree.h */ 140 141 /* 142 * Long form header: bmap btrees. 143 */ 144 typedef struct xfs_btree_lblock 145 { 146 xfs_uint32_t bb_magic; /* magic number for block type */ 147 xfs_uint16_t bb_level; /* 0 is a leaf */ 148 xfs_uint16_t bb_numrecs; /* current # of data records */ 149 xfs_dfsbno_t bb_leftsib; /* left sibling block or NULLDFSBNO */ 150 xfs_dfsbno_t bb_rightsib; /* right sibling block or NULLDFSBNO */ 151 } xfs_btree_lblock_t; 152 153 /* 154 * Combined header and structure, used by common code. 155 */ 156 typedef struct xfs_btree_hdr 157 { 158 xfs_uint32_t bb_magic; /* magic number for block type */ 159 xfs_uint16_t bb_level; /* 0 is a leaf */ 160 xfs_uint16_t bb_numrecs; /* current # of data records */ 161 } xfs_btree_hdr_t; 162 163 typedef struct xfs_btree_block 164 { 165 xfs_btree_hdr_t bb_h; /* header */ 166 union { 167 struct { 168 xfs_agblock_t bb_leftsib; 169 xfs_agblock_t bb_rightsib; 170 } s; /* short form pointers */ 171 struct { 172 xfs_dfsbno_t bb_leftsib; 173 xfs_dfsbno_t bb_rightsib; 174 } l; /* long form pointers */ 175 } bb_u; /* rest */ 176 } xfs_btree_block_t; 177 178 /* those are from xfs_bmap_btree.h */ 179 180 /* 181 * Bmap root header, on-disk form only. 182 */ 183 typedef struct xfs_bmdr_block 184 { 185 xfs_uint16_t bb_level; /* 0 is a leaf */ 186 xfs_uint16_t bb_numrecs; /* current # of data records */ 187 } xfs_bmdr_block_t; 188 189 /* 190 * Bmap btree record and extent descriptor. 191 * For 32-bit kernels, 192 * l0:31 is an extent flag (value 1 indicates non-normal). 193 * l0:0-30 and l1:9-31 are startoff. 194 * l1:0-8, l2:0-31, and l3:21-31 are startblock. 195 * l3:0-20 are blockcount. 196 * For 64-bit kernels, 197 * l0:63 is an extent flag (value 1 indicates non-normal). 198 * l0:9-62 are startoff. 199 * l0:0-8 and l1:21-63 are startblock. 200 * l1:0-20 are blockcount. 201 */ 202 203 #define BMBT_USE_64 1 204 205 typedef struct xfs_bmbt_rec_32 206 { 207 xfs_uint32_t l0, l1, l2, l3; 208 } xfs_bmbt_rec_32_t; 209 typedef struct xfs_bmbt_rec_64 210 { 211 xfs_uint64_t l0, l1; 212 } xfs_bmbt_rec_64_t; 213 214 #if BMBT_USE_64 215 typedef xfs_uint64_t xfs_bmbt_rec_base_t; /* use this for casts */ 216 typedef xfs_bmbt_rec_64_t xfs_bmbt_rec_t, xfs_bmdr_rec_t; 217 #else /* !BMBT_USE_64 */ 218 typedef xfs_uint32_t xfs_bmbt_rec_base_t; /* use this for casts */ 219 typedef xfs_bmbt_rec_32_t xfs_bmbt_rec_t, xfs_bmdr_rec_t; 220 #endif /* BMBT_USE_64 */ 221 222 /* 223 * Key structure for non-leaf levels of the tree. 224 */ 225 typedef struct xfs_bmbt_key 226 { 227 xfs_dfiloff_t br_startoff; /* starting file offset */ 228 } xfs_bmbt_key_t, xfs_bmdr_key_t; 229 230 typedef xfs_dfsbno_t xfs_bmbt_ptr_t, xfs_bmdr_ptr_t; /* btree pointer type */ 231 /* btree block header type */ 232 typedef struct xfs_btree_lblock xfs_bmbt_block_t; 233 234 235 /* those are from xfs_dir2.h */ 236 /* 237 * Directory version 2. 238 * There are 4 possible formats: 239 * shortform 240 * single block - data with embedded leaf at the end 241 * multiple data blocks, single leaf+freeindex block 242 * data blocks, node&leaf blocks (btree), freeindex blocks 243 * 244 * The shortform format is in xfs_dir2_sf.h. 245 * The single block format is in xfs_dir2_block.h. 246 * The data block format is in xfs_dir2_data.h. 247 * The leaf and freeindex block formats are in xfs_dir2_leaf.h. 248 * Node blocks are the same as the other version, in xfs_da_btree.h. 249 */ 250 251 /* 252 * Byte offset in data block and shortform entry. 253 */ 254 typedef xfs_uint16_t xfs_dir2_data_off_t; 255 256 /* 257 * Byte offset in a directory. 258 */ 259 typedef xfs_off_t xfs_dir2_off_t; 260 261 /* those are from xfs_da_btree.h */ 262 /*======================================================================== 263 * Directory Structure when greater than XFS_LBSIZE(mp) bytes. 264 *========================================================================*/ 265 266 /* 267 * This structure is common to both leaf nodes and non-leaf nodes in the Btree. 268 * 269 * Is is used to manage a doubly linked list of all blocks at the same 270 * level in the Btree, and to identify which type of block this is. 271 */ 272 #define XFS_DIR2_LEAF1_MAGIC 0xd2f1 /* magic number: v2 dirlf single blks */ 273 #define XFS_DIR2_LEAFN_MAGIC 0xd2ff /* magic number: v2 dirlf multi blks */ 274 275 typedef struct xfs_da_blkinfo { 276 xfs_dablk_t forw; /* previous block in list */ 277 xfs_dablk_t back; /* following block in list */ 278 xfs_uint16_t magic; /* validity check on block */ 279 xfs_uint16_t pad; /* unused */ 280 } xfs_da_blkinfo_t; 281 282 /* 283 * This is the structure of the root and intermediate nodes in the Btree. 284 * The leaf nodes are defined above. 285 * 286 * Entries are not packed. 287 * 288 * Since we have duplicate keys, use a binary search but always follow 289 * all match in the block, not just the first match found. 290 */ 291 292 typedef struct xfs_da_intnode { 293 struct xfs_da_node_hdr { /* constant-structure header block */ 294 xfs_da_blkinfo_t info; /* block type, links, etc. */ 295 xfs_uint16_t count; /* count of active entries */ 296 xfs_uint16_t level; /* level above leaves (leaf == 0) */ 297 } hdr; 298 struct xfs_da_node_entry { 299 xfs_dahash_t hashval; /* hash value for this descendant */ 300 xfs_dablk_t before; /* Btree block before this key */ 301 } btree[1]; /* variable sized array of keys */ 302 } xfs_da_intnode_t; 303 304 305 /* those are from xfs_dir2_data.h */ 306 /* 307 * Directory format 2, data block structures. 308 */ 309 310 /* 311 * Constants. 312 */ 313 #define XFS_DIR2_DATA_FREE_TAG 0xffff 314 #define XFS_DIR2_DATA_FD_COUNT 3 315 316 /* 317 * Structures. 318 */ 319 320 /* 321 * Describe a free area in the data block. 322 * The freespace will be formatted as a xfs_dir2_data_unused_t. 323 */ 324 typedef struct xfs_dir2_data_free { 325 xfs_dir2_data_off_t offset; /* start of freespace */ 326 xfs_dir2_data_off_t length; /* length of freespace */ 327 } xfs_dir2_data_free_t; 328 329 /* 330 * Header for the data blocks. 331 * Always at the beginning of a directory-sized block. 332 * The code knows that XFS_DIR2_DATA_FD_COUNT is 3. 333 */ 334 typedef struct xfs_dir2_data_hdr { 335 xfs_uint32_t magic; /* XFS_DIR2_DATA_MAGIC */ 336 /* or XFS_DIR2_BLOCK_MAGIC */ 337 xfs_dir2_data_free_t bestfree[XFS_DIR2_DATA_FD_COUNT]; 338 } xfs_dir2_data_hdr_t; 339 340 /* 341 * Active entry in a data block. Aligned to 8 bytes. 342 * Tag appears as the last 2 bytes. 343 */ 344 typedef struct xfs_dir2_data_entry { 345 xfs_ino_t inumber; /* inode number */ 346 xfs_uint8_t namelen; /* name length */ 347 xfs_uint8_t name[1]; /* name bytes, no null */ 348 /* variable offset */ 349 xfs_dir2_data_off_t tag; /* starting offset of us */ 350 } xfs_dir2_data_entry_t; 351 352 /* 353 * Unused entry in a data block. Aligned to 8 bytes. 354 * Tag appears as the last 2 bytes. 355 */ 356 typedef struct xfs_dir2_data_unused { 357 xfs_uint16_t freetag; /* XFS_DIR2_DATA_FREE_TAG */ 358 xfs_dir2_data_off_t length; /* total free length */ 359 /* variable offset */ 360 xfs_dir2_data_off_t tag; /* starting offset of us */ 361 } xfs_dir2_data_unused_t; 362 363 typedef union { 364 xfs_dir2_data_entry_t entry; 365 xfs_dir2_data_unused_t unused; 366 } xfs_dir2_data_union_t; 367 368 369 /* those are from xfs_dir2_leaf.h */ 370 /* 371 * Directory version 2, leaf block structures. 372 */ 373 374 /* 375 * Leaf block header. 376 */ 377 typedef struct xfs_dir2_leaf_hdr { 378 xfs_da_blkinfo_t info; /* header for da routines */ 379 xfs_uint16_t count; /* count of entries */ 380 xfs_uint16_t stale; /* count of stale entries */ 381 } xfs_dir2_leaf_hdr_t; 382 383 384 /* those are from xfs_dir2_block.h */ 385 /* 386 * xfs_dir2_block.h 387 * Directory version 2, single block format structures 388 */ 389 390 /* 391 * The single block format is as follows: 392 * xfs_dir2_data_hdr_t structure 393 * xfs_dir2_data_entry_t and xfs_dir2_data_unused_t structures 394 * xfs_dir2_leaf_entry_t structures 395 * xfs_dir2_block_tail_t structure 396 */ 397 398 #define XFS_DIR2_BLOCK_MAGIC 0x58443242 /* XD2B: for one block dirs */ 399 400 typedef struct xfs_dir2_block_tail { 401 xfs_uint32_t count; /* count of leaf entries */ 402 xfs_uint32_t stale; /* count of stale lf entries */ 403 } xfs_dir2_block_tail_t; 404 405 406 /* those are from xfs_dir2_sf.h */ 407 408 /* 409 * Directory layout when stored internal to an inode. 410 * 411 * Small directories are packed as tightly as possible so as to 412 * fit into the literal area of the inode. 413 */ 414 415 /* 416 * Inode number stored as 8 8-bit values. 417 */ 418 typedef struct { xfs_uint8_t i[8]; } xfs_dir2_ino8_t; 419 420 /* 421 * Inode number stored as 4 8-bit values. 422 * Works a lot of the time, when all the inode numbers in a directory 423 * fit in 32 bits. 424 */ 425 typedef struct { xfs_uint8_t i[4]; } xfs_dir2_ino4_t; 426 427 typedef union { 428 xfs_dir2_ino8_t i8; 429 xfs_dir2_ino4_t i4; 430 } xfs_dir2_inou_t; 431 432 /* 433 * Normalized offset (in a data block) of the entry, really xfs_dir2_data_off_t. 434 * Only need 16 bits, this is the byte offset into the single block form. 435 */ 436 typedef struct { xfs_uint8_t i[2]; } xfs_dir2_sf_off_t; 437 438 /* 439 * The parent directory has a dedicated field, and the self-pointer must 440 * be calculated on the fly. 441 * 442 * Entries are packed toward the top as tightly as possible. The header 443 * and the elements must be bcopy()'d out into a work area to get correct 444 * alignment for the inode number fields. 445 */ 446 typedef struct xfs_dir2_sf_hdr { 447 xfs_uint8_t count; /* count of entries */ 448 xfs_uint8_t i8count; /* count of 8-byte inode #s */ 449 xfs_dir2_inou_t parent; /* parent dir inode number */ 450 } xfs_dir2_sf_hdr_t; 451 452 typedef struct xfs_dir2_sf_entry { 453 xfs_uint8_t namelen; /* actual name length */ 454 xfs_dir2_sf_off_t offset; /* saved offset */ 455 xfs_uint8_t name[1]; /* name, variable size */ 456 xfs_dir2_inou_t inumber; /* inode number, var. offset */ 457 } xfs_dir2_sf_entry_t; 458 459 typedef struct xfs_dir2_sf { 460 xfs_dir2_sf_hdr_t hdr; /* shortform header */ 461 xfs_dir2_sf_entry_t list[1]; /* shortform entries */ 462 } xfs_dir2_sf_t; 463 464 /* those are from xfs_dinode.h */ 465 466 #define XFS_DINODE_VERSION_1 1 467 #define XFS_DINODE_VERSION_2 2 468 #define XFS_DINODE_MAGIC 0x494e /* 'IN' */ 469 470 /* 471 * Disk inode structure. 472 * This is just the header; the inode is expanded to fill a variable size 473 * with the last field expanding. It is split into the core and "other" 474 * because we only need the core part in the in-core inode. 475 */ 476 typedef struct xfs_timestamp { 477 xfs_int32_t t_sec; /* timestamp seconds */ 478 xfs_int32_t t_nsec; /* timestamp nanoseconds */ 479 } xfs_timestamp_t; 480 481 /* 482 * Note: Coordinate changes to this structure with the XFS_DI_* #defines 483 * below and the offsets table in xfs_ialloc_log_di(). 484 */ 485 typedef struct xfs_dinode_core 486 { 487 xfs_uint16_t di_magic; /* inode magic # = XFS_DINODE_MAGIC */ 488 xfs_uint16_t di_mode; /* mode and type of file */ 489 xfs_int8_t di_version; /* inode version */ 490 xfs_int8_t di_format; /* format of di_c data */ 491 xfs_uint16_t di_onlink; /* old number of links to file */ 492 xfs_uint32_t di_uid; /* owner's user id */ 493 xfs_uint32_t di_gid; /* owner's group id */ 494 xfs_uint32_t di_nlink; /* number of links to file */ 495 xfs_uint16_t di_projid; /* owner's project id */ 496 xfs_uint8_t di_pad[10]; /* unused, zeroed space */ 497 xfs_timestamp_t di_atime; /* time last accessed */ 498 xfs_timestamp_t di_mtime; /* time last modified */ 499 xfs_timestamp_t di_ctime; /* time created/inode modified */ 500 xfs_fsize_t di_size; /* number of bytes in file */ 501 xfs_drfsbno_t di_nblocks; /* # of direct & btree blocks used */ 502 xfs_extlen_t di_extsize; /* basic/minimum extent size for file */ 503 xfs_extnum_t di_nextents; /* number of extents in data fork */ 504 xfs_aextnum_t di_anextents; /* number of extents in attribute fork*/ 505 xfs_uint8_t di_forkoff; /* attr fork offs, <<3 for 64b align */ 506 xfs_int8_t di_aformat; /* format of attr fork's data */ 507 xfs_uint32_t di_dmevmask; /* DMIG event mask */ 508 xfs_uint16_t di_dmstate; /* DMIG state info */ 509 xfs_uint16_t di_flags; /* random flags, XFS_DIFLAG_... */ 510 xfs_uint32_t di_gen; /* generation number */ 511 } xfs_dinode_core_t; 512 513 typedef struct xfs_dinode 514 { 515 xfs_dinode_core_t di_core; 516 xfs_agino_t di_next_unlinked;/* agi unlinked list ptr */ 517 union { 518 xfs_bmdr_block_t di_bmbt; /* btree root block */ 519 xfs_bmbt_rec_32_t di_bmx[1]; /* extent list */ 520 xfs_dir2_sf_t di_dir2sf; /* shortform directory v2 */ 521 char di_c[1]; /* local contents */ 522 } di_u; 523 } xfs_dinode_t; 524 525 /* 526 * Values for di_format 527 */ 528 typedef enum xfs_dinode_fmt 529 { 530 XFS_DINODE_FMT_DEV, /* CHR, BLK: di_dev */ 531 XFS_DINODE_FMT_LOCAL, /* DIR, REG: di_c */ 532 /* LNK: di_symlink */ 533 XFS_DINODE_FMT_EXTENTS, /* DIR, REG, LNK: di_bmx */ 534 XFS_DINODE_FMT_BTREE, /* DIR, REG, LNK: di_bmbt */ 535 XFS_DINODE_FMT_UUID /* MNT: di_uuid */ 536 } xfs_dinode_fmt_t; 537 538 /* 539 * File types (mode field) 540 */ 541 #define IFMT 0170000 /* type of file */ 542 #define IFDIR 0040000 /* directory */ 543 #define IFREG 0100000 /* regular */ 544 #define IFLNK 0120000 /* symbolic link */ 545