zfs_fletcher.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19. /*
  20. * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
  21. * Use is subject to license terms.
  22. */
  23. #include <common.h>
  24. #include <malloc.h>
  25. #include <linux/stat.h>
  26. #include <linux/time.h>
  27. #include <linux/ctype.h>
  28. #include <asm/byteorder.h>
  29. #include "zfs_common.h"
  30. #include <zfs/zfs.h>
  31. #include <zfs/zio.h>
  32. #include <zfs/dnode.h>
  33. #include <zfs/uberblock_impl.h>
  34. #include <zfs/vdev_impl.h>
  35. #include <zfs/zio_checksum.h>
  36. #include <zfs/zap_impl.h>
  37. #include <zfs/zap_leaf.h>
  38. #include <zfs/zfs_znode.h>
  39. #include <zfs/dmu.h>
  40. #include <zfs/dmu_objset.h>
  41. #include <zfs/dsl_dir.h>
  42. #include <zfs/dsl_dataset.h>
  43. void
  44. fletcher_2_endian(const void *buf, uint64_t size,
  45. zfs_endian_t endian,
  46. zio_cksum_t *zcp)
  47. {
  48. const uint64_t *ip = buf;
  49. const uint64_t *ipend = ip + (size / sizeof(uint64_t));
  50. uint64_t a0, b0, a1, b1;
  51. for (a0 = b0 = a1 = b1 = 0; ip < ipend; ip += 2) {
  52. a0 += zfs_to_cpu64(ip[0], endian);
  53. a1 += zfs_to_cpu64(ip[1], endian);
  54. b0 += a0;
  55. b1 += a1;
  56. }
  57. zcp->zc_word[0] = cpu_to_zfs64(a0, endian);
  58. zcp->zc_word[1] = cpu_to_zfs64(a1, endian);
  59. zcp->zc_word[2] = cpu_to_zfs64(b0, endian);
  60. zcp->zc_word[3] = cpu_to_zfs64(b1, endian);
  61. }
  62. void
  63. fletcher_4_endian(const void *buf, uint64_t size, zfs_endian_t endian,
  64. zio_cksum_t *zcp)
  65. {
  66. const uint32_t *ip = buf;
  67. const uint32_t *ipend = ip + (size / sizeof(uint32_t));
  68. uint64_t a, b, c, d;
  69. for (a = b = c = d = 0; ip < ipend; ip++) {
  70. a += zfs_to_cpu32(ip[0], endian);
  71. b += a;
  72. c += b;
  73. d += c;
  74. }
  75. zcp->zc_word[0] = cpu_to_zfs64(a, endian);
  76. zcp->zc_word[1] = cpu_to_zfs64(b, endian);
  77. zcp->zc_word[2] = cpu_to_zfs64(c, endian);
  78. zcp->zc_word[3] = cpu_to_zfs64(d, endian);
  79. }