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