diff options
Diffstat (limited to 'test/sandbox/mount.go')
| -rw-r--r-- | test/sandbox/mount.go | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/test/sandbox/mount.go b/test/sandbox/mount.go index 9a3b58c9..d65824f2 100644 --- a/test/sandbox/mount.go +++ b/test/sandbox/mount.go @@ -12,6 +12,7 @@ import "C" import ( "fmt" + "iter" "runtime" "sync" "unsafe" @@ -49,21 +50,38 @@ func (e *Mntent) Is(want *Mntent) bool { (e.Passno == want.Passno || want.Passno == -1) } -func IterMounts(name string, f func(e *Mntent)) error { - m := new(mounts) - m.p = name - if err := m.open(); err != nil { - return err - } +type MountsFile struct { + m *mounts + mu sync.Mutex + done bool +} - for m.scan() { - e := new(Mntent) - m.copy(e) - f(e) - } +func OpenMounts(name string) (*MountsFile, error) { + f := new(MountsFile) + f.m = new(mounts) + f.m.p = name + return f, f.m.open() +} + +func (f *MountsFile) Err() error { return f.m.Err() } +func (f *MountsFile) Entries() iter.Seq[*Mntent] { + return func(yield func(*Mntent) bool) { + f.mu.Lock() + defer f.mu.Unlock() + if f.done { + return + } - m.close() - return m.Err() + for f.m.scan() { + e := new(Mntent) + f.m.copy(e) + if !yield(e) { + return + } + } + f.done = true + f.m.close() + } } type mounts struct { |
