Skip to content

Commit

Permalink
many: rename InfoEntry to MountInfoEntry
Browse files Browse the repository at this point in the history
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
  • Loading branch information
zyga committed Feb 8, 2018
1 parent e705835 commit ab9d1eb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
18 changes: 9 additions & 9 deletions osutil/mountinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import (
"strings"
)

// InfoEntry contains data from /proc/$PID/mountinfo
// MountInfoEntry contains data from /proc/$PID/mountinfo
//
// For details please refer to mountinfo documentation at
// https://www.kernel.org/doc/Documentation/filesystems/proc.txt
type InfoEntry struct {
type MountInfoEntry struct {
MountID int
ParentID int
DevMajor int
Expand All @@ -53,7 +53,7 @@ const ProcSelfMountInfo = "/proc/self/mountinfo"
//
// The file is typically ProcSelfMountInfo but any other process mount table
// can be read the same way.
func LoadMountInfo(fname string) ([]*InfoEntry, error) {
func LoadMountInfo(fname string) ([]*MountInfoEntry, error) {
f, err := os.Open(fname)
if err != nil {
return nil, err
Expand All @@ -63,12 +63,12 @@ func LoadMountInfo(fname string) ([]*InfoEntry, error) {
}

// ReadMountInfo reads and parses a mountinfo file.
func ReadMountInfo(reader io.Reader) ([]*InfoEntry, error) {
func ReadMountInfo(reader io.Reader) ([]*MountInfoEntry, error) {
scanner := bufio.NewScanner(reader)
var entries []*InfoEntry
var entries []*MountInfoEntry
for scanner.Scan() {
s := scanner.Text()
entry, err := ParseInfoEntry(s)
entry, err := ParseMountInfoEntry(s)
if err != nil {
return nil, err
}
Expand All @@ -80,9 +80,9 @@ func ReadMountInfo(reader io.Reader) ([]*InfoEntry, error) {
return entries, nil
}

// ParseInfoEntry parses a single line of /proc/$PID/mountinfo file.
func ParseInfoEntry(s string) (*InfoEntry, error) {
var e InfoEntry
// ParseMountInfoEntry parses a single line of /proc/$PID/mountinfo file.
func ParseMountInfoEntry(s string) (*MountInfoEntry, error) {
var e MountInfoEntry
var err error
fields := strings.Fields(s)
// The format is variable-length, but at least 10 fields are mandatory.
Expand Down
40 changes: 20 additions & 20 deletions osutil/mountinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ type mountinfoSuite struct{}
var _ = Suite(&mountinfoSuite{})

// Check that parsing the example from kernel documentation works correctly.
func (s *mountinfoSuite) TestParseInfoEntry1(c *C) {
entry, err := osutil.ParseInfoEntry(
func (s *mountinfoSuite) TestParseMountInfoEntry1(c *C) {
entry, err := osutil.ParseMountInfoEntry(
"36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue")
c.Assert(err, IsNil)
c.Assert(entry.MountID, Equals, 36)
Expand All @@ -52,23 +52,23 @@ func (s *mountinfoSuite) TestParseInfoEntry1(c *C) {
}

// Check that various combinations of optional fields are parsed correctly.
func (s *mountinfoSuite) TestParseInfoEntry2(c *C) {
func (s *mountinfoSuite) TestParseMountInfoEntry2(c *C) {
// No optional fields.
entry, err := osutil.ParseInfoEntry(
entry, err := osutil.ParseMountInfoEntry(
"36 35 98:0 /mnt1 /mnt2 rw,noatime - ext3 /dev/root rw,errors=continue")
c.Assert(err, IsNil)
c.Assert(entry.MountOptions, DeepEquals, map[string]string{"rw": "", "noatime": ""})
c.Assert(entry.OptionalFields, HasLen, 0)
c.Assert(entry.FsType, Equals, "ext3")
// One optional field.
entry, err = osutil.ParseInfoEntry(
entry, err = osutil.ParseMountInfoEntry(
"36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue")
c.Assert(err, IsNil)
c.Assert(entry.MountOptions, DeepEquals, map[string]string{"rw": "", "noatime": ""})
c.Assert(entry.OptionalFields, DeepEquals, []string{"master:1"})
c.Assert(entry.FsType, Equals, "ext3")
// Two optional fields.
entry, err = osutil.ParseInfoEntry(
entry, err = osutil.ParseMountInfoEntry(
"36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 slave:2 - ext3 /dev/root rw,errors=continue")
c.Assert(err, IsNil)
c.Assert(entry.MountOptions, DeepEquals, map[string]string{"rw": "", "noatime": ""})
Expand All @@ -77,8 +77,8 @@ func (s *mountinfoSuite) TestParseInfoEntry2(c *C) {
}

// Check that white-space is unescaped correctly.
func (s *mountinfoSuite) TestParseInfoEntry3(c *C) {
entry, err := osutil.ParseInfoEntry(
func (s *mountinfoSuite) TestParseMountInfoEntry3(c *C) {
entry, err := osutil.ParseMountInfoEntry(
`36 35 98:0 /mnt\0401 /mnt\0402 rw\040,noatime mas\040ter:1 - ext\0403 /dev/ro\040ot rw\040,errors=continue`)
c.Assert(err, IsNil)
c.Assert(entry.MountID, Equals, 36)
Expand All @@ -96,29 +96,29 @@ func (s *mountinfoSuite) TestParseInfoEntry3(c *C) {
}

// Check that various malformed entries are detected.
func (s *mountinfoSuite) TestParseInfoEntry4(c *C) {
func (s *mountinfoSuite) TestParseMountInfoEntry4(c *C) {
var err error
_, err = osutil.ParseInfoEntry("36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue foo")
_, err = osutil.ParseMountInfoEntry("36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue foo")
c.Assert(err, ErrorMatches, "incorrect number of tail fields, expected 3 but found 4")
_, err = osutil.ParseInfoEntry("36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root")
_, err = osutil.ParseMountInfoEntry("36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root")
c.Assert(err, ErrorMatches, "incorrect number of tail fields, expected 3 but found 2")
_, err = osutil.ParseInfoEntry("36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3")
_, err = osutil.ParseMountInfoEntry("36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3")
c.Assert(err, ErrorMatches, "incorrect number of fields, expected at least 10 but found 9")
_, err = osutil.ParseInfoEntry("36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 -")
_, err = osutil.ParseMountInfoEntry("36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 -")
c.Assert(err, ErrorMatches, "incorrect number of fields, expected at least 10 but found 8")
_, err = osutil.ParseInfoEntry("36 35 98:0 /mnt1 /mnt2 rw,noatime master:1")
_, err = osutil.ParseMountInfoEntry("36 35 98:0 /mnt1 /mnt2 rw,noatime master:1")
c.Assert(err, ErrorMatches, "incorrect number of fields, expected at least 10 but found 7")
_, err = osutil.ParseInfoEntry("36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 garbage1 garbage2 garbage3")
_, err = osutil.ParseMountInfoEntry("36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 garbage1 garbage2 garbage3")
c.Assert(err, ErrorMatches, "list of optional fields is not terminated properly")
_, err = osutil.ParseInfoEntry("foo 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue foo")
_, err = osutil.ParseMountInfoEntry("foo 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue foo")
c.Assert(err, ErrorMatches, `cannot parse mount ID: "foo"`)
_, err = osutil.ParseInfoEntry("36 bar 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue foo")
_, err = osutil.ParseMountInfoEntry("36 bar 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue foo")
c.Assert(err, ErrorMatches, `cannot parse parent mount ID: "bar"`)
_, err = osutil.ParseInfoEntry("36 35 froz:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue foo")
_, err = osutil.ParseMountInfoEntry("36 35 froz:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue foo")
c.Assert(err, ErrorMatches, `cannot parse device major number: "froz"`)
_, err = osutil.ParseInfoEntry("36 35 98:bot /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue foo")
_, err = osutil.ParseMountInfoEntry("36 35 98:bot /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue foo")
c.Assert(err, ErrorMatches, `cannot parse device minor number: "bot"`)
_, err = osutil.ParseInfoEntry("36 35 corrupt /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue foo")
_, err = osutil.ParseMountInfoEntry("36 35 corrupt /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue foo")
c.Assert(err, ErrorMatches, `cannot parse device major:minor number pair: "corrupt"`)
}

Expand Down

0 comments on commit ab9d1eb

Please sign in to comment.