Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9ecf2d1

Browse files
committed
fusefrontend_reverse: store derived values for hard-linked files
With hard links, the path to a file is not unique. This meansthat the ciphertext data depends on the path that is used to accessthe files.Fix that by storing the derived values when we encounter a hard-linkedfile. This means that the first path wins.
1 parentbfc8d47 commit9ecf2d1

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

‎internal/fusefrontend_reverse/rfile.go‎

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import (
55
"encoding/binary"
66
"io"
77
"os"
8+
"syscall"
9+
10+
// In newer Go versions, this has moved to just "sync/syncmap".
11+
"golang.org/x/sync/syncmap"
812

913
"github.com/hanwen/go-fuse/fuse"
1014
"github.com/hanwen/go-fuse/fuse/nodefs"
@@ -26,6 +30,13 @@ type reverseFile struct {
2630
contentEnc*contentenc.ContentEnc
2731
}
2832

33+
varinodeTable syncmap.Map
34+
35+
typederivedIVContainerstruct {
36+
id []byte
37+
block0IV []byte
38+
}
39+
2940
func (rfs*ReverseFS)newFile(relPathstring,flagsuint32) (nodefs.File, fuse.Status) {
3041
absPath,err:=rfs.abs(rfs.decryptPath(relPath))
3142
iferr!=nil {
@@ -35,16 +46,45 @@ func (rfs *ReverseFS) newFile(relPath string, flags uint32) (nodefs.File, fuse.S
3546
iferr!=nil {
3647
returnnil,fuse.ToStatus(err)
3748
}
38-
id:=derivePathIV(relPath,ivPurposeFileID)
49+
varst syscall.Stat_t
50+
err=syscall.Fstat(int(fd.Fd()),&st)
51+
iferr!=nil {
52+
tlog.Warn.Printf("newFile: Fstat error: %v",err)
53+
returnnil,fuse.ToStatus(err)
54+
}
55+
// See if we have that inode number already in the table
56+
// (even if Nlink has dropped to 1)
57+
varderivedIVsderivedIVContainer
58+
v,found:=inodeTable.Load(st.Ino)
59+
iffound {
60+
tlog.Debug.Printf("ino%d: newFile: found in the inode table",st.Ino)
61+
derivedIVs=v.(derivedIVContainer)
62+
}else {
63+
derivedIVs.id=derivePathIV(relPath,ivPurposeFileID)
64+
derivedIVs.block0IV=derivePathIV(relPath,ivPurposeBlock0IV)
65+
// Nlink > 1 means there is more than one path to this file.
66+
// Store the derived values so we always return the same data,
67+
// regardless of the path that is used to access the file.
68+
// This means that the first path wins.
69+
ifst.Nlink>1 {
70+
v,found=inodeTable.LoadOrStore(st.Ino,derivedIVs)
71+
iffound {
72+
// Another thread has stored a different value before we could.
73+
derivedIVs=v.(derivedIVContainer)
74+
}else {
75+
tlog.Debug.Printf("ino%d: newFile: Nlink=%d, stored in the inode table",st.Ino,st.Nlink)
76+
}
77+
}
78+
}
3979
header:= contentenc.FileHeader{
4080
Version:contentenc.CurrentVersion,
41-
ID:id,
81+
ID:derivedIVs.id,
4282
}
4383
return&reverseFile{
4484
File:nodefs.NewDefaultFile(),
4585
fd:fd,
4686
header:header,
47-
block0IV:derivePathIV(relPath,ivPurposeBlock0IV),
87+
block0IV:derivedIVs.block0IV,
4888
contentEnc:rfs.contentEnc,
4989
},fuse.OK
5090
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp