]>
git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blob - fs/btrfs/hash.c
2 * Copyright (C) 2007 Oracle. All rights reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 * Boston, MA 021110-1307, USA.
21 * linux/fs/ext3/hash.c
23 * Copyright (C) 2002 by Theodore Ts'o
25 * This file is released under the GPL v2.
27 * This file may be redistributed under the terms of the GNU Public
31 #include <linux/types.h>
33 #define DELTA 0x9E3779B9
35 static void TEA_transform(__u32 buf
[2], __u32
const in
[])
38 __u32 b0
= buf
[0], b1
= buf
[1];
39 __u32 a
= in
[0], b
= in
[1], c
= in
[2], d
= in
[3];
44 b0
+= ((b1
<< 4)+a
) ^ (b1
+sum
) ^ ((b1
>> 5)+b
);
45 b1
+= ((b0
<< 4)+c
) ^ (b0
+sum
) ^ ((b0
>> 5)+d
);
52 static void str2hashbuf(const char *msg
, int len
, __u32
*buf
, int num
)
57 pad
= (__u32
)len
| ((__u32
)len
<< 8);
63 for (i
=0; i
< len
; i
++) {
66 val
= msg
[i
] + (val
<< 8);
79 int btrfs_name_hash(const char *name
, int len
, u64
*hash_result
)
86 if (len
== 1 && *name
== '.') {
89 } else if (len
== 2 && name
[0] == '.' && name
[1] == '.') {
94 /* Initialize the default seed for the hash checksum functions */
102 str2hashbuf(p
, len
, in
, 4);
103 TEA_transform(buf
, in
);
109 *hash_result
= buf
[0];
111 *hash_result
|= buf
[1];