diff options
Diffstat (limited to 'pkg/sentry/fs')
-rw-r--r-- | pkg/sentry/fs/dev/null.go | 1 | ||||
-rw-r--r-- | pkg/sentry/fs/file.go | 4 | ||||
-rw-r--r-- | pkg/sentry/fs/flags.go | 3 | ||||
-rwxr-xr-x | pkg/sentry/fs/fs_state_autogen.go | 2 |
4 files changed, 8 insertions, 2 deletions
diff --git a/pkg/sentry/fs/dev/null.go b/pkg/sentry/fs/dev/null.go index 18dd08515..4404b97ef 100644 --- a/pkg/sentry/fs/dev/null.go +++ b/pkg/sentry/fs/dev/null.go @@ -97,6 +97,7 @@ func newZeroDevice(ctx context.Context, owner fs.FileOwner, mode linux.FileMode) func (zd *zeroDevice) GetFile(ctx context.Context, dirent *fs.Dirent, flags fs.FileFlags) (*fs.File, error) { flags.Pread = true flags.Pwrite = true + flags.NonSeekable = true return fs.NewFile(ctx, dirent, flags, &zeroFileOperations{}), nil } diff --git a/pkg/sentry/fs/file.go b/pkg/sentry/fs/file.go index 6df7d7b4f..55ffe6c0c 100644 --- a/pkg/sentry/fs/file.go +++ b/pkg/sentry/fs/file.go @@ -267,7 +267,7 @@ func (f *File) Readv(ctx context.Context, dst usermem.IOSequence) (int64, error) reads.Increment() n, err := f.FileOperations.Read(ctx, f, dst, f.offset) - if n > 0 { + if n > 0 && !f.flags.NonSeekable { atomic.AddInt64(&f.offset, n) } f.mu.Unlock() @@ -330,7 +330,7 @@ func (f *File) Writev(ctx context.Context, src usermem.IOSequence) (int64, error // We must hold the lock during the write. n, err := f.FileOperations.Write(ctx, f, src, f.offset) - if n >= 0 { + if n >= 0 && !f.flags.NonSeekable { atomic.StoreInt64(&f.offset, f.offset+n) } f.mu.Unlock() diff --git a/pkg/sentry/fs/flags.go b/pkg/sentry/fs/flags.go index f31bfa0db..1278f9c78 100644 --- a/pkg/sentry/fs/flags.go +++ b/pkg/sentry/fs/flags.go @@ -57,6 +57,9 @@ type FileFlags struct { // Linux sets this flag for all files. Since gVisor is only compatible // with 64-bit Linux, it also sets this flag for all files. LargeFile bool + + // NonSeekable indicates that file.offset isn't used. + NonSeekable bool } // SettableFileFlags is a subset of FileFlags above that can be changed diff --git a/pkg/sentry/fs/fs_state_autogen.go b/pkg/sentry/fs/fs_state_autogen.go index f547ccd0f..5aa800be4 100755 --- a/pkg/sentry/fs/fs_state_autogen.go +++ b/pkg/sentry/fs/fs_state_autogen.go @@ -353,6 +353,7 @@ func (x *FileFlags) save(m state.Map) { m.Save("Directory", &x.Directory) m.Save("Async", &x.Async) m.Save("LargeFile", &x.LargeFile) + m.Save("NonSeekable", &x.NonSeekable) } func (x *FileFlags) afterLoad() {} @@ -368,6 +369,7 @@ func (x *FileFlags) load(m state.Map) { m.Load("Directory", &x.Directory) m.Load("Async", &x.Async) m.Load("LargeFile", &x.LargeFile) + m.Load("NonSeekable", &x.NonSeekable) } func (x *Inode) beforeSave() {} |