]> git.ipfire.org Git - people/ms/u-boot.git/blame - fs/zfs/zfs_fletcher.c
zfs: Add ZFS filesystem support
[people/ms/u-boot.git] / fs / zfs / zfs_fletcher.c
CommitLineData
4d3c95f5
JL
1/*
2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19/*
20 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
21 * Use is subject to license terms.
22 */
23
24#include <common.h>
25#include <malloc.h>
26#include <linux/stat.h>
27#include <linux/time.h>
28#include <linux/ctype.h>
29#include <asm/byteorder.h>
30#include "zfs_common.h"
31
32#include <zfs/zfs.h>
33#include <zfs/zio.h>
34#include <zfs/dnode.h>
35#include <zfs/uberblock_impl.h>
36#include <zfs/vdev_impl.h>
37#include <zfs/zio_checksum.h>
38#include <zfs/zap_impl.h>
39#include <zfs/zap_leaf.h>
40#include <zfs/zfs_znode.h>
41#include <zfs/dmu.h>
42#include <zfs/dmu_objset.h>
43#include <zfs/dsl_dir.h>
44#include <zfs/dsl_dataset.h>
45
46void
47fletcher_2_endian(const void *buf, uint64_t size,
48 zfs_endian_t endian,
49 zio_cksum_t *zcp)
50{
51 const uint64_t *ip = buf;
52 const uint64_t *ipend = ip + (size / sizeof(uint64_t));
53 uint64_t a0, b0, a1, b1;
54
55 for (a0 = b0 = a1 = b1 = 0; ip < ipend; ip += 2) {
56 a0 += zfs_to_cpu64(ip[0], endian);
57 a1 += zfs_to_cpu64(ip[1], endian);
58 b0 += a0;
59 b1 += a1;
60 }
61
62 zcp->zc_word[0] = cpu_to_zfs64(a0, endian);
63 zcp->zc_word[1] = cpu_to_zfs64(a1, endian);
64 zcp->zc_word[2] = cpu_to_zfs64(b0, endian);
65 zcp->zc_word[3] = cpu_to_zfs64(b1, endian);
66}
67
68void
69fletcher_4_endian(const void *buf, uint64_t size, zfs_endian_t endian,
70 zio_cksum_t *zcp)
71{
72 const uint32_t *ip = buf;
73 const uint32_t *ipend = ip + (size / sizeof(uint32_t));
74 uint64_t a, b, c, d;
75
76 for (a = b = c = d = 0; ip < ipend; ip++) {
77 a += zfs_to_cpu32(ip[0], endian);
78 b += a;
79 c += b;
80 d += c;
81 }
82
83 zcp->zc_word[0] = cpu_to_zfs64(a, endian);
84 zcp->zc_word[1] = cpu_to_zfs64(b, endian);
85 zcp->zc_word[2] = cpu_to_zfs64(c, endian);
86 zcp->zc_word[3] = cpu_to_zfs64(d, endian);
87}