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