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