aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/osutil/fileutil_linux.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2017-07-03 14:00:47 +0200
committerDmitry Vyukov <dvyukov@google.com>2017-07-03 14:00:47 +0200
commita7b199253f7a517fd62f36a5d632efee3bac737e (patch)
tree9f981ff2814ed7389e973c02376f8b2618224be2 /pkg/osutil/fileutil_linux.go
parent1438a6de8130467a2fcde187ba80b8a616f8daa0 (diff)
all: use consistent file permissions
Currently we have unix permissions for new files/dirs hardcoded throughout the code base. Some places use 0644, some - 0640, some - 0600 and a variety of other constants. Introduce osutil.MkdirAll/WriteFile that use the default permissions and use them throughout the code base. This makes permissions consistent and also allows to easily change the permissions later if we change our minds. Also merge pkg/fileutil into pkg/osutil as they become dependent on each other. The line between them was poorly defined anyway as both operate on files.
Diffstat (limited to 'pkg/osutil/fileutil_linux.go')
-rw-r--r--pkg/osutil/fileutil_linux.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/pkg/osutil/fileutil_linux.go b/pkg/osutil/fileutil_linux.go
new file mode 100644
index 000000000..415c00353
--- /dev/null
+++ b/pkg/osutil/fileutil_linux.go
@@ -0,0 +1,24 @@
+// Copyright 2017 syzkaller project authors. All rights reserved.
+// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
+
+package osutil
+
+import (
+ "io/ioutil"
+ "path/filepath"
+ "syscall"
+ "unsafe"
+)
+
+// UmountAll recurusively unmounts all mounts in dir.
+func UmountAll(dir string) {
+ files, _ := ioutil.ReadDir(dir)
+ for _, f := range files {
+ name := filepath.Join(dir, f.Name())
+ if f.IsDir() {
+ UmountAll(name)
+ }
+ fn := []byte(name + "\x00")
+ syscall.Syscall(syscall.SYS_UMOUNT2, uintptr(unsafe.Pointer(&fn[0])), syscall.MNT_FORCE, 0)
+ }
+}