Browse code

pkg/mount: include optional field

one linux, the optional field designates the sharedsubtree information,
if any.

Signed-off-by: Vincent Batts <vbatts@redhat.com>

Vincent Batts authored on 2014/11/04 12:05:04
Showing 2 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 package mount
2 2
 
3 3
 type MountInfo struct {
4
-	Id, Parent, Major, Minor int
5
-	Root, Mountpoint, Opts   string
6
-	Fstype, Source, VfsOpts  string
4
+	Id, Parent, Major, Minor         int
5
+	Root, Mountpoint, Opts, Optional string
6
+	Fstype, Source, VfsOpts          string
7 7
 }
... ...
@@ -23,7 +23,7 @@ const (
23 23
 	   (9) filesystem type:  name of filesystem of the form "type[.subtype]"
24 24
 	   (10) mount source:  filesystem specific information or "none"
25 25
 	   (11) super options:  per super block options*/
26
-	mountinfoFormat = "%d %d %d:%d %s %s %s "
26
+	mountinfoFormat = "%d %d %d:%d %s %s %s %s"
27 27
 )
28 28
 
29 29
 // 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) {
49 49
 		}
50 50
 
51 51
 		var (
52
-			p    = &MountInfo{}
53
-			text = s.Text()
52
+			p              = &MountInfo{}
53
+			text           = s.Text()
54
+			optionalFields string
54 55
 		)
55 56
 
56 57
 		if _, err := fmt.Sscanf(text, mountinfoFormat,
57 58
 			&p.Id, &p.Parent, &p.Major, &p.Minor,
58
-			&p.Root, &p.Mountpoint, &p.Opts); err != nil {
59
+			&p.Root, &p.Mountpoint, &p.Opts, &optionalFields); err != nil {
59 60
 			return nil, fmt.Errorf("Scanning '%s' failed: %s", text, err)
60 61
 		}
61 62
 		// Safe as mountinfo encodes mountpoints with spaces as \040.
... ...
@@ -65,6 +66,10 @@ func parseInfoFile(r io.Reader) ([]*MountInfo, error) {
65 65
 			return nil, fmt.Errorf("Error found less than 3 fields post '-' in %q", text)
66 66
 		}
67 67
 
68
+		if optionalFields != "-" {
69
+			p.Optional = optionalFields
70
+		}
71
+
68 72
 		p.Fstype = postSeparatorFields[0]
69 73
 		p.Source = postSeparatorFields[1]
70 74
 		p.VfsOpts = strings.Join(postSeparatorFields[2:], " ")