Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions mount/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Package mount provides a set of functions to mount and unmount mounts.
//
// Currently it supports Linux. For historical reasons, there is also some support for FreeBSD.

package mount
2 changes: 2 additions & 0 deletions mount/flags.go → mount/flags_unix.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !darwin,!windows

package mount

import (
Expand Down
30 changes: 0 additions & 30 deletions mount/flags_unsupported.go

This file was deleted.

24 changes: 19 additions & 5 deletions mount/mount.go → mount/mount_unix.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build go1.13
// +build !darwin,!windows

package mount

Expand All @@ -7,6 +7,7 @@ import (
"sort"

"github.com/moby/sys/mountinfo"
"golang.org/x/sys/unix"
)

// Mount will mount filesystem according to the specified configuration.
Expand All @@ -18,9 +19,22 @@ func Mount(device, target, mType, options string) error {
}

// Unmount lazily unmounts a filesystem on supported platforms, otherwise does
// a normal unmount. If target is not a mount point, no error is returned.
// a normal unmount. If target is not a mount point, no error is returned.
func Unmount(target string) error {
return unmount(target, mntDetach)
err := unix.Unmount(target, mntDetach)
if err == nil || err == unix.EINVAL {
// Ignore "not mounted" error here. Note the same error
// can be returned if flags are invalid, so this code
// assumes that the flags value is always correct.
return nil
}

return &mountError{
op: "umount",
target: target,
flags: uintptr(mntDetach),
err: err,
}
}

// RecursiveUnmount unmounts the target and all mounts underneath, starting
Expand All @@ -32,7 +46,7 @@ func RecursiveUnmount(target string) error {
// platforms, if there are submounts, we'll get EBUSY (and fall back
// to the slow path). NOTE we do not ignore EINVAL here as target might
// not be a mount point itself (but there can be mounts underneath).
if err := unmountBare(target, mntDetach); err == nil {
if err := unix.Unmount(target, mntDetach); err == nil {
return nil
}

Expand All @@ -49,7 +63,7 @@ func RecursiveUnmount(target string) error {

var suberr error
for i, m := range mounts {
err = unmount(m.Mountpoint, mntDetach)
err = Unmount(m.Mountpoint)
if err != nil {
if i == len(mounts)-1 { // last mount
return fmt.Errorf("%w (possible cause: %s)", err, suberr)
Expand Down
2 changes: 2 additions & 0 deletions mount/mounter_freebsd.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build freebsd cgo

package mount

/*
Expand Down
4 changes: 2 additions & 2 deletions mount/mounter_unsupported.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// +build !linux,!freebsd freebsd,!cgo
// +build freebsd,!cgo

package mount

func mount(device, target, mType string, flag uintptr, data string) error {
panic("Not implemented")
panic("cgo required on freebsd")
}
2 changes: 1 addition & 1 deletion mount/sharedsubtree_linux_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build linux,go1.13
// +build linux

package mount

Expand Down
26 changes: 0 additions & 26 deletions mount/unmount_unix.go

This file was deleted.

11 changes: 0 additions & 11 deletions mount/unmount_unsupported.go

This file was deleted.