fusefrontend: use inummap

translate inode numbers on different devices to fix
collisions.

Fixes https://github.com/rfjakob/gocryptfs/issues/435
This commit is contained in:
Jakob Unterwurzacher 2019-11-16 21:36:27 +01:00
parent e5d5ab3973
commit bb6155a51f
2 changed files with 14 additions and 1 deletions

View File

@ -462,6 +462,7 @@ func (f *File) GetAttr(a *fuse.Attr) fuse.Status {
if err != nil { if err != nil {
return fuse.ToStatus(err) return fuse.ToStatus(err)
} }
f.fs.inumMap.TranslateStat(&st)
a.FromStat(&st) a.FromStat(&st)
a.Size = f.contentEnc.CipherSizeToPlainSize(a.Size) a.Size = f.contentEnc.CipherSizeToPlainSize(a.Size)
if f.fs.args.ForceOwner != nil { if f.fs.args.ForceOwner != nil {

View File

@ -19,6 +19,7 @@ import (
"github.com/rfjakob/gocryptfs/internal/configfile" "github.com/rfjakob/gocryptfs/internal/configfile"
"github.com/rfjakob/gocryptfs/internal/contentenc" "github.com/rfjakob/gocryptfs/internal/contentenc"
"github.com/rfjakob/gocryptfs/internal/nametransform" "github.com/rfjakob/gocryptfs/internal/nametransform"
"github.com/rfjakob/gocryptfs/internal/openfiletable"
"github.com/rfjakob/gocryptfs/internal/serialize_reads" "github.com/rfjakob/gocryptfs/internal/serialize_reads"
"github.com/rfjakob/gocryptfs/internal/syscallcompat" "github.com/rfjakob/gocryptfs/internal/syscallcompat"
"github.com/rfjakob/gocryptfs/internal/tlog" "github.com/rfjakob/gocryptfs/internal/tlog"
@ -56,8 +57,11 @@ type FS struct {
// When -idle was used when mounting, idleMonitor() sets it to 1 // When -idle was used when mounting, idleMonitor() sets it to 1
// periodically. // periodically.
IsIdle uint32 IsIdle uint32
// dirCache caches directory fds
dirCache dirCacheStruct dirCache dirCacheStruct
// inumMap translates inode numbers from different devices to unique inode
// numbers.
inumMap *openfiletable.InumMap
} }
//var _ pathfs.FileSystem = &FS{} // Verify that interface is implemented. //var _ pathfs.FileSystem = &FS{} // Verify that interface is implemented.
@ -70,11 +74,18 @@ func NewFS(args Args, c *contentenc.ContentEnc, n nametransform.NameTransformer)
if len(args.Exclude) > 0 { if len(args.Exclude) > 0 {
tlog.Warn.Printf("Forward mode does not support -exclude") tlog.Warn.Printf("Forward mode does not support -exclude")
} }
var st syscall.Stat_t
err := syscall.Stat(args.Cipherdir, &st)
if err != nil {
tlog.Warn.Printf("NewFS: could not stat cipherdir: %v", err)
st.Dev = 0
}
return &FS{ return &FS{
FileSystem: pathfs.NewDefaultFileSystem(), FileSystem: pathfs.NewDefaultFileSystem(),
args: args, args: args,
nameTransform: n, nameTransform: n,
contentEnc: c, contentEnc: c,
inumMap: openfiletable.NewInumMap(st.Dev),
} }
} }
@ -98,6 +109,7 @@ func (fs *FS) GetAttr(relPath string, context *fuse.Context) (*fuse.Attr, fuse.S
} }
a := &fuse.Attr{} a := &fuse.Attr{}
st2 := syscallcompat.Unix2syscall(st) st2 := syscallcompat.Unix2syscall(st)
fs.inumMap.TranslateStat(&st2)
a.FromStat(&st2) a.FromStat(&st2)
if a.IsRegular() { if a.IsRegular() {
a.Size = fs.contentEnc.CipherSizeToPlainSize(a.Size) a.Size = fs.contentEnc.CipherSizeToPlainSize(a.Size)