Debian Codegraph @

tools/libfsimage/ufs/ufs.h

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