From 87d3ed9187cb9caccaa8df0769d4cb722cc5bd00 Mon Sep 17 00:00:00 2001 From: Jesse Dunietz Date: Sat, 6 Oct 2018 15:49:33 -0400 Subject: Add option for autounmount Even though filesystem notifications aren't implemented for FUSE, I decided to try my hand at implementing the autounmount feature (#128). I based it on the EncFS autounmount code, which records filesystem accesses and checks every X seconds whether it's idled long enough to unmount. I've tested the feature locally, but I haven't added any tests for this flag. I also haven't worked with Go before. So please let me know if there's anything that should be done differently. One particular concern: I worked from the assumption that the open files table is unique per-filesystem. If that's not true, I'll need to add an open file count and associated lock to the Filesystem type instead. https://github.com/rfjakob/gocryptfs/pull/265 --- cli_args.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'cli_args.go') diff --git a/cli_args.go b/cli_args.go index dd00658..c073958 100644 --- a/cli_args.go +++ b/cli_args.go @@ -7,6 +7,7 @@ import ( "os" "strconv" "strings" + "time" "github.com/hanwen/go-fuse/fuse" "github.com/rfjakob/gocryptfs/internal/configfile" @@ -33,6 +34,8 @@ type argContainer struct { // Configuration file name override config string notifypid, scryptn int + // Idle time before autounmount + idle time.Duration // Helper variables that are NOT cli options all start with an underscore // _configCustom is true when the user sets a custom config file name. _configCustom bool @@ -187,6 +190,11 @@ func parseCliOpts() (args argContainer) { "successful mount - used internally for daemonization") flagSet.IntVar(&args.scryptn, "scryptn", configfile.ScryptDefaultLogN, "scrypt cost parameter logN. Possible values: 10-28. "+ "A lower value speeds up mounting and reduces its memory needs, but makes the password susceptible to brute-force attacks") + + flagSet.DurationVar(&args.idle, "i", 0, "Alias for -idle") + flagSet.DurationVar(&args.idle, "idle", 0, "Auto-unmount after specified idle duration (ignored in reverse mode). "+ + "Durations are specified like \"500s\" or \"2h45m\". 0 means stay mounted indefinitely.") + var dummyString string flagSet.StringVar(&dummyString, "o", "", "For compatibility with mount(1), options can be also passed as a comma-separated list to -o on the end.") // Actual parsing @@ -247,6 +255,10 @@ func parseCliOpts() (args argContainer) { tlog.Fatal.Printf("The options -extpass and -trezor cannot be used at the same time") os.Exit(exitcodes.Usage) } + if args.idle < 0 { + tlog.Fatal.Printf("Idle timeout cannot be less than 0") + os.Exit(exitcodes.Usage) + } return args } -- cgit v1.2.3