From 6b69b955d7613ff391984661a7269eabc86020e3 Mon Sep 17 00:00:00 2001 From: Dean Deng Date: Fri, 19 Jun 2020 06:37:40 -0700 Subject: Support all seek options in gofer specialFileFD.Seek. Updates #2923. PiperOrigin-RevId: 317298186 --- pkg/sentry/fsimpl/gofer/special_file.go | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'pkg/sentry/fsimpl/gofer/special_file.go') diff --git a/pkg/sentry/fsimpl/gofer/special_file.go b/pkg/sentry/fsimpl/gofer/special_file.go index e6e29b329..a92008208 100644 --- a/pkg/sentry/fsimpl/gofer/special_file.go +++ b/pkg/sentry/fsimpl/gofer/special_file.go @@ -221,21 +221,12 @@ func (fd *specialFileFD) Seek(ctx context.Context, offset int64, whence int32) ( } fd.mu.Lock() defer fd.mu.Unlock() - switch whence { - case linux.SEEK_SET: - // Use offset as given. - case linux.SEEK_CUR: - offset += fd.off - default: - // SEEK_END, SEEK_DATA, and SEEK_HOLE aren't supported since it's not - // clear that file size is even meaningful for these files. - return 0, syserror.EINVAL - } - if offset < 0 { - return 0, syserror.EINVAL + newOffset, err := regularFileSeekLocked(ctx, fd.dentry(), fd.off, offset, whence) + if err != nil { + return 0, err } - fd.off = offset - return offset, nil + fd.off = newOffset + return newOffset, nil } // Sync implements vfs.FileDescriptionImpl.Sync. -- cgit v1.2.3