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