From 8f30e895b21558e0450c00a19fd766d324288fc1 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Mon, 3 Nov 2014 22:05:04 -0500 Subject: [PATCH 1/2] pkg/mount: include optional field one linux, the optional field designates the sharedsubtree information, if any. Signed-off-by: Vincent Batts --- mount/mountinfo.go | 6 +++--- mount/mountinfo_linux.go | 13 +++++++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/mount/mountinfo.go b/mount/mountinfo.go index 78b83ce..ec8e8bc 100644 --- a/mount/mountinfo.go +++ b/mount/mountinfo.go @@ -1,7 +1,7 @@ package mount type MountInfo struct { - Id, Parent, Major, Minor int - Root, Mountpoint, Opts string - Fstype, Source, VfsOpts string + Id, Parent, Major, Minor int + Root, Mountpoint, Opts, Optional string + Fstype, Source, VfsOpts string } diff --git a/mount/mountinfo_linux.go b/mount/mountinfo_linux.go index 84bf551..e6c28da 100644 --- a/mount/mountinfo_linux.go +++ b/mount/mountinfo_linux.go @@ -23,7 +23,7 @@ const ( (9) filesystem type: name of filesystem of the form "type[.subtype]" (10) mount source: filesystem specific information or "none" (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 @@ -49,13 +49,14 @@ func parseInfoFile(r io.Reader) ([]*MountInfo, error) { } var ( - p = &MountInfo{} - text = s.Text() + p = &MountInfo{} + text = s.Text() + optionalFields string ) if _, err := fmt.Sscanf(text, mountinfoFormat, &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) } // Safe as mountinfo encodes mountpoints with spaces as \040. @@ -65,6 +66,10 @@ func parseInfoFile(r io.Reader) ([]*MountInfo, error) { return nil, fmt.Errorf("Error found less than 3 fields post '-' in %q", text) } + if optionalFields != "-" { + p.Optional = optionalFields + } + p.Fstype = postSeparatorFields[0] p.Source = postSeparatorFields[1] p.VfsOpts = strings.Join(postSeparatorFields[2:], " ") From d2a55acf47e77dfb5af8cc0e06c8656566524006 Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Mon, 17 Nov 2014 16:17:06 -0500 Subject: [PATCH 2/2] pkg/mount: testing mountinfo fields Signed-off-by: Vincent Batts --- mount/mountinfo_linux_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/mount/mountinfo_linux_test.go b/mount/mountinfo_linux_test.go index 3c21447..e92b7e2 100644 --- a/mount/mountinfo_linux_test.go +++ b/mount/mountinfo_linux_test.go @@ -446,3 +446,32 @@ func TestParseGentooMountinfo(t *testing.T) { 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]) + } +}