removed accidental commit
[grub2/phcoder.git] / fs / zfs_fletcher.c
blob2bca3bf0010488e3ea582f4789ec397edf45d581
1 /*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
4 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
5 * Copyright (C) 2009 Free Software Foundation, Inc.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <grub/err.h>
23 #include <grub/file.h>
24 #include <grub/mm.h>
25 #include <grub/misc.h>
26 #include <grub/disk.h>
27 #include <grub/dl.h>
28 #include <grub/types.h>
29 #include <grub/zfs/zfs.h>
30 #include <grub/zfs/zio.h>
31 #include <grub/zfs/dnode.h>
32 #include <grub/zfs/uberblock_impl.h>
33 #include <grub/zfs/vdev_impl.h>
34 #include <grub/zfs/zio_checksum.h>
35 #include <grub/zfs/zap_impl.h>
36 #include <grub/zfs/zap_leaf.h>
37 #include <grub/zfs/zfs_znode.h>
38 #include <grub/zfs/dmu.h>
39 #include <grub/zfs/dmu_objset.h>
40 #include <grub/zfs/dsl_dir.h>
41 #include <grub/zfs/dsl_dataset.h>
43 void
44 fletcher_2(const void *buf, grub_uint64_t size, grub_zfs_endian_t endian,
45 zio_cksum_t *zcp)
47 const grub_uint64_t *ip = buf;
48 const grub_uint64_t *ipend = ip + (size / sizeof (grub_uint64_t));
49 grub_uint64_t a0, b0, a1, b1;
51 for (a0 = b0 = a1 = b1 = 0; ip < ipend; ip += 2)
53 a0 += grub_zfs_to_cpu64 (ip[0], endian);
54 a1 += grub_zfs_to_cpu64 (ip[1], endian);
55 b0 += a0;
56 b1 += a1;
59 zcp->zc_word[0] = grub_cpu_to_zfs64 (a0, endian);
60 zcp->zc_word[1] = grub_cpu_to_zfs64 (a1, endian);
61 zcp->zc_word[2] = grub_cpu_to_zfs64 (b0, endian);
62 zcp->zc_word[3] = grub_cpu_to_zfs64 (b1, endian);
65 void
66 fletcher_4 (const void *buf, grub_uint64_t size, grub_zfs_endian_t endian,
67 zio_cksum_t *zcp)
69 const grub_uint32_t *ip = buf;
70 const grub_uint32_t *ipend = ip + (size / sizeof (grub_uint32_t));
71 grub_uint64_t a, b, c, d;
73 for (a = b = c = d = 0; ip < ipend; ip++)
75 a += grub_zfs_to_cpu32 (ip[0], endian);;
76 b += a;
77 c += b;
78 d += c;
81 zcp->zc_word[0] = grub_cpu_to_zfs64 (a, endian);
82 zcp->zc_word[1] = grub_cpu_to_zfs64 (b, endian);
83 zcp->zc_word[2] = grub_cpu_to_zfs64 (c, endian);
84 zcp->zc_word[3] = grub_cpu_to_zfs64 (d, endian);