xref: /original-bsd/sys/ufs/ffs/fs.h (revision 2c9a935d)
1 /*
2  * Copyright (c) 1982, 1986, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)fs.h	8.13 (Berkeley) 03/21/95
8  */
9 
10 /*
11  * Each disk drive contains some number of file systems.
12  * A file system consists of a number of cylinder groups.
13  * Each cylinder group has inodes and data.
14  *
15  * A file system is described by its super-block, which in turn
16  * describes the cylinder groups.  The super-block is critical
17  * data and is replicated in each cylinder group to protect against
18  * catastrophic loss.  This is done at `newfs' time and the critical
19  * super-block data does not change, so the copies need not be
20  * referenced further unless disaster strikes.
21  *
22  * For file system fs, the offsets of the various blocks of interest
23  * are given in the super block as:
24  *	[fs->fs_sblkno]		Super-block
25  *	[fs->fs_cblkno]		Cylinder group block
26  *	[fs->fs_iblkno]		Inode blocks
27  *	[fs->fs_dblkno]		Data blocks
28  * The beginning of cylinder group cg in fs, is given by
29  * the ``cgbase(fs, cg)'' macro.
30  *
31  * The first boot and super blocks are given in absolute disk addresses.
32  * The byte-offset forms are preferred, as they don't imply a sector size.
33  */
34 #define BBSIZE		8192
35 #define SBSIZE		8192
36 #define	BBOFF		((off_t)(0))
37 #define	SBOFF		((off_t)(BBOFF + BBSIZE))
38 #define	BBLOCK		((ufs_daddr_t)(0))
39 #define	SBLOCK		((ufs_daddr_t)(BBLOCK + BBSIZE / DEV_BSIZE))
40 
41 /*
42  * Addresses stored in inodes are capable of addressing fragments
43  * of `blocks'. File system blocks of at most size MAXBSIZE can
44  * be optionally broken into 2, 4, or 8 pieces, each of which is
45  * addressible; these pieces may be DEV_BSIZE, or some multiple of
46  * a DEV_BSIZE unit.
47  *
48  * Large files consist of exclusively large data blocks.  To avoid
49  * undue wasted disk space, the last data block of a small file may be
50  * allocated as only as many fragments of a large block as are
51  * necessary.  The file system format retains only a single pointer
52  * to such a fragment, which is a piece of a single large block that
53  * has been divided.  The size of such a fragment is determinable from
54  * information in the inode, using the ``blksize(fs, ip, lbn)'' macro.
55  *
56  * The file system records space availability at the fragment level;
57  * to determine block availability, aligned fragments are examined.
58  */
59 
60 /*
61  * MINBSIZE is the smallest allowable block size.
62  * In order to insure that it is possible to create files of size
63  * 2^32 with only two levels of indirection, MINBSIZE is set to 4096.
64  * MINBSIZE must be big enough to hold a cylinder group block,
65  * thus changes to (struct cg) must keep its size within MINBSIZE.
66  * Note that super blocks are always of size SBSIZE,
67  * and that both SBSIZE and MAXBSIZE must be >= MINBSIZE.
68  */
69 #define MINBSIZE	4096
70 
71 /*
72  * The path name on which the file system is mounted is maintained
73  * in fs_fsmnt. MAXMNTLEN defines the amount of space allocated in
74  * the super block for this name.
75  */
76 #define MAXMNTLEN	512
77 
78 /*
79  * The limit on the amount of summary information per file system
80  * is defined by MAXCSBUFS. It is currently parameterized for a
81  * size of 128 bytes (2 million cylinder groups on machines with
82  * 32-bit pointers, and 1 million on 64-bit machines). One pointer
83  * is taken away to point to an array of cluster sizes that is
84  * computed as cylinder groups are inspected.
85  */
86 #define	MAXCSBUFS	((128 / sizeof(void *)) - 1)
87 
88 /*
89  * A summary of contiguous blocks of various sizes is maintained
90  * in each cylinder group. Normally this is set by the initial
91  * value of fs_maxcontig. To conserve space, a maximum summary size
92  * is set by FS_MAXCONTIG.
93  */
94 #define FS_MAXCONTIG	16
95 
96 /*
97  * MINFREE gives the minimum acceptable percentage of file system
98  * blocks which may be free. If the freelist drops below this level
99  * only the superuser may continue to allocate blocks. This may
100  * be set to 0 if no reserve of free blocks is deemed necessary,
101  * however throughput drops by fifty percent if the file system
102  * is run at between 95% and 100% full; thus the minimum default
103  * value of fs_minfree is 5%. However, to get good clustering
104  * performance, 10% is a better choice. hence we use 10% as our
105  * default value. With 10% free space, fragmentation is not a
106  * problem, so we choose to optimize for time.
107  */
108 #define MINFREE		5
109 #define DEFAULTOPT	FS_OPTTIME
110 
111 /*
112  * Per cylinder group information; summarized in blocks allocated
113  * from first cylinder group data blocks.  These blocks have to be
114  * read in from fs_csaddr (size fs_cssize) in addition to the
115  * super block.
116  *
117  * N.B. sizeof(struct csum) must be a power of two in order for
118  * the ``fs_cs'' macro to work (see below).
119  */
120 struct csum {
121 	int32_t	cs_ndir;		/* number of directories */
122 	int32_t	cs_nbfree;		/* number of free blocks */
123 	int32_t	cs_nifree;		/* number of free inodes */
124 	int32_t	cs_nffree;		/* number of free frags */
125 };
126 
127 /*
128  * Super block for an FFS file system.
129  */
130 struct fs {
131 	int32_t	 fs_firstfield;		/* historic file system linked list, */
132 	int32_t	 fs_unused_1;		/*     used for incore super blocks */
133 	ufs_daddr_t fs_sblkno;		/* addr of super-block in filesys */
134 	ufs_daddr_t fs_cblkno;		/* offset of cyl-block in filesys */
135 	ufs_daddr_t fs_iblkno;		/* offset of inode-blocks in filesys */
136 	ufs_daddr_t fs_dblkno;		/* offset of first data after cg */
137 	int32_t	 fs_cgoffset;		/* cylinder group offset in cylinder */
138 	int32_t	 fs_cgmask;		/* used to calc mod fs_ntrak */
139 	time_t 	 fs_time;		/* last time written */
140 	int32_t	 fs_size;		/* number of blocks in fs */
141 	int32_t	 fs_dsize;		/* number of data blocks in fs */
142 	int32_t	 fs_ncg;		/* number of cylinder groups */
143 	int32_t	 fs_bsize;		/* size of basic blocks in fs */
144 	int32_t	 fs_fsize;		/* size of frag blocks in fs */
145 	int32_t	 fs_frag;		/* number of frags in a block in fs */
146 /* these are configuration parameters */
147 	int32_t	 fs_minfree;		/* minimum percentage of free blocks */
148 	int32_t	 fs_rotdelay;		/* num of ms for optimal next block */
149 	int32_t	 fs_rps;		/* disk revolutions per second */
150 /* these fields can be computed from the others */
151 	int32_t	 fs_bmask;		/* ``blkoff'' calc of blk offsets */
152 	int32_t	 fs_fmask;		/* ``fragoff'' calc of frag offsets */
153 	int32_t	 fs_bshift;		/* ``lblkno'' calc of logical blkno */
154 	int32_t	 fs_fshift;		/* ``numfrags'' calc number of frags */
155 /* these are configuration parameters */
156 	int32_t	 fs_maxcontig;		/* max number of contiguous blks */
157 	int32_t	 fs_maxbpg;		/* max number of blks per cyl group */
158 /* these fields can be computed from the others */
159 	int32_t	 fs_fragshift;		/* block to frag shift */
160 	int32_t	 fs_fsbtodb;		/* fsbtodb and dbtofsb shift constant */
161 	int32_t	 fs_sbsize;		/* actual size of super block */
162 	int32_t	 fs_csmask;		/* csum block offset */
163 	int32_t	 fs_csshift;		/* csum block number */
164 	int32_t	 fs_nindir;		/* value of NINDIR */
165 	int32_t	 fs_inopb;		/* value of INOPB */
166 	int32_t	 fs_nspf;		/* value of NSPF */
167 /* yet another configuration parameter */
168 	int32_t	 fs_optim;		/* optimization preference, see below */
169 /* these fields are derived from the hardware */
170 	int32_t	 fs_npsect;		/* # sectors/track including spares */
171 	int32_t	 fs_interleave;		/* hardware sector interleave */
172 	int32_t	 fs_trackskew;		/* sector 0 skew, per track */
173 	int32_t	 fs_headswitch;		/* head switch time, usec */
174 	int32_t	 fs_trkseek;		/* track-to-track seek, usec */
175 /* sizes determined by number of cylinder groups and their sizes */
176 	ufs_daddr_t fs_csaddr;		/* blk addr of cyl grp summary area */
177 	int32_t	 fs_cssize;		/* size of cyl grp summary area */
178 	int32_t	 fs_cgsize;		/* cylinder group size */
179 /* these fields are derived from the hardware */
180 	int32_t	 fs_ntrak;		/* tracks per cylinder */
181 	int32_t	 fs_nsect;		/* sectors per track */
182 	int32_t  fs_spc;			/* sectors per cylinder */
183 /* this comes from the disk driver partitioning */
184 	int32_t	 fs_ncyl;		/* cylinders in file system */
185 /* these fields can be computed from the others */
186 	int32_t	 fs_cpg;			/* cylinders per group */
187 	int32_t	 fs_ipg;			/* inodes per group */
188 	int32_t	 fs_fpg;			/* blocks per group * fs_frag */
189 /* this data must be re-computed after crashes */
190 	struct	csum fs_cstotal;	/* cylinder summary information */
191 /* these fields are cleared at mount time */
192 	int8_t   fs_fmod;		/* super block modified flag */
193 	int8_t   fs_clean;		/* file system is clean flag */
194 	int8_t 	 fs_ronly;		/* mounted read-only flag */
195 	int8_t   fs_flags;		/* currently unused flag */
196 	u_char	 fs_fsmnt[MAXMNTLEN];	/* name mounted on */
197 /* these fields retain the current block allocation info */
198 	int32_t	 fs_cgrotor;		/* last cg searched */
199 	struct	csum *fs_csp[MAXCSBUFS];/* list of fs_cs info buffers */
200 	int32_t	 *fs_maxcluster;	/* max cluster in each cyl group */
201 	int32_t	 fs_cpc;		/* cyl per cycle in postbl */
202 	int16_t	 fs_opostbl[16][8];	/* old rotation block list head */
203 	int32_t	 fs_sparecon[50];	/* reserved for future constants */
204 	int32_t	 fs_contigsumsize;	/* size of cluster summary array */
205 	int32_t	 fs_maxsymlinklen;	/* max length of an internal symlink */
206 	int32_t	 fs_inodefmt;		/* format of on-disk inodes */
207 	u_int64_t fs_maxfilesize;	/* maximum representable file size */
208 	int64_t	 fs_qbmask;		/* ~fs_bmask for use with 64-bit size */
209 	int64_t	 fs_qfmask;		/* ~fs_fmask for use with 64-bit size */
210 	int32_t	 fs_state;		/* validate fs_clean field */
211 	int32_t	 fs_postblformat;	/* format of positional layout tables */
212 	int32_t	 fs_nrpos;		/* number of rotational positions */
213 	int32_t	 fs_postbloff;		/* (u_int16) rotation block list head */
214 	int32_t	 fs_rotbloff;		/* (u_int8) blocks for each rotation */
215 	int32_t	 fs_magic;		/* magic number */
216 	u_int8_t fs_space[1];		/* list of blocks for each rotation */
217 /* actually longer */
218 };
219 
220 /*
221  * Filesystem identification
222  */
223 #define	FS_MAGIC	0x011954	/* the fast filesystem magic number */
224 #define	FS_OKAY		0x7c269d38	/* superblock checksum */
225 #define FS_42INODEFMT	-1		/* 4.2BSD inode format */
226 #define FS_44INODEFMT	2		/* 4.4BSD inode format */
227 /*
228  * Preference for optimization.
229  */
230 #define FS_OPTTIME	0	/* minimize allocation time */
231 #define FS_OPTSPACE	1	/* minimize disk fragmentation */
232 
233 /*
234  * Rotational layout table format types
235  */
236 #define FS_42POSTBLFMT		-1	/* 4.2BSD rotational table format */
237 #define FS_DYNAMICPOSTBLFMT	1	/* dynamic rotational table format */
238 /*
239  * Macros for access to superblock array structures
240  */
241 #define fs_postbl(fs, cylno) \
242     (((fs)->fs_postblformat == FS_42POSTBLFMT) \
243     ? ((fs)->fs_opostbl[cylno]) \
244     : ((int16_t *)((u_int8_t *)(fs) + \
245 	(fs)->fs_postbloff) + (cylno) * (fs)->fs_nrpos))
246 #define fs_rotbl(fs) \
247     (((fs)->fs_postblformat == FS_42POSTBLFMT) \
248     ? ((fs)->fs_space) \
249     : ((u_int8_t *)((u_int8_t *)(fs) + (fs)->fs_rotbloff)))
250 
251 /*
252  * The size of a cylinder group is calculated by CGSIZE. The maximum size
253  * is limited by the fact that cylinder groups are at most one block.
254  * Its size is derived from the size of the maps maintained in the
255  * cylinder group and the (struct cg) size.
256  */
257 #define CGSIZE(fs) \
258     /* base cg */	(sizeof(struct cg) + sizeof(int32_t) + \
259     /* blktot size */	(fs)->fs_cpg * sizeof(int32_t) + \
260     /* blks size */	(fs)->fs_cpg * (fs)->fs_nrpos * sizeof(int16_t) + \
261     /* inode map */	howmany((fs)->fs_ipg, NBBY) + \
262     /* block map */	howmany((fs)->fs_cpg * (fs)->fs_spc / NSPF(fs), NBBY) +\
263     /* if present */	((fs)->fs_contigsumsize <= 0 ? 0 : \
264     /* cluster sum */	(fs)->fs_contigsumsize * sizeof(int32_t) + \
265     /* cluster map */	howmany((fs)->fs_cpg * (fs)->fs_spc / NSPB(fs), NBBY)))
266 
267 /*
268  * Convert cylinder group to base address of its global summary info.
269  *
270  * N.B. This macro assumes that sizeof(struct csum) is a power of two.
271  */
272 #define fs_cs(fs, indx) \
273 	fs_csp[(indx) >> (fs)->fs_csshift][(indx) & ~(fs)->fs_csmask]
274 
275 /*
276  * Cylinder group block for a file system.
277  */
278 #define	CG_MAGIC	0x090255
279 struct cg {
280 	int32_t	 cg_firstfield;		/* historic cyl groups linked list */
281 	int32_t	 cg_magic;		/* magic number */
282 	time_t	 cg_time;		/* time last written */
283 	int32_t	 cg_cgx;		/* we are the cgx'th cylinder group */
284 	int16_t	 cg_ncyl;		/* number of cyl's this cg */
285 	int16_t	 cg_niblk;		/* number of inode blocks this cg */
286 	int32_t	 cg_ndblk;		/* number of data blocks this cg */
287 	struct	csum cg_cs;		/* cylinder summary information */
288 	int32_t	 cg_rotor;		/* position of last used block */
289 	int32_t	 cg_frotor;		/* position of last used frag */
290 	int32_t	 cg_irotor;		/* position of last used inode */
291 	int32_t	 cg_frsum[MAXFRAG];	/* counts of available frags */
292 	int32_t	 cg_btotoff;		/* (int32) block totals per cylinder */
293 	int32_t	 cg_boff;		/* (u_int16) free block positions */
294 	int32_t	 cg_iusedoff;		/* (u_int8) used inode map */
295 	int32_t	 cg_freeoff;		/* (u_int8) free block map */
296 	int32_t	 cg_nextfreeoff;	/* (u_int8) next available space */
297 	int32_t	 cg_clustersumoff;	/* (u_int32) counts of avail clusters */
298 	int32_t	 cg_clusteroff;		/* (u_int8) free cluster map */
299 	int32_t	 cg_nclusterblks;	/* number of clusters this cg */
300 	int32_t	 cg_sparecon[13];	/* reserved for future use */
301 	u_int8_t cg_space[1];		/* space for cylinder group maps */
302 /* actually longer */
303 };
304 
305 /*
306  * Macros for access to cylinder group array structures
307  */
308 #define cg_blktot(cgp) \
309     (((cgp)->cg_magic != CG_MAGIC) \
310     ? (((struct ocg *)(cgp))->cg_btot) \
311     : ((int32_t *)((u_int8_t *)(cgp) + (cgp)->cg_btotoff)))
312 #define cg_blks(fs, cgp, cylno) \
313     (((cgp)->cg_magic != CG_MAGIC) \
314     ? (((struct ocg *)(cgp))->cg_b[cylno]) \
315     : ((int16_t *)((u_int8_t *)(cgp) + \
316 	(cgp)->cg_boff) + (cylno) * (fs)->fs_nrpos))
317 #define cg_inosused(cgp) \
318     (((cgp)->cg_magic != CG_MAGIC) \
319     ? (((struct ocg *)(cgp))->cg_iused) \
320     : ((u_int8_t *)((u_int8_t *)(cgp) + (cgp)->cg_iusedoff)))
321 #define cg_blksfree(cgp) \
322     (((cgp)->cg_magic != CG_MAGIC) \
323     ? (((struct ocg *)(cgp))->cg_free) \
324     : ((u_int8_t *)((u_int8_t *)(cgp) + (cgp)->cg_freeoff)))
325 #define cg_chkmagic(cgp) \
326     ((cgp)->cg_magic == CG_MAGIC || ((struct ocg *)(cgp))->cg_magic == CG_MAGIC)
327 #define cg_clustersfree(cgp) \
328     ((u_int8_t *)((u_int8_t *)(cgp) + (cgp)->cg_clusteroff))
329 #define cg_clustersum(cgp) \
330     ((int32_t *)((u_int8_t *)(cgp) + (cgp)->cg_clustersumoff))
331 
332 /*
333  * The following structure is defined
334  * for compatibility with old file systems.
335  */
336 struct ocg {
337 	int32_t	 cg_firstfield;		/* historic linked list of cyl groups */
338 	int32_t	 cg_unused_1;		/*     used for incore cyl groups */
339 	time_t	 cg_time;		/* time last written */
340 	int32_t	 cg_cgx;		/* we are the cgx'th cylinder group */
341 	int16_t	 cg_ncyl;		/* number of cyl's this cg */
342 	int16_t	 cg_niblk;		/* number of inode blocks this cg */
343 	int32_t	 cg_ndblk;		/* number of data blocks this cg */
344 	struct	csum cg_cs;		/* cylinder summary information */
345 	int32_t	 cg_rotor;		/* position of last used block */
346 	int32_t	 cg_frotor;		/* position of last used frag */
347 	int32_t	 cg_irotor;		/* position of last used inode */
348 	int32_t	 cg_frsum[8];		/* counts of available frags */
349 	int32_t	 cg_btot[32];		/* block totals per cylinder */
350 	int16_t	 cg_b[32][8];		/* positions of free blocks */
351 	u_int8_t cg_iused[256];		/* used inode map */
352 	int32_t	 cg_magic;		/* magic number */
353 	u_int8_t cg_free[1];		/* free block map */
354 /* actually longer */
355 };
356 
357 /*
358  * Turn file system block numbers into disk block addresses.
359  * This maps file system blocks to device size blocks.
360  */
361 #define fsbtodb(fs, b)	((b) << (fs)->fs_fsbtodb)
362 #define	dbtofsb(fs, b)	((b) >> (fs)->fs_fsbtodb)
363 
364 /*
365  * Cylinder group macros to locate things in cylinder groups.
366  * They calc file system addresses of cylinder group data structures.
367  */
368 #define	cgbase(fs, c)	((ufs_daddr_t)((fs)->fs_fpg * (c)))
369 #define	cgdmin(fs, c)	(cgstart(fs, c) + (fs)->fs_dblkno)	/* 1st data */
370 #define	cgimin(fs, c)	(cgstart(fs, c) + (fs)->fs_iblkno)	/* inode blk */
371 #define	cgsblock(fs, c)	(cgstart(fs, c) + (fs)->fs_sblkno)	/* super blk */
372 #define	cgtod(fs, c)	(cgstart(fs, c) + (fs)->fs_cblkno)	/* cg block */
373 #define cgstart(fs, c)							\
374 	(cgbase(fs, c) + (fs)->fs_cgoffset * ((c) & ~((fs)->fs_cgmask)))
375 
376 /*
377  * Macros for handling inode numbers:
378  *     inode number to file system block offset.
379  *     inode number to cylinder group number.
380  *     inode number to file system block address.
381  */
382 #define	ino_to_cg(fs, x)	((x) / (fs)->fs_ipg)
383 #define	ino_to_fsba(fs, x)						\
384 	((ufs_daddr_t)(cgimin(fs, ino_to_cg(fs, x)) +			\
385 	    (blkstofrags((fs), (((x) % (fs)->fs_ipg) / INOPB(fs))))))
386 #define	ino_to_fsbo(fs, x)	((x) % INOPB(fs))
387 
388 /*
389  * Give cylinder group number for a file system block.
390  * Give cylinder group block number for a file system block.
391  */
392 #define	dtog(fs, d)	((d) / (fs)->fs_fpg)
393 #define	dtogd(fs, d)	((d) % (fs)->fs_fpg)
394 
395 /*
396  * Extract the bits for a block from a map.
397  * Compute the cylinder and rotational position of a cyl block addr.
398  */
399 #define blkmap(fs, map, loc) \
400     (((map)[(loc) / NBBY] >> ((loc) % NBBY)) & (0xff >> (NBBY - (fs)->fs_frag)))
401 #define cbtocylno(fs, bno) \
402     ((bno) * NSPF(fs) / (fs)->fs_spc)
403 #define cbtorpos(fs, bno) \
404     (((bno) * NSPF(fs) % (fs)->fs_spc / (fs)->fs_nsect * (fs)->fs_trackskew + \
405      (bno) * NSPF(fs) % (fs)->fs_spc % (fs)->fs_nsect * (fs)->fs_interleave) % \
406      (fs)->fs_nsect * (fs)->fs_nrpos / (fs)->fs_npsect)
407 
408 /*
409  * The following macros optimize certain frequently calculated
410  * quantities by using shifts and masks in place of divisions
411  * modulos and multiplications.
412  */
413 #define blkoff(fs, loc)		/* calculates (loc % fs->fs_bsize) */ \
414 	((loc) & (fs)->fs_qbmask)
415 #define fragoff(fs, loc)	/* calculates (loc % fs->fs_fsize) */ \
416 	((loc) & (fs)->fs_qfmask)
417 #define lblktosize(fs, blk)	/* calculates (blk * fs->fs_bsize) */ \
418 	((blk) << (fs)->fs_bshift)
419 #define lblkno(fs, loc)		/* calculates (loc / fs->fs_bsize) */ \
420 	((loc) >> (fs)->fs_bshift)
421 #define numfrags(fs, loc)	/* calculates (loc / fs->fs_fsize) */ \
422 	((loc) >> (fs)->fs_fshift)
423 #define blkroundup(fs, size)	/* calculates roundup(size, fs->fs_bsize) */ \
424 	(((size) + (fs)->fs_qbmask) & (fs)->fs_bmask)
425 #define fragroundup(fs, size)	/* calculates roundup(size, fs->fs_fsize) */ \
426 	(((size) + (fs)->fs_qfmask) & (fs)->fs_fmask)
427 #define fragstoblks(fs, frags)	/* calculates (frags / fs->fs_frag) */ \
428 	((frags) >> (fs)->fs_fragshift)
429 #define blkstofrags(fs, blks)	/* calculates (blks * fs->fs_frag) */ \
430 	((blks) << (fs)->fs_fragshift)
431 #define fragnum(fs, fsb)	/* calculates (fsb % fs->fs_frag) */ \
432 	((fsb) & ((fs)->fs_frag - 1))
433 #define blknum(fs, fsb)		/* calculates rounddown(fsb, fs->fs_frag) */ \
434 	((fsb) &~ ((fs)->fs_frag - 1))
435 
436 /*
437  * Determine the number of available frags given a
438  * percentage to hold in reserve.
439  */
440 #define freespace(fs, percentreserved) \
441 	(blkstofrags((fs), (fs)->fs_cstotal.cs_nbfree) + \
442 	(fs)->fs_cstotal.cs_nffree - ((fs)->fs_dsize * (percentreserved) / 100))
443 
444 /*
445  * Determining the size of a file block in the file system.
446  */
447 #define blksize(fs, ip, lbn) \
448 	(((lbn) >= NDADDR || (ip)->i_size >= ((lbn) + 1) << (fs)->fs_bshift) \
449 	    ? (fs)->fs_bsize \
450 	    : (fragroundup(fs, blkoff(fs, (ip)->i_size))))
451 #define dblksize(fs, dip, lbn) \
452 	(((lbn) >= NDADDR || (dip)->di_size >= ((lbn) + 1) << (fs)->fs_bshift) \
453 	    ? (fs)->fs_bsize \
454 	    : (fragroundup(fs, blkoff(fs, (dip)->di_size))))
455 
456 /*
457  * Number of disk sectors per block/fragment; assumes DEV_BSIZE byte
458  * sector size.
459  */
460 #define	NSPB(fs)	((fs)->fs_nspf << (fs)->fs_fragshift)
461 #define	NSPF(fs)	((fs)->fs_nspf)
462 
463 /*
464  * Number of inodes in a secondary storage block/fragment.
465  */
466 #define	INOPB(fs)	((fs)->fs_inopb)
467 #define	INOPF(fs)	((fs)->fs_inopb >> (fs)->fs_fragshift)
468 
469 /*
470  * Number of indirects in a file system block.
471  */
472 #define	NINDIR(fs)	((fs)->fs_nindir)
473 
474 extern int inside[], around[];
475 extern u_char *fragtbl[];
476