Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Jorgen Lundman | 9b4a1f9 | 2012-07-19 20:48:25 +0000 | [diff] [blame] | 2 | /* |
| 3 | * GRUB -- GRand Unified Bootloader |
| 4 | * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc. |
Jorgen Lundman | 9b4a1f9 | 2012-07-19 20:48:25 +0000 | [diff] [blame] | 5 | */ |
| 6 | /* |
| 7 | * Copyright 2007 Sun Microsystems, Inc. All rights reserved. |
| 8 | * Use is subject to license terms. |
| 9 | */ |
| 10 | |
Jorgen Lundman | 9b4a1f9 | 2012-07-19 20:48:25 +0000 | [diff] [blame] | 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 | |
| 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 | |
| 32 | void |
| 33 | fletcher_2_endian(const void *buf, uint64_t size, |
| 34 | zfs_endian_t endian, |
| 35 | zio_cksum_t *zcp) |
| 36 | { |
| 37 | const uint64_t *ip = buf; |
| 38 | const uint64_t *ipend = ip + (size / sizeof(uint64_t)); |
| 39 | uint64_t a0, b0, a1, b1; |
| 40 | |
| 41 | for (a0 = b0 = a1 = b1 = 0; ip < ipend; ip += 2) { |
| 42 | a0 += zfs_to_cpu64(ip[0], endian); |
| 43 | a1 += zfs_to_cpu64(ip[1], endian); |
| 44 | b0 += a0; |
| 45 | b1 += a1; |
| 46 | } |
| 47 | |
| 48 | zcp->zc_word[0] = cpu_to_zfs64(a0, endian); |
| 49 | zcp->zc_word[1] = cpu_to_zfs64(a1, endian); |
| 50 | zcp->zc_word[2] = cpu_to_zfs64(b0, endian); |
| 51 | zcp->zc_word[3] = cpu_to_zfs64(b1, endian); |
| 52 | } |
| 53 | |
| 54 | void |
| 55 | fletcher_4_endian(const void *buf, uint64_t size, zfs_endian_t endian, |
| 56 | zio_cksum_t *zcp) |
| 57 | { |
| 58 | const uint32_t *ip = buf; |
| 59 | const uint32_t *ipend = ip + (size / sizeof(uint32_t)); |
| 60 | uint64_t a, b, c, d; |
| 61 | |
| 62 | for (a = b = c = d = 0; ip < ipend; ip++) { |
| 63 | a += zfs_to_cpu32(ip[0], endian); |
| 64 | b += a; |
| 65 | c += b; |
| 66 | d += c; |
| 67 | } |
| 68 | |
| 69 | zcp->zc_word[0] = cpu_to_zfs64(a, endian); |
| 70 | zcp->zc_word[1] = cpu_to_zfs64(b, endian); |
| 71 | zcp->zc_word[2] = cpu_to_zfs64(c, endian); |
| 72 | zcp->zc_word[3] = cpu_to_zfs64(d, endian); |
| 73 | } |