From e8809125d40b5086dc8adc1b9d75d99a9755278d Mon Sep 17 00:00:00 2001 From: Ophestra Date: Sun, 23 Mar 2025 22:17:36 +0900 Subject: sandbox: verify outcome via mountinfo This contains much more information than /proc/mounts and allows for more fields to be checked. This also removes the dependency on the test package. Signed-off-by: Ophestra --- sandbox/vfs/mountinfo.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'sandbox/vfs') diff --git a/sandbox/vfs/mountinfo.go b/sandbox/vfs/mountinfo.go index c834b0e9..e0c9d411 100644 --- a/sandbox/vfs/mountinfo.go +++ b/sandbox/vfs/mountinfo.go @@ -6,6 +6,7 @@ import ( "fmt" "io" "iter" + "slices" "strconv" "strings" "syscall" @@ -236,3 +237,22 @@ func parseMountInfoLine(s string, ent *MountInfoEntry) error { return nil } + +func (e *MountInfoEntry) EqualWithIgnore(want *MountInfoEntry) bool { + return (e.ID == want.ID || want.ID == -1) && + (e.Parent == want.Parent || want.Parent == -1) && + (e.Devno == want.Devno || (want.Devno[0] == -1 && want.Devno[1] == -1)) && + (e.Root == want.Root || want.Root == "\x00") && + (e.Target == want.Target || want.Target == "\x00") && + (e.VfsOptstr == want.VfsOptstr || want.VfsOptstr == "\x00") && + (slices.Equal(e.OptFields, want.OptFields) || (len(want.OptFields) == 1 && want.OptFields[0] == "\x00")) && + (e.FsType == want.FsType || want.FsType == "\x00") && + (e.Source == want.Source || want.Source == "\x00") && + (e.FsOptstr == want.FsOptstr || want.FsOptstr == "\x00") +} + +func (e *MountInfoEntry) String() string { + return fmt.Sprintf("%d %d %d:%d %s %s %s %s %s %s %s", + e.ID, e.Parent, e.Devno[0], e.Devno[1], e.Root, e.Target, e.VfsOptstr, + strings.Join(append(e.OptFields, "-"), " "), e.FsType, e.Source, e.FsOptstr) +} -- cgit v1.3.1