mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #8937 from vbatts/vbatts-mount_optional_fields
pkg/mount: include optional field
This commit is contained in:
commit
379c0da464
3 changed files with 41 additions and 7 deletions
|
@ -1,7 +1,7 @@
|
||||||
package mount
|
package mount
|
||||||
|
|
||||||
type MountInfo struct {
|
type MountInfo struct {
|
||||||
Id, Parent, Major, Minor int
|
Id, Parent, Major, Minor int
|
||||||
Root, Mountpoint, Opts string
|
Root, Mountpoint, Opts, Optional string
|
||||||
Fstype, Source, VfsOpts string
|
Fstype, Source, VfsOpts string
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ const (
|
||||||
(9) filesystem type: name of filesystem of the form "type[.subtype]"
|
(9) filesystem type: name of filesystem of the form "type[.subtype]"
|
||||||
(10) mount source: filesystem specific information or "none"
|
(10) mount source: filesystem specific information or "none"
|
||||||
(11) super options: per super block options*/
|
(11) super options: per super block options*/
|
||||||
mountinfoFormat = "%d %d %d:%d %s %s %s "
|
mountinfoFormat = "%d %d %d:%d %s %s %s %s"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Parse /proc/self/mountinfo because comparing Dev and ino does not work from bind mounts
|
// Parse /proc/self/mountinfo because comparing Dev and ino does not work from bind mounts
|
||||||
|
@ -51,13 +51,14 @@ func parseInfoFile(r io.Reader) ([]*MountInfo, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
p = &MountInfo{}
|
p = &MountInfo{}
|
||||||
text = s.Text()
|
text = s.Text()
|
||||||
|
optionalFields string
|
||||||
)
|
)
|
||||||
|
|
||||||
if _, err := fmt.Sscanf(text, mountinfoFormat,
|
if _, err := fmt.Sscanf(text, mountinfoFormat,
|
||||||
&p.Id, &p.Parent, &p.Major, &p.Minor,
|
&p.Id, &p.Parent, &p.Major, &p.Minor,
|
||||||
&p.Root, &p.Mountpoint, &p.Opts); err != nil {
|
&p.Root, &p.Mountpoint, &p.Opts, &optionalFields); err != nil {
|
||||||
return nil, fmt.Errorf("Scanning '%s' failed: %s", text, err)
|
return nil, fmt.Errorf("Scanning '%s' failed: %s", text, err)
|
||||||
}
|
}
|
||||||
// Safe as mountinfo encodes mountpoints with spaces as \040.
|
// Safe as mountinfo encodes mountpoints with spaces as \040.
|
||||||
|
@ -67,6 +68,10 @@ func parseInfoFile(r io.Reader) ([]*MountInfo, error) {
|
||||||
return nil, fmt.Errorf("Error found less than 3 fields post '-' in %q", text)
|
return nil, fmt.Errorf("Error found less than 3 fields post '-' in %q", text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if optionalFields != "-" {
|
||||||
|
p.Optional = optionalFields
|
||||||
|
}
|
||||||
|
|
||||||
p.Fstype = postSeparatorFields[0]
|
p.Fstype = postSeparatorFields[0]
|
||||||
p.Source = postSeparatorFields[1]
|
p.Source = postSeparatorFields[1]
|
||||||
p.VfsOpts = strings.Join(postSeparatorFields[2:], " ")
|
p.VfsOpts = strings.Join(postSeparatorFields[2:], " ")
|
||||||
|
|
|
@ -446,3 +446,32 @@ func TestParseGentooMountinfo(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseFedoraMountinfoFields(t *testing.T) {
|
||||||
|
r := bytes.NewBuffer([]byte(fedoraMountinfo))
|
||||||
|
infos, err := parseInfoFile(r)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
expectedLength := 58
|
||||||
|
if len(infos) != expectedLength {
|
||||||
|
t.Fatalf("Expected %d entries, got %d", expectedLength, len(infos))
|
||||||
|
}
|
||||||
|
mi := MountInfo{
|
||||||
|
Id: 15,
|
||||||
|
Parent: 35,
|
||||||
|
Major: 0,
|
||||||
|
Minor: 3,
|
||||||
|
Root: "/",
|
||||||
|
Mountpoint: "/proc",
|
||||||
|
Opts: "rw,nosuid,nodev,noexec,relatime",
|
||||||
|
Optional: "shared:5",
|
||||||
|
Fstype: "proc",
|
||||||
|
Source: "proc",
|
||||||
|
VfsOpts: "rw",
|
||||||
|
}
|
||||||
|
|
||||||
|
if *infos[0] != mi {
|
||||||
|
t.Fatalf("expected %#v, got %#v", mi, infos[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue