summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/fs/inode_overlay_test.go
diff options
context:
space:
mode:
authorNicolas Lacasse <nlacasse@google.com>2019-01-14 20:33:29 -0800
committerShentubot <shentubot@google.com>2019-01-14 20:34:28 -0800
commitdc8450b5676d4c4ac9bcfa23cabd862e0060527d (patch)
treea4ef1ad59764f46f674b7003221ba8ae399b9e65 /pkg/sentry/fs/inode_overlay_test.go
parent343ebe9789087b099ea7feae19879f5c24e59bf1 (diff)
Remove fs.Handle, ramfs.Entry, and all the DeprecatedFileOperations.
More helper structs have been added to the fsutil package to make it easier to implement fs.InodeOperations and fs.FileOperations. PiperOrigin-RevId: 229305982 Change-Id: Ib6f8d3862f4216745116857913dbfa351530223b
Diffstat (limited to 'pkg/sentry/fs/inode_overlay_test.go')
-rw-r--r--pkg/sentry/fs/inode_overlay_test.go62
1 files changed, 53 insertions, 9 deletions
diff --git a/pkg/sentry/fs/inode_overlay_test.go b/pkg/sentry/fs/inode_overlay_test.go
index 9e922d008..bc91be226 100644
--- a/pkg/sentry/fs/inode_overlay_test.go
+++ b/pkg/sentry/fs/inode_overlay_test.go
@@ -19,7 +19,8 @@ import (
"gvisor.googlesource.com/gvisor/pkg/sentry/context"
"gvisor.googlesource.com/gvisor/pkg/sentry/fs"
- ramfstest "gvisor.googlesource.com/gvisor/pkg/sentry/fs/ramfs/test"
+ "gvisor.googlesource.com/gvisor/pkg/sentry/fs/fsutil"
+ "gvisor.googlesource.com/gvisor/pkg/sentry/fs/ramfs"
"gvisor.googlesource.com/gvisor/pkg/sentry/kernel/contexttest"
"gvisor.googlesource.com/gvisor/pkg/syserror"
)
@@ -376,7 +377,8 @@ type dir struct {
// List of negative child names.
negative []string
- // Whether DeprecatedReaddir has been called on this dir.
+ // ReaddirCalled records whether Readdir was called on a file
+ // corresponding to this inode.
ReaddirCalled bool
}
@@ -390,10 +392,19 @@ func (d *dir) Getxattr(inode *fs.Inode, name string) ([]byte, error) {
return nil, syserror.ENOATTR
}
-// DeprecatedReaddir implements InodeOperations.DeprecatedReaddir.
-func (d *dir) DeprecatedReaddir(ctx context.Context, dirctx *fs.DirCtx, offset int) (int, error) {
- d.ReaddirCalled = true
- return d.InodeOperations.DeprecatedReaddir(ctx, dirctx, offset)
+// GetFile implements InodeOperations.GetFile.
+func (d *dir) GetFile(ctx context.Context, dirent *fs.Dirent, flags fs.FileFlags) (*fs.File, error) {
+ file, err := d.InodeOperations.GetFile(ctx, dirent, flags)
+ if err != nil {
+ return nil, err
+ }
+ defer file.DecRef()
+ // Wrap the file's FileOperations in a dirFile.
+ fops := &dirFile{
+ FileOperations: file.FileOperations,
+ inode: d,
+ }
+ return fs.NewFile(ctx, dirent, flags, fops), nil
}
type dirContent struct {
@@ -401,12 +412,45 @@ type dirContent struct {
dir bool
}
+type dirFile struct {
+ fs.FileOperations
+ inode *dir
+}
+
+type inode struct {
+ 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.InodeNotTruncatable `state:"nosave"`
+ fsutil.InodeNotVirtual `state:"nosave"`
+
+ fsutil.InodeSimpleAttributes
+ fsutil.InodeStaticFileGetter
+}
+
+// Readdir implements fs.FileOperations.Readdir. It sets the ReaddirCalled
+// field on the inode.
+func (f *dirFile) Readdir(ctx context.Context, file *fs.File, ser fs.DentrySerializer) (int64, error) {
+ f.inode.ReaddirCalled = true
+ return f.FileOperations.Readdir(ctx, file, ser)
+}
+
func newTestRamfsInode(ctx context.Context, msrc *fs.MountSource) *fs.Inode {
- return fs.NewInode(ramfstest.NewFile(ctx, fs.FilePermissions{}), msrc, fs.StableAttr{Type: fs.RegularFile})
+ inode := fs.NewInode(&inode{
+ InodeStaticFileGetter: fsutil.InodeStaticFileGetter{
+ Contents: []byte("foobar"),
+ },
+ }, msrc, fs.StableAttr{Type: fs.RegularFile})
+ return inode
}
func newTestRamfsDir(ctx context.Context, contains []dirContent, negative []string) *fs.Inode {
- msrc := fs.NewCachingMountSource(nil, fs.MountSourceFlags{})
+ msrc := fs.NewPseudoMountSource()
contents := make(map[string]*fs.Inode)
for _, c := range contains {
if c.dir {
@@ -415,7 +459,7 @@ func newTestRamfsDir(ctx context.Context, contains []dirContent, negative []stri
contents[c.name] = newTestRamfsInode(ctx, msrc)
}
}
- dops := ramfstest.NewDir(ctx, contents, fs.FilePermissions{
+ dops := ramfs.NewDir(ctx, contents, fs.RootOwner, fs.FilePermissions{
User: fs.PermMask{Read: true, Execute: true},
})
return fs.NewInode(&dir{