github.com/craftyguy/u-root@v1.0.0/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  package mount
     6  
     7  import (
     8  	"errors"
     9  	"fmt"
    10  
    11  	"golang.org/x/sys/unix"
    12  )
    13  
    14  func Mount(dev, path, fsType, data string, flags uintptr) error {
    15  	if err := unix.Mount(dev, path, fsType, flags, data); err != nil {
    16  		return fmt.Errorf("Mount %q on %q type %q flags %x: %v",
    17  			dev, path, fsType, flags, err)
    18  	}
    19  	return nil
    20  }
    21  
    22  func Unmount(path string, force, lazy bool) error {
    23  	var flags = unix.UMOUNT_NOFOLLOW
    24  	if len(path) == 0 {
    25  		return errors.New("path cannot be empty")
    26  	}
    27  	if force && lazy {
    28  		return errors.New("force and lazy unmount cannot both be set")
    29  	}
    30  	if force {
    31  		flags |= unix.MNT_FORCE
    32  	}
    33  	if lazy {
    34  		flags |= unix.MNT_DETACH
    35  	}
    36  	if err := unix.Unmount(path, flags); err != nil {
    37  		return fmt.Errorf("umount %q flags %x: %v", path, flags, err)
    38  	}
    39  	return nil
    40  }