xref: /illumos-gate/usr/src/uts/common/fs/ufs/ufs_tables.c (revision dd72704bd9e794056c558153663c739e2012d721)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1998 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 /*
31  * University Copyright- Copyright (c) 1982, 1986, 1988
32  * The Regents of the University of California
33  * All Rights Reserved
34  *
35  * University Acknowledgment- Portions of this document are derived from
36  * software developed by the University of California, Berkeley, and its
37  * contributors.
38  */
39 
40 #include <sys/types.h>
41 #include <sys/param.h>
42 
43 /*
44  * Bit patterns for identifying fragments in the block map
45  * used as ((map & around) == inside)
46  */
47 int around[9] = {
48 	0x3, 0x7, 0xf, 0x1f, 0x3f, 0x7f, 0xff, 0x1ff, 0x3ff
49 };
50 int inside[9] = {
51 	0x0, 0x2, 0x6, 0xe, 0x1e, 0x3e, 0x7e, 0xfe, 0x1fe
52 };
53 
54 /*
55  * Given a block map bit pattern, the frag tables tell whether a
56  * particular size fragment is available.
57  *
58  * used as:
59  * if ((1 << (size - 1)) & fragtbl[fs->fs_frag][map] {
60  *	at least one fragment of the indicated size is available
61  * }
62  *
63  * These tables are used by the scanc instruction on the VAX to
64  * quickly find an appropriate fragment.
65  */
66 uchar_t fragtbl124[256] = {
67 	0x00, 0x16, 0x16, 0x2a, 0x16, 0x16, 0x26, 0x4e,
68 	0x16, 0x16, 0x16, 0x3e, 0x2a, 0x3e, 0x4e, 0x8a,
69 	0x16, 0x16, 0x16, 0x3e, 0x16, 0x16, 0x36, 0x5e,
70 	0x16, 0x16, 0x16, 0x3e, 0x3e, 0x3e, 0x5e, 0x9e,
71 	0x16, 0x16, 0x16, 0x3e, 0x16, 0x16, 0x36, 0x5e,
72 	0x16, 0x16, 0x16, 0x3e, 0x3e, 0x3e, 0x5e, 0x9e,
73 	0x2a, 0x3e, 0x3e, 0x2a, 0x3e, 0x3e, 0x2e, 0x6e,
74 	0x3e, 0x3e, 0x3e, 0x3e, 0x2a, 0x3e, 0x6e, 0xaa,
75 	0x16, 0x16, 0x16, 0x3e, 0x16, 0x16, 0x36, 0x5e,
76 	0x16, 0x16, 0x16, 0x3e, 0x3e, 0x3e, 0x5e, 0x9e,
77 	0x16, 0x16, 0x16, 0x3e, 0x16, 0x16, 0x36, 0x5e,
78 	0x16, 0x16, 0x16, 0x3e, 0x3e, 0x3e, 0x5e, 0x9e,
79 	0x26, 0x36, 0x36, 0x2e, 0x36, 0x36, 0x26, 0x6e,
80 	0x36, 0x36, 0x36, 0x3e, 0x2e, 0x3e, 0x6e, 0xae,
81 	0x4e, 0x5e, 0x5e, 0x6e, 0x5e, 0x5e, 0x6e, 0x4e,
82 	0x5e, 0x5e, 0x5e, 0x7e, 0x6e, 0x7e, 0x4e, 0xce,
83 	0x16, 0x16, 0x16, 0x3e, 0x16, 0x16, 0x36, 0x5e,
84 	0x16, 0x16, 0x16, 0x3e, 0x3e, 0x3e, 0x5e, 0x9e,
85 	0x16, 0x16, 0x16, 0x3e, 0x16, 0x16, 0x36, 0x5e,
86 	0x16, 0x16, 0x16, 0x3e, 0x3e, 0x3e, 0x5e, 0x9e,
87 	0x16, 0x16, 0x16, 0x3e, 0x16, 0x16, 0x36, 0x5e,
88 	0x16, 0x16, 0x16, 0x3e, 0x3e, 0x3e, 0x5e, 0x9e,
89 	0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x7e,
90 	0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x7e, 0xbe,
91 	0x2a, 0x3e, 0x3e, 0x2a, 0x3e, 0x3e, 0x2e, 0x6e,
92 	0x3e, 0x3e, 0x3e, 0x3e, 0x2a, 0x3e, 0x6e, 0xaa,
93 	0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x7e,
94 	0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x7e, 0xbe,
95 	0x4e, 0x5e, 0x5e, 0x6e, 0x5e, 0x5e, 0x6e, 0x4e,
96 	0x5e, 0x5e, 0x5e, 0x7e, 0x6e, 0x7e, 0x4e, 0xce,
97 	0x8a, 0x9e, 0x9e, 0xaa, 0x9e, 0x9e, 0xae, 0xce,
98 	0x9e, 0x9e, 0x9e, 0xbe, 0xaa, 0xbe, 0xce, 0x8a,
99 };
100 
101 uchar_t fragtbl8[256] = {
102 	0x00, 0x01, 0x01, 0x02, 0x01, 0x01, 0x02, 0x04,
103 	0x01, 0x01, 0x01, 0x03, 0x02, 0x03, 0x04, 0x08,
104 	0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05,
105 	0x02, 0x03, 0x03, 0x02, 0x04, 0x05, 0x08, 0x10,
106 	0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05,
107 	0x01, 0x01, 0x01, 0x03, 0x03, 0x03, 0x05, 0x09,
108 	0x02, 0x03, 0x03, 0x02, 0x03, 0x03, 0x02, 0x06,
109 	0x04, 0x05, 0x05, 0x06, 0x08, 0x09, 0x10, 0x20,
110 	0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05,
111 	0x01, 0x01, 0x01, 0x03, 0x03, 0x03, 0x05, 0x09,
112 	0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05,
113 	0x03, 0x03, 0x03, 0x03, 0x05, 0x05, 0x09, 0x11,
114 	0x02, 0x03, 0x03, 0x02, 0x03, 0x03, 0x02, 0x06,
115 	0x03, 0x03, 0x03, 0x03, 0x02, 0x03, 0x06, 0x0a,
116 	0x04, 0x05, 0x05, 0x06, 0x05, 0x05, 0x06, 0x04,
117 	0x08, 0x09, 0x09, 0x0a, 0x10, 0x11, 0x20, 0x40,
118 	0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05,
119 	0x01, 0x01, 0x01, 0x03, 0x03, 0x03, 0x05, 0x09,
120 	0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05,
121 	0x03, 0x03, 0x03, 0x03, 0x05, 0x05, 0x09, 0x11,
122 	0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05,
123 	0x01, 0x01, 0x01, 0x03, 0x03, 0x03, 0x05, 0x09,
124 	0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x07,
125 	0x05, 0x05, 0x05, 0x07, 0x09, 0x09, 0x11, 0x21,
126 	0x02, 0x03, 0x03, 0x02, 0x03, 0x03, 0x02, 0x06,
127 	0x03, 0x03, 0x03, 0x03, 0x02, 0x03, 0x06, 0x0a,
128 	0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x07,
129 	0x02, 0x03, 0x03, 0x02, 0x06, 0x07, 0x0a, 0x12,
130 	0x04, 0x05, 0x05, 0x06, 0x05, 0x05, 0x06, 0x04,
131 	0x05, 0x05, 0x05, 0x07, 0x06, 0x07, 0x04, 0x0c,
132 	0x08, 0x09, 0x09, 0x0a, 0x09, 0x09, 0x0a, 0x0c,
133 	0x10, 0x11, 0x11, 0x12, 0x20, 0x21, 0x40, 0x80,
134 };
135 
136 /*
137  * The actual fragtbl array.
138  */
139 uchar_t *fragtbl[MAXFRAG + 1] = {
140 	0, fragtbl124, fragtbl124, 0, fragtbl124, 0, 0, 0, fragtbl8,
141 };
142