Skip to content

Commit

Permalink
mount: remove Windows stubs
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
thaJeztah committed Oct 1, 2020
1 parent 32b8cf3 commit 7a52162
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 94 deletions.
5 changes: 5 additions & 0 deletions mount/doc.go
@@ -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
@@ -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.

30 changes: 0 additions & 30 deletions mount/mount.go

This file was deleted.

53 changes: 33 additions & 20 deletions mount/unmount_unix.go → mount/mount_unix.go
@@ -1,4 +1,4 @@
// +build !windows
// +build !darwin,!windows

package mount

Expand All @@ -10,7 +10,37 @@ import (
"golang.org/x/sys/unix"
)

func recursiveUnmount(target string) error {
// Mount will mount filesystem according to the specified configuration.
// Options must be specified like the mount or fstab unix commands:
// "opt1=val1,opt2=val2". See flags.go for supported option flags.
func Mount(device, target, mType, options string) error {
flag, data := parseOptions(options)
return mount(device, target, mType, uintptr(flag), data)
}

// Unmount lazily unmounts a filesystem on supported platforms, otherwise does
// a normal unmount. If target is not a mount point, no error is returned.
func Unmount(target string) error {
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
// with the deepest mount first. The argument does not have to be a mount
// point itself.
func RecursiveUnmount(target string) error {
// Fast path, works if target is a mount point that can be unmounted.
// On Linux, mntDetach flag ensures a recursive unmount. For other
// platforms, if there are submounts, we'll get EBUSY (and fall back
Expand All @@ -33,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 All @@ -49,20 +79,3 @@ func recursiveUnmount(target string) error {
}
return nil
}

func unmount(target string, flags int) error {
err := unix.Unmount(target, flags)
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(flags),
err: err,
}
}
2 changes: 2 additions & 0 deletions mount/mounter_freebsd.go
@@ -1,3 +1,5 @@
// +build freebsd cgo

package mount

/*
Expand Down
4 changes: 2 additions & 2 deletions mount/mounter_unsupported.go
@@ -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
@@ -1,4 +1,4 @@
// +build linux,go1.13
// +build linux

package mount

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

This file was deleted.

0 comments on commit 7a52162

Please sign in to comment.