summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/fs/sys/devices.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/sentry/fs/sys/devices.go')
-rw-r--r--pkg/sentry/fs/sys/devices.go51
1 files changed, 29 insertions, 22 deletions
diff --git a/pkg/sentry/fs/sys/devices.go b/pkg/sentry/fs/sys/devices.go
index e64aa0edc..8b728a4e4 100644
--- a/pkg/sentry/fs/sys/devices.go
+++ b/pkg/sentry/fs/sys/devices.go
@@ -16,43 +16,50 @@ package sys
import (
"fmt"
- "io"
+ "gvisor.googlesource.com/gvisor/pkg/abi/linux"
"gvisor.googlesource.com/gvisor/pkg/sentry/context"
"gvisor.googlesource.com/gvisor/pkg/sentry/fs"
- "gvisor.googlesource.com/gvisor/pkg/sentry/fs/ramfs"
+ "gvisor.googlesource.com/gvisor/pkg/sentry/fs/fsutil"
"gvisor.googlesource.com/gvisor/pkg/sentry/kernel"
- "gvisor.googlesource.com/gvisor/pkg/sentry/usermem"
- "gvisor.googlesource.com/gvisor/pkg/syserror"
)
// +stateify savable
type cpunum struct {
- ramfs.Entry
+ fsutil.InodeGenericChecker `state:"nosave"`
+ fsutil.InodeNoExtendedAttributes `state:"nosave"`
+ fsutil.InodeNoopRelease `state:"nosave"`
+ fsutil.InodeNoopWriteOut `state:"nosave"`
+ fsutil.InodeNotDirectory `state:"nosave"`
+ fsutil.InodeNotMappable `state:"nosave"`
+ fsutil.InodeNotSocket `state:"nosave"`
+ fsutil.InodeNotSymlink `state:"nosave"`
+ fsutil.InodeNotVirtual `state:"nosave"`
+ fsutil.InodeNotTruncatable `state:"nosave"`
+
+ fsutil.InodeSimpleAttributes
+ fsutil.InodeStaticFileGetter
+
+ // k is the system kernel.
+ k *kernel.Kernel
}
-func (c *cpunum) DeprecatedPreadv(ctx context.Context, dst usermem.IOSequence, offset int64) (int64, error) {
- if offset < 0 {
- return 0, syserror.EINVAL
- }
+var _ fs.InodeOperations = (*cpunum)(nil)
+func newPossible(ctx context.Context, msrc *fs.MountSource) *fs.Inode {
+ var maxCore uint
k := kernel.KernelFromContext(ctx)
- if k == nil {
- return 0, io.EOF
+ if k != nil {
+ maxCore = k.ApplicationCores() - 1
}
+ contents := []byte(fmt.Sprintf("0-%d\n", maxCore))
- str := []byte(fmt.Sprintf("0-%d\n", k.ApplicationCores()-1))
- if offset >= int64(len(str)) {
- return 0, io.EOF
+ c := &cpunum{
+ InodeSimpleAttributes: fsutil.NewInodeSimpleAttributes(ctx, fs.RootOwner, fs.FilePermsFromMode(0444), linux.SYSFS_MAGIC),
+ InodeStaticFileGetter: fsutil.InodeStaticFileGetter{
+ Contents: contents,
+ },
}
-
- n, err := dst.CopyOut(ctx, str[offset:])
- return int64(n), err
-}
-
-func newPossible(ctx context.Context, msrc *fs.MountSource) *fs.Inode {
- c := &cpunum{}
- c.InitEntry(ctx, fs.RootOwner, fs.FilePermsFromMode(0444))
return newFile(c, msrc)
}