zfs_fletcher.c 1.8 KB

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