xref: /original-bsd/sys/ufs/ffs/ffs_tables.c (revision a141c157)
1 /*
2  * Copyright (c) 1982, 1986 Regents of the University of California.
3  * All rights reserved.  The Berkeley software License Agreement
4  * specifies the terms and conditions for redistribution.
5  *
6  *	@(#)ffs_tables.c	7.2 (Berkeley) 04/13/87
7  */
8 
9 #ifdef KERNEL
10 #include "param.h"
11 #else
12 #include <sys/param.h>
13 #endif
14 
15 /*
16  * Bit patterns for identifying fragments in the block map
17  * used as ((map & around) == inside)
18  */
19 int around[9] = {
20 	0x3, 0x7, 0xf, 0x1f, 0x3f, 0x7f, 0xff, 0x1ff, 0x3ff
21 };
22 int inside[9] = {
23 	0x0, 0x2, 0x6, 0xe, 0x1e, 0x3e, 0x7e, 0xfe, 0x1fe
24 };
25 
26 /*
27  * Given a block map bit pattern, the frag tables tell whether a
28  * particular size fragment is available.
29  *
30  * used as:
31  * if ((1 << (size - 1)) & fragtbl[fs->fs_frag][map] {
32  *	at least one fragment of the indicated size is available
33  * }
34  *
35  * These tables are used by the scanc instruction on the VAX to
36  * quickly find an appropriate fragment.
37  */
38 u_char fragtbl124[256] = {
39 	0x00, 0x16, 0x16, 0x2a, 0x16, 0x16, 0x26, 0x4e,
40 	0x16, 0x16, 0x16, 0x3e, 0x2a, 0x3e, 0x4e, 0x8a,
41 	0x16, 0x16, 0x16, 0x3e, 0x16, 0x16, 0x36, 0x5e,
42 	0x16, 0x16, 0x16, 0x3e, 0x3e, 0x3e, 0x5e, 0x9e,
43 	0x16, 0x16, 0x16, 0x3e, 0x16, 0x16, 0x36, 0x5e,
44 	0x16, 0x16, 0x16, 0x3e, 0x3e, 0x3e, 0x5e, 0x9e,
45 	0x2a, 0x3e, 0x3e, 0x2a, 0x3e, 0x3e, 0x2e, 0x6e,
46 	0x3e, 0x3e, 0x3e, 0x3e, 0x2a, 0x3e, 0x6e, 0xaa,
47 	0x16, 0x16, 0x16, 0x3e, 0x16, 0x16, 0x36, 0x5e,
48 	0x16, 0x16, 0x16, 0x3e,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0x9e, 0x9e, 0xae, 0xce,
70 	0x9e, 0x9e, 0x9e, 0xbe, 0xaa, 0xbe, 0xce, 0x8a,
71 };
72 
73 u_char fragtbl8[256] = {
74 	0x00, 0x01, 0x01, 0x02, 0x01, 0x01, 0x02, 0x04,
75 	0x01, 0x01, 0x01, 0x03, 0x02, 0x03, 0x04, 0x08,
76 	0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05,
77 	0x02, 0x03, 0x03, 0x02, 0x04, 0x05, 0x08, 0x10,
78 	0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05,
79 	0x01, 0x01, 0x01, 0x03, 0x03, 0x03, 0x05, 0x09,
80 	0x02, 0x03, 0x03, 0x02, 0x03, 0x03, 0x02, 0x06,
81 	0x04, 0x05, 0x05, 0x06, 0x08, 0x09, 0x10, 0x20,
82 	0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05,
83 	0x01, 0x01, 0x01, 0x03, 0x03, 0x03, 0x05, 0x09,
84 	0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05,
85 	0x03, 0x03, 0x03, 0x03, 0x05, 0x05, 0x09, 0x11,
86 	0x02, 0x03, 0x03, 0x02, 0x03, 0x03, 0x02, 0x06,
87 	0x03, 0x03, 0x03, 0x03, 0x02, 0x03, 0x06, 0x0a,
88 	0x04, 0x05, 0x05, 0x06, 0x05, 0x05, 0x06, 0x04,
89 	0x08, 0x09, 0x09, 0x0a, 0x10, 0x11, 0x20, 0x40,
90 	0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05,
91 	0x01, 0x01, 0x01, 0x03, 0x03, 0x03, 0x05, 0x09,
92 	0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05,
93 	0x03, 0x03, 0x03, 0x03, 0x05, 0x05, 0x09, 0x11,
94 	0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05,
95 	0x01, 0x01, 0x01, 0x03, 0x03, 0x03, 0x05, 0x09,
96 	0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x07,
97 	0x05, 0x05, 0x05, 0x07, 0x09, 0x09, 0x11, 0x21,
98 	0x02, 0x03, 0x03, 0x02, 0x03, 0x03, 0x02, 0x06,
99 	0x03, 0x03, 0x03, 0x03, 0x02, 0x03, 0x06, 0x0a,
100 	0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x07,
101 	0x02, 0x03, 0x03, 0x02, 0x06, 0x07, 0x0a, 0x12,
102 	0x04, 0x05, 0x05, 0x06, 0x05, 0x05, 0x06, 0x04,
103 	0x05, 0x05, 0x05, 0x07, 0x06, 0x07, 0x04, 0x0c,
104 	0x08, 0x09, 0x09, 0x0a, 0x09, 0x09, 0x0a, 0x0c,
105 	0x10, 0x11, 0x11, 0x12, 0x20, 0x21, 0x40, 0x80,
106 };
107 
108 /*
109  * The actual fragtbl array.
110  */
111 u_char *fragtbl[MAXFRAG + 1] = {
112 	0, fragtbl124, fragtbl124, 0, fragtbl124, 0, 0, 0, fragtbl8,
113 };
114