Skip to content

Commit 7a52162

Browse files
committed
mount: remove Windows stubs
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 32b8cf3 commit 7a52162

9 files changed

Lines changed: 45 additions & 94 deletions

mount/doc.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Package mount provides a set of functions to mount and unmount mounts.
2+
//
3+
// Currently it supports Linux. For historical reasons, there is also some support for FreeBSD.
4+
5+
package mount

mount/flags.go renamed to mount/flags_unix.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build !darwin,!windows
2+
13
package mount
24

35
import (

mount/flags_unsupported.go

Lines changed: 0 additions & 30 deletions
This file was deleted.

mount/mount.go

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build !windows
1+
// +build !darwin,!windows
22

33
package mount
44

@@ -10,7 +10,37 @@ import (
1010
"golang.org/x/sys/unix"
1111
)
1212

13-
func recursiveUnmount(target string) error {
13+
// Mount will mount filesystem according to the specified configuration.
14+
// Options must be specified like the mount or fstab unix commands:
15+
// "opt1=val1,opt2=val2". See flags.go for supported option flags.
16+
func Mount(device, target, mType, options string) error {
17+
flag, data := parseOptions(options)
18+
return mount(device, target, mType, uintptr(flag), data)
19+
}
20+
21+
// Unmount lazily unmounts a filesystem on supported platforms, otherwise does
22+
// a normal unmount. If target is not a mount point, no error is returned.
23+
func Unmount(target string) error {
24+
err := unix.Unmount(target, mntDetach)
25+
if err == nil || err == unix.EINVAL {
26+
// Ignore "not mounted" error here. Note the same error
27+
// can be returned if flags are invalid, so this code
28+
// assumes that the flags value is always correct.
29+
return nil
30+
}
31+
32+
return &mountError{
33+
op: "umount",
34+
target: target,
35+
flags: uintptr(mntDetach),
36+
err: err,
37+
}
38+
}
39+
40+
// RecursiveUnmount unmounts the target and all mounts underneath, starting
41+
// with the deepest mount first. The argument does not have to be a mount
42+
// point itself.
43+
func RecursiveUnmount(target string) error {
1444
// Fast path, works if target is a mount point that can be unmounted.
1545
// On Linux, mntDetach flag ensures a recursive unmount. For other
1646
// platforms, if there are submounts, we'll get EBUSY (and fall back
@@ -33,7 +63,7 @@ func recursiveUnmount(target string) error {
3363

3464
var suberr error
3565
for i, m := range mounts {
36-
err = unmount(m.Mountpoint, mntDetach)
66+
err = Unmount(m.Mountpoint)
3767
if err != nil {
3868
if i == len(mounts)-1 { // last mount
3969
return fmt.Errorf("%w (possible cause: %s)", err, suberr)
@@ -49,20 +79,3 @@ func recursiveUnmount(target string) error {
4979
}
5080
return nil
5181
}
52-
53-
func unmount(target string, flags int) error {
54-
err := unix.Unmount(target, flags)
55-
if err == nil || err == unix.EINVAL {
56-
// Ignore "not mounted" error here. Note the same error
57-
// can be returned if flags are invalid, so this code
58-
// assumes that the flags value is always correct.
59-
return nil
60-
}
61-
62-
return &mountError{
63-
op: "umount",
64-
target: target,
65-
flags: uintptr(flags),
66-
err: err,
67-
}
68-
}

mount/mounter_freebsd.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build freebsd cgo
2+
13
package mount
24

35
/*

mount/mounter_unsupported.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// +build !linux,!freebsd freebsd,!cgo
1+
// +build freebsd,!cgo
22

33
package mount
44

55
func mount(device, target, mType string, flag uintptr, data string) error {
6-
panic("Not implemented")
6+
panic("cgo required on freebsd")
77
}

mount/sharedsubtree_linux_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// +build linux,go1.13
1+
// +build linux
22

33
package mount
44

mount/unmount_unsupported.go

Lines changed: 0 additions & 11 deletions
This file was deleted.

0 commit comments

Comments
 (0)