1// +build !windows 2 3/* 4 Copyright The containerd Authors. 5 6 Licensed under the Apache License, Version 2.0 (the "License"); 7 you may not use this file except in compliance with the License. 8 You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 See the License for the specific language governing permissions and 16 limitations under the License. 17*/ 18 19package os 20 21import ( 22 "github.com/containerd/containerd/mount" 23 "golang.org/x/sys/unix" 24) 25 26// UNIX collects unix system level operations that need to be 27// mocked out during tests. 28type UNIX interface { 29 Mount(source string, target string, fstype string, flags uintptr, data string) error 30 Unmount(target string) error 31 LookupMount(path string) (mount.Info, error) 32} 33 34// Mount will call unix.Mount to mount the file. 35func (RealOS) Mount(source string, target string, fstype string, flags uintptr, data string) error { 36 return unix.Mount(source, target, fstype, flags, data) 37} 38 39// Unmount will call Unmount to unmount the file. 40func (RealOS) Unmount(target string) error { 41 return Unmount(target) 42} 43 44// LookupMount gets mount info of a given path. 45func (RealOS) LookupMount(path string) (mount.Info, error) { 46 return mount.Lookup(path) 47} 48 49// Unmount unmounts the target. It does not return an error in case the target is not mounted. 50// In case the target does not exist, the appropriate error is returned. 51func Unmount(target string) error { 52 err := unix.Unmount(target, unix.MNT_DETACH) 53 if err == unix.EINVAL { 54 // ignore "not mounted" error 55 err = nil 56 } 57 58 return err 59} 60