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