dec-multia: make netboot possible, add aboot bootloader
[openadk.git] / package / aboot / src / include / ufs.h
blob2629632fba52fce6ad28976a37ed0965b9f91a86
1 /*
2 * Copyright (c) 1982, 1986 Regents of the University of California.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 /*
18 * Mach Operating System
19 * Copyright (c) 1993 Carnegie Mellon University
20 * All Rights Reserved.
22 * Permission to use, copy, modify and distribute this software and its
23 * documentation is hereby granted, provided that both the copyright
24 * notice and this permission notice appear in all copies of the
25 * software, derivative works or modified versions, and any portions
26 * thereof, and that both notices appear in supporting documentation.
28 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
29 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
30 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
32 * Carnegie Mellon requests users of this software to return to
34 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
35 * School of Computer Science
36 * Carnegie Mellon University
37 * Pittsburgh PA 15213-3890
39 * any improvements or extensions that they make and grant Carnegie Mellon
40 * the rights to redistribute these changes.
43 * HISTORY
44 * $Log: ufs.h,v $
45 * Revision 1.1.1.1 2004/04/25 20:38:21 vorlon
46 * Initial import of upstream source
48 * Revision 1.1.1.1 2001/10/08 23:03:52 wgwoods
49 * initial import of CVS source from alphalinux.org, plus a couple bugfixes
51 * Revision 1.1.1.1 2000/05/03 03:58:23 dhd
52 * Initial import (from 0.7 release)
54 * Revision 2.3 93/03/09 10:49:48 danner
55 * Make damn sure we get sys/types.h from the right place.
56 * [93/03/05 af]
58 * Revision 2.2 93/02/05 08:01:43 danner
59 * Adapted for alpha.
60 * [93/02/04 af]
62 * Revision 2.2 90/08/27 21:45:05 dbg
63 * Created.
64 * [90/07/16 dbg]
69 * Common definitions for Berkeley Fast File System.
71 #include <linux/types.h>
73 #define DEV_BSIZE 512
75 #ifndef NBBY
76 #define NBBY 8
77 #endif
80 * The file system is made out of blocks of at most MAXBSIZE units,
81 * with smaller units (fragments) only in the last direct block.
82 * MAXBSIZE primarily determines the size of buffers in the buffer
83 * pool. It may be made larger without any effect on existing
84 * file systems; however, making it smaller may make some file
85 * systems unmountable.
87 * Note that the disk devices are assumed to have DEV_BSIZE "sectors"
88 * and that fragments must be some multiple of this size.
90 #define MAXBSIZE 8192
91 #define MAXFRAG 8
94 * MAXPATHLEN defines the longest permissible path length
95 * after expanding symbolic links.
97 * MAXSYMLINKS defines the maximum number of symbolic links
98 * that may be expanded in a path name. It should be set
99 * high enough to allow all legitimate uses, but halt infinite
100 * loops reasonably quickly.
103 #define MAXPATHLEN 1024
104 #define MAXSYMLINKS 8
108 * Error codes for file system errors.
111 #define FS_NOT_DIRECTORY 5000 /* not a directory */
112 #define FS_NO_ENTRY 5001 /* name not found */
113 #define FS_NAME_TOO_LONG 5002 /* name too long */
114 #define FS_SYMLINK_LOOP 5003 /* symbolic link loop */
115 #define FS_INVALID_FS 5004 /* bad file system */
116 #define FS_NOT_IN_FILE 5005 /* offset not in file */
117 #define FS_INVALID_PARAMETER 5006 /* bad parameter to
118 a routine */
120 * Each disk drive contains some number of file systems.
121 * A file system consists of a number of cylinder groups.
122 * Each cylinder group has inodes and data.
124 * A file system is described by its super-block, which in turn
125 * describes the cylinder groups. The super-block is critical
126 * data and is replicated in each cylinder group to protect against
127 * catastrophic loss. This is done at `newfs' time and the critical
128 * super-block data does not change, so the copies need not be
129 * referenced further unless disaster strikes.
131 * For file system fs, the offsets of the various blocks of interest
132 * are given in the super block as:
133 * [fs->fs_sblkno] Super-block
134 * [fs->fs_cblkno] Cylinder group block
135 * [fs->fs_iblkno] Inode blocks
136 * [fs->fs_dblkno] Data blocks
137 * The beginning of cylinder group cg in fs, is given by
138 * the ``cgbase(fs, cg)'' macro.
140 * The first boot and super blocks are given in absolute disk addresses.
141 * The byte-offset forms are preferred, as they don't imply a sector size.
143 #define BBSIZE 8192
144 #define SBSIZE 8192
145 #define BBOFF ((off_t)(0))
146 #define SBOFF ((off_t)(BBOFF + BBSIZE))
147 #define BBLOCK ((__kernel_daddr_t)(0))
148 #define SBLOCK ((__kernel_daddr_t)(BBLOCK + BBSIZE / DEV_BSIZE))
151 * Addresses stored in inodes are capable of addressing fragments
152 * of `blocks'. File system blocks of at most size MAXBSIZE can
153 * be optionally broken into 2, 4, or 8 pieces, each of which is
154 * addressable; these pieces may be DEV_BSIZE, or some multiple of
155 * a DEV_BSIZE unit.
157 * Large files consist of exclusively large data blocks. To avoid
158 * undue wasted disk space, the last data block of a small file may be
159 * allocated as only as many fragments of a large block as are
160 * necessary. The file system format retains only a single pointer
161 * to such a fragment, which is a piece of a single large block that
162 * has been divided. The size of such a fragment is determinable from
163 * information in the inode, using the ``blksize(fs, ip, lbn)'' macro.
165 * The file system records space availability at the fragment level;
166 * to determine block availability, aligned fragments are examined.
168 * The root inode is the root of the file system.
169 * Inode 0 can't be used for normal purposes and
170 * historically bad blocks were linked to inode 1,
171 * thus the root inode is 2. (inode 1 is no longer used for
172 * this purpose, however numerous dump tapes make this
173 * assumption, so we are stuck with it)
175 #define ROOTINO ((__kernel_ino_t)2) /* i number of all roots */
178 * MINBSIZE is the smallest allowable block size.
179 * In order to insure that it is possible to create files of size
180 * 2^32 with only two levels of indirection, MINBSIZE is set to 4096.
181 * MINBSIZE must be big enough to hold a cylinder group block,
182 * thus changes to (struct cg) must keep its size within MINBSIZE.
183 * Note that super blocks are always of size SBSIZE,
184 * and that both SBSIZE and MAXBSIZE must be >= MINBSIZE.
186 #define MINBSIZE 4096
189 * The path name on which the file system is mounted is maintained
190 * in fs_fsmnt. MAXMNTLEN defines the amount of space allocated in
191 * the super block for this name.
192 * The limit on the amount of summary information per file system
193 * is defined by MAXCSBUFS. It is currently parameterized for a
194 * maximum of two million cylinders.
196 #define MAXMNTLEN 512
197 #define MAXCSBUFS 32
200 * Per cylinder group information; summarized in blocks allocated
201 * from first cylinder group data blocks. These blocks have to be
202 * read in from fs_csaddr (size fs_cssize) in addition to the
203 * super block.
205 * N.B. sizeof(struct csum) must be a power of two in order for
206 * the ``fs_cs'' macro to work (see below).
208 struct csum {
209 int cs_ndir; /* number of directories */
210 int cs_nbfree; /* number of free blocks */
211 int cs_nifree; /* number of free inodes */
212 int cs_nffree; /* number of free frags */
215 typedef int ext_time_t;
216 typedef struct {
217 unsigned int val[2];
218 } quad;
221 * Super block for a file system.
223 #define FS_MAGIC 0x011954
224 struct fs
226 int xxx1; /* struct fs *fs_link;*/
227 int xxx2; /* struct fs *fs_rlink;*/
228 __kernel_daddr_t fs_sblkno; /* addr of super-block in filesys */
229 __kernel_daddr_t fs_cblkno; /* offset of cyl-block in filesys */
230 __kernel_daddr_t fs_iblkno; /* offset of inode-blocks in filesys */
231 __kernel_daddr_t fs_dblkno; /* offset of first data after cg */
232 int fs_cgoffset; /* cylinder group offset in cylinder */
233 int fs_cgmask; /* used to calc mod fs_ntrak */
234 ext_time_t fs_time; /* last time written */
235 int fs_size; /* number of blocks in fs */
236 int fs_dsize; /* number of data blocks in fs */
237 int fs_ncg; /* number of cylinder groups */
238 int fs_bsize; /* size of basic blocks in fs */
239 int fs_fsize; /* size of frag blocks in fs */
240 int fs_frag; /* number of frags in a block in fs */
241 /* these are configuration parameters */
242 int fs_minfree; /* minimum percentage of free blocks */
243 int fs_rotdelay; /* num of ms for optimal next block */
244 int fs_rps; /* disk revolutions per second */
245 /* these fields can be computed from the others */
246 int fs_bmask; /* ``blkoff'' calc of blk offsets */
247 int fs_fmask; /* ``fragoff'' calc of frag offsets */
248 int fs_bshift; /* ``lblkno'' calc of logical blkno */
249 int fs_fshift; /* ``numfrags'' calc number of frags */
250 /* these are configuration parameters */
251 int fs_maxcontig; /* max number of contiguous blks */
252 int fs_maxbpg; /* max number of blks per cyl group */
253 /* these fields can be computed from the others */
254 int fs_fragshift; /* block to frag shift */
255 int fs_fsbtodb; /* fsbtodb and dbtofsb shift constant */
256 int fs_sbsize; /* actual size of super block */
257 int fs_csmask; /* csum block offset */
258 int fs_csshift; /* csum block number */
259 int fs_nindir; /* value of NINDIR */
260 int fs_inopb; /* value of INOPB */
261 int fs_nspf; /* value of NSPF */
262 /* yet another configuration parameter */
263 int fs_optim; /* optimization preference, see below */
264 /* these fields are derived from the hardware */
265 int fs_npsect; /* # sectors/track including spares */
266 int fs_interleave; /* hardware sector interleave */
267 int fs_trackskew; /* sector 0 skew, per track */
268 int fs_headswitch; /* head switch time, usec */
269 int fs_trkseek; /* track-to-track seek, usec */
270 /* sizes determined by number of cylinder groups and their sizes */
271 __kernel_daddr_t fs_csaddr; /* blk addr of cyl grp summary area */
272 int fs_cssize; /* size of cyl grp summary area */
273 int fs_cgsize; /* cylinder group size */
274 /* these fields are derived from the hardware */
275 int fs_ntrak; /* tracks per cylinder */
276 int fs_nsect; /* sectors per track */
277 int fs_spc; /* sectors per cylinder */
278 /* this comes from the disk driver partitioning */
279 int fs_ncyl; /* cylinders in file system */
280 /* these fields can be computed from the others */
281 int fs_cpg; /* cylinders per group */
282 int fs_ipg; /* inodes per group */
283 int fs_fpg; /* blocks per group * fs_frag */
284 /* this data must be re-computed after crashes */
285 struct csum fs_cstotal; /* cylinder summary information */
286 /* these fields are cleared at mount time */
287 char fs_fmod; /* super block modified flag */
288 char fs_clean; /* file system is clean flag */
289 char fs_ronly; /* mounted read-only flag */
290 char fs_flags; /* currently unused flag */
291 char fs_fsmnt[MAXMNTLEN]; /* name mounted on */
292 /* these fields retain the current block allocation info */
293 int fs_cgrotor; /* last cg searched */
294 #ifdef __alpha__
295 int was_fs_csp[MAXCSBUFS]; /* unused on Alpha */
296 #else
297 struct csum *fs_csp[MAXCSBUFS];/* list of fs_cs info buffers */
298 #endif
299 int fs_cpc; /* cyl per cycle in postbl */
300 short fs_opostbl[16][8]; /* old rotation block list head */
301 int fs_sparecon[56]; /* reserved for future constants */
302 quad fs_qbmask; /* ~fs_bmask - for use with quad size */
303 quad fs_qfmask; /* ~fs_fmask - for use with quad size */
304 int fs_postblformat; /* format of positional layout tables */
305 int fs_nrpos; /* number of rotaional positions */
306 int fs_postbloff; /* (short) rotation block list head */
307 int fs_rotbloff; /* (u_char) blocks for each rotation */
308 int fs_magic; /* magic number */
309 unsigned char fs_space[1]; /* list of blocks for each rotation */
310 /* actually longer */
313 * Preference for optimization.
315 #define FS_OPTTIME 0 /* minimize allocation time */
316 #define FS_OPTSPACE 1 /* minimize disk fragmentation */
319 * Rotational layout table format types
321 #define FS_42POSTBLFMT -1 /* 4.2BSD rotational table format */
322 #define FS_DYNAMICPOSTBLFMT 1 /* dynamic rotational table format */
324 * Macros for access to superblock array structures
326 #define fs_postbl(fs, cylno) \
327 (((fs)->fs_postblformat == FS_42POSTBLFMT) \
328 ? ((fs)->fs_opostbl[cylno]) \
329 : ((short *)((char *)(fs) + (fs)->fs_postbloff) + (cylno) * (fs)->fs_nrpos))
330 #define fs_rotbl(fs) \
331 (((fs)->fs_postblformat == FS_42POSTBLFMT) \
332 ? ((fs)->fs_space) \
333 : ((unsigned char *)((char *)(fs) + (fs)->fs_rotbloff)))
336 * Convert cylinder group to base address of its global summary info.
338 * N.B. This macro assumes that sizeof(struct csum) is a power of two.
340 #define fs_cs(fs, indx) \
341 fs_csp[(indx) >> (fs)->fs_csshift][(indx) & ~(fs)->fs_csmask]
344 * Cylinder group block for a file system.
346 #define CG_MAGIC 0x090255
347 struct cg {
348 int xxx1; /* struct cg *cg_link;*/
349 int cg_magic; /* magic number */
350 ext_time_t cg_time; /* time last written */
351 int cg_cgx; /* we are the cgx'th cylinder group */
352 short cg_ncyl; /* number of cyl's this cg */
353 short cg_niblk; /* number of inode blocks this cg */
354 int cg_ndblk; /* number of data blocks this cg */
355 struct csum cg_cs; /* cylinder summary information */
356 int cg_rotor; /* position of last used block */
357 int cg_frotor; /* position of last used frag */
358 int cg_irotor; /* position of last used inode */
359 int cg_frsum[MAXFRAG]; /* counts of available frags */
360 int cg_btotoff; /* (long) block totals per cylinder */
361 int cg_boff; /* (short) free block positions */
362 int cg_iusedoff; /* (char) used inode map */
363 int cg_freeoff; /* (u_char) free block map */
364 int cg_nextfreeoff; /* (u_char) next available space */
365 int cg_sparecon[16]; /* reserved for future use */
366 unsigned char cg_space[1]; /* space for cylinder group maps */
367 /* actually longer */
370 * Macros for access to cylinder group array structures
372 #define cg_blktot(cgp) \
373 (((cgp)->cg_magic != CG_MAGIC) \
374 ? (((struct ocg *)(cgp))->cg_btot) \
375 : ((int *)((char *)(cgp) + (cgp)->cg_btotoff)))
376 #define cg_blks(fs, cgp, cylno) \
377 (((cgp)->cg_magic != CG_MAGIC) \
378 ? (((struct ocg *)(cgp))->cg_b[cylno]) \
379 : ((short *)((char *)(cgp) + (cgp)->cg_boff) + (cylno) * (fs)->fs_nrpos))
380 #define cg_inosused(cgp) \
381 (((cgp)->cg_magic != CG_MAGIC) \
382 ? (((struct ocg *)(cgp))->cg_iused) \
383 : ((char *)((char *)(cgp) + (cgp)->cg_iusedoff)))
384 #define cg_blksfree(cgp) \
385 (((cgp)->cg_magic != CG_MAGIC) \
386 ? (((struct ocg *)(cgp))->cg_free) \
387 : ((unsigned char *)((char *)(cgp) + (cgp)->cg_freeoff)))
388 #define cg_chkmagic(cgp) \
389 ((cgp)->cg_magic == CG_MAGIC || ((struct ocg *)(cgp))->cg_magic == CG_MAGIC)
392 * The following structure is defined
393 * for compatibility with old file systems.
395 struct ocg {
396 int xxx1; /* struct ocg *cg_link;*/
397 int xxx2; /* struct ocg *cg_rlink;*/
398 ext_time_t cg_time; /* time last written */
399 int cg_cgx; /* we are the cgx'th cylinder group */
400 short cg_ncyl; /* number of cyl's this cg */
401 short cg_niblk; /* number of inode blocks this cg */
402 int cg_ndblk; /* number of data blocks this cg */
403 struct csum cg_cs; /* cylinder summary information */
404 int cg_rotor; /* position of last used block */
405 int cg_frotor; /* position of last used frag */
406 int cg_irotor; /* position of last used inode */
407 int cg_frsum[8]; /* counts of available frags */
408 int cg_btot[32]; /* block totals per cylinder */
409 short cg_b[32][8]; /* positions of free blocks */
410 char cg_iused[256]; /* used inode map */
411 int cg_magic; /* magic number */
412 unsigned char cg_free[1]; /* free block map */
413 /* actually longer */
417 * Turn file system block numbers into disk block addresses.
418 * This maps file system blocks to device size blocks.
420 #define fsbtodb(fs, b) ((b) << (fs)->fs_fsbtodb)
421 #define dbtofsb(fs, b) ((b) >> (fs)->fs_fsbtodb)
424 * Cylinder group macros to locate things in cylinder groups.
425 * They calc file system addresses of cylinder group data structures.
427 #define cgbase(fs, c) ((__kernel_daddr_t)((fs)->fs_fpg * (c)))
428 #define cgstart(fs, c) \
429 (cgbase(fs, c) + (fs)->fs_cgoffset * ((c) & ~((fs)->fs_cgmask)))
430 #define cgsblock(fs, c) (cgstart(fs, c) + (fs)->fs_sblkno) /* super blk */
431 #define cgtod(fs, c) (cgstart(fs, c) + (fs)->fs_cblkno) /* cg block */
432 #define cgimin(fs, c) (cgstart(fs, c) + (fs)->fs_iblkno) /* inode blk */
433 #define cgdmin(fs, c) (cgstart(fs, c) + (fs)->fs_dblkno) /* 1st data */
436 * Macros for handling inode numbers:
437 * inode number to file system block offset.
438 * inode number to cylinder group number.
439 * inode number to file system block address.
441 #define itoo(fs, x) ((x) % INOPB(fs))
442 #define itog(fs, x) ((x) / (fs)->fs_ipg)
443 #define itod(fs, x) \
444 ((__kernel_daddr_t)(cgimin(fs, itog(fs, x)) + \
445 (blkstofrags((fs), (((x) % (fs)->fs_ipg) / INOPB(fs))))))
448 * Give cylinder group number for a file system block.
449 * Give cylinder group block number for a file system block.
451 #define dtog(fs, d) ((d) / (fs)->fs_fpg)
452 #define dtogd(fs, d) ((d) % (fs)->fs_fpg)
455 * Extract the bits for a block from a map.
456 * Compute the cylinder and rotational position of a cyl block addr.
458 #define blkmap(fs, map, loc) \
459 (((map)[(loc) / NBBY] >> ((loc) % NBBY)) & (0xff >> (NBBY - (fs)->fs_frag)))
460 #define cbtocylno(fs, bno) \
461 ((bno) * NSPF(fs) / (fs)->fs_spc)
462 #define cbtorpos(fs, bno) \
463 (((bno) * NSPF(fs) % (fs)->fs_spc / (fs)->fs_nsect * (fs)->fs_trackskew + \
464 (bno) * NSPF(fs) % (fs)->fs_spc % (fs)->fs_nsect * (fs)->fs_interleave) % \
465 (fs)->fs_nsect * (fs)->fs_nrpos / (fs)->fs_npsect)
468 * The following macros optimize certain frequently calculated
469 * quantities by using shifts and masks in place of divisions
470 * modulos and multiplications.
472 #define blkoff(fs, loc) /* calculates (loc % fs->fs_bsize) */ \
473 ((loc) & ~(fs)->fs_bmask)
474 #define fragoff(fs, loc) /* calculates (loc % fs->fs_fsize) */ \
475 ((loc) & ~(fs)->fs_fmask)
476 #define lblkno(fs, loc) /* calculates (loc / fs->fs_bsize) */ \
477 ((loc) >> (fs)->fs_bshift)
478 #define numfrags(fs, loc) /* calculates (loc / fs->fs_fsize) */ \
479 ((loc) >> (fs)->fs_fshift)
480 #define blkroundup(fs, size) /* calculates roundup(size, fs->fs_bsize) */ \
481 (((size) + (fs)->fs_bsize - 1) & (fs)->fs_bmask)
482 #define fragroundup(fs, size) /* calculates roundup(size, fs->fs_fsize) */ \
483 (((size) + (fs)->fs_fsize - 1) & (fs)->fs_fmask)
484 #define fragstoblks(fs, frags) /* calculates (frags / fs->fs_frag) */ \
485 ((frags) >> (fs)->fs_fragshift)
486 #define blkstofrags(fs, blks) /* calculates (blks * fs->fs_frag) */ \
487 ((blks) << (fs)->fs_fragshift)
488 #define fragnum(fs, fsb) /* calculates (fsb % fs->fs_frag) */ \
489 ((fsb) & ((fs)->fs_frag - 1))
490 #define blknum(fs, fsb) /* calculates rounddown(fsb, fs->fs_frag) */ \
491 ((fsb) &~ ((fs)->fs_frag - 1))
494 * Determine the number of available frags given a
495 * percentage to hold in reserve
497 #define freespace(fs, percentreserved) \
498 (blkstofrags((fs), (fs)->fs_cstotal.cs_nbfree) + \
499 (fs)->fs_cstotal.cs_nffree - ((fs)->fs_dsize * (percentreserved) / 100))
502 * Determining the size of a file block in the file system.
504 #define blksize(fs, ip, lbn) \
505 (((lbn) >= NDADDR || (ip)->i_size >= ((lbn) + 1) << (fs)->fs_bshift) \
506 ? (fs)->fs_bsize \
507 : (fragroundup(fs, blkoff(fs, (ip)->i_size))))
508 #define dblksize(fs, dip, lbn) \
509 (((lbn) >= NDADDR || (dip)->di_size >= ((lbn) + 1) << (fs)->fs_bshift) \
510 ? (fs)->fs_bsize \
511 : (fragroundup(fs, blkoff(fs, (dip)->di_size))))
514 * Number of disk sectors per block; assumes DEV_BSIZE byte sector size.
516 #define NSPB(fs) ((fs)->fs_nspf << (fs)->fs_fragshift)
517 #define NSPF(fs) ((fs)->fs_nspf)
520 * INOPB is the number of inodes in a secondary storage block.
522 #define INOPB(fs) ((fs)->fs_inopb)
523 #define INOPF(fs) ((fs)->fs_inopb >> (fs)->fs_fragshift)
526 * NINDIR is the number of indirects in a file system block.
528 #define NINDIR(fs) ((fs)->fs_nindir)
531 * Copyright (c) 1982, 1986, 1989 The Regents of the University of California.
532 * All rights reserved.
534 * Redistribution and use in source and binary forms are permitted
535 * provided that the above copyright notice and this paragraph are
536 * duplicated in all such forms and that any documentation,
537 * advertising materials, and other materials related to such
538 * distribution and use acknowledge that the software was developed
539 * by the University of California, Berkeley. The name of the
540 * University may not be used to endorse or promote products derived
541 * from this software without specific prior written permission.
542 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
543 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
544 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
546 * @(#)dir.h 7.6 (Berkeley) 5/9/89
550 * A directory consists of some number of blocks of DIRBLKSIZ
551 * bytes, where DIRBLKSIZ is chosen such that it can be transferred
552 * to disk in a single atomic operation (e.g. 512 bytes on most machines).
554 * Each DIRBLKSIZ byte block contains some number of directory entry
555 * structures, which are of variable length. Each directory entry has
556 * a struct direct at the front of it, containing its inode number,
557 * the length of the entry, and the length of the name contained in
558 * the entry. These are followed by the name padded to a 4 byte boundary
559 * with null bytes. All names are guaranteed null terminated.
560 * The maximum length of a name in a directory is MAXNAMLEN.
562 * The macro DIRSIZ(dp) gives the amount of space required to represent
563 * a directory entry. Free space in a directory is represented by
564 * entries which have dp->d_reclen > DIRSIZ(dp). All DIRBLKSIZ bytes
565 * in a directory block are claimed by the directory entries. This
566 * usually results in the last entry in a directory having a large
567 * dp->d_reclen. When entries are deleted from a directory, the
568 * space is returned to the previous entry in the same directory
569 * block by increasing its dp->d_reclen. If the first entry of
570 * a directory block is free, then its dp->d_ino is set to 0.
571 * Entries other than the first in a directory do not normally have
572 * dp->d_ino set to 0.
574 #define DIRBLKSIZ DEV_BSIZE
575 #define MAXNAMLEN 255
577 struct direct {
578 unsigned int d_ino; /* inode number of entry */
579 unsigned short d_reclen; /* length of this record */
580 unsigned short d_namlen; /* length of string in d_name */
581 char d_name[MAXNAMLEN + 1]; /* name with length <= MAXNAMLEN */
585 * The DIRSIZ macro gives the minimum record length which will hold
586 * the directory entry. This requires the amount of space in struct direct
587 * without the d_name field, plus enough space for the name with a terminating
588 * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
590 #undef DIRSIZ
591 #define DIRSIZ(dp) \
592 ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
595 * The I node is the focus of all file activity in the BSD Fast File System.
596 * There is a unique inode allocated for each active file,
597 * each current directory, each mounted-on file, text file, and the root.
598 * An inode is 'named' by its dev/inumber pair. (iget/iget.c)
599 * Data in icommon is read in from permanent inode on volume.
602 #define NDADDR 12 /* direct addresses in inode */
603 #define NIADDR 3 /* indirect addresses in inode */
605 #define MAX_FASTLINK_SIZE ((NDADDR + NIADDR) * sizeof(__kernel_daddr_t))
607 struct icommon {
608 unsigned short ic_mode; /* 0: mode and type of file */
609 short ic_nlink; /* 2: number of links to file */
610 unsigned short ic_uid; /* 4: owner's user id */
611 unsigned short ic_gid; /* 6: owner's group id */
612 long ic_size; /* 8: number of bytes in file */
613 ext_time_t ic_atime; /* 16: time last accessed */
614 int ic_atspare;
615 ext_time_t ic_mtime; /* 24: time last modified */
616 int ic_mtspare;
617 ext_time_t ic_ctime; /* 32: last time inode changed */
618 int ic_ctspare;
619 union {
620 struct {
621 __kernel_daddr_t Mb_db[NDADDR]; /* 40: disk block addresses */
622 __kernel_daddr_t Mb_ib[NIADDR]; /* 88: indirect blocks */
623 } ic_Mb;
624 char ic_Msymlink[MAX_FASTLINK_SIZE];
625 /* 40: symbolic link name */
626 } ic_Mun;
627 #define ic_db ic_Mun.ic_Mb.Mb_db
628 #define ic_ib ic_Mun.ic_Mb.Mb_ib
629 #define ic_symlink ic_Mun.ic_Msymlink
630 int ic_flags; /* 100: status, currently unused */
631 #define IC_FASTLINK 0x0001 /* Symbolic link in inode */
632 int ic_blocks; /* 104: blocks actually held */
633 int ic_gen; /* 108: generation number */
634 int ic_spare[4]; /* 112: reserved, currently unused */
637 #define i_mode i_ic.ic_mode
638 #define i_nlink i_ic.ic_nlink
639 #define i_uid i_ic.ic_uid
640 #define i_gid i_ic.ic_gid
641 #if BYTE_MSF
642 #define i_size i_ic.ic_size
643 #else /* BYTE_LSF */
644 #define i_size i_ic.ic_size
645 #endif
646 #define i_db i_ic.ic_db
647 #define i_ib i_ic.ic_ib
648 #define i_atime i_ic.ic_atime
649 #define i_mtime i_ic.ic_mtime
650 #define i_ctime i_ic.ic_ctime
651 #define i_blocks i_ic.ic_blocks
652 #define i_rdev i_ic.ic_db[0]
653 #define i_symlink i_ic.ic_symlink
654 #define i_flags i_ic.ic_flags
655 #define i_gen i_ic.ic_gen
657 /* modes */
658 #define IFMT 0170000 /* type of file */
659 #define IFCHR 0020000 /* character special */
660 #define IFDIR 0040000 /* directory */
661 #define IFBLK 0060000 /* block special */
662 #define IFREG 0100000 /* regular */
663 #define IFLNK 0120000 /* symbolic link */
664 #define IFSOCK 0140000 /* socket */
666 #define ISUID 04000 /* set user id on execution */
667 #define ISGID 02000 /* set group id on execution */
668 #define ISVTX 01000 /* save swapped text even after use */
669 #define IREAD 0400 /* read, write, execute permissions */
670 #define IWRITE 0200
671 #define IEXEC 0100
674 * Same structure, but on disk.
676 struct dinode {
677 union {
678 struct icommon di_com;
679 char di_char[128];
680 } di_un;
682 #define di_ic di_un.di_com
684 struct dev_t {
685 int handle;
686 unsigned int first_block;
687 unsigned int last_block;
690 typedef unsigned int recnum_t;