mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
![Sebastiaan van Stijn](/assets/img/avatar_default.png)
full diff: https://github.com/moby/sys/compare/mountinfo/v0.1.3...mountinfo/v0.4.0 > Note that this dependency uses submodules, providing "github.com/moby/sys/mount" > and "github.com/moby/sys/mountinfo". Our vendoring tool (vndr) currently doesn't > support submodules, so we vendor the top-level moby/sys repository (which contains > both) and pick the most recent tag, which could be either `mountinfo/vXXX` or > `mount/vXXX`. github.com/moby/sys/mountinfo v0.4.0 -------------------------------------------------------------------------------- Breaking changes: - `PidMountInfo` is now deprecated and will be removed before v1.0; users should switch to `GetMountsFromReader` Fixes and improvements: - run filter after all fields are parsed - correct handling errors from bufio.Scan - documentation formatting fixes github.com/moby/sys/mountinfo v0.3.1 -------------------------------------------------------------------------------- - mount: use MNT_* flags from golang.org/x/sys/unix on freebsd - various godoc and CI fixes - mountinfo: make GetMountinfoFromReader Linux-specific - Add support for OpenBSD in addition to FreeBSD - mountinfo: use idiomatic naming for fields github.com/moby/sys/mountinfo v0.2.0 -------------------------------------------------------------------------------- Bug fixes: - Fix path unescaping for paths with double quotes Improvements: - Mounted: speed up by adding fast paths using openat2 (Linux-only) and stat - Mounted: relax path requirements (allow relative, non-cleaned paths, symlinks) - Unescape fstype and source fields - Documentation improvements Testing/CI: - Unit tests: exclude darwin - CI: run tests under Fedora 32 to test openat2 - TestGetMounts: fix for Ubuntu build system - Makefile: fix ignoring test failures - CI: add cross build github.com/moby/sys/mount v0.1.1 -------------------------------------------------------------------------------- https://github.com/moby/sys/releases/tag/mount%2Fv0.1.1 Improvements: - RecursiveUnmount: add a fast path (#26) - Unmount: improve doc - fix CI linter warning on Windows Testing/CI: - Unit tests: exclude darwin - Makefile: fix ignoring test failures - CI: add cross build Signed-off-by: Sebastiaan van Stijn <github@gone.nl> Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
66 lines
1.6 KiB
Go
66 lines
1.6 KiB
Go
// +build linux freebsd,cgo openbsd,cgo
|
|
|
|
package mountinfo
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
func mountedByStat(path string) (bool, error) {
|
|
var st unix.Stat_t
|
|
|
|
if err := unix.Lstat(path, &st); err != nil {
|
|
if err == unix.ENOENT {
|
|
// Treat ENOENT as "not mounted".
|
|
return false, nil
|
|
}
|
|
return false, &os.PathError{Op: "stat", Path: path, Err: err}
|
|
}
|
|
dev := st.Dev
|
|
parent := filepath.Dir(path)
|
|
if err := unix.Lstat(parent, &st); err != nil {
|
|
return false, &os.PathError{Op: "stat", Path: parent, Err: err}
|
|
}
|
|
if dev != st.Dev {
|
|
// Device differs from that of parent,
|
|
// so definitely a mount point.
|
|
return true, nil
|
|
}
|
|
// NB: this does not detect bind mounts on Linux.
|
|
return false, nil
|
|
}
|
|
|
|
func normalizePath(path string) (realPath string, err error) {
|
|
if realPath, err = filepath.Abs(path); err != nil {
|
|
return "", fmt.Errorf("unable to get absolute path for %q: %w", path, err)
|
|
}
|
|
if realPath, err = filepath.EvalSymlinks(realPath); err != nil {
|
|
return "", fmt.Errorf("failed to canonicalise path for %q: %w", path, err)
|
|
}
|
|
if _, err := os.Stat(realPath); err != nil {
|
|
return "", fmt.Errorf("failed to stat target of %q: %w", path, err)
|
|
}
|
|
return realPath, nil
|
|
}
|
|
|
|
func mountedByMountinfo(path string) (bool, error) {
|
|
path, err := normalizePath(path)
|
|
if err != nil {
|
|
if errors.Is(err, unix.ENOENT) {
|
|
// treat ENOENT as "not mounted"
|
|
return false, nil
|
|
}
|
|
return false, err
|
|
}
|
|
entries, err := GetMounts(SingleEntryFilter(path))
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
return len(entries) > 0, nil
|
|
}
|