From 8ebb2147d9eff47da10054ede27c5e399617bc0b Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Mon, 26 Jun 2017 13:42:52 +0200 Subject: pkg/fileutil: port to darwin --- pkg/fileutil/fileutil_linux.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 pkg/fileutil/fileutil_linux.go (limited to 'pkg/fileutil/fileutil_linux.go') diff --git a/pkg/fileutil/fileutil_linux.go b/pkg/fileutil/fileutil_linux.go new file mode 100644 index 000000000..217036256 --- /dev/null +++ b/pkg/fileutil/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 fileutil + +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) + } +} -- cgit mrf-deployment