xref: /freebsd/sys/ufs/ffs/ffs_tables.c (revision a463023d6d11f3fa38d614dd16a23c3ee94217f7)
1df8bae1dSRodney W. Grimes /*
2df8bae1dSRodney W. Grimes  * Copyright (c) 1982, 1986, 1993
3df8bae1dSRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
4df8bae1dSRodney W. Grimes  *
5df8bae1dSRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
6df8bae1dSRodney W. Grimes  * modification, are permitted provided that the following conditions
7df8bae1dSRodney W. Grimes  * are met:
8df8bae1dSRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
9df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
10df8bae1dSRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
11df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
12df8bae1dSRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
13df8bae1dSRodney W. Grimes  * 3. All advertising materials mentioning features or use of this software
14df8bae1dSRodney W. Grimes  *    must display the following acknowledgement:
15df8bae1dSRodney W. Grimes  *	This product includes software developed by the University of
16df8bae1dSRodney W. Grimes  *	California, Berkeley and its contributors.
17df8bae1dSRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
18df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
19df8bae1dSRodney W. Grimes  *    without specific prior written permission.
20df8bae1dSRodney W. Grimes  *
21df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
32df8bae1dSRodney W. Grimes  *
33df8bae1dSRodney W. Grimes  *	@(#)ffs_tables.c	8.1 (Berkeley) 6/11/93
34c3aac50fSPeter Wemm  * $FreeBSD$
35df8bae1dSRodney W. Grimes  */
36df8bae1dSRodney W. Grimes 
37df8bae1dSRodney W. Grimes #include <sys/param.h>
38a463023dSPoul-Henning Kamp #include <ufs/ffs/fs.h>
39df8bae1dSRodney W. Grimes 
40df8bae1dSRodney W. Grimes /*
41df8bae1dSRodney W. Grimes  * Bit patterns for identifying fragments in the block map
42df8bae1dSRodney W. Grimes  * used as ((map & around) == inside)
43df8bae1dSRodney W. Grimes  */
44df8bae1dSRodney W. Grimes int around[9] = {
45df8bae1dSRodney W. Grimes 	0x3, 0x7, 0xf, 0x1f, 0x3f, 0x7f, 0xff, 0x1ff, 0x3ff
46df8bae1dSRodney W. Grimes };
47df8bae1dSRodney W. Grimes int inside[9] = {
48df8bae1dSRodney W. Grimes 	0x0, 0x2, 0x6, 0xe, 0x1e, 0x3e, 0x7e, 0xfe, 0x1fe
49df8bae1dSRodney W. Grimes };
50df8bae1dSRodney W. Grimes 
51df8bae1dSRodney W. Grimes /*
52df8bae1dSRodney W. Grimes  * Given a block map bit pattern, the frag tables tell whether a
53df8bae1dSRodney W. Grimes  * particular size fragment is available.
54df8bae1dSRodney W. Grimes  *
55df8bae1dSRodney W. Grimes  * used as:
56df8bae1dSRodney W. Grimes  * if ((1 << (size - 1)) & fragtbl[fs->fs_frag][map] {
57df8bae1dSRodney W. Grimes  *	at least one fragment of the indicated size is available
58df8bae1dSRodney W. Grimes  * }
59df8bae1dSRodney W. Grimes  *
60df8bae1dSRodney W. Grimes  * These tables are used by the scanc instruction on the VAX to
61df8bae1dSRodney W. Grimes  * quickly find an appropriate fragment.
62df8bae1dSRodney W. Grimes  */
63b8dce649SPoul-Henning Kamp static u_char fragtbl124[256] = {
64df8bae1dSRodney W. Grimes 	0x00, 0x16, 0x16, 0x2a, 0x16, 0x16, 0x26, 0x4e,
65df8bae1dSRodney W. Grimes 	0x16, 0x16, 0x16, 0x3e, 0x2a, 0x3e, 0x4e, 0x8a,
66df8bae1dSRodney W. Grimes 	0x16, 0x16, 0x16, 0x3e, 0x16, 0x16, 0x36, 0x5e,
67df8bae1dSRodney W. Grimes 	0x16, 0x16, 0x16, 0x3e, 0x3e, 0x3e, 0x5e, 0x9e,
68df8bae1dSRodney W. Grimes 	0x16, 0x16, 0x16, 0x3e, 0x16, 0x16, 0x36, 0x5e,
69df8bae1dSRodney W. Grimes 	0x16, 0x16, 0x16, 0x3e, 0x3e, 0x3e, 0x5e, 0x9e,
70df8bae1dSRodney W. Grimes 	0x2a, 0x3e, 0x3e, 0x2a, 0x3e, 0x3e, 0x2e, 0x6e,
71df8bae1dSRodney W. Grimes 	0x3e, 0x3e, 0x3e, 0x3e, 0x2a, 0x3e, 0x6e, 0xaa,
72df8bae1dSRodney W. Grimes 	0x16, 0x16, 0x16, 0x3e, 0x16, 0x16, 0x36, 0x5e,
73df8bae1dSRodney W. Grimes 	0x16, 0x16, 0x16, 0x3e, 0x3e, 0x3e, 0x5e, 0x9e,
74df8bae1dSRodney W. Grimes 	0x16, 0x16, 0x16, 0x3e, 0x16, 0x16, 0x36, 0x5e,
75df8bae1dSRodney W. Grimes 	0x16, 0x16, 0x16, 0x3e, 0x3e, 0x3e, 0x5e, 0x9e,
76df8bae1dSRodney W. Grimes 	0x26, 0x36, 0x36, 0x2e, 0x36, 0x36, 0x26, 0x6e,
77df8bae1dSRodney W. Grimes 	0x36, 0x36, 0x36, 0x3e, 0x2e, 0x3e, 0x6e, 0xae,
78df8bae1dSRodney W. Grimes 	0x4e, 0x5e, 0x5e, 0x6e, 0x5e, 0x5e, 0x6e, 0x4e,
79df8bae1dSRodney W. Grimes 	0x5e, 0x5e, 0x5e, 0x7e, 0x6e, 0x7e, 0x4e, 0xce,
80df8bae1dSRodney W. Grimes 	0x16, 0x16, 0x16, 0x3e, 0x16, 0x16, 0x36, 0x5e,
81df8bae1dSRodney W. Grimes 	0x16, 0x16, 0x16, 0x3e, 0x3e, 0x3e, 0x5e, 0x9e,
82df8bae1dSRodney W. Grimes 	0x16, 0x16, 0x16, 0x3e, 0x16, 0x16, 0x36, 0x5e,
83df8bae1dSRodney W. Grimes 	0x16, 0x16, 0x16, 0x3e, 0x3e, 0x3e, 0x5e, 0x9e,
84df8bae1dSRodney W. Grimes 	0x16, 0x16, 0x16, 0x3e, 0x16, 0x16, 0x36, 0x5e,
85df8bae1dSRodney W. Grimes 	0x16, 0x16, 0x16, 0x3e, 0x3e, 0x3e, 0x5e, 0x9e,
86df8bae1dSRodney W. Grimes 	0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x7e,
87df8bae1dSRodney W. Grimes 	0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x7e, 0xbe,
88df8bae1dSRodney W. Grimes 	0x2a, 0x3e, 0x3e, 0x2a, 0x3e, 0x3e, 0x2e, 0x6e,
89df8bae1dSRodney W. Grimes 	0x3e, 0x3e, 0x3e, 0x3e, 0x2a, 0x3e, 0x6e, 0xaa,
90df8bae1dSRodney W. Grimes 	0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x7e,
91df8bae1dSRodney W. Grimes 	0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x7e, 0xbe,
92df8bae1dSRodney W. Grimes 	0x4e, 0x5e, 0x5e, 0x6e, 0x5e, 0x5e, 0x6e, 0x4e,
93df8bae1dSRodney W. Grimes 	0x5e, 0x5e, 0x5e, 0x7e, 0x6e, 0x7e, 0x4e, 0xce,
94df8bae1dSRodney W. Grimes 	0x8a, 0x9e, 0x9e, 0xaa, 0x9e, 0x9e, 0xae, 0xce,
95df8bae1dSRodney W. Grimes 	0x9e, 0x9e, 0x9e, 0xbe, 0xaa, 0xbe, 0xce, 0x8a,
96df8bae1dSRodney W. Grimes };
97df8bae1dSRodney W. Grimes 
98b8dce649SPoul-Henning Kamp static u_char fragtbl8[256] = {
99df8bae1dSRodney W. Grimes 	0x00, 0x01, 0x01, 0x02, 0x01, 0x01, 0x02, 0x04,
100df8bae1dSRodney W. Grimes 	0x01, 0x01, 0x01, 0x03, 0x02, 0x03, 0x04, 0x08,
101df8bae1dSRodney W. Grimes 	0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05,
102df8bae1dSRodney W. Grimes 	0x02, 0x03, 0x03, 0x02, 0x04, 0x05, 0x08, 0x10,
103df8bae1dSRodney W. Grimes 	0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05,
104df8bae1dSRodney W. Grimes 	0x01, 0x01, 0x01, 0x03, 0x03, 0x03, 0x05, 0x09,
105df8bae1dSRodney W. Grimes 	0x02, 0x03, 0x03, 0x02, 0x03, 0x03, 0x02, 0x06,
106df8bae1dSRodney W. Grimes 	0x04, 0x05, 0x05, 0x06, 0x08, 0x09, 0x10, 0x20,
107df8bae1dSRodney W. Grimes 	0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05,
108df8bae1dSRodney W. Grimes 	0x01, 0x01, 0x01, 0x03, 0x03, 0x03, 0x05, 0x09,
109df8bae1dSRodney W. Grimes 	0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05,
110df8bae1dSRodney W. Grimes 	0x03, 0x03, 0x03, 0x03, 0x05, 0x05, 0x09, 0x11,
111df8bae1dSRodney W. Grimes 	0x02, 0x03, 0x03, 0x02, 0x03, 0x03, 0x02, 0x06,
112df8bae1dSRodney W. Grimes 	0x03, 0x03, 0x03, 0x03, 0x02, 0x03, 0x06, 0x0a,
113df8bae1dSRodney W. Grimes 	0x04, 0x05, 0x05, 0x06, 0x05, 0x05, 0x06, 0x04,
114df8bae1dSRodney W. Grimes 	0x08, 0x09, 0x09, 0x0a, 0x10, 0x11, 0x20, 0x40,
115df8bae1dSRodney W. Grimes 	0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05,
116df8bae1dSRodney W. Grimes 	0x01, 0x01, 0x01, 0x03, 0x03, 0x03, 0x05, 0x09,
117df8bae1dSRodney W. Grimes 	0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05,
118df8bae1dSRodney W. Grimes 	0x03, 0x03, 0x03, 0x03, 0x05, 0x05, 0x09, 0x11,
119df8bae1dSRodney W. Grimes 	0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05,
120df8bae1dSRodney W. Grimes 	0x01, 0x01, 0x01, 0x03, 0x03, 0x03, 0x05, 0x09,
121df8bae1dSRodney W. Grimes 	0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x07,
122df8bae1dSRodney W. Grimes 	0x05, 0x05, 0x05, 0x07, 0x09, 0x09, 0x11, 0x21,
123df8bae1dSRodney W. Grimes 	0x02, 0x03, 0x03, 0x02, 0x03, 0x03, 0x02, 0x06,
124df8bae1dSRodney W. Grimes 	0x03, 0x03, 0x03, 0x03, 0x02, 0x03, 0x06, 0x0a,
125df8bae1dSRodney W. Grimes 	0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x07,
126df8bae1dSRodney W. Grimes 	0x02, 0x03, 0x03, 0x02, 0x06, 0x07, 0x0a, 0x12,
127df8bae1dSRodney W. Grimes 	0x04, 0x05, 0x05, 0x06, 0x05, 0x05, 0x06, 0x04,
128df8bae1dSRodney W. Grimes 	0x05, 0x05, 0x05, 0x07, 0x06, 0x07, 0x04, 0x0c,
129df8bae1dSRodney W. Grimes 	0x08, 0x09, 0x09, 0x0a, 0x09, 0x09, 0x0a, 0x0c,
130df8bae1dSRodney W. Grimes 	0x10, 0x11, 0x11, 0x12, 0x20, 0x21, 0x40, 0x80,
131df8bae1dSRodney W. Grimes };
132df8bae1dSRodney W. Grimes 
133df8bae1dSRodney W. Grimes /*
134df8bae1dSRodney W. Grimes  * The actual fragtbl array.
135df8bae1dSRodney W. Grimes  */
136df8bae1dSRodney W. Grimes u_char *fragtbl[MAXFRAG + 1] = {
137df8bae1dSRodney W. Grimes 	0, fragtbl124, fragtbl124, 0, fragtbl124, 0, 0, 0, fragtbl8,
138df8bae1dSRodney W. Grimes };
139