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

Commitd12aa57

Browse files
committed
fusefronted_reverse: fix ino collision between .name and .diriv files
A directory with a long name has two associated virtual files:the .name file and the .diriv files.These used to get the same inode number: $ ls -di1 * */* 33313535 gocryptfs.longname.2togDFouca9mrTwtfF1RNW5DZRAQY8alaR7wO_Xd5Zw 1000000000033313535 gocryptfs.longname.2togDFouca9mrTwtfF1RNW5DZRAQY8alaR7wO_Xd5Zw/gocryptfs.diriv 1000000000033313535 gocryptfs.longname.2togDFouca9mrTwtfF1RNW5DZRAQY8alaR7wO_Xd5Zw.nameWith this change we use another prefix (2 instead of 1) for .name files. $ ls -di1 * */* 33313535 gocryptfs.longname.2togDFouca9mrTwtfF1RNW5DZRAQY8alaR7wO_Xd5Zw 1000000000033313535 gocryptfs.longname.2togDFouca9mrTwtfF1RNW5DZRAQY8alaR7wO_Xd5Zw/gocryptfs.diriv 2000000000033313535 gocryptfs.longname.2togDFouca9mrTwtfF1RNW5DZRAQY8alaR7wO_Xd5Zw.name
1 parentd5133ca commitd12aa57

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

‎internal/fusefrontend_reverse/reverse_longnames.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,5 @@ func (rfs *ReverseFS) newNameFile(relPath string) (nodefs.File, fuse.Status) {
100100
}
101101
content:= []byte(rfs.nameTransform.EncryptName(pName,dirIV))
102102
parentFile:=filepath.Join(rfs.args.Cipherdir,pDir,pName)
103-
returnrfs.newVirtualFile(content,parentFile)
103+
returnrfs.newVirtualFile(content,parentFile,inoBaseNameFile)
104104
}

‎internal/fusefrontend_reverse/rfs.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ func (rfs *ReverseFS) GetAttr(relPath string, context *fuse.Context) (*fuse.Attr
162162
returnnil,fuse.ToStatus(err)
163163
}
164164
// Instead of risking an inode number collision, we return an error.
165-
ifst.Ino>virtualInoBase {
165+
ifst.Ino>inoBaseMin {
166166
tlog.Warn.Printf("GetAttr %q: backing file inode number %d crosses reserved space, max=%d. Returning EOVERFLOW.",
167-
relPath,st.Ino,virtualInoBase)
167+
relPath,st.Ino,inoBaseMin)
168168
returnnil,fuse.ToStatus(syscall.EOVERFLOW)
169169
}
170170
vara fuse.Attr

‎internal/fusefrontend_reverse/virtualfile.go‎

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package fusefrontend_reverse
22

33
import (
4+
"log"
45
"syscall"
56

67
"github.com/hanwen/go-fuse/fuse"
@@ -14,12 +15,19 @@ const (
1415
// virtualFileMode is the mode to use for virtual files (gocryptfs.diriv and
1516
// *.name). They are always readable, as stated in func Access
1617
virtualFileMode=syscall.S_IFREG|0444
17-
// virtualInoBase is the start of the inode number range that is used
18-
// for virtual files.
18+
// inoBaseDirIV is the start of the inode number range that is used
19+
// for virtual gocryptfs.diriv files. inoBaseNameFile is the thing for
20+
// *.name files.
1921
// The value 10^19 is just below 2^60. A power of 10 has been chosen so the
2022
// "ls -li" output (which is base-10) is easy to read.
21-
// 10^19 is the largest power of 10 that is smaller than UINT64_MAX/2.
22-
virtualInoBase=uint64(1000000000000000000)
23+
// 10^19 is the largest power of 10 that is smaller than
24+
// INT64_MAX (=UINT64_MAX/2). This avoids signedness issues.
25+
inoBaseDirIV=uint64(1000000000000000000)
26+
inoBaseNameFile=uint64(2000000000000000000)
27+
// inoBaseMin marks the start of the inode number space that is
28+
// reserved for virtual files. It is the lowest of the inoBaseXXX values
29+
// above.
30+
inoBaseMin=inoBaseDirIV
2331
)
2432

2533
func (rfs*ReverseFS)newDirIVFile(cRelPathstring) (nodefs.File, fuse.Status) {
@@ -28,7 +36,7 @@ func (rfs *ReverseFS) newDirIVFile(cRelPath string) (nodefs.File, fuse.Status) {
2836
iferr!=nil {
2937
returnnil,fuse.ToStatus(err)
3038
}
31-
returnrfs.newVirtualFile(pathiv.Derive(cDir,pathiv.PurposeDirIV),absDir)
39+
returnrfs.newVirtualFile(pathiv.Derive(cDir,pathiv.PurposeDirIV),absDir,inoBaseDirIV)
3240
}
3341

3442
typevirtualFilestruct {
@@ -38,17 +46,23 @@ type virtualFile struct {
3846
content []byte
3947
// absolute path to a parent file
4048
parentFilestring
49+
// inode number of a virtual file is inode of parent file plus inoBase
50+
inoBaseuint64
4151
}
4252

4353
// newVirtualFile creates a new in-memory file that does not have a representation
4454
// on disk. "content" is the file content. Timestamps and file owner are copied
4555
// from "parentFile" (absolute plaintext path). For a "gocryptfs.diriv" file, you
4656
// would use the parent directory as "parentFile".
47-
func (rfs*ReverseFS)newVirtualFile(content []byte,parentFilestring) (nodefs.File, fuse.Status) {
57+
func (rfs*ReverseFS)newVirtualFile(content []byte,parentFilestring,inoBaseuint64) (nodefs.File, fuse.Status) {
58+
ifinoBase<inoBaseMin {
59+
log.Panicf("BUG: virtual inode number base %d is below reserved space",inoBase)
60+
}
4861
return&virtualFile{
4962
File:nodefs.NewDefaultFile(),
5063
content:content,
5164
parentFile:parentFile,
65+
inoBase:inoBase,
5266
},fuse.OK
5367
}
5468

@@ -72,12 +86,12 @@ func (f *virtualFile) GetAttr(a *fuse.Attr) fuse.Status {
7286
tlog.Debug.Printf("GetAttr: Lstat %q: %v\n",f.parentFile,err)
7387
returnfuse.ToStatus(err)
7488
}
75-
ifst.Ino>virtualInoBase {
89+
ifst.Ino>inoBaseMin {
7690
tlog.Warn.Printf("virtualFile.GetAttr: parent file inode number %d crosses reserved space, max=%d. Returning EOVERFLOW.",
77-
st.Ino,virtualInoBase)
91+
st.Ino,inoBaseMin)
7892
returnfuse.ToStatus(syscall.EOVERFLOW)
7993
}
80-
st.Ino=st.Ino+virtualInoBase
94+
st.Ino=st.Ino+f.inoBase
8195
st.Size=int64(len(f.content))
8296
st.Mode=virtualFileMode
8397
st.Nlink=1

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp