mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
32d506b394
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>
44 lines
2.7 KiB
Go
44 lines
2.7 KiB
Go
// Package mountinfo provides a set of functions to retrieve information about OS mounts.
|
|
//
|
|
// Currently it supports Linux. For historical reasons, there is also some support for FreeBSD and OpenBSD,
|
|
// and a shallow implementation for Windows, but in general this is Linux-only package, so
|
|
// the rest of the document only applies to Linux, unless explicitly specified otherwise.
|
|
//
|
|
// In Linux, information about mounts seen by the current process is available from
|
|
// /proc/self/mountinfo. Note that due to mount namespaces, different processes can
|
|
// see different mounts. A per-process mountinfo table is available from /proc/<PID>/mountinfo,
|
|
// where <PID> is a numerical process identifier.
|
|
//
|
|
// In general, /proc is not a very efficient interface, and mountinfo is not an exception.
|
|
// For example, there is no way to get information about a specific mount point (i.e. it
|
|
// is all-or-nothing). This package tries to hide the /proc ineffectiveness by using
|
|
// parse filters while reading mountinfo. A filter can skip some entries, or stop
|
|
// processing the rest of the file once the needed information is found.
|
|
//
|
|
// For mountinfo filters that accept path as an argument, the path must be absolute,
|
|
// having all symlinks resolved, and being cleaned (i.e. no extra slashes or dots).
|
|
// One way to achieve all of the above is to employ filepath.Abs followed by
|
|
// filepath.EvalSymlinks (the latter calls filepath.Clean on the result so
|
|
// there is no need to explicitly call filepath.Clean).
|
|
//
|
|
// NOTE that in many cases there is no need to consult mountinfo at all. Here are some
|
|
// of the cases where mountinfo should not be parsed:
|
|
//
|
|
// 1. Before performing a mount. Usually, this is not needed, but if required (say to
|
|
// prevent over-mounts), to check whether a directory is mounted, call os.Lstat
|
|
// on it and its parent directory, and compare their st.Sys().(*syscall.Stat_t).Dev
|
|
// fields -- if they differ, then the directory is the mount point. NOTE this does
|
|
// not work for bind mounts. Optionally, the filesystem type can also be checked
|
|
// by calling unix.Statfs and checking the Type field (i.e. filesystem type).
|
|
//
|
|
// 2. After performing a mount. If there is no error returned, the mount succeeded;
|
|
// checking the mount table for a new mount is redundant and expensive.
|
|
//
|
|
// 3. Before performing an unmount. It is more efficient to do an unmount and ignore
|
|
// a specific error (EINVAL) which tells the directory is not mounted.
|
|
//
|
|
// 4. After performing an unmount. If there is no error returned, the unmount succeeded.
|
|
//
|
|
// 5. To find the mount point root of a specific directory. You can perform os.Stat()
|
|
// on the directory and traverse up until the Dev field of a parent directory differs.
|
|
package mountinfo
|