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