1 1.9 christos /* $NetBSD: ffs_tables.c,v 1.9 2005/12/11 12:25:25 christos 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.7 lukem #if HAVE_NBTOOL_CONFIG_H 35 1.7 lukem #include "nbtool_config.h" 36 1.5 tv #endif 37 1.5 tv 38 1.7 lukem #include <sys/cdefs.h> 39 1.9 christos __KERNEL_RCSID(0, "$NetBSD: ffs_tables.c,v 1.9 2005/12/11 12:25:25 christos Exp $"); 40 1.1 mycroft 41 1.1 mycroft #include <sys/param.h> 42 1.1 mycroft 43 1.1 mycroft /* 44 1.1 mycroft * Bit patterns for identifying fragments in the block map 45 1.1 mycroft * used as ((map & around) == inside) 46 1.1 mycroft */ 47 1.3 jdolecek const int around[9] = { 48 1.1 mycroft 0x3, 0x7, 0xf, 0x1f, 0x3f, 0x7f, 0xff, 0x1ff, 0x3ff 49 1.1 mycroft }; 50 1.3 jdolecek const int inside[9] = { 51 1.1 mycroft 0x0, 0x2, 0x6, 0xe, 0x1e, 0x3e, 0x7e, 0xfe, 0x1fe 52 1.1 mycroft }; 53 1.1 mycroft 54 1.1 mycroft /* 55 1.1 mycroft * Given a block map bit pattern, the frag tables tell whether a 56 1.8 perry * particular size fragment is available. 57 1.1 mycroft * 58 1.1 mycroft * used as: 59 1.1 mycroft * if ((1 << (size - 1)) & fragtbl[fs->fs_frag][map] { 60 1.1 mycroft * at least one fragment of the indicated size is available 61 1.1 mycroft * } 62 1.1 mycroft * 63 1.1 mycroft * These tables are used by the scanc instruction on the VAX to 64 1.1 mycroft * quickly find an appropriate fragment. 65 1.1 mycroft */ 66 1.3 jdolecek const u_char fragtbl124[256] = { 67 1.1 mycroft 0x00, 0x16, 0x16, 0x2a, 0x16, 0x16, 0x26, 0x4e, 68 1.1 mycroft 0x16, 0x16, 0x16, 0x3e, 0x2a, 0x3e, 0x4e, 0x8a, 69 1.1 mycroft 0x16, 0x16, 0x16, 0x3e, 0x16, 0x16, 0x36, 0x5e, 70 1.1 mycroft 0x16, 0x16, 0x16, 0x3e, 0x3e, 0x3e, 0x5e, 0x9e, 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 0x2a, 0x3e, 0x3e, 0x2a, 0x3e, 0x3e, 0x2e, 0x6e, 74 1.1 mycroft 0x3e, 0x3e, 0x3e, 0x3e, 0x2a, 0x3e, 0x6e, 0xaa, 75 1.1 mycroft 0x16, 0x16, 0x16, 0x3e, 0x16, 0x16, 0x36, 0x5e, 76 1.1 mycroft 0x16, 0x16, 0x16, 0x3e, 0x3e, 0x3e, 0x5e, 0x9e, 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 0x26, 0x36, 0x36, 0x2e, 0x36, 0x36, 0x26, 0x6e, 80 1.1 mycroft 0x36, 0x36, 0x36, 0x3e, 0x2e, 0x3e, 0x6e, 0xae, 81 1.1 mycroft 0x4e, 0x5e, 0x5e, 0x6e, 0x5e, 0x5e, 0x6e, 0x4e, 82 1.1 mycroft 0x5e, 0x5e, 0x5e, 0x7e, 0x6e, 0x7e, 0x4e, 0xce, 83 1.1 mycroft 0x16, 0x16, 0x16, 0x3e, 0x16, 0x16, 0x36, 0x5e, 84 1.1 mycroft 0x16, 0x16, 0x16, 0x3e, 0x3e, 0x3e, 0x5e, 0x9e, 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 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x7e, 90 1.1 mycroft 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x7e, 0xbe, 91 1.1 mycroft 0x2a, 0x3e, 0x3e, 0x2a, 0x3e, 0x3e, 0x2e, 0x6e, 92 1.1 mycroft 0x3e, 0x3e, 0x3e, 0x3e, 0x2a, 0x3e, 0x6e, 0xaa, 93 1.1 mycroft 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x7e, 94 1.1 mycroft 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x3e, 0x7e, 0xbe, 95 1.1 mycroft 0x4e, 0x5e, 0x5e, 0x6e, 0x5e, 0x5e, 0x6e, 0x4e, 96 1.1 mycroft 0x5e, 0x5e, 0x5e, 0x7e, 0x6e, 0x7e, 0x4e, 0xce, 97 1.1 mycroft 0x8a, 0x9e, 0x9e, 0xaa, 0x9e, 0x9e, 0xae, 0xce, 98 1.1 mycroft 0x9e, 0x9e, 0x9e, 0xbe, 0xaa, 0xbe, 0xce, 0x8a, 99 1.1 mycroft }; 100 1.1 mycroft 101 1.3 jdolecek const u_char fragtbl8[256] = { 102 1.1 mycroft 0x00, 0x01, 0x01, 0x02, 0x01, 0x01, 0x02, 0x04, 103 1.1 mycroft 0x01, 0x01, 0x01, 0x03, 0x02, 0x03, 0x04, 0x08, 104 1.1 mycroft 0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05, 105 1.1 mycroft 0x02, 0x03, 0x03, 0x02, 0x04, 0x05, 0x08, 0x10, 106 1.1 mycroft 0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05, 107 1.1 mycroft 0x01, 0x01, 0x01, 0x03, 0x03, 0x03, 0x05, 0x09, 108 1.1 mycroft 0x02, 0x03, 0x03, 0x02, 0x03, 0x03, 0x02, 0x06, 109 1.1 mycroft 0x04, 0x05, 0x05, 0x06, 0x08, 0x09, 0x10, 0x20, 110 1.1 mycroft 0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05, 111 1.1 mycroft 0x01, 0x01, 0x01, 0x03, 0x03, 0x03, 0x05, 0x09, 112 1.1 mycroft 0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05, 113 1.1 mycroft 0x03, 0x03, 0x03, 0x03, 0x05, 0x05, 0x09, 0x11, 114 1.1 mycroft 0x02, 0x03, 0x03, 0x02, 0x03, 0x03, 0x02, 0x06, 115 1.1 mycroft 0x03, 0x03, 0x03, 0x03, 0x02, 0x03, 0x06, 0x0a, 116 1.1 mycroft 0x04, 0x05, 0x05, 0x06, 0x05, 0x05, 0x06, 0x04, 117 1.1 mycroft 0x08, 0x09, 0x09, 0x0a, 0x10, 0x11, 0x20, 0x40, 118 1.1 mycroft 0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05, 119 1.1 mycroft 0x01, 0x01, 0x01, 0x03, 0x03, 0x03, 0x05, 0x09, 120 1.1 mycroft 0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05, 121 1.1 mycroft 0x03, 0x03, 0x03, 0x03, 0x05, 0x05, 0x09, 0x11, 122 1.1 mycroft 0x01, 0x01, 0x01, 0x03, 0x01, 0x01, 0x03, 0x05, 123 1.1 mycroft 0x01, 0x01, 0x01, 0x03, 0x03, 0x03, 0x05, 0x09, 124 1.1 mycroft 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x07, 125 1.1 mycroft 0x05, 0x05, 0x05, 0x07, 0x09, 0x09, 0x11, 0x21, 126 1.1 mycroft 0x02, 0x03, 0x03, 0x02, 0x03, 0x03, 0x02, 0x06, 127 1.1 mycroft 0x03, 0x03, 0x03, 0x03, 0x02, 0x03, 0x06, 0x0a, 128 1.1 mycroft 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x07, 129 1.1 mycroft 0x02, 0x03, 0x03, 0x02, 0x06, 0x07, 0x0a, 0x12, 130 1.1 mycroft 0x04, 0x05, 0x05, 0x06, 0x05, 0x05, 0x06, 0x04, 131 1.1 mycroft 0x05, 0x05, 0x05, 0x07, 0x06, 0x07, 0x04, 0x0c, 132 1.1 mycroft 0x08, 0x09, 0x09, 0x0a, 0x09, 0x09, 0x0a, 0x0c, 133 1.1 mycroft 0x10, 0x11, 0x11, 0x12, 0x20, 0x21, 0x40, 0x80, 134 1.1 mycroft }; 135 1.1 mycroft 136 1.1 mycroft /* 137 1.1 mycroft * The actual fragtbl array. 138 1.1 mycroft */ 139 1.3 jdolecek const u_char * const fragtbl[MAXFRAG + 1] = { 140 1.1 mycroft 0, fragtbl124, fragtbl124, 0, fragtbl124, 0, 0, 0, fragtbl8, 141 1.1 mycroft }; 142