aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorJakob Unterwurzacher2021-03-07 17:22:29 +0100
committerJakob Unterwurzacher2021-03-07 17:22:29 +0100
commite2dc52a9657e530820b2d5b49ad7425b529029ce (patch)
tree75683d1194615dc2774a1b0f99850b798ade2b83 /internal
parenteaca820e876bfcdc67323eac6dd43ecc420968f2 (diff)
v2api: -sharestorage: disable hard link tracking & add tests
Hard link tracking was not correctly disabled since the migration to the go-fuse v2 api. Add a test to ensure it stays off. Fixes https://github.com/rfjakob/gocryptfs/issues/525
Diffstat (limited to 'internal')
-rw-r--r--internal/fusefrontend/args.go3
-rw-r--r--internal/fusefrontend/node_helpers.go3
-rw-r--r--internal/fusefrontend/root_node.go10
-rw-r--r--internal/inomap/inomap.go11
4 files changed, 24 insertions, 3 deletions
diff --git a/internal/fusefrontend/args.go b/internal/fusefrontend/args.go
index 5eb6bff..ae1c30c 100644
--- a/internal/fusefrontend/args.go
+++ b/internal/fusefrontend/args.go
@@ -46,4 +46,7 @@ type Args struct {
Suid bool
// Enable the FUSE kernel_cache option
KernelCache bool
+ // SharedStorage disables caching & hard link tracking,
+ // enabled via cli flag "-sharedstorage"
+ SharedStorage bool
}
diff --git a/internal/fusefrontend/node_helpers.go b/internal/fusefrontend/node_helpers.go
index ad92043..f99e6df 100644
--- a/internal/fusefrontend/node_helpers.go
+++ b/internal/fusefrontend/node_helpers.go
@@ -102,8 +102,9 @@ func (n *Node) prepareAtSyscall(child string) (dirfd int, cName string, errno sy
// newChild attaches a new child inode to n.
// The passed-in `st` will be modified to get a unique inode number.
func (n *Node) newChild(ctx context.Context, st *syscall.Stat_t, out *fuse.EntryOut) *fs.Inode {
- // Get unique inode number
rn := n.rootNode()
+ // Get stable inode number based on underlying (device,ino) pair
+ // (or set to zero in case of `-sharestorage`)
rn.inoMap.TranslateStat(st)
out.Attr.FromStat(st)
// Create child node
diff --git a/internal/fusefrontend/root_node.go b/internal/fusefrontend/root_node.go
index e03e250..bdefafa 100644
--- a/internal/fusefrontend/root_node.go
+++ b/internal/fusefrontend/root_node.go
@@ -50,7 +50,7 @@ type RootNode struct {
IsIdle uint32
// inoMap translates inode numbers from different devices to unique inode
// numbers.
- inoMap *inomap.InoMap
+ inoMap inomap.TranslateStater
}
func NewRootNode(args Args, c *contentenc.ContentEnc, n nametransform.NameTransformer) *RootNode {
@@ -60,12 +60,18 @@ func NewRootNode(args Args, c *contentenc.ContentEnc, n nametransform.NameTransf
if len(args.Exclude) > 0 {
tlog.Warn.Printf("Forward mode does not support -exclude")
}
- return &RootNode{
+ rn := &RootNode{
args: args,
nameTransform: n,
contentEnc: c,
inoMap: inomap.New(),
}
+ // In `-sharedstorage` mode we always set the inode number to zero.
+ // This makes go-fuse generate a new inode number for each lookup.
+ if args.SharedStorage {
+ rn.inoMap = &inomap.TranslateStatZero{}
+ }
+ return rn
}
// mangleOpenFlags is used by Create() and Open() to convert the open flags the user
diff --git a/internal/inomap/inomap.go b/internal/inomap/inomap.go
index 82d50b0..0977a46 100644
--- a/internal/inomap/inomap.go
+++ b/internal/inomap/inomap.go
@@ -104,3 +104,14 @@ func (m *InoMap) TranslateStat(st *syscall.Stat_t) {
in := QInoFromStat(st)
st.Ino = m.Translate(in)
}
+
+type TranslateStater interface {
+ TranslateStat(st *syscall.Stat_t)
+}
+
+// TranslateStatZero always sets st.Ino to zero. Used for `-sharedstorage`.
+type TranslateStatZero struct{}
+
+func (z TranslateStatZero) TranslateStat(st *syscall.Stat_t) {
+ st.Ino = 0
+}