diff options
Diffstat (limited to 'pkg/sentry/fs/ramfs')
-rw-r--r-- | pkg/sentry/fs/ramfs/BUILD | 37 | ||||
-rw-r--r-- | pkg/sentry/fs/ramfs/ramfs_state_autogen.go | 170 | ||||
-rw-r--r-- | pkg/sentry/fs/ramfs/tree_test.go | 80 |
3 files changed, 170 insertions, 117 deletions
diff --git a/pkg/sentry/fs/ramfs/BUILD b/pkg/sentry/fs/ramfs/BUILD deleted file mode 100644 index 8ca823fb3..000000000 --- a/pkg/sentry/fs/ramfs/BUILD +++ /dev/null @@ -1,37 +0,0 @@ -load("//tools:defs.bzl", "go_library", "go_test") - -package(licenses = ["notice"]) - -go_library( - name = "ramfs", - srcs = [ - "dir.go", - "socket.go", - "symlink.go", - "tree.go", - ], - visibility = ["//pkg/sentry:internal"], - deps = [ - "//pkg/abi/linux", - "//pkg/context", - "//pkg/sentry/fs", - "//pkg/sentry/fs/anon", - "//pkg/sentry/fs/fsutil", - "//pkg/sentry/socket/unix/transport", - "//pkg/sync", - "//pkg/syserror", - "//pkg/usermem", - "//pkg/waiter", - ], -) - -go_test( - name = "ramfs_test", - size = "small", - srcs = ["tree_test.go"], - library = ":ramfs", - deps = [ - "//pkg/sentry/contexttest", - "//pkg/sentry/fs", - ], -) diff --git a/pkg/sentry/fs/ramfs/ramfs_state_autogen.go b/pkg/sentry/fs/ramfs/ramfs_state_autogen.go new file mode 100644 index 000000000..bfa355c84 --- /dev/null +++ b/pkg/sentry/fs/ramfs/ramfs_state_autogen.go @@ -0,0 +1,170 @@ +// automatically generated by stateify. + +package ramfs + +import ( + "gvisor.dev/gvisor/pkg/state" +) + +func (x *Dir) StateTypeName() string { + return "pkg/sentry/fs/ramfs.Dir" +} + +func (x *Dir) StateFields() []string { + return []string{ + "InodeSimpleAttributes", + "InodeSimpleExtendedAttributes", + "children", + "dentryMap", + } +} + +func (x *Dir) beforeSave() {} + +func (x *Dir) StateSave(m state.Sink) { + x.beforeSave() + m.Save(0, &x.InodeSimpleAttributes) + m.Save(1, &x.InodeSimpleExtendedAttributes) + m.Save(2, &x.children) + m.Save(3, &x.dentryMap) +} + +func (x *Dir) afterLoad() {} + +func (x *Dir) StateLoad(m state.Source) { + m.Load(0, &x.InodeSimpleAttributes) + m.Load(1, &x.InodeSimpleExtendedAttributes) + m.Load(2, &x.children) + m.Load(3, &x.dentryMap) +} + +func (x *dirFileOperations) StateTypeName() string { + return "pkg/sentry/fs/ramfs.dirFileOperations" +} + +func (x *dirFileOperations) StateFields() []string { + return []string{ + "dirCursor", + "dir", + } +} + +func (x *dirFileOperations) beforeSave() {} + +func (x *dirFileOperations) StateSave(m state.Sink) { + x.beforeSave() + m.Save(0, &x.dirCursor) + m.Save(1, &x.dir) +} + +func (x *dirFileOperations) afterLoad() {} + +func (x *dirFileOperations) StateLoad(m state.Source) { + m.Load(0, &x.dirCursor) + m.Load(1, &x.dir) +} + +func (x *Socket) StateTypeName() string { + return "pkg/sentry/fs/ramfs.Socket" +} + +func (x *Socket) StateFields() []string { + return []string{ + "InodeSimpleAttributes", + "InodeSimpleExtendedAttributes", + "ep", + } +} + +func (x *Socket) beforeSave() {} + +func (x *Socket) StateSave(m state.Sink) { + x.beforeSave() + m.Save(0, &x.InodeSimpleAttributes) + m.Save(1, &x.InodeSimpleExtendedAttributes) + m.Save(2, &x.ep) +} + +func (x *Socket) afterLoad() {} + +func (x *Socket) StateLoad(m state.Source) { + m.Load(0, &x.InodeSimpleAttributes) + m.Load(1, &x.InodeSimpleExtendedAttributes) + m.Load(2, &x.ep) +} + +func (x *socketFileOperations) StateTypeName() string { + return "pkg/sentry/fs/ramfs.socketFileOperations" +} + +func (x *socketFileOperations) StateFields() []string { + return []string{} +} + +func (x *socketFileOperations) beforeSave() {} + +func (x *socketFileOperations) StateSave(m state.Sink) { + x.beforeSave() +} + +func (x *socketFileOperations) afterLoad() {} + +func (x *socketFileOperations) StateLoad(m state.Source) { +} + +func (x *Symlink) StateTypeName() string { + return "pkg/sentry/fs/ramfs.Symlink" +} + +func (x *Symlink) StateFields() []string { + return []string{ + "InodeSimpleAttributes", + "InodeSimpleExtendedAttributes", + "Target", + } +} + +func (x *Symlink) beforeSave() {} + +func (x *Symlink) StateSave(m state.Sink) { + x.beforeSave() + m.Save(0, &x.InodeSimpleAttributes) + m.Save(1, &x.InodeSimpleExtendedAttributes) + m.Save(2, &x.Target) +} + +func (x *Symlink) afterLoad() {} + +func (x *Symlink) StateLoad(m state.Source) { + m.Load(0, &x.InodeSimpleAttributes) + m.Load(1, &x.InodeSimpleExtendedAttributes) + m.Load(2, &x.Target) +} + +func (x *symlinkFileOperations) StateTypeName() string { + return "pkg/sentry/fs/ramfs.symlinkFileOperations" +} + +func (x *symlinkFileOperations) StateFields() []string { + return []string{} +} + +func (x *symlinkFileOperations) beforeSave() {} + +func (x *symlinkFileOperations) StateSave(m state.Sink) { + x.beforeSave() +} + +func (x *symlinkFileOperations) afterLoad() {} + +func (x *symlinkFileOperations) StateLoad(m state.Source) { +} + +func init() { + state.Register((*Dir)(nil)) + state.Register((*dirFileOperations)(nil)) + state.Register((*Socket)(nil)) + state.Register((*socketFileOperations)(nil)) + state.Register((*Symlink)(nil)) + state.Register((*symlinkFileOperations)(nil)) +} diff --git a/pkg/sentry/fs/ramfs/tree_test.go b/pkg/sentry/fs/ramfs/tree_test.go deleted file mode 100644 index 3e0d1e07e..000000000 --- a/pkg/sentry/fs/ramfs/tree_test.go +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2018 The gVisor Authors. -// -// 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 ramfs - -import ( - "testing" - - "gvisor.dev/gvisor/pkg/sentry/contexttest" - "gvisor.dev/gvisor/pkg/sentry/fs" -) - -func TestMakeDirectoryTree(t *testing.T) { - - for _, test := range []struct { - name string - subdirs []string - }{ - { - name: "abs paths", - subdirs: []string{ - "/tmp", - "/tmp/a/b", - "/tmp/a/c/d", - "/tmp/c", - "/proc", - "/dev/a/b", - "/tmp", - }, - }, - { - name: "rel paths", - subdirs: []string{ - "tmp", - "tmp/a/b", - "tmp/a/c/d", - "tmp/c", - "proc", - "dev/a/b", - "tmp", - }, - }, - } { - ctx := contexttest.Context(t) - mount := fs.NewPseudoMountSource(ctx) - tree, err := MakeDirectoryTree(ctx, mount, test.subdirs) - if err != nil { - t.Errorf("%s: failed to make ramfs tree, got error %v, want nil", test.name, err) - continue - } - - // Expect to be able to find each of the paths. - mm, err := fs.NewMountNamespace(ctx, tree) - if err != nil { - t.Errorf("%s: failed to create mount manager: %v", test.name, err) - continue - } - root := mm.Root() - defer mm.DecRef(ctx) - - for _, p := range test.subdirs { - maxTraversals := uint(0) - if _, err := mm.FindInode(ctx, root, nil, p, &maxTraversals); err != nil { - t.Errorf("%s: failed to find node %s: %v", test.name, p, err) - break - } - } - } -} |