xref: /illumos-gate/usr/src/grub/grub-0.97/stage2/ufs.h (revision 1b8adde7)
1 /*
2  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 #ifndef _GRUB_UFS_H
7 #define _GRUB_UFS_H_
8 
9 #ifdef	FSYS_UFS
10 
11 /* ufs specific constants */
12 #define UFS_SBLOCK	16
13 #define UFS_SBSIZE	8192
14 #define	UFS_MAGIC	0x011954
15 #define	ROOTINO		2	/* i number of all roots */
16 #define UFS_NDADDR	12	/* direct blocks */
17 #define	UFS_NIADDR	3	/* indirect blocks */
18 #define	MAXMNTLEN	512
19 #define	MAXCSBUFS	32
20 
21 /* file types */
22 #define	IFMT		0xf000
23 #define	IFREG		0x8000
24 #define	IFDIR		0x4000
25 
26 typedef unsigned char	grub_uchar_t;
27 typedef	unsigned short	grub_ushort_t;
28 typedef	unsigned short	grub_o_mode_t;
29 typedef	unsigned short	grub_o_uid_t;
30 typedef	unsigned short	grub_o_gid_t;
31 typedef	long		grub_ino_t;
32 typedef	long		grub_int32_t;
33 typedef	long		grub_uid_t;
34 typedef	long		grub_gid_t;
35 typedef unsigned long	grub_uint32_t;
36 typedef unsigned long	grub_daddr32_t;
37 typedef	unsigned long	grub_time32_t;
38 typedef struct { int val[2]; } grub_quad_t;
39 
40 struct timeval32 {
41   	grub_time32_t	tv_sec;
42 	grub_int32_t	tv_usec;
43 };
44 
45 /*
46  * Per cylinder group information; summarized in blocks allocated
47  * from first cylinder group data blocks.  These blocks have to be
48  * read in from fs_csaddr (size fs_cssize) in addition to the
49  * super block.
50  *
51  * N.B. sizeof (struct csum) must be a power of two in order for
52  * the ``fs_cs'' macro to work (see below).
53  */
54 struct csum {
55 	grub_int32_t	cs_ndir;	/* number of directories */
56 	grub_int32_t	cs_nbfree;	/* number of free blocks */
57 	grub_int32_t	cs_nifree;	/* number of free inodes */
58 	grub_int32_t	cs_nffree;	/* number of free frags */
59 };
60 
61 /* Ufs super block */
62 struct fs {
63 	grub_uint32_t	fs_link;	/* linked list of file systems */
64 	grub_uint32_t	fs_rolled;	/* logging only: fs fully rolled */
65 	grub_daddr32_t	fs_sblkno;	/* addr of super-block in filesys */
66 	grub_daddr32_t	fs_cblkno;	/* offset of cyl-block in filesys */
67 	grub_daddr32_t	fs_iblkno;	/* offset of inode-blocks in filesys */
68 	grub_daddr32_t	fs_dblkno;	/* offset of first data after cg */
69 	grub_int32_t	fs_cgoffset;	/* cylinder group offset in cylinder */
70 	grub_int32_t	fs_cgmask;	/* used to calc mod fs_ntrak */
71 	grub_time32_t	fs_time;	/* last time written */
72 	grub_int32_t	fs_size;	/* number of blocks in fs */
73 	grub_int32_t	fs_dsize;	/* number of data blocks in fs */
74 	grub_int32_t	fs_ncg;		/* number of cylinder groups */
75 	grub_int32_t	fs_bsize;	/* size of basic blocks in fs */
76 	grub_int32_t	fs_fsize;	/* size of frag blocks in fs */
77 	grub_int32_t	fs_frag;	/* number of frags in a block in fs */
78 	/* these are configuration parameters */
79 	grub_int32_t	fs_minfree;	/* minimum percentage of free blocks */
80 	grub_int32_t	fs_rotdelay;	/* num of ms for optimal next block */
81 	grub_int32_t	fs_rps;		/* disk revolutions per second */
82 	/* these fields can be computed from the others */
83 	grub_int32_t	fs_bmask;	/* ``blkoff'' calc of blk offsets */
84 	grub_int32_t	fs_fmask;	/* ``fragoff'' calc of frag offsets */
85 	grub_int32_t	fs_bshift;	/* ``lblkno'' calc of logical blkno */
86 	grub_int32_t	fs_fshift;	/* ``numfrags'' calc number of frags */
87 	/* these are configuration parameters */
88 	grub_int32_t	fs_maxcontig;	/* max number of contiguous blks */
89 	grub_int32_t	fs_maxbpg;	/* max number of blks per cyl group */
90 	/* these fields can be computed from the others */
91 	grub_int32_t	fs_fragshift;	/* block to frag shift */
92 	grub_int32_t	fs_fsbtodb;	/* fsbtodb and dbtofsb shift constant */
93 	grub_int32_t	fs_sbsize;	/* actual size of super block */
94 	grub_int32_t	fs_csmask;	/* csum block offset */
95 	grub_int32_t	fs_csshift;	/* csum block number */
96 	grub_int32_t	fs_nindir;	/* value of NINDIR */
97 	grub_int32_t	fs_inopb;	/* value of INOPB */
98 	grub_int32_t	fs_nspf;	/* value of NSPF */
99 	/* yet another configuration parameter */
100 	grub_int32_t	fs_optim;	/* optimization preference, see below */
101 	/* these fields are derived from the hardware */
102 	/* USL SVR4 compatibility */
103 	/*
104 	 *	* USL SVR4 compatibility
105 	 *
106 	 * There was a significant divergence here between Solaris and
107 	 * SVR4 for x86.	By swapping these two members in the superblock,
108 	 * we get read-only compatibility of SVR4 filesystems.	Otherwise
109 	 * there would be no compatibility.	This change was introduced
110 	 * during bootstrapping of Solaris on x86.	By making this ifdef'ed
111 	 * on byte order, we provide ongoing compatibility across all
112 	 * platforms with the same byte order, the highest compatibility
113 	 * that can be achieved.
114 	 */
115 	grub_int32_t	fs_state;	/* file system state time stamp */
116 	grub_int32_t	fs_si;		/* summary info state - lufs only */
117 	grub_int32_t	fs_trackskew;	/* sector 0 skew, per track */
118 	/* unique id for this filesystem (currently unused and unmaintained) */
119 	/* In 4.3 Tahoe this space is used by fs_headswitch and fs_trkseek */
120 	/* Neither of those fields is used in the Tahoe code right now but */
121 	/* there could be problems if they are.	*/
122 	grub_int32_t	fs_id[2];	/* file system id */
123 	/* sizes determined by number of cylinder groups and their sizes */
124 	grub_daddr32_t	fs_csaddr;	/* blk addr of cyl grp summary area */
125 	grub_int32_t	fs_cssize;	/* size of cyl grp summary area */
126 	grub_int32_t	fs_cgsize;	/* cylinder group size */
127 	/* these fields are derived from the hardware */
128 	grub_int32_t	fs_ntrak;	/* tracks per cylinder */
129 	grub_int32_t	fs_nsect;	/* sectors per track */
130 	grub_int32_t	fs_spc;		/* sectors per cylinder */
131 	/* this comes from the disk driver partitioning */
132 	grub_int32_t	fs_ncyl;	/* cylinders in file system */
133 	/* these fields can be computed from the others */
134 	grub_int32_t	fs_cpg;		/* cylinders per group */
135 	grub_int32_t	fs_ipg;		/* inodes per group */
136 	grub_int32_t	fs_fpg;		/* blocks per group * fs_frag */
137 	/* this data must be re-computed after crashes */
138 	struct csum	fs_cstotal;	/* cylinder summary information */
139 	/* these fields are cleared at mount time */
140 	char		fs_fmod;	/* super block modified flag */
141 	char		fs_clean;	/* file system state flag */
142 	char		fs_ronly;	/* mounted read-only flag */
143 	char		fs_flags;	/* largefiles flag, etc. */
144 	char		fs_fsmnt[MAXMNTLEN];	/* name mounted on */
145 	/* these fields retain the current block allocation info */
146 	grub_int32_t	fs_cgrotor;	/* last cg searched */
147 	/*
148 	 * The following used to be fs_csp[MAXCSBUFS]. It was not
149 	 * used anywhere except in old utilities.  We removed this
150 	 * in 5.6 and expect fs_u.fs_csp to be used instead.
151 	 * We no longer limit fs_cssize based on MAXCSBUFS.
152 	 */
153 	union {	/* fs_cs (csum) info */
154 		grub_uint32_t	fs_csp_pad[MAXCSBUFS];
155 		struct csum	*fs_csp;
156 	} fs_u;
157 	grub_int32_t	fs_cpc;		/* cyl per cycle in postbl */
158 	short		fs_opostbl[16][8];  /* old rotation block list head */
159 	grub_int32_t	fs_sparecon[51];    /* reserved for future constants */
160 	grub_int32_t	fs_version;	/* minor version of MTB ufs */
161 	grub_int32_t	fs_logbno;	/* block # of embedded log */
162 	grub_int32_t	fs_reclaim;	/* reclaim open, deleted files */
163 	grub_int32_t	fs_sparecon2;	/* reserved for future constant */
164 	/* USL SVR4 compatibility */
165 	grub_int32_t	fs_npsect;	/* # sectors/track including spares */
166 	grub_quad_t	fs_qbmask;	/* ~fs_bmask - for use with quad size */
167 	grub_quad_t	fs_qfmask;	/* ~fs_fmask - for use with quad size */
168 	grub_int32_t	fs_postblformat; /* fmt of positional layout tables */
169 	grub_int32_t	fs_nrpos;	/* number of rotaional positions */
170 	grub_int32_t	fs_postbloff;	/* (short) rotation block list head */
171 	grub_int32_t	fs_rotbloff;	/* (grub_uchar_t) blocks for each */
172 					/* rotation */
173 	grub_int32_t	fs_magic;	/* magic number */
174 	grub_uchar_t	fs_space[1];	/* list of blocks for each rotation */
175 	/* actually longer */
176 };
177 
178 struct icommon {
179 	grub_o_mode_t	ic_smode;	/* 0: mode and type of file */
180 	short		ic_nlink;	/* 2: number of links to file */
181 	grub_o_uid_t	ic_suid;	/* 4: owner's user id */
182 	grub_o_gid_t	ic_sgid;	/* 6: owner's group id */
183 	grub_uint32_t	ic_sizelo;	/* 8: number of bytes in file */
184 	grub_uint32_t	ic_sizehi;	/* 12: number of bytes in file */
185 	struct timeval32 ic_atime;	/* 16: time last accessed */
186 	struct timeval32 ic_mtime;	/* 24: time last modified */
187 	struct timeval32 ic_ctime;	/* 32: last time inode changed */
188 	grub_daddr32_t	ic_db[UFS_NDADDR];	/* 40: disk block addresses */
189 	grub_daddr32_t	ic_ib[UFS_NIADDR];	/* 88: indirect blocks */
190 	grub_int32_t	ic_flags;	/* 100: cflags */
191 	grub_int32_t	ic_blocks;	/* 104: 512 byte blocks actually held */
192 	grub_int32_t	ic_gen;		/* 108: generation number */
193 	grub_int32_t	ic_shadow;	/* 112: shadow inode */
194 	grub_uid_t	ic_uid;		/* 116: long EFT version of uid */
195 	grub_gid_t	ic_gid;		/* 120: long EFT version of gid */
196 	grub_uint32_t	ic_oeftflag;	/* 124: extended attr directory ino, */
197 					/*      0 = none */
198 };
199 
200 struct direct {
201 	grub_ino_t	d_ino;
202 	grub_ushort_t	d_reclen;
203 	grub_ushort_t	d_namelen;
204 	char		d_name[MAXNAMELEN + 1];
205 };
206 
207 /* inode macros */
208 #define INOPB(fs)       ((fs)->fs_inopb)
209 #define itoo(fs, x)	((x) % (grub_uint32_t)INOPB(fs))
210 #define	itog(fs, x)	((x) / (grub_uint32_t)(fs)->fs_ipg)
211 #define itod(fs, x)	((grub_daddr32_t)(cgimin(fs, itog(fs, x)) + \
212   (blkstofrags((fs), \
213   ((x) % (grub_uint32_t)(fs)->fs_ipg / (grub_uint32_t)INOPB(fs))))))
214 
215 /* block conversion macros */
216 #define	UFS_NINDIR(fs)	((fs)->fs_nindir)	/* # of indirects */
217 #define blkoff(fs, loc)	((int)((loc & ~(fs)->fs_bmask)))
218 #define lblkno(fs, loc) ((grub_int32_t)((loc) >> (fs)->fs_bshift))
219 /* frag to blk */
220 #define fsbtodb(fs, b)	(((grub_daddr32_t)(b)) << (fs)->fs_fsbtodb)
221 #define blkstofrags(fs, b) ((b) << (fs)->fs_fragshift)
222 
223 /* cynlinder group macros */
224 #define cgbase(fs, c)	((grub_daddr32_t)((fs)->fs_fpg * (c)))
225 #define	cgimin(fs, c)	(cgstart(fs, c) + (fs)->fs_iblkno) /* inode block */
226 #define cgstart(fs, c) \
227   (cgbase(fs, c) + (fs)->fs_cgoffset * ((c) & ~((fs)->fs_cgmask)))
228 
229 #endif	/* FSYS_UFS */
230 
231 #endif /* !_GRUB_UFS_H */
232