zfs_fletcher.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. /*
  8. * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
  9. * Use is subject to license terms.
  10. */
  11. #include <common.h>
  12. #include <malloc.h>
  13. #include <linux/stat.h>
  14. #include <linux/time.h>
  15. #include <linux/ctype.h>
  16. #include <asm/byteorder.h>
  17. #include "zfs_common.h"
  18. #include <zfs/zfs.h>
  19. #include <zfs/zio.h>
  20. #include <zfs/dnode.h>
  21. #include <zfs/uberblock_impl.h>
  22. #include <zfs/vdev_impl.h>
  23. #include <zfs/zio_checksum.h>
  24. #include <zfs/zap_impl.h>
  25. #include <zfs/zap_leaf.h>
  26. #include <zfs/zfs_znode.h>
  27. #include <zfs/dmu.h>
  28. #include <zfs/dmu_objset.h>
  29. #include <zfs/dsl_dir.h>
  30. #include <zfs/dsl_dataset.h>
  31. void
  32. fletcher_2_endian(const void *buf, uint64_t size,
  33. zfs_endian_t endian,
  34. zio_cksum_t *zcp)
  35. {
  36. const uint64_t *ip = buf;
  37. const uint64_t *ipend = ip + (size / sizeof(uint64_t));
  38. uint64_t a0, b0, a1, b1;
  39. for (a0 = b0 = a1 = b1 = 0; ip < ipend; ip += 2) {
  40. a0 += zfs_to_cpu64(ip[0], endian);
  41. a1 += zfs_to_cpu64(ip[1], endian);
  42. b0 += a0;
  43. b1 += a1;
  44. }
  45. zcp->zc_word[0] = cpu_to_zfs64(a0, endian);
  46. zcp->zc_word[1] = cpu_to_zfs64(a1, endian);
  47. zcp->zc_word[2] = cpu_to_zfs64(b0, endian);
  48. zcp->zc_word[3] = cpu_to_zfs64(b1, endian);
  49. }
  50. void
  51. fletcher_4_endian(const void *buf, uint64_t size, zfs_endian_t endian,
  52. zio_cksum_t *zcp)
  53. {
  54. const uint32_t *ip = buf;
  55. const uint32_t *ipend = ip + (size / sizeof(uint32_t));
  56. uint64_t a, b, c, d;
  57. for (a = b = c = d = 0; ip < ipend; ip++) {
  58. a += zfs_to_cpu32(ip[0], endian);
  59. b += a;
  60. c += b;
  61. d += c;
  62. }
  63. zcp->zc_word[0] = cpu_to_zfs64(a, endian);
  64. zcp->zc_word[1] = cpu_to_zfs64(b, endian);
  65. zcp->zc_word[2] = cpu_to_zfs64(c, endian);
  66. zcp->zc_word[3] = cpu_to_zfs64(d, endian);
  67. }