summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/fs/sys
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/sentry/fs/sys')
-rw-r--r--pkg/sentry/fs/sys/BUILD3
-rw-r--r--pkg/sentry/fs/sys/devices.go51
-rw-r--r--pkg/sentry/fs/sys/fs.go2
-rw-r--r--pkg/sentry/fs/sys/sys.go10
4 files changed, 34 insertions, 32 deletions
diff --git a/pkg/sentry/fs/sys/BUILD b/pkg/sentry/fs/sys/BUILD
index 5ba23d5da..7de928e16 100644
--- a/pkg/sentry/fs/sys/BUILD
+++ b/pkg/sentry/fs/sys/BUILD
@@ -13,12 +13,13 @@ go_library(
importpath = "gvisor.googlesource.com/gvisor/pkg/sentry/fs/sys",
visibility = ["//pkg/sentry:internal"],
deps = [
+ "//pkg/abi/linux",
"//pkg/sentry/context",
"//pkg/sentry/device",
"//pkg/sentry/fs",
+ "//pkg/sentry/fs/fsutil",
"//pkg/sentry/fs/ramfs",
"//pkg/sentry/kernel",
"//pkg/sentry/usermem",
- "//pkg/syserror",
],
)
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)
}
diff --git a/pkg/sentry/fs/sys/fs.go b/pkg/sentry/fs/sys/fs.go
index 5ce33f87f..301fef038 100644
--- a/pkg/sentry/fs/sys/fs.go
+++ b/pkg/sentry/fs/sys/fs.go
@@ -24,6 +24,8 @@ import (
// +stateify savable
type filesystem struct{}
+var _ fs.Filesystem = (*filesystem)(nil)
+
func init() {
fs.RegisterFilesystem(&filesystem{})
}
diff --git a/pkg/sentry/fs/sys/sys.go b/pkg/sentry/fs/sys/sys.go
index 7cc1942c7..c5b56fe69 100644
--- a/pkg/sentry/fs/sys/sys.go
+++ b/pkg/sentry/fs/sys/sys.go
@@ -22,13 +22,6 @@ import (
"gvisor.googlesource.com/gvisor/pkg/sentry/usermem"
)
-// sys is a root sys node.
-//
-// +stateify savable
-type sys struct {
- ramfs.Dir
-}
-
func newFile(node fs.InodeOperations, msrc *fs.MountSource) *fs.Inode {
sattr := fs.StableAttr{
DeviceID: sysfsDevice.DeviceID(),
@@ -40,8 +33,7 @@ func newFile(node fs.InodeOperations, msrc *fs.MountSource) *fs.Inode {
}
func newDir(ctx context.Context, msrc *fs.MountSource, contents map[string]*fs.Inode) *fs.Inode {
- d := &sys{}
- d.InitDir(ctx, contents, fs.RootOwner, fs.FilePermsFromMode(0555))
+ d := ramfs.NewDir(ctx, contents, fs.RootOwner, fs.FilePermsFromMode(0555))
return fs.NewInode(d, msrc, fs.StableAttr{
DeviceID: sysfsDevice.DeviceID(),
InodeID: sysfsDevice.NextIno(),