fuse: Mix inode hashes in a non-symmetric way
Since 0.15 (#4020), inodes are generated as hashes of names, xor'd with the parent inode. That means that the inode of a/b/b is h(a/b/b) = h(a) ^ h(b) ^ h(b) = h(a). I.e., the grandchild has the same inode as the grandparent. GNU find trips over this because it thinks it has encountered a loop in the filesystem, and fails to search a/b/b. This happens more generally when the same name occurs an even number of times. Fix this by multiplying the parent by a large prime, so the combining operation is not longer symmetric in its arguments. This is what the FNV hash does, which we used prior to 0.15. The hash is now h(a/b/b) = h(b) ^ p*(h(b) ^ p*h(a)) Note that we already ensure that h(x) is never zero. Collisions can still occur, but they should be much less likely to occur within a single path. Fixes #4253.
This commit is contained in:
parent
f646406822
commit
a0885d5d69
3 changed files with 33 additions and 2 deletions
|
@ -226,6 +226,17 @@ func TestInodeFromNode(t *testing.T) {
|
|||
ino1 = inodeFromNode(1, node)
|
||||
ino2 = inodeFromNode(2, node)
|
||||
rtest.Assert(t, ino1 != ino2, "same inode %d but different parent", ino1)
|
||||
|
||||
// Regression test: in a path a/b/b, the grandchild should not get the
|
||||
// same inode as the grandparent.
|
||||
a := &restic.Node{Name: "a", Type: "dir", Links: 2}
|
||||
ab := &restic.Node{Name: "b", Type: "dir", Links: 2}
|
||||
abb := &restic.Node{Name: "b", Type: "dir", Links: 2}
|
||||
inoA := inodeFromNode(1, a)
|
||||
inoAb := inodeFromNode(inoA, ab)
|
||||
inoAbb := inodeFromNode(inoAb, abb)
|
||||
rtest.Assert(t, inoA != inoAb, "inode(a/b) = inode(a)")
|
||||
rtest.Assert(t, inoA != inoAbb, "inode(a/b/b) = inode(a)")
|
||||
}
|
||||
|
||||
var sink uint64
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue