summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/fs/ext/ext.go
diff options
context:
space:
mode:
authorAyush Ranjan <ayushranjan@google.com>2019-07-17 14:46:57 -0700
committergVisor bot <gvisor-bot@google.com>2019-07-17 14:48:04 -0700
commit8e3e021aca89427381af75a47f19b1fe78bf132e (patch)
tree030a8863bf5dace84d5aac3ea8e5063645837893 /pkg/sentry/fs/ext/ext.go
parent609cd91e3fc3359af263b52f494116ddbc800f77 (diff)
ext: Filesystem init implementation.
PiperOrigin-RevId: 258645957
Diffstat (limited to 'pkg/sentry/fs/ext/ext.go')
-rw-r--r--pkg/sentry/fs/ext/ext.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/pkg/sentry/fs/ext/ext.go b/pkg/sentry/fs/ext/ext.go
index 7602e2bf0..9d33be08f 100644
--- a/pkg/sentry/fs/ext/ext.go
+++ b/pkg/sentry/fs/ext/ext.go
@@ -19,7 +19,9 @@ import (
"io"
"sync"
+ "gvisor.dev/gvisor/pkg/abi/linux"
"gvisor.dev/gvisor/pkg/sentry/fs/ext/disklayout"
+ "gvisor.dev/gvisor/pkg/syserror"
)
// Filesystem implements vfs.FilesystemImpl.
@@ -47,3 +49,27 @@ type Filesystem struct {
// Immutable after initialization.
bgs []disklayout.BlockGroup
}
+
+// newFilesystem is the Filesystem constructor.
+func newFilesystem(dev io.ReadSeeker) (*Filesystem, error) {
+ fs := Filesystem{dev: dev}
+ var err error
+
+ fs.sb, err = readSuperBlock(dev)
+ if err != nil {
+ return nil, err
+ }
+
+ if fs.sb.Magic() != linux.EXT_SUPER_MAGIC {
+ // mount(2) specifies that EINVAL should be returned if the superblock is
+ // invalid.
+ return nil, syserror.EINVAL
+ }
+
+ fs.bgs, err = readBlockGroups(dev, fs.sb)
+ if err != nil {
+ return nil, err
+ }
+
+ return &fs, nil
+}