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