github.com/oweisse/u-root@v0.0.0-20181109060735-d005ad25fef1/pkg/mount/mount_linux.go (about) 1 // Copyright 2012-2017 the u-root Authors. All rights reserved 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // The mount package implements functions for mounting and unmounting 6 // file systems and defines the mount interface. 7 package mount 8 9 import ( 10 "errors" 11 "fmt" 12 13 "golang.org/x/sys/unix" 14 ) 15 16 func Mount(dev, path, fsType, data string, flags uintptr) error { 17 if err := unix.Mount(dev, path, fsType, flags, data); err != nil { 18 return fmt.Errorf("Mount %q on %q type %q flags %x: %v", 19 dev, path, fsType, flags, err) 20 } 21 return nil 22 } 23 24 func Unmount(path string, force, lazy bool) error { 25 var flags = unix.UMOUNT_NOFOLLOW 26 if len(path) == 0 { 27 return errors.New("path cannot be empty") 28 } 29 if force && lazy { 30 return errors.New("force and lazy unmount cannot both be set") 31 } 32 if force { 33 flags |= unix.MNT_FORCE 34 } 35 if lazy { 36 flags |= unix.MNT_DETACH 37 } 38 if err := unix.Unmount(path, flags); err != nil { 39 return fmt.Errorf("umount %q flags %x: %v", path, flags, err) 40 } 41 return nil 42 }