diff options
author | Jamie Liu <jamieliu@google.com> | 2019-12-12 13:17:47 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2019-12-12 13:19:33 -0800 |
commit | 93d429d5b1e3801fb4c29568bcd40d6854c9fe94 (patch) | |
tree | cc0f6940b131fbb3aecb34fe22104a3bd28daa70 /pkg/sentry/vfs/context.go | |
parent | 007707a0726602bc99fc0dccaf2994ad967b9d96 (diff) |
Implement memmap.MappingIdentity for vfs.FileDescription.
PiperOrigin-RevId: 285255855
Diffstat (limited to 'pkg/sentry/vfs/context.go')
-rw-r--r-- | pkg/sentry/vfs/context.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/pkg/sentry/vfs/context.go b/pkg/sentry/vfs/context.go index 32cf9151b..705194ebc 100644 --- a/pkg/sentry/vfs/context.go +++ b/pkg/sentry/vfs/context.go @@ -24,6 +24,9 @@ type contextID int const ( // CtxMountNamespace is a Context.Value key for a MountNamespace. CtxMountNamespace contextID = iota + + // CtxRoot is a Context.Value key for a VFS root. + CtxRoot ) // MountNamespaceFromContext returns the MountNamespace used by ctx. It does @@ -35,3 +38,13 @@ func MountNamespaceFromContext(ctx context.Context) *MountNamespace { } return nil } + +// RootFromContext returns the VFS root used by ctx. It takes a reference on +// the returned VirtualDentry. If ctx does not have a specific VFS root, +// RootFromContext returns a zero-value VirtualDentry. +func RootFromContext(ctx context.Context) VirtualDentry { + if v := ctx.Value(CtxRoot); v != nil { + return v.(VirtualDentry) + } + return VirtualDentry{} +} |