zfs_fletcher.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 1999,2000,2001,2002,2003,2004,2009 Free Software Foundation, Inc.
  4. * Copyright 2007 Sun Microsystems, Inc.
  5. *
  6. * GRUB is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * GRUB is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <grub/err.h>
  20. #include <grub/file.h>
  21. #include <grub/mm.h>
  22. #include <grub/misc.h>
  23. #include <grub/disk.h>
  24. #include <grub/dl.h>
  25. #include <grub/types.h>
  26. #include <grub/zfs/zfs.h>
  27. #include <grub/zfs/zio.h>
  28. #include <grub/zfs/dnode.h>
  29. #include <grub/zfs/uberblock_impl.h>
  30. #include <grub/zfs/vdev_impl.h>
  31. #include <grub/zfs/zio_checksum.h>
  32. #include <grub/zfs/zap_impl.h>
  33. #include <grub/zfs/zap_leaf.h>
  34. #include <grub/zfs/zfs_znode.h>
  35. #include <grub/zfs/dmu.h>
  36. #include <grub/zfs/dmu_objset.h>
  37. #include <grub/zfs/dsl_dir.h>
  38. #include <grub/zfs/dsl_dataset.h>
  39. void
  40. fletcher_2(const void *buf, grub_uint64_t size, grub_zfs_endian_t endian,
  41. zio_cksum_t *zcp)
  42. {
  43. const grub_uint64_t *ip = buf;
  44. const grub_uint64_t *ipend = ip + (size / sizeof (grub_uint64_t));
  45. grub_uint64_t a0, b0, a1, b1;
  46. for (a0 = b0 = a1 = b1 = 0; ip < ipend; ip += 2)
  47. {
  48. a0 += grub_zfs_to_cpu64 (ip[0], endian);
  49. a1 += grub_zfs_to_cpu64 (ip[1], endian);
  50. b0 += a0;
  51. b1 += a1;
  52. }
  53. zcp->zc_word[0] = grub_cpu_to_zfs64 (a0, endian);
  54. zcp->zc_word[1] = grub_cpu_to_zfs64 (a1, endian);
  55. zcp->zc_word[2] = grub_cpu_to_zfs64 (b0, endian);
  56. zcp->zc_word[3] = grub_cpu_to_zfs64 (b1, endian);
  57. }
  58. void
  59. fletcher_4 (const void *buf, grub_uint64_t size, grub_zfs_endian_t endian,
  60. zio_cksum_t *zcp)
  61. {
  62. const grub_uint32_t *ip = buf;
  63. const grub_uint32_t *ipend = ip + (size / sizeof (grub_uint32_t));
  64. grub_uint64_t a, b, c, d;
  65. for (a = b = c = d = 0; ip < ipend; ip++)
  66. {
  67. a += grub_zfs_to_cpu32 (ip[0], endian);;
  68. b += a;
  69. c += b;
  70. d += c;
  71. }
  72. zcp->zc_word[0] = grub_cpu_to_zfs64 (a, endian);
  73. zcp->zc_word[1] = grub_cpu_to_zfs64 (b, endian);
  74. zcp->zc_word[2] = grub_cpu_to_zfs64 (c, endian);
  75. zcp->zc_word[3] = grub_cpu_to_zfs64 (d, endian);
  76. }