1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/vendor/github.com/moby/sys/mount/flags_unix.go

140 lines
3.6 KiB
Go
Raw Normal View History

vendor: moby/sys mountinfo/v0.4.0 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>
2020-09-16 04:27:03 -04:00
// +build !darwin,!windows
package mount
import (
"fmt"
"strings"
)
var flags = map[string]struct {
clear bool
flag int
}{
"defaults": {false, 0},
"ro": {false, RDONLY},
"rw": {true, RDONLY},
"suid": {true, NOSUID},
"nosuid": {false, NOSUID},
"dev": {true, NODEV},
"nodev": {false, NODEV},
"exec": {true, NOEXEC},
"noexec": {false, NOEXEC},
"sync": {false, SYNCHRONOUS},
"async": {true, SYNCHRONOUS},
"dirsync": {false, DIRSYNC},
"remount": {false, REMOUNT},
"mand": {false, MANDLOCK},
"nomand": {true, MANDLOCK},
"atime": {true, NOATIME},
"noatime": {false, NOATIME},
"diratime": {true, NODIRATIME},
"nodiratime": {false, NODIRATIME},
"bind": {false, BIND},
"rbind": {false, RBIND},
"unbindable": {false, UNBINDABLE},
"runbindable": {false, RUNBINDABLE},
"private": {false, PRIVATE},
"rprivate": {false, RPRIVATE},
"shared": {false, SHARED},
"rshared": {false, RSHARED},
"slave": {false, SLAVE},
"rslave": {false, RSLAVE},
"relatime": {false, RELATIME},
"norelatime": {true, RELATIME},
"strictatime": {false, STRICTATIME},
"nostrictatime": {true, STRICTATIME},
}
var validFlags = map[string]bool{
"": true,
"size": true,
"mode": true,
"uid": true,
"gid": true,
"nr_inodes": true,
"nr_blocks": true,
"mpol": true,
}
var propagationFlags = map[string]bool{
"bind": true,
"rbind": true,
"unbindable": true,
"runbindable": true,
"private": true,
"rprivate": true,
"shared": true,
"rshared": true,
"slave": true,
"rslave": true,
}
// MergeTmpfsOptions merge mount options to make sure there is no duplicate.
func MergeTmpfsOptions(options []string) ([]string, error) {
// We use collisions maps to remove duplicates.
// For flag, the key is the flag value (the key for propagation flag is -1)
// For data=value, the key is the data
flagCollisions := map[int]bool{}
dataCollisions := map[string]bool{}
var newOptions []string
// We process in reverse order
for i := len(options) - 1; i >= 0; i-- {
option := options[i]
if option == "defaults" {
continue
}
if f, ok := flags[option]; ok && f.flag != 0 {
// There is only one propagation mode
key := f.flag
if propagationFlags[option] {
key = -1
}
// Check to see if there is collision for flag
if !flagCollisions[key] {
// We prepend the option and add to collision map
newOptions = append([]string{option}, newOptions...)
flagCollisions[key] = true
}
continue
}
opt := strings.SplitN(option, "=", 2)
if len(opt) != 2 || !validFlags[opt[0]] {
return nil, fmt.Errorf("Invalid tmpfs option %q", opt)
}
if !dataCollisions[opt[0]] {
// We prepend the option and add to collision map
newOptions = append([]string{option}, newOptions...)
dataCollisions[opt[0]] = true
}
}
return newOptions, nil
}
// Parse fstab type mount options into mount() flags
// and device specific data
func parseOptions(options string) (int, string) {
var (
flag int
data []string
)
for _, o := range strings.Split(options, ",") {
// If the option does not exist in the flags table or the flag
// is not supported on the platform,
// then it is a data value for a specific fs type
if f, exists := flags[o]; exists && f.flag != 0 {
if f.clear {
flag &= ^f.flag
} else {
flag |= f.flag
}
} else {
data = append(data, o)
}
}
return flag, strings.Join(data, ",")
}