diff options
author | Jamie Liu <jamieliu@google.com> | 2019-12-11 13:40:57 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2019-12-11 14:26:32 -0800 |
commit | 481dbfa5ab24ec2c0752b9e748d3617285603c4e (patch) | |
tree | cec1be5f8514b22987d965f7531051da1985d376 /pkg/sentry/vfs/filesystem_impl_util.go | |
parent | 0d027262e09184f61ea0707935534fc2fc4af7e7 (diff) |
Add vfs.Pathname{WithDeleted,ForGetcwd}.
The former is needed for vfs.FileDescription to implement
memmap.MappingIdentity, and the latter is needed to implement getcwd(2).
PiperOrigin-RevId: 285051855
Diffstat (limited to 'pkg/sentry/vfs/filesystem_impl_util.go')
-rw-r--r-- | pkg/sentry/vfs/filesystem_impl_util.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/pkg/sentry/vfs/filesystem_impl_util.go b/pkg/sentry/vfs/filesystem_impl_util.go index 465e610e0..7315a588e 100644 --- a/pkg/sentry/vfs/filesystem_impl_util.go +++ b/pkg/sentry/vfs/filesystem_impl_util.go @@ -16,6 +16,8 @@ package vfs import ( "strings" + + "gvisor.dev/gvisor/pkg/fspath" ) // GenericParseMountOptions parses a comma-separated list of options of the @@ -41,3 +43,27 @@ func GenericParseMountOptions(str string) map[string]string { } return m } + +// GenericPrependPath may be used by implementations of +// FilesystemImpl.PrependPath() for which a single statically-determined lock +// or set of locks is sufficient to ensure its preconditions (as opposed to +// e.g. per-Dentry locks). +// +// Preconditions: Dentry.Name() and Dentry.Parent() must be held constant for +// vd.Dentry() and all of its ancestors. +func GenericPrependPath(vfsroot, vd VirtualDentry, b *fspath.Builder) error { + mnt, d := vd.mount, vd.dentry + for { + if mnt == vfsroot.mount && d == vfsroot.dentry { + return PrependPathAtVFSRootError{} + } + if d == mnt.root { + return nil + } + if d.parent == nil { + return PrependPathAtNonMountRootError{} + } + b.PrependComponent(d.name) + d = d.parent + } +} |