xref: /illumos-gate/usr/src/grub/grub-0.97/stage2/xfs.h (revision 1b8adde7)
17c478bd9Sstevel@tonic-gate /* xfs.h - an extraction from xfsprogs-1.3.5/include/xfs* into one file */
27c478bd9Sstevel@tonic-gate /*
37c478bd9Sstevel@tonic-gate  *  GRUB  --  GRand Unified Bootloader
47c478bd9Sstevel@tonic-gate  *  Copyright (C) 2000  Silicon Graphics, Inc.  All Rights Reserved.
57c478bd9Sstevel@tonic-gate  *  Copyright (C) 2001,2004  Free Software Foundation, Inc.
67c478bd9Sstevel@tonic-gate  *
77c478bd9Sstevel@tonic-gate  *  This program is free software; you can redistribute it and/or modify it
87c478bd9Sstevel@tonic-gate  *  under the terms of version 2 of the GNU General Public License as
97c478bd9Sstevel@tonic-gate  *  published by the Free Software Foundation.
107c478bd9Sstevel@tonic-gate  *
117c478bd9Sstevel@tonic-gate  *  This program is distributed in the hope that it would be useful, but
127c478bd9Sstevel@tonic-gate  *  WITHOUT ANY WARRANTY; without even the implied warranty of
137c478bd9Sstevel@tonic-gate  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
147c478bd9Sstevel@tonic-gate  *
157c478bd9Sstevel@tonic-gate  *  Further, this software is distributed without any warranty that it is
167c478bd9Sstevel@tonic-gate  *  free of the rightful claim of any third person regarding infringement
177c478bd9Sstevel@tonic-gate  *  or the like.  Any license provided herein, whether implied or
187c478bd9Sstevel@tonic-gate  *  otherwise, applies only to this software file.  Patent licenses, if
197c478bd9Sstevel@tonic-gate  *  any, provided herein do not apply to combinations of this program with
207c478bd9Sstevel@tonic-gate  *  other software, or any other product whatsoever.
217c478bd9Sstevel@tonic-gate  *
227c478bd9Sstevel@tonic-gate  *  You should have received a copy of the GNU General Public License along
237c478bd9Sstevel@tonic-gate  *  with this program; if not, write the Free Software Foundation, Inc., 59
247c478bd9Sstevel@tonic-gate  *  Temple Place - Suite 330, Boston MA 02111-1307, USA.
257c478bd9Sstevel@tonic-gate  *
267c478bd9Sstevel@tonic-gate  *  Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
277c478bd9Sstevel@tonic-gate  *  Mountain View, CA  94043, or:
287c478bd9Sstevel@tonic-gate  *
297c478bd9Sstevel@tonic-gate  *  http://www.sgi.com
307c478bd9Sstevel@tonic-gate  *
317c478bd9Sstevel@tonic-gate  *  For further information regarding this notice, see:
327c478bd9Sstevel@tonic-gate  *
337c478bd9Sstevel@tonic-gate  *  http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
347c478bd9Sstevel@tonic-gate  */
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate typedef signed char	xfs_int8_t;
377c478bd9Sstevel@tonic-gate typedef unsigned char	xfs_uint8_t;
387c478bd9Sstevel@tonic-gate typedef short		xfs_int16_t;
397c478bd9Sstevel@tonic-gate typedef unsigned short	xfs_uint16_t;
407c478bd9Sstevel@tonic-gate typedef int		xfs_int32_t;
417c478bd9Sstevel@tonic-gate typedef unsigned int	xfs_uint32_t;
427c478bd9Sstevel@tonic-gate typedef long long	xfs_int64_t;
437c478bd9Sstevel@tonic-gate typedef unsigned long long xfs_uint64_t;
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate typedef xfs_uint64_t	xfs_ino_t;
467c478bd9Sstevel@tonic-gate typedef	xfs_uint32_t	xfs_agino_t;
477c478bd9Sstevel@tonic-gate typedef xfs_int64_t	xfs_daddr_t;
487c478bd9Sstevel@tonic-gate typedef xfs_int64_t	xfs_off_t;
497c478bd9Sstevel@tonic-gate typedef xfs_uint8_t	uuid_t[16];
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate /* those are from xfs_types.h */
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate typedef xfs_uint32_t	xfs_agblock_t;	/* blockno in alloc. group */
557c478bd9Sstevel@tonic-gate typedef	xfs_uint32_t	xfs_extlen_t;	/* extent length in blocks */
567c478bd9Sstevel@tonic-gate typedef	xfs_uint32_t	xfs_agnumber_t;	/* allocation group number */
577c478bd9Sstevel@tonic-gate typedef xfs_int32_t	xfs_extnum_t;	/* # of extents in a file */
587c478bd9Sstevel@tonic-gate typedef xfs_int16_t	xfs_aextnum_t;	/* # extents in an attribute fork */
597c478bd9Sstevel@tonic-gate typedef	xfs_int64_t	xfs_fsize_t;	/* bytes in a file */
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate typedef	xfs_uint32_t	xfs_dablk_t;	/* dir/attr block number (in file) */
627c478bd9Sstevel@tonic-gate typedef	xfs_uint32_t	xfs_dahash_t;	/* dir/attr hash value */
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate /*
657c478bd9Sstevel@tonic-gate  * Disk based types:
667c478bd9Sstevel@tonic-gate  */
677c478bd9Sstevel@tonic-gate typedef xfs_uint64_t	xfs_dfsbno_t;	/* blockno in filesystem (agno|agbno) */
687c478bd9Sstevel@tonic-gate typedef xfs_uint64_t	xfs_drfsbno_t;	/* blockno in filesystem (raw) */
697c478bd9Sstevel@tonic-gate typedef	xfs_uint64_t	xfs_drtbno_t;	/* extent (block) in realtime area */
707c478bd9Sstevel@tonic-gate typedef	xfs_uint64_t	xfs_dfiloff_t;	/* block number in a file */
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate typedef	xfs_uint64_t	xfs_fsblock_t;	/* blockno in filesystem (agno|agbno) */
737c478bd9Sstevel@tonic-gate typedef	xfs_uint64_t	xfs_fileoff_t;	/* block number in a file */
747c478bd9Sstevel@tonic-gate typedef	xfs_uint64_t	xfs_filblks_t;	/* number of blocks in a file */
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate /* those are from xfs_sb.h */
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate #define	XFS_SB_MAGIC		0x58465342	/* 'XFSB'*/
807c478bd9Sstevel@tonic-gate #define	XFS_SB_VERSION_4	4		/* 6.2+ - bitmask version */
817c478bd9Sstevel@tonic-gate #define	XFS_SB_VERSION_NUMBITS	0x000f
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate typedef struct xfs_sb
847c478bd9Sstevel@tonic-gate {
857c478bd9Sstevel@tonic-gate 	xfs_uint32_t	sb_magicnum;	/* magic number == XFS_SB_MAGIC */
867c478bd9Sstevel@tonic-gate 	xfs_uint32_t	sb_blocksize;	/* logical block size, bytes */
877c478bd9Sstevel@tonic-gate 	xfs_drfsbno_t	sb_dblocks;	/* number of data blocks */
887c478bd9Sstevel@tonic-gate 	xfs_drfsbno_t	sb_rblocks;	/* number of realtime blocks */
897c478bd9Sstevel@tonic-gate 	xfs_drtbno_t	sb_rextents;	/* number of realtime extents */
907c478bd9Sstevel@tonic-gate 	uuid_t		sb_uuid;	/* file system unique id */
917c478bd9Sstevel@tonic-gate 	xfs_dfsbno_t	sb_logstart;	/* starting block of log if internal */
927c478bd9Sstevel@tonic-gate 	xfs_ino_t	sb_rootino;	/* root inode number */
937c478bd9Sstevel@tonic-gate 	xfs_ino_t	sb_rbmino;	/* bitmap inode for realtime extents */
947c478bd9Sstevel@tonic-gate 	xfs_ino_t	sb_rsumino;	/* summary inode for rt bitmap */
957c478bd9Sstevel@tonic-gate 	xfs_agblock_t	sb_rextsize;	/* realtime extent size, blocks */
967c478bd9Sstevel@tonic-gate 	xfs_agblock_t	sb_agblocks;	/* size of an allocation group */
977c478bd9Sstevel@tonic-gate 	xfs_agnumber_t	sb_agcount;	/* number of allocation groups */
987c478bd9Sstevel@tonic-gate 	xfs_extlen_t	sb_rbmblocks;	/* number of rt bitmap blocks */
997c478bd9Sstevel@tonic-gate 	xfs_extlen_t	sb_logblocks;	/* number of log blocks */
1007c478bd9Sstevel@tonic-gate 	xfs_uint16_t	sb_versionnum;	/* header version == XFS_SB_VERSION */
1017c478bd9Sstevel@tonic-gate 	xfs_uint16_t	sb_sectsize;	/* volume sector size, bytes */
1027c478bd9Sstevel@tonic-gate 	xfs_uint16_t	sb_inodesize;	/* inode size, bytes */
1037c478bd9Sstevel@tonic-gate 	xfs_uint16_t	sb_inopblock;	/* inodes per block */
1047c478bd9Sstevel@tonic-gate 	char		sb_fname[12];	/* file system name */
1057c478bd9Sstevel@tonic-gate 	xfs_uint8_t	sb_blocklog;	/* log2 of sb_blocksize */
1067c478bd9Sstevel@tonic-gate 	xfs_uint8_t	sb_sectlog;	/* log2 of sb_sectsize */
1077c478bd9Sstevel@tonic-gate 	xfs_uint8_t	sb_inodelog;	/* log2 of sb_inodesize */
1087c478bd9Sstevel@tonic-gate 	xfs_uint8_t	sb_inopblog;	/* log2 of sb_inopblock */
1097c478bd9Sstevel@tonic-gate 	xfs_uint8_t	sb_agblklog;	/* log2 of sb_agblocks (rounded up) */
1107c478bd9Sstevel@tonic-gate 	xfs_uint8_t	sb_rextslog;	/* log2 of sb_rextents */
1117c478bd9Sstevel@tonic-gate 	xfs_uint8_t	sb_inprogress;	/* mkfs is in progress, don't mount */
1127c478bd9Sstevel@tonic-gate 	xfs_uint8_t	sb_imax_pct;	/* max % of fs for inode space */
1137c478bd9Sstevel@tonic-gate 					/* statistics */
1147c478bd9Sstevel@tonic-gate 	/*
1157c478bd9Sstevel@tonic-gate 	 * These fields must remain contiguous.  If you really
1167c478bd9Sstevel@tonic-gate 	 * want to change their layout, make sure you fix the
1177c478bd9Sstevel@tonic-gate 	 * code in xfs_trans_apply_sb_deltas().
1187c478bd9Sstevel@tonic-gate 	 */
1197c478bd9Sstevel@tonic-gate 	xfs_uint64_t	sb_icount;	/* allocated inodes */
1207c478bd9Sstevel@tonic-gate 	xfs_uint64_t	sb_ifree;	/* free inodes */
1217c478bd9Sstevel@tonic-gate 	xfs_uint64_t	sb_fdblocks;	/* free data blocks */
1227c478bd9Sstevel@tonic-gate 	xfs_uint64_t	sb_frextents;	/* free realtime extents */
1237c478bd9Sstevel@tonic-gate 	/*
1247c478bd9Sstevel@tonic-gate 	 * End contiguous fields.
1257c478bd9Sstevel@tonic-gate 	 */
1267c478bd9Sstevel@tonic-gate 	xfs_ino_t	sb_uquotino;	/* user quota inode */
1277c478bd9Sstevel@tonic-gate 	xfs_ino_t	sb_gquotino;	/* group quota inode */
1287c478bd9Sstevel@tonic-gate 	xfs_uint16_t	sb_qflags;	/* quota flags */
1297c478bd9Sstevel@tonic-gate 	xfs_uint8_t	sb_flags;	/* misc. flags */
1307c478bd9Sstevel@tonic-gate 	xfs_uint8_t	sb_shared_vn;	/* shared version number */
1317c478bd9Sstevel@tonic-gate 	xfs_extlen_t	sb_inoalignmt;	/* inode chunk alignment, fsblocks */
1327c478bd9Sstevel@tonic-gate 	xfs_uint32_t	sb_unit;	/* stripe or raid unit */
1337c478bd9Sstevel@tonic-gate 	xfs_uint32_t	sb_width;	/* stripe or raid width */
1347c478bd9Sstevel@tonic-gate 	xfs_uint8_t	sb_dirblklog;	/* log2 of dir block size (fsbs) */
1357c478bd9Sstevel@tonic-gate         xfs_uint8_t       sb_dummy[7];    /* padding */
1367c478bd9Sstevel@tonic-gate } xfs_sb_t;
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate /* those are from xfs_btree.h */
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate /*
1427c478bd9Sstevel@tonic-gate  * Long form header: bmap btrees.
1437c478bd9Sstevel@tonic-gate  */
1447c478bd9Sstevel@tonic-gate typedef struct xfs_btree_lblock
1457c478bd9Sstevel@tonic-gate {
1467c478bd9Sstevel@tonic-gate 	xfs_uint32_t	bb_magic;	/* magic number for block type */
1477c478bd9Sstevel@tonic-gate 	xfs_uint16_t	bb_level;	/* 0 is a leaf */
1487c478bd9Sstevel@tonic-gate 	xfs_uint16_t	bb_numrecs;	/* current # of data records */
1497c478bd9Sstevel@tonic-gate 	xfs_dfsbno_t	bb_leftsib;	/* left sibling block or NULLDFSBNO */
1507c478bd9Sstevel@tonic-gate 	xfs_dfsbno_t	bb_rightsib;	/* right sibling block or NULLDFSBNO */
1517c478bd9Sstevel@tonic-gate } xfs_btree_lblock_t;
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate /*
1547c478bd9Sstevel@tonic-gate  * Combined header and structure, used by common code.
1557c478bd9Sstevel@tonic-gate  */
1567c478bd9Sstevel@tonic-gate typedef struct xfs_btree_hdr
1577c478bd9Sstevel@tonic-gate {
1587c478bd9Sstevel@tonic-gate 	xfs_uint32_t	bb_magic;	/* magic number for block type */
1597c478bd9Sstevel@tonic-gate 	xfs_uint16_t	bb_level;	/* 0 is a leaf */
1607c478bd9Sstevel@tonic-gate 	xfs_uint16_t	bb_numrecs;	/* current # of data records */
1617c478bd9Sstevel@tonic-gate } xfs_btree_hdr_t;
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate typedef struct xfs_btree_block
1647c478bd9Sstevel@tonic-gate {
1657c478bd9Sstevel@tonic-gate 	xfs_btree_hdr_t	bb_h;		/* header */
1667c478bd9Sstevel@tonic-gate 	union		{
1677c478bd9Sstevel@tonic-gate 		struct	{
1687c478bd9Sstevel@tonic-gate 			xfs_agblock_t	bb_leftsib;
1697c478bd9Sstevel@tonic-gate 			xfs_agblock_t	bb_rightsib;
1707c478bd9Sstevel@tonic-gate 		}	s;		/* short form pointers */
1717c478bd9Sstevel@tonic-gate 		struct	{
1727c478bd9Sstevel@tonic-gate 			xfs_dfsbno_t	bb_leftsib;
1737c478bd9Sstevel@tonic-gate 			xfs_dfsbno_t	bb_rightsib;
1747c478bd9Sstevel@tonic-gate 		}	l;		/* long form pointers */
1757c478bd9Sstevel@tonic-gate 	}		bb_u;		/* rest */
1767c478bd9Sstevel@tonic-gate } xfs_btree_block_t;
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate /* those are from xfs_bmap_btree.h */
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate /*
1817c478bd9Sstevel@tonic-gate  * Bmap root header, on-disk form only.
1827c478bd9Sstevel@tonic-gate  */
1837c478bd9Sstevel@tonic-gate typedef struct xfs_bmdr_block
1847c478bd9Sstevel@tonic-gate {
1857c478bd9Sstevel@tonic-gate 	xfs_uint16_t	bb_level;	/* 0 is a leaf */
1867c478bd9Sstevel@tonic-gate 	xfs_uint16_t	bb_numrecs;	/* current # of data records */
1877c478bd9Sstevel@tonic-gate } xfs_bmdr_block_t;
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate /*
1907c478bd9Sstevel@tonic-gate  * Bmap btree record and extent descriptor.
1917c478bd9Sstevel@tonic-gate  * For 32-bit kernels,
1927c478bd9Sstevel@tonic-gate  *  l0:31 is an extent flag (value 1 indicates non-normal).
1937c478bd9Sstevel@tonic-gate  *  l0:0-30 and l1:9-31 are startoff.
1947c478bd9Sstevel@tonic-gate  *  l1:0-8, l2:0-31, and l3:21-31 are startblock.
1957c478bd9Sstevel@tonic-gate  *  l3:0-20 are blockcount.
1967c478bd9Sstevel@tonic-gate  * For 64-bit kernels,
1977c478bd9Sstevel@tonic-gate  *  l0:63 is an extent flag (value 1 indicates non-normal).
1987c478bd9Sstevel@tonic-gate  *  l0:9-62 are startoff.
1997c478bd9Sstevel@tonic-gate  *  l0:0-8 and l1:21-63 are startblock.
2007c478bd9Sstevel@tonic-gate  *  l1:0-20 are blockcount.
2017c478bd9Sstevel@tonic-gate  */
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate #define	BMBT_USE_64	1
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate typedef struct xfs_bmbt_rec_32
2067c478bd9Sstevel@tonic-gate {
2077c478bd9Sstevel@tonic-gate 	xfs_uint32_t		l0, l1, l2, l3;
2087c478bd9Sstevel@tonic-gate } xfs_bmbt_rec_32_t;
2097c478bd9Sstevel@tonic-gate typedef struct xfs_bmbt_rec_64
2107c478bd9Sstevel@tonic-gate {
2117c478bd9Sstevel@tonic-gate 	xfs_uint64_t		l0, l1;
2127c478bd9Sstevel@tonic-gate } xfs_bmbt_rec_64_t;
2137c478bd9Sstevel@tonic-gate 
2147c478bd9Sstevel@tonic-gate #if BMBT_USE_64
2157c478bd9Sstevel@tonic-gate typedef	xfs_uint64_t	xfs_bmbt_rec_base_t;	/* use this for casts */
2167c478bd9Sstevel@tonic-gate typedef xfs_bmbt_rec_64_t xfs_bmbt_rec_t, xfs_bmdr_rec_t;
2177c478bd9Sstevel@tonic-gate #else	/* !BMBT_USE_64 */
2187c478bd9Sstevel@tonic-gate typedef	xfs_uint32_t	xfs_bmbt_rec_base_t;	/* use this for casts */
2197c478bd9Sstevel@tonic-gate typedef xfs_bmbt_rec_32_t xfs_bmbt_rec_t, xfs_bmdr_rec_t;
2207c478bd9Sstevel@tonic-gate #endif	/* BMBT_USE_64 */
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate /*
2237c478bd9Sstevel@tonic-gate  * Key structure for non-leaf levels of the tree.
2247c478bd9Sstevel@tonic-gate  */
2257c478bd9Sstevel@tonic-gate typedef struct xfs_bmbt_key
2267c478bd9Sstevel@tonic-gate {
2277c478bd9Sstevel@tonic-gate 	xfs_dfiloff_t	br_startoff;	/* starting file offset */
2287c478bd9Sstevel@tonic-gate } xfs_bmbt_key_t, xfs_bmdr_key_t;
2297c478bd9Sstevel@tonic-gate 
2307c478bd9Sstevel@tonic-gate typedef xfs_dfsbno_t xfs_bmbt_ptr_t, xfs_bmdr_ptr_t;	/* btree pointer type */
2317c478bd9Sstevel@tonic-gate 					/* btree block header type */
2327c478bd9Sstevel@tonic-gate typedef	struct xfs_btree_lblock xfs_bmbt_block_t;
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate /* those are from xfs_dir2.h */
2367c478bd9Sstevel@tonic-gate /*
2377c478bd9Sstevel@tonic-gate  * Directory version 2.
2387c478bd9Sstevel@tonic-gate  * There are 4 possible formats:
2397c478bd9Sstevel@tonic-gate  *	shortform
2407c478bd9Sstevel@tonic-gate  *	single block - data with embedded leaf at the end
2417c478bd9Sstevel@tonic-gate  *	multiple data blocks, single leaf+freeindex block
2427c478bd9Sstevel@tonic-gate  *	data blocks, node&leaf blocks (btree), freeindex blocks
2437c478bd9Sstevel@tonic-gate  *
2447c478bd9Sstevel@tonic-gate  *	The shortform format is in xfs_dir2_sf.h.
2457c478bd9Sstevel@tonic-gate  *	The single block format is in xfs_dir2_block.h.
2467c478bd9Sstevel@tonic-gate  *	The data block format is in xfs_dir2_data.h.
2477c478bd9Sstevel@tonic-gate  *	The leaf and freeindex block formats are in xfs_dir2_leaf.h.
2487c478bd9Sstevel@tonic-gate  *	Node blocks are the same as the other version, in xfs_da_btree.h.
2497c478bd9Sstevel@tonic-gate  */
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate /*
2527c478bd9Sstevel@tonic-gate  * Byte offset in data block and shortform entry.
2537c478bd9Sstevel@tonic-gate  */
2547c478bd9Sstevel@tonic-gate typedef	xfs_uint16_t	xfs_dir2_data_off_t;
2557c478bd9Sstevel@tonic-gate 
2567c478bd9Sstevel@tonic-gate /*
2577c478bd9Sstevel@tonic-gate  * Byte offset in a directory.
2587c478bd9Sstevel@tonic-gate  */
2597c478bd9Sstevel@tonic-gate typedef	xfs_off_t		xfs_dir2_off_t;
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate /* those are from xfs_da_btree.h */
2627c478bd9Sstevel@tonic-gate /*========================================================================
2637c478bd9Sstevel@tonic-gate  * Directory Structure when greater than XFS_LBSIZE(mp) bytes.
2647c478bd9Sstevel@tonic-gate  *========================================================================*/
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate /*
2677c478bd9Sstevel@tonic-gate  * This structure is common to both leaf nodes and non-leaf nodes in the Btree.
2687c478bd9Sstevel@tonic-gate  *
2697c478bd9Sstevel@tonic-gate  * Is is used to manage a doubly linked list of all blocks at the same
2707c478bd9Sstevel@tonic-gate  * level in the Btree, and to identify which type of block this is.
2717c478bd9Sstevel@tonic-gate  */
2727c478bd9Sstevel@tonic-gate #define	XFS_DIR2_LEAF1_MAGIC	0xd2f1	/* magic number: v2 dirlf single blks */
2737c478bd9Sstevel@tonic-gate #define	XFS_DIR2_LEAFN_MAGIC	0xd2ff	/* magic number: v2 dirlf multi blks */
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate typedef struct xfs_da_blkinfo {
2767c478bd9Sstevel@tonic-gate 	xfs_dablk_t forw;			/* previous block in list */
2777c478bd9Sstevel@tonic-gate 	xfs_dablk_t back;			/* following block in list */
2787c478bd9Sstevel@tonic-gate 	xfs_uint16_t magic;			/* validity check on block */
2797c478bd9Sstevel@tonic-gate 	xfs_uint16_t pad;				/* unused */
2807c478bd9Sstevel@tonic-gate } xfs_da_blkinfo_t;
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate /*
2837c478bd9Sstevel@tonic-gate  * This is the structure of the root and intermediate nodes in the Btree.
2847c478bd9Sstevel@tonic-gate  * The leaf nodes are defined above.
2857c478bd9Sstevel@tonic-gate  *
2867c478bd9Sstevel@tonic-gate  * Entries are not packed.
2877c478bd9Sstevel@tonic-gate  *
2887c478bd9Sstevel@tonic-gate  * Since we have duplicate keys, use a binary search but always follow
2897c478bd9Sstevel@tonic-gate  * all match in the block, not just the first match found.
2907c478bd9Sstevel@tonic-gate  */
2917c478bd9Sstevel@tonic-gate 
2927c478bd9Sstevel@tonic-gate typedef struct xfs_da_intnode {
2937c478bd9Sstevel@tonic-gate 	struct xfs_da_node_hdr {	/* constant-structure header block */
2947c478bd9Sstevel@tonic-gate 		xfs_da_blkinfo_t info;	/* block type, links, etc. */
2957c478bd9Sstevel@tonic-gate 		xfs_uint16_t count;	/* count of active entries */
2967c478bd9Sstevel@tonic-gate 		xfs_uint16_t level;	/* level above leaves (leaf == 0) */
2977c478bd9Sstevel@tonic-gate 	} hdr;
2987c478bd9Sstevel@tonic-gate 	struct xfs_da_node_entry {
2997c478bd9Sstevel@tonic-gate 		xfs_dahash_t hashval;	/* hash value for this descendant */
3007c478bd9Sstevel@tonic-gate 		xfs_dablk_t before;	/* Btree block before this key */
3017c478bd9Sstevel@tonic-gate 	} btree[1];			/* variable sized array of keys */
3027c478bd9Sstevel@tonic-gate } xfs_da_intnode_t;
3037c478bd9Sstevel@tonic-gate 
3047c478bd9Sstevel@tonic-gate 
3057c478bd9Sstevel@tonic-gate /* those are from xfs_dir2_data.h */
3067c478bd9Sstevel@tonic-gate /*
3077c478bd9Sstevel@tonic-gate  * Directory format 2, data block structures.
3087c478bd9Sstevel@tonic-gate  */
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate /*
3117c478bd9Sstevel@tonic-gate  * Constants.
3127c478bd9Sstevel@tonic-gate  */
3137c478bd9Sstevel@tonic-gate #define	XFS_DIR2_DATA_FREE_TAG	0xffff
3147c478bd9Sstevel@tonic-gate #define	XFS_DIR2_DATA_FD_COUNT	3
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate /*
3177c478bd9Sstevel@tonic-gate  * Structures.
3187c478bd9Sstevel@tonic-gate  */
3197c478bd9Sstevel@tonic-gate 
3207c478bd9Sstevel@tonic-gate /*
3217c478bd9Sstevel@tonic-gate  * Describe a free area in the data block.
3227c478bd9Sstevel@tonic-gate  * The freespace will be formatted as a xfs_dir2_data_unused_t.
3237c478bd9Sstevel@tonic-gate  */
3247c478bd9Sstevel@tonic-gate typedef struct xfs_dir2_data_free {
3257c478bd9Sstevel@tonic-gate 	xfs_dir2_data_off_t	offset;		/* start of freespace */
3267c478bd9Sstevel@tonic-gate 	xfs_dir2_data_off_t	length;		/* length of freespace */
3277c478bd9Sstevel@tonic-gate } xfs_dir2_data_free_t;
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate /*
3307c478bd9Sstevel@tonic-gate  * Header for the data blocks.
3317c478bd9Sstevel@tonic-gate  * Always at the beginning of a directory-sized block.
3327c478bd9Sstevel@tonic-gate  * The code knows that XFS_DIR2_DATA_FD_COUNT is 3.
3337c478bd9Sstevel@tonic-gate  */
3347c478bd9Sstevel@tonic-gate typedef struct xfs_dir2_data_hdr {
3357c478bd9Sstevel@tonic-gate 	xfs_uint32_t		magic;		/* XFS_DIR2_DATA_MAGIC */
3367c478bd9Sstevel@tonic-gate 						/* or XFS_DIR2_BLOCK_MAGIC */
3377c478bd9Sstevel@tonic-gate 	xfs_dir2_data_free_t	bestfree[XFS_DIR2_DATA_FD_COUNT];
3387c478bd9Sstevel@tonic-gate } xfs_dir2_data_hdr_t;
3397c478bd9Sstevel@tonic-gate 
3407c478bd9Sstevel@tonic-gate /*
3417c478bd9Sstevel@tonic-gate  * Active entry in a data block.  Aligned to 8 bytes.
3427c478bd9Sstevel@tonic-gate  * Tag appears as the last 2 bytes.
3437c478bd9Sstevel@tonic-gate  */
3447c478bd9Sstevel@tonic-gate typedef struct xfs_dir2_data_entry {
3457c478bd9Sstevel@tonic-gate 	xfs_ino_t		inumber;	/* inode number */
3467c478bd9Sstevel@tonic-gate 	xfs_uint8_t		namelen;	/* name length */
3477c478bd9Sstevel@tonic-gate 	xfs_uint8_t		name[1];	/* name bytes, no null */
3487c478bd9Sstevel@tonic-gate 						/* variable offset */
3497c478bd9Sstevel@tonic-gate 	xfs_dir2_data_off_t	tag;		/* starting offset of us */
3507c478bd9Sstevel@tonic-gate } xfs_dir2_data_entry_t;
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate /*
3537c478bd9Sstevel@tonic-gate  * Unused entry in a data block.  Aligned to 8 bytes.
3547c478bd9Sstevel@tonic-gate  * Tag appears as the last 2 bytes.
3557c478bd9Sstevel@tonic-gate  */
3567c478bd9Sstevel@tonic-gate typedef struct xfs_dir2_data_unused {
3577c478bd9Sstevel@tonic-gate 	xfs_uint16_t		freetag;	/* XFS_DIR2_DATA_FREE_TAG */
3587c478bd9Sstevel@tonic-gate 	xfs_dir2_data_off_t	length;		/* total free length */
3597c478bd9Sstevel@tonic-gate 						/* variable offset */
3607c478bd9Sstevel@tonic-gate 	xfs_dir2_data_off_t	tag;		/* starting offset of us */
3617c478bd9Sstevel@tonic-gate } xfs_dir2_data_unused_t;
3627c478bd9Sstevel@tonic-gate 
3637c478bd9Sstevel@tonic-gate typedef union {
3647c478bd9Sstevel@tonic-gate 	xfs_dir2_data_entry_t	entry;
3657c478bd9Sstevel@tonic-gate 	xfs_dir2_data_unused_t	unused;
3667c478bd9Sstevel@tonic-gate } xfs_dir2_data_union_t;
3677c478bd9Sstevel@tonic-gate 
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate /* those are from xfs_dir2_leaf.h */
3707c478bd9Sstevel@tonic-gate /*
3717c478bd9Sstevel@tonic-gate  * Directory version 2, leaf block structures.
3727c478bd9Sstevel@tonic-gate  */
3737c478bd9Sstevel@tonic-gate 
3747c478bd9Sstevel@tonic-gate /*
3757c478bd9Sstevel@tonic-gate  * Leaf block header.
3767c478bd9Sstevel@tonic-gate  */
3777c478bd9Sstevel@tonic-gate typedef struct xfs_dir2_leaf_hdr {
3787c478bd9Sstevel@tonic-gate 	xfs_da_blkinfo_t	info;		/* header for da routines */
3797c478bd9Sstevel@tonic-gate 	xfs_uint16_t		count;		/* count of entries */
3807c478bd9Sstevel@tonic-gate 	xfs_uint16_t		stale;		/* count of stale entries */
3817c478bd9Sstevel@tonic-gate } xfs_dir2_leaf_hdr_t;
3827c478bd9Sstevel@tonic-gate 
3837c478bd9Sstevel@tonic-gate 
3847c478bd9Sstevel@tonic-gate /* those are from xfs_dir2_block.h */
3857c478bd9Sstevel@tonic-gate /*
3867c478bd9Sstevel@tonic-gate  * xfs_dir2_block.h
3877c478bd9Sstevel@tonic-gate  * Directory version 2, single block format structures
3887c478bd9Sstevel@tonic-gate  */
3897c478bd9Sstevel@tonic-gate 
3907c478bd9Sstevel@tonic-gate /*
3917c478bd9Sstevel@tonic-gate  * The single block format is as follows:
3927c478bd9Sstevel@tonic-gate  * xfs_dir2_data_hdr_t structure
3937c478bd9Sstevel@tonic-gate  * xfs_dir2_data_entry_t and xfs_dir2_data_unused_t structures
3947c478bd9Sstevel@tonic-gate  * xfs_dir2_leaf_entry_t structures
3957c478bd9Sstevel@tonic-gate  * xfs_dir2_block_tail_t structure
3967c478bd9Sstevel@tonic-gate  */
3977c478bd9Sstevel@tonic-gate 
3987c478bd9Sstevel@tonic-gate #define	XFS_DIR2_BLOCK_MAGIC	0x58443242	/* XD2B: for one block dirs */
3997c478bd9Sstevel@tonic-gate 
4007c478bd9Sstevel@tonic-gate typedef struct xfs_dir2_block_tail {
4017c478bd9Sstevel@tonic-gate 	xfs_uint32_t	count;			/* count of leaf entries */
4027c478bd9Sstevel@tonic-gate 	xfs_uint32_t	stale;			/* count of stale lf entries */
4037c478bd9Sstevel@tonic-gate } xfs_dir2_block_tail_t;
4047c478bd9Sstevel@tonic-gate 
4057c478bd9Sstevel@tonic-gate 
4067c478bd9Sstevel@tonic-gate /* those are from xfs_dir2_sf.h */
4077c478bd9Sstevel@tonic-gate 
4087c478bd9Sstevel@tonic-gate /*
4097c478bd9Sstevel@tonic-gate  * Directory layout when stored internal to an inode.
4107c478bd9Sstevel@tonic-gate  *
4117c478bd9Sstevel@tonic-gate  * Small directories are packed as tightly as possible so as to
4127c478bd9Sstevel@tonic-gate  * fit into the literal area of the inode.
4137c478bd9Sstevel@tonic-gate  */
4147c478bd9Sstevel@tonic-gate 
4157c478bd9Sstevel@tonic-gate /*
4167c478bd9Sstevel@tonic-gate  * Inode number stored as 8 8-bit values.
4177c478bd9Sstevel@tonic-gate  */
4187c478bd9Sstevel@tonic-gate typedef	struct { xfs_uint8_t i[8]; } xfs_dir2_ino8_t;
4197c478bd9Sstevel@tonic-gate 
4207c478bd9Sstevel@tonic-gate /*
4217c478bd9Sstevel@tonic-gate  * Inode number stored as 4 8-bit values.
4227c478bd9Sstevel@tonic-gate  * Works a lot of the time, when all the inode numbers in a directory
4237c478bd9Sstevel@tonic-gate  * fit in 32 bits.
4247c478bd9Sstevel@tonic-gate  */
4257c478bd9Sstevel@tonic-gate typedef struct { xfs_uint8_t i[4]; } xfs_dir2_ino4_t;
4267c478bd9Sstevel@tonic-gate 
4277c478bd9Sstevel@tonic-gate typedef union {
4287c478bd9Sstevel@tonic-gate 	xfs_dir2_ino8_t	i8;
4297c478bd9Sstevel@tonic-gate 	xfs_dir2_ino4_t	i4;
4307c478bd9Sstevel@tonic-gate } xfs_dir2_inou_t;
4317c478bd9Sstevel@tonic-gate 
4327c478bd9Sstevel@tonic-gate /*
4337c478bd9Sstevel@tonic-gate  * Normalized offset (in a data block) of the entry, really xfs_dir2_data_off_t.
4347c478bd9Sstevel@tonic-gate  * Only need 16 bits, this is the byte offset into the single block form.
4357c478bd9Sstevel@tonic-gate  */
4367c478bd9Sstevel@tonic-gate typedef struct { xfs_uint8_t i[2]; } xfs_dir2_sf_off_t;
4377c478bd9Sstevel@tonic-gate 
4387c478bd9Sstevel@tonic-gate /*
4397c478bd9Sstevel@tonic-gate  * The parent directory has a dedicated field, and the self-pointer must
4407c478bd9Sstevel@tonic-gate  * be calculated on the fly.
4417c478bd9Sstevel@tonic-gate  *
4427c478bd9Sstevel@tonic-gate  * Entries are packed toward the top as tightly as possible.  The header
4437c478bd9Sstevel@tonic-gate  * and the elements must be bcopy()'d out into a work area to get correct
4447c478bd9Sstevel@tonic-gate  * alignment for the inode number fields.
4457c478bd9Sstevel@tonic-gate  */
4467c478bd9Sstevel@tonic-gate typedef struct xfs_dir2_sf_hdr {
4477c478bd9Sstevel@tonic-gate 	xfs_uint8_t		count;		/* count of entries */
4487c478bd9Sstevel@tonic-gate 	xfs_uint8_t		i8count;	/* count of 8-byte inode #s */
4497c478bd9Sstevel@tonic-gate 	xfs_dir2_inou_t		parent;		/* parent dir inode number */
4507c478bd9Sstevel@tonic-gate } xfs_dir2_sf_hdr_t;
4517c478bd9Sstevel@tonic-gate 
4527c478bd9Sstevel@tonic-gate typedef struct xfs_dir2_sf_entry {
4537c478bd9Sstevel@tonic-gate 	xfs_uint8_t		namelen;	/* actual name length */
4547c478bd9Sstevel@tonic-gate 	xfs_dir2_sf_off_t	offset;		/* saved offset */
4557c478bd9Sstevel@tonic-gate 	xfs_uint8_t		name[1];	/* name, variable size */
4567c478bd9Sstevel@tonic-gate 	xfs_dir2_inou_t		inumber;	/* inode number, var. offset */
4577c478bd9Sstevel@tonic-gate } xfs_dir2_sf_entry_t;
4587c478bd9Sstevel@tonic-gate 
4597c478bd9Sstevel@tonic-gate typedef struct xfs_dir2_sf {
4607c478bd9Sstevel@tonic-gate 	xfs_dir2_sf_hdr_t	hdr;		/* shortform header */
4617c478bd9Sstevel@tonic-gate 	xfs_dir2_sf_entry_t	list[1];	/* shortform entries */
4627c478bd9Sstevel@tonic-gate } xfs_dir2_sf_t;
4637c478bd9Sstevel@tonic-gate 
4647c478bd9Sstevel@tonic-gate /* those are from xfs_dinode.h */
4657c478bd9Sstevel@tonic-gate 
4667c478bd9Sstevel@tonic-gate #define	XFS_DINODE_VERSION_1	1
4677c478bd9Sstevel@tonic-gate #define	XFS_DINODE_VERSION_2	2
4687c478bd9Sstevel@tonic-gate #define	XFS_DINODE_MAGIC	0x494e	/* 'IN' */
4697c478bd9Sstevel@tonic-gate 
4707c478bd9Sstevel@tonic-gate /*
4717c478bd9Sstevel@tonic-gate  * Disk inode structure.
4727c478bd9Sstevel@tonic-gate  * This is just the header; the inode is expanded to fill a variable size
4737c478bd9Sstevel@tonic-gate  * with the last field expanding.  It is split into the core and "other"
4747c478bd9Sstevel@tonic-gate  * because we only need the core part in the in-core inode.
4757c478bd9Sstevel@tonic-gate  */
4767c478bd9Sstevel@tonic-gate typedef struct xfs_timestamp {
4777c478bd9Sstevel@tonic-gate 	xfs_int32_t	t_sec;		/* timestamp seconds */
4787c478bd9Sstevel@tonic-gate 	xfs_int32_t	t_nsec;		/* timestamp nanoseconds */
4797c478bd9Sstevel@tonic-gate } xfs_timestamp_t;
4807c478bd9Sstevel@tonic-gate 
4817c478bd9Sstevel@tonic-gate /*
4827c478bd9Sstevel@tonic-gate  * Note: Coordinate changes to this structure with the XFS_DI_* #defines
4837c478bd9Sstevel@tonic-gate  * below and the offsets table in xfs_ialloc_log_di().
4847c478bd9Sstevel@tonic-gate  */
4857c478bd9Sstevel@tonic-gate typedef struct xfs_dinode_core
4867c478bd9Sstevel@tonic-gate {
4877c478bd9Sstevel@tonic-gate 	xfs_uint16_t	di_magic;	/* inode magic # = XFS_DINODE_MAGIC */
4887c478bd9Sstevel@tonic-gate 	xfs_uint16_t	di_mode;	/* mode and type of file */
4897c478bd9Sstevel@tonic-gate 	xfs_int8_t	di_version;	/* inode version */
4907c478bd9Sstevel@tonic-gate 	xfs_int8_t	di_format;	/* format of di_c data */
4917c478bd9Sstevel@tonic-gate 	xfs_uint16_t	di_onlink;	/* old number of links to file */
4927c478bd9Sstevel@tonic-gate 	xfs_uint32_t	di_uid;		/* owner's user id */
4937c478bd9Sstevel@tonic-gate 	xfs_uint32_t	di_gid;		/* owner's group id */
4947c478bd9Sstevel@tonic-gate 	xfs_uint32_t	di_nlink;	/* number of links to file */
4957c478bd9Sstevel@tonic-gate 	xfs_uint16_t	di_projid;	/* owner's project id */
4967c478bd9Sstevel@tonic-gate 	xfs_uint8_t	di_pad[10];	/* unused, zeroed space */
4977c478bd9Sstevel@tonic-gate 	xfs_timestamp_t	di_atime;	/* time last accessed */
4987c478bd9Sstevel@tonic-gate 	xfs_timestamp_t	di_mtime;	/* time last modified */
4997c478bd9Sstevel@tonic-gate 	xfs_timestamp_t	di_ctime;	/* time created/inode modified */
5007c478bd9Sstevel@tonic-gate 	xfs_fsize_t	di_size;	/* number of bytes in file */
5017c478bd9Sstevel@tonic-gate 	xfs_drfsbno_t	di_nblocks;	/* # of direct & btree blocks used */
5027c478bd9Sstevel@tonic-gate 	xfs_extlen_t	di_extsize;	/* basic/minimum extent size for file */
5037c478bd9Sstevel@tonic-gate 	xfs_extnum_t	di_nextents;	/* number of extents in data fork */
5047c478bd9Sstevel@tonic-gate 	xfs_aextnum_t	di_anextents;	/* number of extents in attribute fork*/
5057c478bd9Sstevel@tonic-gate 	xfs_uint8_t	di_forkoff;	/* attr fork offs, <<3 for 64b align */
5067c478bd9Sstevel@tonic-gate 	xfs_int8_t	di_aformat;	/* format of attr fork's data */
5077c478bd9Sstevel@tonic-gate 	xfs_uint32_t	di_dmevmask;	/* DMIG event mask */
5087c478bd9Sstevel@tonic-gate 	xfs_uint16_t	di_dmstate;	/* DMIG state info */
5097c478bd9Sstevel@tonic-gate 	xfs_uint16_t	di_flags;	/* random flags, XFS_DIFLAG_... */
5107c478bd9Sstevel@tonic-gate 	xfs_uint32_t	di_gen;		/* generation number */
5117c478bd9Sstevel@tonic-gate } xfs_dinode_core_t;
5127c478bd9Sstevel@tonic-gate 
5137c478bd9Sstevel@tonic-gate typedef struct xfs_dinode
5147c478bd9Sstevel@tonic-gate {
5157c478bd9Sstevel@tonic-gate 	xfs_dinode_core_t	di_core;
5167c478bd9Sstevel@tonic-gate 	xfs_agino_t		di_next_unlinked;/* agi unlinked list ptr */
5177c478bd9Sstevel@tonic-gate 	union {
5187c478bd9Sstevel@tonic-gate 		xfs_bmdr_block_t di_bmbt;	/* btree root block */
5197c478bd9Sstevel@tonic-gate 		xfs_bmbt_rec_32_t di_bmx[1];	/* extent list */
5207c478bd9Sstevel@tonic-gate 		xfs_dir2_sf_t	di_dir2sf;	/* shortform directory v2 */
5217c478bd9Sstevel@tonic-gate 		char		di_c[1];	/* local contents */
5227c478bd9Sstevel@tonic-gate 	} di_u;
5237c478bd9Sstevel@tonic-gate } xfs_dinode_t;
5247c478bd9Sstevel@tonic-gate 
5257c478bd9Sstevel@tonic-gate /*
5267c478bd9Sstevel@tonic-gate  * Values for di_format
5277c478bd9Sstevel@tonic-gate  */
5287c478bd9Sstevel@tonic-gate typedef enum xfs_dinode_fmt
5297c478bd9Sstevel@tonic-gate {
5307c478bd9Sstevel@tonic-gate 	XFS_DINODE_FMT_DEV,		/* CHR, BLK: di_dev */
5317c478bd9Sstevel@tonic-gate 	XFS_DINODE_FMT_LOCAL,		/* DIR, REG: di_c */
5327c478bd9Sstevel@tonic-gate 					/* LNK: di_symlink */
5337c478bd9Sstevel@tonic-gate 	XFS_DINODE_FMT_EXTENTS,		/* DIR, REG, LNK: di_bmx */
5347c478bd9Sstevel@tonic-gate 	XFS_DINODE_FMT_BTREE,		/* DIR, REG, LNK: di_bmbt */
5357c478bd9Sstevel@tonic-gate 	XFS_DINODE_FMT_UUID 		/* MNT: di_uuid */
5367c478bd9Sstevel@tonic-gate } xfs_dinode_fmt_t;
5377c478bd9Sstevel@tonic-gate 
5387c478bd9Sstevel@tonic-gate /*
5397c478bd9Sstevel@tonic-gate  * File types (mode field)
5407c478bd9Sstevel@tonic-gate  */
5417c478bd9Sstevel@tonic-gate #define	IFMT		0170000		/* type of file */
5427c478bd9Sstevel@tonic-gate #define	IFDIR		0040000		/* directory */
5437c478bd9Sstevel@tonic-gate #define	IFREG		0100000		/* regular */
5447c478bd9Sstevel@tonic-gate #define	IFLNK		0120000		/* symbolic link */
545