17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * Copyright (C) 2004 Free Software Foundation, Inc.
37c478bdstevel@tonic-gate * Copyright (c) 2002 Networks Associates Technology, Inc.
47c478bdstevel@tonic-gate * All rights reserved.
57c478bdstevel@tonic-gate *
67c478bdstevel@tonic-gate * This software was developed for the FreeBSD Project by Marshall
77c478bdstevel@tonic-gate * Kirk McKusick and Network Associates Laboratories, the Security
87c478bdstevel@tonic-gate * Research Division of Network Associates, Inc. under DARPA/SPAWAR
97c478bdstevel@tonic-gate * contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA CHATS
107c478bdstevel@tonic-gate * research program
117c478bdstevel@tonic-gate *
127c478bdstevel@tonic-gate * Copyright (c) 1982, 1989, 1993
137c478bdstevel@tonic-gate *	The Regents of the University of California.  All rights reserved.
147c478bdstevel@tonic-gate * (c) UNIX System Laboratories, Inc.
157c478bdstevel@tonic-gate * All or some portions of this file are derived from material licensed
167c478bdstevel@tonic-gate * to the University of California by American Telephone and Telegraph
177c478bdstevel@tonic-gate * Co. or Unix System Laboratories, Inc. and are reproduced herein with
187c478bdstevel@tonic-gate * the permission of UNIX System Laboratories, Inc.
197c478bdstevel@tonic-gate *
207c478bdstevel@tonic-gate * Redistribution and use in source and binary forms, with or without
217c478bdstevel@tonic-gate * modification, are permitted provided that the following conditions
227c478bdstevel@tonic-gate * are met:
237c478bdstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright
247c478bdstevel@tonic-gate *    notice, this list of conditions and the following disclaimer.
257c478bdstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright
267c478bdstevel@tonic-gate *    notice, this list of conditions and the following disclaimer in the
277c478bdstevel@tonic-gate *    documentation and/or other materials provided with the distribution.
287c478bdstevel@tonic-gate * 3. The names of the authors may not be used to endorse or promote
297c478bdstevel@tonic-gate *    products derived from this software without specific prior written
307c478bdstevel@tonic-gate *    permission.
317c478bdstevel@tonic-gate *
327c478bdstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
337c478bdstevel@tonic-gate * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
347c478bdstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
357c478bdstevel@tonic-gate * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
367c478bdstevel@tonic-gate * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
377c478bdstevel@tonic-gate * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
387c478bdstevel@tonic-gate * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
397c478bdstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
407c478bdstevel@tonic-gate * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
417c478bdstevel@tonic-gate * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
427c478bdstevel@tonic-gate * SUCH DAMAGE.
437c478bdstevel@tonic-gate *
447c478bdstevel@tonic-gate *	@(#)dinode.h	8.3 (Berkeley) 1/21/94
457c478bdstevel@tonic-gate * $FreeBSD: src/sys/ufs/ufs/dinode.h,v 1.11 2002/07/16 22:36:00 mckusick Exp $
467c478bdstevel@tonic-gate */
477c478bdstevel@tonic-gate
487c478bdstevel@tonic-gate#ifndef _GRUB_UFS2_H_
497c478bdstevel@tonic-gate#define _GRUB_UFS2_H_
507c478bdstevel@tonic-gate
517c478bdstevel@tonic-gatetypedef signed char            grub_int8_t;
527c478bdstevel@tonic-gatetypedef signed short           grub_int16_t;
537c478bdstevel@tonic-gatetypedef signed int             grub_int32_t;
547c478bdstevel@tonic-gatetypedef signed long long int   grub_int64_t;
557c478bdstevel@tonic-gatetypedef unsigned char          grub_uint8_t;
567c478bdstevel@tonic-gatetypedef unsigned short         grub_uint16_t;
577c478bdstevel@tonic-gatetypedef unsigned int           grub_uint32_t;
587c478bdstevel@tonic-gatetypedef unsigned long long int grub_uint64_t;
597c478bdstevel@tonic-gate
607c478bdstevel@tonic-gatetypedef grub_uint8_t                grub_u_char;
617c478bdstevel@tonic-gatetypedef grub_uint32_t               grub_u_int;
627c478bdstevel@tonic-gate
637c478bdstevel@tonic-gatetypedef grub_uint8_t                grub_u_int8_t;
647c478bdstevel@tonic-gatetypedef grub_uint16_t               grub_u_int16_t;
657c478bdstevel@tonic-gatetypedef grub_uint32_t               grub_u_int32_t;
667c478bdstevel@tonic-gatetypedef grub_uint64_t               grub_u_int64_t;
677c478bdstevel@tonic-gate
687c478bdstevel@tonic-gate#define i_size di_size
697c478bdstevel@tonic-gate
707c478bdstevel@tonic-gate
717c478bdstevel@tonic-gate#define DEV_BSIZE 512
727c478bdstevel@tonic-gate
737c478bdstevel@tonic-gate/*
747c478bdstevel@tonic-gate * The root inode is the root of the filesystem.  Inode 0 can't be used for
757c478bdstevel@tonic-gate * normal purposes and historically bad blocks were linked to inode 1, thus
767c478bdstevel@tonic-gate * the root inode is 2.  (Inode 1 is no longer used for this purpose, however
777c478bdstevel@tonic-gate * numerous dump tapes make this assumption, so we are stuck with it).
787c478bdstevel@tonic-gate */
797c478bdstevel@tonic-gate#define	ROOTINO	((grub_ino_t)2)
807c478bdstevel@tonic-gate
817c478bdstevel@tonic-gate/*
827c478bdstevel@tonic-gate * The size of physical and logical block numbers and time fields in UFS.
837c478bdstevel@tonic-gate */
847c478bdstevel@tonic-gatetypedef grub_int32_t ufs1_daddr_t;
857c478bdstevel@tonic-gatetypedef	grub_int64_t	ufs2_daddr_t;
867c478bdstevel@tonic-gatetypedef grub_int64_t ufs_lbn_t;
877c478bdstevel@tonic-gatetypedef grub_int64_t ufs_time_t;
887c478bdstevel@tonic-gate
897c478bdstevel@tonic-gate/* inode number */
907c478bdstevel@tonic-gatetypedef grub_uint32_t      grub_ino_t;
917c478bdstevel@tonic-gate
927c478bdstevel@tonic-gate/* File permissions. */
937c478bdstevel@tonic-gate#define	IEXEC		0000100		/* Executable. */
947c478bdstevel@tonic-gate#define	IWRITE		0000200		/* Writeable. */
957c478bdstevel@tonic-gate#define	IREAD		0000400		/* Readable. */
967c478bdstevel@tonic-gate#define	ISVTX		0001000		/* Sticky bit. */
977c478bdstevel@tonic-gate#define	ISGID		0002000		/* Set-gid. */
987c478bdstevel@tonic-gate#define	ISUID		0004000		/* Set-uid. */
997c478bdstevel@tonic-gate
1007c478bdstevel@tonic-gate/* File types. */
1017c478bdstevel@tonic-gate#define	IFMT		0170000		/* Mask of file type. */
1027c478bdstevel@tonic-gate#define	IFIFO		0010000		/* Named pipe (fifo). */
1037c478bdstevel@tonic-gate#define	IFCHR		0020000		/* Character device. */
1047c478bdstevel@tonic-gate#define	IFDIR		0040000		/* Directory file. */
1057c478bdstevel@tonic-gate#define	IFBLK		0060000		/* Block device. */
1067c478bdstevel@tonic-gate#define	IFREG		0100000		/* Regular file. */
1077c478bdstevel@tonic-gate#define	IFLNK		0120000		/* Symbolic link. */
1087c478bdstevel@tonic-gate#define	IFSOCK		0140000		/* UNIX domain socket. */
1097c478bdstevel@tonic-gate#define	IFWHT		0160000		/* Whiteout. */
1107c478bdstevel@tonic-gate
1117c478bdstevel@tonic-gate/*
1127c478bdstevel@tonic-gate * A dinode contains all the meta-data associated with a UFS2 file.
1137c478bdstevel@tonic-gate * This structure defines the on-disk format of a dinode. Since
1147c478bdstevel@tonic-gate * this structure describes an on-disk structure, all its fields
1157c478bdstevel@tonic-gate * are defined by types with precise widths.
1167c478bdstevel@tonic-gate */
1177c478bdstevel@tonic-gate
1187c478bdstevel@tonic-gate#define	NXADDR	2			/* External addresses in inode. */
1197c478bdstevel@tonic-gate#define	NDADDR	12			/* Direct addresses in inode. */
1207c478bdstevel@tonic-gate#define	NIADDR	3			/* Indirect addresses in inode. */
1217c478bdstevel@tonic-gate
1227c478bdstevel@tonic-gatestruct ufs1_dinode {
1237c478bdstevel@tonic-gate	grub_u_int16_t       di_mode;        /*   0: IFMT, permissions; see below. */
1247c478bdstevel@tonic-gate	grub_int16_t         di_nlink;       /*   2: File link count. */
1257c478bdstevel@tonic-gate	union {
1267c478bdstevel@tonic-gate		grub_u_int16_t oldids[2];    /*   4: Ffs: old user and group ids. */
1277c478bdstevel@tonic-gate	} di_u;
1287c478bdstevel@tonic-gate	grub_u_int64_t       di_size;        /*   8: File byte count. */
1297c478bdstevel@tonic-gate	grub_int32_t         di_atime;       /*  16: Last access time. */
1307c478bdstevel@tonic-gate	grub_int32_t         di_atimensec;   /*  20: Last access time. */
1317c478bdstevel@tonic-gate	grub_int32_t         di_mtime;       /*  24: Last modified time. */
1327c478bdstevel@tonic-gate	grub_int32_t         di_mtimensec;   /*  28: Last modified time. */
1337c478bdstevel@tonic-gate	grub_int32_t         di_ctime;       /*  32: Last inode change time. */
1347c478bdstevel@tonic-gate	grub_int32_t         di_ctimensec;   /*  36: Last inode change time. */
1357c478bdstevel@tonic-gate	ufs1_daddr_t    di_db[NDADDR];  /*  40: Direct disk blocks. */
1367c478bdstevel@tonic-gate	ufs1_daddr_t    di_ib[NIADDR];  /*  88: Indirect disk blocks. */
1377c478bdstevel@tonic-gate	grub_u_int32_t       di_flags;       /* 100: Status flags (chflags). */
1387c478bdstevel@tonic-gate	grub_int32_t         di_blocks;      /* 104: Blocks actually held. */
1397c478bdstevel@tonic-gate	grub_int32_t         di_gen;         /* 108: Generation number. */
1407c478bdstevel@tonic-gate	grub_u_int32_t       di_uid;         /* 112: File owner. */
1417c478bdstevel@tonic-gate	grub_u_int32_t       di_gid;         /* 116: File group. */
1427c478bdstevel@tonic-gate	grub_int32_t         di_spare[2];    /* 120: Reserved; currently unused */
1437c478bdstevel@tonic-gate};
1447c478bdstevel@tonic-gate
1457c478bdstevel@tonic-gatestruct ufs2_dinode {
1467c478bdstevel@tonic-gate	grub_u_int16_t	di_mode;	/*   0: IFMT, permissions; see below. */
1477c478bdstevel@tonic-gate	grub_int16_t		di_nlink;	/*   2: File link count. */
1487c478bdstevel@tonic-gate	grub_u_int32_t	di_uid;		/*   4: File owner. */
1497c478bdstevel@tonic-gate	grub_u_int32_t	di_gid;		/*   8: File group. */
1507c478bdstevel@tonic-gate	grub_u_int32_t	di_blksize;	/*  12: Inode blocksize. */
1517c478bdstevel@tonic-gate	grub_u_int64_t	di_size;	/*  16: File byte count. */
1527c478bdstevel@tonic-gate	grub_u_int64_t	di_blocks;	/*  24: Bytes actually held. */
1537c478bdstevel@tonic-gate	ufs_time_t	di_atime;	/*  32: Last access time. */
1547c478bdstevel@tonic-gate	ufs_time_t	di_mtime;	/*  40: Last modified time. */
1557c478bdstevel@tonic-gate	ufs_time_t	di_ctime;	/*  48: Last inode change time. */
1567c478bdstevel@tonic-gate	ufs_time_t	di_birthtime;	/*  56: Inode creation time. */
1577c478bdstevel@tonic-gate	grub_int32_t		di_mtimensec;	/*  64: Last modified time. */
1587c478bdstevel@tonic-gate	grub_int32_t		di_atimensec;	/*  68: Last access time. */
1597c478bdstevel@tonic-gate	grub_int32_t		di_ctimensec;	/*  72: Last inode change time. */
1607c478bdstevel@tonic-gate	grub_int32_t		di_birthnsec;	/*  76: Inode creation time. */
1617c478bdstevel@tonic-gate	grub_int32_t		di_gen;		/*  80: Generation number. */
1627c478bdstevel@tonic-gate	grub_u_int32_t	di_kernflags;	/*  84: Kernel flags. */
1637c478bdstevel@tonic-gate	grub_u_int32_t	di_flags;	/*  88: Status flags (chflags). */
1647c478bdstevel@tonic-gate	grub_int32_t		di_extsize;	/*  92: External attributes block. */
1657c478bdstevel@tonic-gate	ufs2_daddr_t	di_extb[NXADDR];/*  96: External attributes block. */
1667c478bdstevel@tonic-gate	ufs2_daddr_t	di_db[NDADDR];	/* 112: Direct disk blocks. */
1677c478bdstevel@tonic-gate	ufs2_daddr_t	di_ib[NIADDR];	/* 208: Indirect disk blocks. */
1687c478bdstevel@tonic-gate	grub_int64_t		di_spare[3];	/* 232: Reserved; currently unused */
1697c478bdstevel@tonic-gate};
1707c478bdstevel@tonic-gate
1717c478bdstevel@tonic-gate#define	MAXNAMLEN	255
1727c478bdstevel@tonic-gate
1737c478bdstevel@tonic-gatestruct	direct {
1747c478bdstevel@tonic-gate	grub_u_int32_t d_ino;		/* inode number of entry */
1757c478bdstevel@tonic-gate	grub_u_int16_t d_reclen;		/* length of this record */
1767c478bdstevel@tonic-gate	grub_u_int8_t  d_type; 		/* file type, see below */
1777c478bdstevel@tonic-gate	grub_u_int8_t  d_namlen;		/* length of string in d_name */
1787c478bdstevel@tonic-gate	char	  d_name[MAXNAMLEN + 1];/* name with length <= MAXNAMLEN */
1797c478bdstevel@tonic-gate};
1807c478bdstevel@tonic-gate
1817c478bdstevel@tonic-gate/*
1827c478bdstevel@tonic-gate * File types
1837c478bdstevel@tonic-gate */
1847c478bdstevel@tonic-gate#define DT_UNKNOWN       0
1857c478bdstevel@tonic-gate#define DT_FIFO          1
1867c478bdstevel@tonic-gate#define DT_CHR           2
1877c478bdstevel@tonic-gate#define DT_DIR           4
1887c478bdstevel@tonic-gate#define DT_BLK           6
1897c478bdstevel@tonic-gate#define DT_REG           8
1907c478bdstevel@tonic-gate#define DT_LNK          10
1917c478bdstevel@tonic-gate#define DT_SOCK         12
1927c478bdstevel@tonic-gate#define DT_WHT          14
1937c478bdstevel@tonic-gate
1947c478bdstevel@tonic-gate/*
1957c478bdstevel@tonic-gate * Superblock offsets
1967c478bdstevel@tonic-gate */
1977c478bdstevel@tonic-gate#define SBLOCK_FLOPPY        0
1987c478bdstevel@tonic-gate#define SBLOCK_UFS1       8192
1997c478bdstevel@tonic-gate#define SBLOCK_UFS2      65536
2007c478bdstevel@tonic-gate#define SBLOCK_PIGGY    262144
2017c478bdstevel@tonic-gate#define SBLOCKSIZE        8192
2027c478bdstevel@tonic-gate#define SBLOCKSEARCH \
2037c478bdstevel@tonic-gate	{ SBLOCK_UFS2, SBLOCK_UFS1, SBLOCK_FLOPPY, SBLOCK_PIGGY, -1 }
2047c478bdstevel@tonic-gate
2057c478bdstevel@tonic-gate#define MAXMNTLEN	512
2067c478bdstevel@tonic-gate
2077c478bdstevel@tonic-gate#define	NOCSPTRS	((128 / sizeof(void *)) - 4)
2087c478bdstevel@tonic-gate
2097c478bdstevel@tonic-gate/*
2107c478bdstevel@tonic-gate * The maximum number of snapshot nodes that can be associated
2117c478bdstevel@tonic-gate * with each filesystem. This limit affects only the number of
2127c478bdstevel@tonic-gate * snapshot files that can be recorded within the superblock so
2137c478bdstevel@tonic-gate * that they can be found when the filesystem is mounted. However,
2147c478bdstevel@tonic-gate * maintaining too many will slow the filesystem performance, so
2157c478bdstevel@tonic-gate * having this limit is a good idea.
2167c478bdstevel@tonic-gate */
2177c478bdstevel@tonic-gate#define FSMAXSNAP 20
2187c478bdstevel@tonic-gate
2197c478bdstevel@tonic-gate/*
2207c478bdstevel@tonic-gate * Per cylinder group information; summarized in blocks allocated
2217c478bdstevel@tonic-gate * from first cylinder group data blocks.  These blocks have to be
2227c478bdstevel@tonic-gate * read in from fs_csaddr (size fs_cssize) in addition to the
2237c478bdstevel@tonic-gate * super block.
2247c478bdstevel@tonic-gate */
2257c478bdstevel@tonic-gatestruct csum {
2267c478bdstevel@tonic-gate	grub_int32_t	cs_ndir;		/* number of directories */
2277c478bdstevel@tonic-gate	grub_int32_t	cs_nbfree;		/* number of free blocks */
2287c478bdstevel@tonic-gate	grub_int32_t	cs_nifree;		/* number of free inodes */
2297c478bdstevel@tonic-gate	grub_int32_t	cs_nffree;		/* number of free frags */
2307c478bdstevel@tonic-gate};
2317c478bdstevel@tonic-gate
2327c478bdstevel@tonic-gatestruct csum_total {
2337c478bdstevel@tonic-gate	grub_int64_t	cs_ndir;		/* number of directories */
2347c478bdstevel@tonic-gate	grub_int64_t	cs_nbfree;		/* number of free blocks */
2357c478bdstevel@tonic-gate	grub_int64_t	cs_nifree;		/* number of free inodes */
2367c478bdstevel@tonic-gate	grub_int64_t	cs_nffree;		/* number of free frags */
2377c478bdstevel@tonic-gate	grub_int64_t	cs_numclusters;		/* number of free clusters */
2387c478bdstevel@tonic-gate	grub_int64_t	cs_spare[3];		/* future expansion */
2397c478bdstevel@tonic-gate};
2407c478bdstevel@tonic-gate
2417c478bdstevel@tonic-gate/*
2427c478bdstevel@tonic-gate * Super block for an FFS filesystem.
2437c478bdstevel@tonic-gate */
2447c478bdstevel@tonic-gatestruct fs {
2457c478bdstevel@tonic-gate	grub_int32_t	 fs_firstfield;		/* historic filesystem linked list, */
2467c478bdstevel@tonic-gate	grub_int32_t	 fs_unused_1;		/*     used for incore super blocks */
2477c478bdstevel@tonic-gate	grub_int32_t	 fs_sblkno;		/* offset of super-block in filesys */
2487c478bdstevel@tonic-gate	grub_int32_t	 fs_cblkno;		/* offset of cyl-block in filesys */
2497c478bdstevel@tonic-gate	grub_int32_t	 fs_iblkno;		/* offset of inode-blocks in filesys */
2507c478bdstevel@tonic-gate	grub_int32_t	 fs_dblkno;		/* offset of first data after cg */
2517c478bdstevel@tonic-gate	grub_int32_t	 fs_old_cgoffset;	/* cylinder group offset in cylinder */
2527c478bdstevel@tonic-gate	grub_int32_t	 fs_old_cgmask;		/* used to calc mod fs_ntrak */
2537c478bdstevel@tonic-gate	grub_int32_t  fs_old_time;		/* last time written */
2547c478bdstevel@tonic-gate	grub_int32_t	 fs_old_size;		/* number of blocks in fs */
2557c478bdstevel@tonic-gate	grub_int32_t	 fs_old_dsize;		/* number of data blocks in fs */
2567c478bdstevel@tonic-gate	grub_int32_t	 fs_ncg;		/* number of cylinder groups */
2577c478bdstevel@tonic-gate	grub_int32_t	 fs_bsize;		/* size of basic blocks in fs */
2587c478bdstevel@tonic-gate	grub_int32_t	 fs_fsize;		/* size of frag blocks in fs */
2597c478bdstevel@tonic-gate	grub_int32_t	 fs_frag;		/* number of frags in a block in fs */
2607c478bdstevel@tonic-gate/* these are configuration parameters */
2617c478bdstevel@tonic-gate	grub_int32_t	 fs_minfree;		/* minimum percentage of free blocks */
2627c478bdstevel@tonic-gate	grub_int32_t	 fs_old_rotdelay;	/* num of ms for optimal next block */
2637c478bdstevel@tonic-gate	grub_int32_t	 fs_old_rps;		/* disk revolutions per second */
2647c478bdstevel@tonic-gate/* these fields can be computed from the others */
2657c478bdstevel@tonic-gate	grub_int32_t	 fs_bmask;		/* ``blkoff'' calc of blk offsets */
2667c478bdstevel@tonic-gate	grub_int32_t	 fs_fmask;		/* ``fragoff'' calc of frag offsets */
2677c478bdstevel@tonic-gate	grub_int32_t	 fs_bshift;		/* ``lblkno'' calc of logical blkno */
2687c478bdstevel@tonic-gate	grub_int32_t	 fs_fshift;		/* ``numfrags'' calc number of frags */
2697c478bdstevel@tonic-gate/* these are configuration parameters */
2707c478bdstevel@tonic-gate	grub_int32_t	 fs_maxcontig;		/* max number of contiguous blks */
2717c478bdstevel@tonic-gate	grub_int32_t	 fs_maxbpg;		/* max number of blks per cyl group */
2727c478bdstevel@tonic-gate/* these fields can be computed from the others */
2737c478bdstevel@tonic-gate	grub_int32_t	 fs_fragshift;		/* block to frag shift */
2747c478bdstevel@tonic-gate	grub_int32_t	 fs_fsbtodb;		/* fsbtodb and dbtofsb shift constant */
2757c478bdstevel@tonic-gate	grub_int32_t	 fs_sbsize;		/* actual size of super block */
2767c478bdstevel@tonic-gate	grub_int32_t	 fs_spare1[2];		/* old fs_csmask */
2777c478bdstevel@tonic-gate					/* old fs_csshift */
2787c478bdstevel@tonic-gate	grub_int32_t	 fs_nindir;		/* value of NINDIR */
2797c478bdstevel@tonic-gate	grub_int32_t	 fs_inopb;		/* value of INOPB */
2807c478bdstevel@tonic-gate	grub_int32_t	 fs_old_nspf;		/* value of NSPF */
2817c478bdstevel@tonic-gate/* yet another configuration parameter */
2827c478bdstevel@tonic-gate	grub_int32_t	 fs_optim;		/* optimization preference, see below */
2837c478bdstevel@tonic-gate	grub_int32_t	 fs_old_npsect;		/* # sectors/track including spares */
2847c478bdstevel@tonic-gate	grub_int32_t	 fs_old_interleave;	/* hardware sector interleave */
2857c478bdstevel@tonic-gate	grub_int32_t	 fs_old_trackskew;	/* sector 0 skew, per track */
2867c478bdstevel@tonic-gate	grub_int32_t	 fs_id[2];		/* unique filesystem id */
2877c478bdstevel@tonic-gate/* sizes determined by number of cylinder groups and their sizes */
2887c478bdstevel@tonic-gate	grub_int32_t	 fs_old_csaddr;		/* blk addr of cyl grp summary area */
2897c478bdstevel@tonic-gate	grub_int32_t	 fs_cssize;		/* size of cyl grp summary area */
2907c478bdstevel@tonic-gate	grub_int32_t	 fs_cgsize;		/* cylinder group size */
2917c478bdstevel@tonic-gate	grub_int32_t	 fs_spare2;		/* old fs_ntrak */
2927c478bdstevel@tonic-gate	grub_int32_t	 fs_old_nsect;		/* sectors per track */
2937c478bdstevel@tonic-gate	grub_int32_t  fs_old_spc;		/* sectors per cylinder */
2947c478bdstevel@tonic-gate	grub_int32_t	 fs_old_ncyl;		/* cylinders in filesystem */
2957c478bdstevel@tonic-gate	grub_int32_t	 fs_old_cpg;		/* cylinders per group */
2967c478bdstevel@tonic-gate	grub_int32_t	 fs_ipg;		/* inodes per group */
2977c478bdstevel@tonic-gate	grub_int32_t	 fs_fpg;		/* blocks per group * fs_frag */
2987c478bdstevel@tonic-gate/* this data must be re-computed after crashes */
2997c478bdstevel@tonic-gate	struct	csum fs_old_cstotal;	/* cylinder summary information */
3007c478bdstevel@tonic-gate/* these fields are cleared at mount time */
3017c478bdstevel@tonic-gate	grub_int8_t   fs_fmod;		/* super block modified flag */
3027c478bdstevel@tonic-gate	grub_int8_t   fs_clean;		/* filesystem is clean flag */
3037c478bdstevel@tonic-gate	grub_int8_t 	 fs_ronly;		/* mounted read-only flag */
3047c478bdstevel@tonic-gate	grub_int8_t   fs_old_flags;		/* old FS_ flags */
3057c478bdstevel@tonic-gate	grub_u_char	 fs_fsmnt[MAXMNTLEN];	/* name mounted on */
3067c478bdstevel@tonic-gate/* these fields retain the current block allocation info */
3077c478bdstevel@tonic-gate	grub_int32_t	 fs_cgrotor;		/* last cg searched */
3087c478bdstevel@tonic-gate	void 	*fs_ocsp[NOCSPTRS];	/* padding; was list of fs_cs buffers */
3097c478bdstevel@tonic-gate	grub_u_int8_t *fs_contigdirs;	/* # of contiguously allocated dirs */
3107c478bdstevel@tonic-gate	struct	csum *fs_csp;		/* cg summary info buffer for fs_cs */
3117c478bdstevel@tonic-gate	grub_int32_t	*fs_maxcluster;		/* max cluster in each cyl group */
3127c478bdstevel@tonic-gate	grub_u_int	*fs_active;		/* used by snapshots to track fs */
3137c478bdstevel@tonic-gate	grub_int32_t	 fs_old_cpc;		/* cyl per cycle in postbl */
3147c478bdstevel@tonic-gate	grub_int32_t	 fs_maxbsize;		/* maximum blocking factor permitted */
3157c478bdstevel@tonic-gate	grub_int64_t	 fs_sparecon64[17];	/* old rotation block list head */
3167c478bdstevel@tonic-gate	grub_int64_t	 fs_sblockloc;		/* byte offset of standard superblock */
3177c478bdstevel@tonic-gate	struct	csum_total fs_cstotal;	/* cylinder summary information */
3187c478bdstevel@tonic-gate	ufs_time_t fs_time;		/* last time written */
3197c478bdstevel@tonic-gate	grub_int64_t	 fs_size;		/* number of blocks in fs */
3207c478bdstevel@tonic-gate	grub_int64_t	 fs_dsize;		/* number of data blocks in fs */
3217c478bdstevel@tonic-gate	ufs2_daddr_t fs_csaddr;		/* blk addr of cyl grp summary area */
3227c478bdstevel@tonic-gate	grub_int64_t	 fs_pendingblocks;	/* blocks in process of being freed */
3237c478bdstevel@tonic-gate	grub_int32_t	 fs_pendinginodes;	/* inodes in process of being freed */
3247c478bdstevel@tonic-gate	grub_int32_t	 fs_snapinum[FSMAXSNAP];/* list of snapshot inode numbers */
3257c478bdstevel@tonic-gate	grub_int32_t	 fs_avgfilesize;	/* expected average file size */
3267c478bdstevel@tonic-gate	grub_int32_t	 fs_avgfpdir;		/* expected # of files per directory */
3277c478bdstevel@tonic-gate	grub_int32_t	 fs_save_cgsize;	/* save real cg size to use fs_bsize */
3287c478bdstevel@tonic-gate	grub_int32_t	 fs_sparecon32[26];	/* reserved for future constants */
3297c478bdstevel@tonic-gate	grub_int32_t  fs_flags;		/* see FS_ flags below */
3307c478bdstevel@tonic-gate	grub_int32_t	 fs_contigsumsize;	/* size of cluster summary array */
3317c478bdstevel@tonic-gate	grub_int32_t	 fs_maxsymlinklen;	/* max length of an internal symlink */
3327c478bdstevel@tonic-gate	grub_int32_t	 fs_old_inodefmt;	/* format of on-disk inodes */
3337c478bdstevel@tonic-gate	grub_u_int64_t fs_maxfilesize;	/* maximum representable file size */
3347c478bdstevel@tonic-gate	grub_int64_t	 fs_qbmask;		/* ~fs_bmask for use with 64-bit size */
3357c478bdstevel@tonic-gate	grub_int64_t	 fs_qfmask;		/* ~fs_fmask for use with 64-bit size */
3367c478bdstevel@tonic-gate	grub_int32_t	 fs_state;		/* validate fs_clean field */
3377c478bdstevel@tonic-gate	grub_int32_t	 fs_old_postblformat;	/* format of positional layout tables */
3387c478bdstevel@tonic-gate	grub_int32_t	 fs_old_nrpos;		/* number of rotational positions */
3397c478bdstevel@tonic-gate	grub_int32_t	 fs_spare5[2];		/* old fs_postbloff */
3407c478bdstevel@tonic-gate					/* old fs_rotbloff */
3417c478bdstevel@tonic-gate	grub_int32_t	 fs_magic;		/* magic number */
3427c478bdstevel@tonic-gate};
3437c478bdstevel@tonic-gate
3447c478bdstevel@tonic-gate/*
3457c478bdstevel@tonic-gate * Filesystem identification
3467c478bdstevel@tonic-gate */
3477c478bdstevel@tonic-gate#define FS_UFS1_MAGIC   0x011954        /* UFS1 fast filesystem magic number */
3487c478bdstevel@tonic-gate#define	FS_UFS2_MAGIC	0x19540119	/* UFS2 fast filesystem magic number */
3497c478bdstevel@tonic-gate
3507c478bdstevel@tonic-gate/*
3517c478bdstevel@tonic-gate * Turn filesystem block numbers into disk block addresses.
3527c478bdstevel@tonic-gate * This maps filesystem blocks to device size blocks.
3537c478bdstevel@tonic-gate */
3547c478bdstevel@tonic-gate#define fsbtodb(fs, b)	((b) << (fs)->fs_fsbtodb)
3557c478bdstevel@tonic-gate#define	dbtofsb(fs, b)	((b) >> (fs)->fs_fsbtodb)
3567c478bdstevel@tonic-gate
3577c478bdstevel@tonic-gate/*
3587c478bdstevel@tonic-gate * Cylinder group macros to locate things in cylinder groups.
3597c478bdstevel@tonic-gate * They calc filesystem addresses of cylinder group data structures.
3607c478bdstevel@tonic-gate */
3617c478bdstevel@tonic-gate#define	cgbase(fs, c)	((ufs2_daddr_t)((fs)->fs_fpg * (c)))
3627c478bdstevel@tonic-gate#define	cgimin(fs, c)	(cgstart(fs, c) + (fs)->fs_iblkno)	/* inode blk */
3637c478bdstevel@tonic-gate#define cgstart(fs, c)							\
3647c478bdstevel@tonic-gate       ((fs)->fs_magic == FS_UFS2_MAGIC ? cgbase(fs, c) :		\
3657c478bdstevel@tonic-gate       (cgbase(fs, c) + (fs)->fs_old_cgoffset * ((c) & ~((fs)->fs_old_cgmask))))
3667c478bdstevel@tonic-gate
3677c478bdstevel@tonic-gate/*
3687c478bdstevel@tonic-gate * Macros for handling inode numbers:
3697c478bdstevel@tonic-gate *     inode number to filesystem block offset.
3707c478bdstevel@tonic-gate *     inode number to cylinder group number.
3717c478bdstevel@tonic-gate *     inode number to filesystem block address.
3727c478bdstevel@tonic-gate */
3737c478bdstevel@tonic-gate#define	ino_to_cg(fs, x)	((x) / (fs)->fs_ipg)
3747c478bdstevel@tonic-gate#define	ino_to_fsba(fs, x)						\
3757c478bdstevel@tonic-gate	((ufs2_daddr_t)(cgimin(fs, ino_to_cg(fs, x)) +			\
3767c478bdstevel@tonic-gate	    (blkstofrags((fs), (((x) % (fs)->fs_ipg) / INOPB(fs))))))
3777c478bdstevel@tonic-gate#define	ino_to_fsbo(fs, x)	((x) % INOPB(fs))
3787c478bdstevel@tonic-gate
3797c478bdstevel@tonic-gate/*
3807c478bdstevel@tonic-gate * The following macros optimize certain frequently calculated
3817c478bdstevel@tonic-gate * quantities by using shifts and masks in place of divisions
3827c478bdstevel@tonic-gate * modulos and multiplications.
3837c478bdstevel@tonic-gate */
3847c478bdstevel@tonic-gate#define blkoff(fs, loc)		/* calculates (loc % fs->fs_bsize) */ \
3857c478bdstevel@tonic-gate	((loc) & (fs)->fs_qbmask)
3867c478bdstevel@tonic-gate
3877c478bdstevel@tonic-gate/* Use this only when `blk' is known to be small, e.g., < NDADDR. */
3887c478bdstevel@tonic-gate#define smalllblktosize(fs, blk)    /* calculates (blk * fs->fs_bsize) */ \
3897c478bdstevel@tonic-gate	((blk) << (fs)->fs_bshift)
3907c478bdstevel@tonic-gate
3917c478bdstevel@tonic-gate
3927c478bdstevel@tonic-gate#define lblkno(fs, loc)		/* calculates (loc / fs->fs_bsize) */ \
3937c478bdstevel@tonic-gate	((loc) >> (fs)->fs_bshift)
3947c478bdstevel@tonic-gate
3957c478bdstevel@tonic-gate#define fragroundup(fs, size)	/* calculates roundup(size, fs->fs_fsize) */ \
3967c478bdstevel@tonic-gate	(((size) + (fs)->fs_qfmask) & (fs)->fs_fmask)
3977c478bdstevel@tonic-gate
3987c478bdstevel@tonic-gate#define fragstoblks(fs, frags)	/* calculates (frags / fs->fs_frag) */ \
3997c478bdstevel@tonic-gate	((frags) >> (fs)->fs_fragshift)
4007c478bdstevel@tonic-gate#define blkstofrags(fs, blks)	/* calculates (blks * fs->fs_frag) */ \
4017c478bdstevel@tonic-gate	((blks) << (fs)->fs_fragshift)
4027c478bdstevel@tonic-gate#define fragnum(fs, fsb)	/* calculates (fsb % fs->fs_frag) */ \
4037c478bdstevel@tonic-gate	((fsb) & ((fs)->fs_frag - 1))
4047c478bdstevel@tonic-gate#define blknum(fs, fsb)		/* calculates rounddown(fsb, fs->fs_frag) */ \
4057c478bdstevel@tonic-gate	((fsb) &~ ((fs)->fs_frag - 1))
4067c478bdstevel@tonic-gate
4077c478bdstevel@tonic-gate/*
4087c478bdstevel@tonic-gate * Determining the size of a file block in the filesystem.
4097c478bdstevel@tonic-gate */
4107c478bdstevel@tonic-gate#define blksize(fs, ip, lbn) \
4117c478bdstevel@tonic-gate	(((lbn) >= NDADDR || (ip)->i_size >= smalllblktosize(fs, (lbn) + 1)) \
4127c478bdstevel@tonic-gate	    ? (fs)->fs_bsize \
4137c478bdstevel@tonic-gate	    : (fragroundup(fs, blkoff(fs, (ip)->i_size))))
4147c478bdstevel@tonic-gate#define sblksize(fs, size, lbn) \
4157c478bdstevel@tonic-gate	(((lbn) >= NDADDR || (size) >= ((lbn) + 1) << (fs)->fs_bshift) \
4167c478bdstevel@tonic-gate	  ? (fs)->fs_bsize \
4177c478bdstevel@tonic-gate	  : (fragroundup(fs, blkoff(fs, (size)))))
4187c478bdstevel@tonic-gate
4197c478bdstevel@tonic-gate
4207c478bdstevel@tonic-gate/*
4217c478bdstevel@tonic-gate * Number of inodes in a secondary storage block/fragment.
4227c478bdstevel@tonic-gate */
4237c478bdstevel@tonic-gate#define	INOPB(fs)	((fs)->fs_inopb)
4247c478bdstevel@tonic-gate#define	INOPF(fs)	((fs)->fs_inopb >> (fs)->fs_fragshift)
4257c478bdstevel@tonic-gate
4267c478bdstevel@tonic-gate/*
4277c478bdstevel@tonic-gate * Number of indirects in a filesystem block.
4287c478bdstevel@tonic-gate */
4297c478bdstevel@tonic-gate#define	NINDIR(fs)	((fs)->fs_nindir)
4307c478bdstevel@tonic-gate
4317c478bdstevel@tonic-gate#define FS_UNCLEAN    0x01      /* filesystem not clean at mount */
4327c478bdstevel@tonic-gate#define FS_DOSOFTDEP  0x02      /* filesystem using soft dependencies */
4337c478bdstevel@tonic-gate#define FS_NEEDSFSCK  0x04      /* filesystem needs sync fsck before mount */
4347c478bdstevel@tonic-gate#define FS_INDEXDIRS  0x08      /* kernel supports indexed directories */
4357c478bdstevel@tonic-gate#define FS_ACLS       0x10      /* file system has ACLs enabled */
4367c478bdstevel@tonic-gate#define FS_MULTILABEL 0x20      /* file system is MAC multi-label */
4377c478bdstevel@tonic-gate#define FS_FLAGS_UPDATED 0x80   /* flags have been moved to new location */
4387c478bdstevel@tonic-gate
4397c478bdstevel@tonic-gate#endif /* _GRUB_UFS2_H_ */
440