aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorJoseph Richey <joerichey@google.com>2017-08-22 11:46:39 -0700
committerGitHub <noreply@github.com>2017-08-22 11:46:39 -0700
commit17794e94ebe140dc74f93abb8132f5295ee2004e (patch)
tree3e79eee2f6e266ea7cd4eab7473bde7faa01e585 /util
parentb4d51e0f4d34dbfd78e23662f3dfd90e86ae5e48 (diff)
parent50256fab010adfde1b349160460659fb03d8c8ac (diff)
Merge pull request #39 from google/purge
Purge command now clears cache
Diffstat (limited to 'util')
-rw-r--r--util/util.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/util/util.go b/util/util.go
index 14d23e2..acdc3fc 100644
--- a/util/util.go
+++ b/util/util.go
@@ -25,6 +25,7 @@ package util
import (
"bufio"
+ "log"
"math"
"os"
"unsafe"
@@ -97,3 +98,19 @@ func ReadLine() (string, error) {
scanner.Scan()
return scanner.Text(), scanner.Err()
}
+
+// DropInodeCache instructs the kernel to clear the global cache of inodes and
+// dentries. This has the effect of making encrypted directories whose keys
+// are not present no longer accessible. Requires root privileges.
+func DropInodeCache() error {
+ log.Print("dropping page caches")
+ // See: https://www.kernel.org/doc/Documentation/sysctl/vm.txt
+ file, err := os.OpenFile("/proc/sys/vm/drop_caches", os.O_WRONLY|os.O_SYNC, 0)
+ if err != nil {
+ return err
+ }
+ defer file.Close()
+ // "2" just clears the inodes and dentries
+ _, err = file.WriteString("2")
+ return err
+}