github.com/shaardie/u-root@v4.0.1-0.20190127173353-f24a1c26aa2e+incompatible/pkg/loop/loop_linux.go (about) 1 // Copyright 2018 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 loop 6 7 import ( 8 "golang.org/x/sys/unix" 9 ) 10 11 const forceUnmount = unix.MNT_FORCE | unix.MNT_DETACH 12 13 // Unmount unmounts and frees a loop. If it is mounted, it will try to unmount it. 14 // If the unmount fails, we try to free it anyway, after trying a more 15 // forceful unmount. We don't log errors, but we do return a concatentation 16 // of whatever errors occur. 17 func (l *Loop) Unmount(flags int) error { 18 if l.Mounted { 19 if err := unix.Unmount(l.Dir, flags); err != nil { 20 unix.Unmount(l.Dir, flags|forceUnmount) 21 } 22 } 23 return ClearFile(l.Dev) 24 }