Blob


1 /*
2 * An FFS file system is a sequence of cylinder groups.
3 *
4 * Each cylinder group is laid out as follows:
5 *
6 * fs superblock (Fsblk)
7 * cylinder group block (Cgblk)
8 * inodes
9 * data
10 *
11 * The location of the fs superblock in the first cylinder
12 * group is known. The rest of the info about cylinder group
13 * layout can be derived from the super block.
14 */
16 #define daddr_t u32int
17 #define time_t u32int
19 typedef struct Cgblk Cgblk;
20 typedef struct Cylgrp Cylgrp;
21 typedef struct Cylsum Cylsum;
22 typedef struct Ffs Ffs;
23 typedef struct Fsblk Fsblk;
24 typedef struct Inode Inode;
25 typedef struct Dirent Dirent;
27 enum
28 {
29 BYTESPERSEC = 512,
31 /* constants for Fsblk */
32 FSMAXMNTLEN = 512,
33 FSNOCSPTRS = 128 / sizeof(void*) - 3,
34 FSMAXSNAP = 20,
35 FSMAGIC = 0x011954,
36 FSCHECKSUM = 0x7c269d38,
38 /* Fsblk.inodefmt */
39 FS42INODEFMT = -1,
40 FS44INODEFMT = 2,
42 /* offset and size of first boot block */
43 BBOFF = 0,
44 BBSIZE = 8192,
46 /* offset and size of first super block */
47 SBOFF = BBOFF+BBSIZE,
48 SBSIZE = 8192,
50 /* minimum block size */
51 MINBSIZE = 4096,
53 /* maximum fragments per block */
54 MAXFRAG = 8,
56 /* constants for Cgblk */
57 CGMAGIC = 0x090255,
59 /* inode-related */
60 ROOTINODE = 2,
61 WHITEOUT = 1,
63 NDADDR = 12,
64 NIADDR = 3,
66 /* permissions in Inode.mode */
67 IEXEC = 00100,
68 IWRITE = 0200,
69 IREAD = 0400,
70 ISVTX = 01000,
71 ISGID = 02000,
72 ISUID = 04000,
74 /* type in Inode.mode */
75 IFMT = 0170000,
76 IFIFO = 0010000,
77 IFCHR = 0020000,
78 IFDIR = 0040000,
79 IFBLK = 0060000,
80 IFREG = 0100000,
81 IFLNK = 0120000,
82 IFSOCK = 0140000,
83 IFWHT = 0160000,
85 /* type in Dirent.type */
86 DTUNKNOWN = 0,
87 DTFIFO = 1,
88 DTCHR = 2,
89 DTDIR = 4,
90 DTBLK = 6,
91 DTREG = 8,
92 DTLNK = 10,
93 DTSOCK = 12,
94 DTWHT = 14,
95 };
97 struct Cylsum
98 {
99 u32int ndir;
100 u32int nbfree;
101 u32int nifree;
102 u32int nffree;
103 };
105 struct Fsblk
107 u32int unused0;
108 u32int unused1;
109 daddr_t sfragno; /* fragment address of super block in file system */
110 daddr_t cfragno; /* fragment address if cylinder block in file system */
111 daddr_t ifragno; /* fragment offset of inode blocks in file system */
112 daddr_t dfragno; /* fragment offset of data blocks in cg */
113 u32int cgoffset; /* block (maybe fragment?) offset of Cgblk in cylinder */
114 u32int cgmask;
115 time_t time;
116 u32int nfrag; /* number of blocks in fs * fragsperblock */
117 u32int ndfrag;
118 u32int ncg; /* number of cylinder groups in fs */
119 u32int blocksize; /* block size in fs */
120 u32int fragsize; /* frag size in fs */
121 u32int fragsperblock; /* fragments per block: blocksize / fragsize */
122 u32int minfree; /* ignored by us */
123 u32int rotdelay; /* ... */
124 u32int rps;
125 u32int bmask;
126 u32int fmask;
127 u32int bshift;
128 u32int fshift;
129 u32int maxcontig;
130 u32int maxbpg;
131 u32int fragshift;
132 u32int fsbtodbshift;
133 u32int sbsize; /* size of super block */
134 u32int unused2; /* more stuff we don't use ... */
135 u32int unused3;
136 u32int nindir;
137 u32int inosperblock; /* inodes per block */
138 u32int nspf;
139 u32int optim;
140 u32int npsect;
141 u32int interleave;
142 u32int trackskew;
143 u32int id[2];
144 daddr_t csaddr; /* blk addr of cyl grp summary area */
145 u32int cssize; /* size of cyl grp summary area */
146 u32int cgsize; /* cylinder group size */
147 u32int trackspercyl; /* tracks per cylinder */
148 u32int secspertrack; /* sectors per track */
149 u32int secspercyl; /* sectors per cylinder */
150 u32int ncyl; /* cylinders in fs */
151 u32int cylspergroup; /* cylinders per group */
152 u32int inospergroup; /* inodes per group */
153 u32int fragspergroup; /* data blocks per group * fragperblock */
154 Cylsum cstotal; /* more unused... */
155 u8int fmod;
156 u8int clean;
157 u8int ronly;
158 u8int flags;
159 char fsmnt[FSMAXMNTLEN];
160 u32int cgrotor;
161 void* ocsp[FSNOCSPTRS];
162 u8int* contigdirs;
163 Cylsum* csp;
164 u32int* maxcluster;
165 u32int cpc;
166 u16int opostbl[16][8];
167 u32int snapinum[FSMAXSNAP];
168 u32int avgfilesize;
169 u32int avgfpdir;
170 u32int sparecon[26];
171 u32int pendingblocks;
172 u32int pendinginodes;
173 u32int contigsumsize;
174 u32int maxsymlinklen;
175 u32int inodefmt; /* format of on-disk inodes */
176 u64int maxfilesize; /* maximum representable file size */
177 u64int qbmask;
178 u64int qfmask;
179 u32int state;
180 u32int postblformat;
181 u32int nrpos;
182 u32int postbloff;
183 u32int rotbloff;
184 u32int magic; /* FS_MAGIC */
185 };
187 /*
188 * Cylinder group block for a file system.
189 */
190 struct Cgblk
192 u32int unused0;
193 u32int magic; /* CGMAGIC */
194 u32int time; /* time last written */
195 u32int num; /* we are cg #cgnum */
196 u16int ncyl; /* number of cylinders in gp */
197 u16int nino; /* number of inodes */
198 u32int nfrag; /* number of fragments */
199 Cylsum csum;
200 u32int rotor;
201 u32int frotor;
202 u32int irotor;
203 u32int frsum[MAXFRAG]; /* counts of available frags */
204 u32int btotoff;
205 u32int boff;
206 u32int imapoff; /* offset to used inode map */
207 u32int fmapoff; /* offset to free fragment map */
208 u32int nextfrag; /* next free fragment */
209 u32int csumoff;
210 u32int clusteroff;
211 u32int ncluster;
212 u32int sparecon[13];
213 };
215 struct Cylgrp
217 /* these are block numbers not fragment numbers */
218 u32int bno; /* disk block address of start of cg */
219 u32int ibno; /* disk block address of first inode */
220 u32int dbno; /* disk block address of first data */
221 u32int cgblkno;
222 };
224 /*
225 * this is the on-disk structure
226 */
227 struct Inode
229 u16int mode;
230 u16int nlink;
231 u32int unused;
232 u64int size;
233 u32int atime;
234 u32int atimensec;
235 u32int mtime;
236 u32int mtimensec;
237 u32int ctime;
238 u32int ctimensec;
239 /* rdev is db[0] */
240 u32int db[NDADDR];
241 u32int ib[NIADDR];
242 u32int flags;
243 u32int nblock;
244 u32int gen;
245 u32int uid;
246 u32int gid;
247 u32int spare[2];
248 };
250 struct Dirent
252 u32int ino;
253 u16int reclen;
254 u8int type;
255 u8int namlen;
256 char name[1];
257 };
259 /*
260 * main file system structure
261 */
262 struct Ffs
264 int blocksize;
265 int nblock;
266 int fragsize;
267 int fragsperblock;
268 int inosperblock;
269 int blockspergroup;
270 int fragspergroup;
271 int inospergroup;
273 u32int nfrag;
274 u32int ndfrag;
276 int ncg;
277 Cylgrp *cg;
279 Disk *disk;
280 };