summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/fusefrontend/fs.go5
-rw-r--r--internal/fusefrontend/names.go6
-rw-r--r--internal/openfiletable/open_file_table.go8
3 files changed, 19 insertions, 0 deletions
diff --git a/internal/fusefrontend/fs.go b/internal/fusefrontend/fs.go
index 1b6941e..c0d6151 100644
--- a/internal/fusefrontend/fs.go
+++ b/internal/fusefrontend/fs.go
@@ -47,6 +47,11 @@ type FS struct {
// "gocryptfs -fsck" reads from the channel to also catch these transparently-
// mitigated corruptions.
MitigatedCorruptions chan string
+ // Track accesses to the filesystem so that we can know when to autounmount.
+ // An access is considered to have happened on every call to encryptPath,
+ // which is called as part of every filesystem operation.
+ // (This flag uses a uint32 so that it can be reset with CompareAndSwapUint32.)
+ AccessedSinceLastCheck uint32
}
var _ pathfs.FileSystem = &FS{} // Verify that interface is implemented.
diff --git a/internal/fusefrontend/names.go b/internal/fusefrontend/names.go
index 5530e3e..3bf64d5 100644
--- a/internal/fusefrontend/names.go
+++ b/internal/fusefrontend/names.go
@@ -60,9 +60,15 @@ func (fs *FS) openBackingDir(relPath string) (dirfd int, cName string, err error
// encryptPath - encrypt relative plaintext path
func (fs *FS) encryptPath(plainPath string) (string, error) {
+ if plainPath != "" { // Empty path gets encrypted all the time without actual file accesses.
+ fs.AccessedSinceLastCheck = 1
+ } else { // Empty string gets encrypted as empty string
+ return plainPath, nil
+ }
if fs.args.PlaintextNames {
return plainPath, nil
}
+
fs.dirIVLock.RLock()
cPath, err := fs.nameTransform.EncryptPathDirIV(plainPath, fs.args.Cipherdir)
tlog.Debug.Printf("encryptPath '%s' -> '%s' (err: %v)", plainPath, cPath, err)
diff --git a/internal/openfiletable/open_file_table.go b/internal/openfiletable/open_file_table.go
index e21c96d..4a8ce28 100644
--- a/internal/openfiletable/open_file_table.go
+++ b/internal/openfiletable/open_file_table.go
@@ -112,3 +112,11 @@ func (c *countingMutex) Lock() {
func WriteOpCount() uint64 {
return atomic.LoadUint64(&t.writeOpCount)
}
+
+// CountOpenFiles returns how many entries are currently in the table
+// in a threadsafe manner.
+func CountOpenFiles() int {
+ t.Lock()
+ defer t.Unlock()
+ return len(t.entries)
+}