2019-04-29 21:25:05 +00:00
|
|
|
// Copyright 2018 The gVisor Authors.
|
2018-04-27 17:37:02 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
// Package anon implements an anonymous inode, useful for implementing
|
|
|
|
// inodes for pseudo filesystems.
|
|
|
|
package anon
|
|
|
|
|
|
|
|
import (
|
2019-06-13 23:49:09 +00:00
|
|
|
"gvisor.dev/gvisor/pkg/abi/linux"
|
|
|
|
"gvisor.dev/gvisor/pkg/sentry/context"
|
|
|
|
"gvisor.dev/gvisor/pkg/sentry/fs"
|
|
|
|
"gvisor.dev/gvisor/pkg/sentry/fs/fsutil"
|
|
|
|
"gvisor.dev/gvisor/pkg/sentry/usermem"
|
2018-04-27 17:37:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// NewInode constructs an anonymous Inode that is not associated
|
|
|
|
// with any real filesystem. Some types depend on completely pseudo
|
|
|
|
// "anon" inodes (eventfds, epollfds, etc).
|
|
|
|
func NewInode(ctx context.Context) *fs.Inode {
|
2019-01-15 04:33:29 +00:00
|
|
|
iops := &fsutil.SimpleFileInode{
|
|
|
|
InodeSimpleAttributes: fsutil.NewInodeSimpleAttributes(ctx, fs.RootOwner, fs.FilePermissions{
|
|
|
|
User: fs.PermMask{Read: true, Write: true},
|
|
|
|
}, linux.ANON_INODE_FS_MAGIC),
|
|
|
|
}
|
2019-06-14 01:39:43 +00:00
|
|
|
return fs.NewInode(ctx, iops, fs.NewPseudoMountSource(ctx), fs.StableAttr{
|
2018-04-27 17:37:02 +00:00
|
|
|
Type: fs.Anonymous,
|
|
|
|
DeviceID: PseudoDevice.DeviceID(),
|
|
|
|
InodeID: PseudoDevice.NextIno(),
|
|
|
|
BlockSize: usermem.PageSize,
|
|
|
|
})
|
|
|
|
}
|