aboutsummaryrefslogtreecommitdiff
path: root/internal/fusefrontend_reverse/virtualfile.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2017-04-01 17:19:15 +0200
committerJakob Unterwurzacher2017-04-01 17:19:15 +0200
commit778c955eea1fdc16666f51f6f0a2fab0f580dbf0 (patch)
treef956c11bbc8a055dc9b72a842487bbb6ed4cbbc3 /internal/fusefrontend_reverse/virtualfile.go
parente87aebb835b91ba66f288030ee3510df42b860a9 (diff)
fusefrontend_reverse: switch to stable inode numbers
The volatile inode numbers that we used before cause "find" to complain and error out. Virtual inode numbers are derived from their parent file inode number by adding 10^19, which is hopefully large enough no never cause problems in practice. If the backing directory contains inode numbers higher than that, stat() on these files will return EOVERFLOW. Example directory lising after this change: $ ls -i 926473 gocryptfs.conf 1000000000000926466 gocryptfs.diriv 944878 gocryptfs.longname.hmZojMqC6ns47eyVxLlH2ailKjN9bxfosi3C-FR8mjA 1000000000000944878 gocryptfs.longname.hmZojMqC6ns47eyVxLlH2ailKjN9bxfosi3C-FR8mjA.name 934408 Tdfbf02CKsTaGVYnAsSypA
Diffstat (limited to 'internal/fusefrontend_reverse/virtualfile.go')
-rw-r--r--internal/fusefrontend_reverse/virtualfile.go22
1 files changed, 18 insertions, 4 deletions
diff --git a/internal/fusefrontend_reverse/virtualfile.go b/internal/fusefrontend_reverse/virtualfile.go
index 2bd9e88..00fa726 100644
--- a/internal/fusefrontend_reverse/virtualfile.go
+++ b/internal/fusefrontend_reverse/virtualfile.go
@@ -9,6 +9,18 @@ import (
"github.com/rfjakob/gocryptfs/internal/tlog"
)
+const (
+ // virtualFileMode is the mode to use for virtual files (gocryptfs.diriv and
+ // *.name). They are always readable, as stated in func Access
+ virtualFileMode = syscall.S_IFREG | 0444
+ // virtualInoBase is the start of the inode number range that is used
+ // for virtual files.
+ // The value 10^19 is just below 2^60. A power of 10 has been chosen so the
+ // "ls -li" output (which is base-10) is easy to read.
+ // 10^19 is the largest power of 10 that is smaller than UINT64_MAX/2.
+ virtualInoBase = uint64(1000000000000000000)
+)
+
func (rfs *ReverseFS) newDirIVFile(cRelPath string) (nodefs.File, fuse.Status) {
cDir := saneDir(cRelPath)
absDir, err := rfs.abs(rfs.decryptPath(cDir))
@@ -25,8 +37,6 @@ type virtualFile struct {
content []byte
// absolute path to a parent file
parentFile string
- // inode number
- ino uint64
}
// newVirtualFile creates a new in-memory file that does not have a representation
@@ -38,7 +48,6 @@ func (rfs *ReverseFS) newVirtualFile(content []byte, parentFile string) (nodefs.
File: nodefs.NewDefaultFile(),
content: content,
parentFile: parentFile,
- ino: rfs.inoGen.next(),
}, fuse.OK
}
@@ -62,7 +71,12 @@ func (f *virtualFile) GetAttr(a *fuse.Attr) fuse.Status {
tlog.Debug.Printf("GetAttr: Lstat %q: %v\n", f.parentFile, err)
return fuse.ToStatus(err)
}
- st.Ino = f.ino
+ if st.Ino > virtualInoBase {
+ tlog.Warn.Printf("virtualFile.GetAttr: parent file inode number %d crosses reserved space, max=%d. Returning EOVERFLOW.",
+ st.Ino, virtualInoBase)
+ return fuse.ToStatus(syscall.EOVERFLOW)
+ }
+ st.Ino = st.Ino + virtualInoBase
st.Size = int64(len(f.content))
st.Mode = virtualFileMode
st.Nlink = 1