diff options
author | Ayush Ranjan <ayushranjan@google.com> | 2019-07-30 19:42:50 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2019-07-30 19:43:59 -0700 |
commit | 5afa642deb190dbacee225d05f58de69f775d3f3 (patch) | |
tree | a086d06ea3193f72770f5ca7620dfc8979e9d531 /pkg/sentry/fs/ext/regular_file.go | |
parent | 9fbe984dc13f1af42bf3a73b696f7358794dd2d4 (diff) |
ext: Migrate from using fileReader custom interface to using io.Reader.
It gets rid of holding state of the io.Reader offset (which is anyways held by
the vfs.FileDescriptor struct. It is also odd using a io.Reader becuase we
using io.ReaderAt to interact with the device. So making a io.ReaderAt wrapper
makes more sense.
Most importantly, it gets rid of the complexity of extracting the file reader
from a regular file implementation and then using it. Now we can just use the
regular file implementation as a reader which is more intuitive.
PiperOrigin-RevId: 260846927
Diffstat (limited to 'pkg/sentry/fs/ext/regular_file.go')
-rw-r--r-- | pkg/sentry/fs/ext/regular_file.go | 22 |
1 files changed, 4 insertions, 18 deletions
diff --git a/pkg/sentry/fs/ext/regular_file.go b/pkg/sentry/fs/ext/regular_file.go index b48f61795..fb1bd38ef 100644 --- a/pkg/sentry/fs/ext/regular_file.go +++ b/pkg/sentry/fs/ext/regular_file.go @@ -18,20 +18,6 @@ import ( "io" ) -// fileReader is used to abstact away the complexity of how the file data is -// stored under the hood. Provides a method to get a file reader which can be -// used to read file data without worrying about how it is organized on disk. -type fileReader interface { - - // getFileReader returns a Reader implementation which can be used to read a - // file. It abstracts away the complexity of how the file is actually - // organized on disk. The reader is initialized with the passed offset. - // - // This reader is not meant to be retained across Read operations as it needs - // to be reinitialized with the correct offset for every Read. - getFileReader(dev io.ReaderAt, blkSize uint64, offset uint64) io.Reader -} - // regularFile represents a regular file's inode. This too follows the // inheritance pattern prevelant in the vfs layer described in // pkg/sentry/vfs/README.md. @@ -40,12 +26,12 @@ type regularFile struct { // This is immutable. The first field of fileReader implementations must be // regularFile to ensure temporality. - impl fileReader + impl io.ReaderAt } // newRegularFile is the regularFile constructor. It figures out what kind of // file this is and initializes the fileReader. -func newRegularFile(dev io.ReaderAt, blkSize uint64, inode inode) (*regularFile, error) { +func newRegularFile(inode inode) (*regularFile, error) { regFile := regularFile{ inode: inode, } @@ -53,7 +39,7 @@ func newRegularFile(dev io.ReaderAt, blkSize uint64, inode inode) (*regularFile, inodeFlags := inode.diskInode.Flags() if inodeFlags.Extents { - file, err := newExtentFile(dev, blkSize, regFile) + file, err := newExtentFile(regFile) if err != nil { return nil, err } @@ -72,7 +58,7 @@ func newRegularFile(dev io.ReaderAt, blkSize uint64, inode inode) (*regularFile, return &file.regFile, nil } - file, err := newBlockMapFile(blkSize, regFile) + file, err := newBlockMapFile(regFile) if err != nil { return nil, err } |