summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/fs/ext/utils.go
diff options
context:
space:
mode:
authorAyush Ranjan <ayushranjan@google.com>2019-07-29 19:16:07 -0700
committergVisor bot <gvisor-bot@google.com>2019-07-29 19:17:27 -0700
commitddf25e3331a18a74d0e01d74fee7f82963fe778c (patch)
treecdf7054d670703d929b01761012823adc69e90a0 /pkg/sentry/fs/ext/utils.go
parentb765eb45894ea426d2c6d167b6ceb662db6ff4d2 (diff)
ext: extent reader implementation.
PiperOrigin-RevId: 260629559
Diffstat (limited to 'pkg/sentry/fs/ext/utils.go')
-rw-r--r--pkg/sentry/fs/ext/utils.go17
1 files changed, 17 insertions, 0 deletions
diff --git a/pkg/sentry/fs/ext/utils.go b/pkg/sentry/fs/ext/utils.go
index 8790c7778..7c33919e0 100644
--- a/pkg/sentry/fs/ext/utils.go
+++ b/pkg/sentry/fs/ext/utils.go
@@ -41,6 +41,23 @@ func readFromDisk(dev io.ReadSeeker, abOff int64, v interface{}) error {
return nil
}
+// readFull is a wrapper around io.ReadFull which enforces the absolute offset
+// parameter so that we can ensure that we do not perform incorrect reads from
+// stale previously used offsets.
+//
+// Precondition: Must hold the mutex of the filesystem containing dev.
+func readFull(dev io.ReadSeeker, abOff int64, dst []byte) (int, error) {
+ if _, err := dev.Seek(abOff, io.SeekStart); err != nil {
+ return 0, syserror.EIO
+ }
+
+ n, err := io.ReadFull(dev, dst)
+ if err != nil {
+ err = syserror.EIO
+ }
+ return n, err
+}
+
// readSuperBlock reads the SuperBlock from block group 0 in the underlying
// device. There are three versions of the superblock. This function identifies
// and returns the correct version.