ffs_tables.c 5.6 KB

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