github.com/rck/u-root@v0.0.0-20180106144920-7eb602e381bb/cmds/umount/umount_linux.go (about) 1 // Copyright 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 package main 6 7 import ( 8 "errors" 9 "flag" 10 "fmt" 11 12 "golang.org/x/sys/unix" 13 ) 14 15 var ( 16 force = flag.Bool("f", false, "Force unmount") 17 lazy = flag.Bool("l", false, "Lazy unmount") 18 ) 19 20 func umount() error { 21 var flags = unix.UMOUNT_NOFOLLOW 22 flag.Parse() 23 a := flag.Args() 24 if len(a) != 1 { 25 return errors.New("Usage: umount [-f | -l] path") 26 } 27 if *force && *lazy { 28 return errors.New("force and lazy unmount cannot both be set") 29 } 30 path := a[0] 31 if *force { 32 flags |= unix.MNT_FORCE 33 } 34 if *lazy { 35 flags |= unix.MNT_DETACH 36 } 37 if err := unix.Unmount(path, flags); err != nil { 38 return fmt.Errorf("umount :%s: flags %x: %v", path, flags, err) 39 } 40 return nil 41 }