summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/fs/ext/disklayout
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/disklayout
parent609cd91e3fc3359af263b52f494116ddbc800f77 (diff)
ext: Filesystem init implementation.
PiperOrigin-RevId: 258645957
Diffstat (limited to 'pkg/sentry/fs/ext/disklayout')
-rw-r--r--pkg/sentry/fs/ext/disklayout/block_group.go10
-rw-r--r--pkg/sentry/fs/ext/disklayout/superblock.go9
-rw-r--r--pkg/sentry/fs/ext/disklayout/superblock_old.go3
3 files changed, 19 insertions, 3 deletions
diff --git a/pkg/sentry/fs/ext/disklayout/block_group.go b/pkg/sentry/fs/ext/disklayout/block_group.go
index 32ea3d97d..ad6f4fef8 100644
--- a/pkg/sentry/fs/ext/disklayout/block_group.go
+++ b/pkg/sentry/fs/ext/disklayout/block_group.go
@@ -18,6 +18,16 @@ package disklayout
// is split into a series of block groups. This provides an access layer to
// information needed to access and use a block group.
//
+// Location:
+// - The block group descriptor table is always placed in the blocks
+// immediately after the block containing the superblock.
+// - The 1st block group descriptor in the original table is in the
+// (sb.FirstDataBlock() + 1)th block.
+// - See SuperBlock docs to see where the block group descriptor table is
+// replicated.
+// - sb.BgDescSize() must be used as the block group descriptor entry size
+// while reading the table from disk.
+//
// See https://www.kernel.org/doc/html/latest/filesystems/ext4/globals.html#block-group-descriptors.
type BlockGroup interface {
// InodeTable returns the absolute block number of the block containing the
diff --git a/pkg/sentry/fs/ext/disklayout/superblock.go b/pkg/sentry/fs/ext/disklayout/superblock.go
index e4b8f46fb..7a337a5e0 100644
--- a/pkg/sentry/fs/ext/disklayout/superblock.go
+++ b/pkg/sentry/fs/ext/disklayout/superblock.go
@@ -14,6 +14,11 @@
package disklayout
+const (
+ // SbOffset is the absolute offset at which the superblock is placed.
+ SbOffset = 1024
+)
+
// SuperBlock should be implemented by structs representing the ext superblock.
// The superblock holds a lot of information about the enclosing filesystem.
// This interface aims to provide access methods to important information held
@@ -57,8 +62,6 @@ type SuperBlock interface {
//
// If the filesystem has 1kb data blocks then this should return 1. For all
// other configurations, this typically returns 0.
- //
- // The first block group descriptor is in (FirstDataBlock() + 1)th block.
FirstDataBlock() uint32
// BlockSize returns the size of one data block in this filesystem.
@@ -128,7 +131,7 @@ type SuperBlock interface {
}
// SbRevision is the type for superblock revisions.
-type SbRevision int
+type SbRevision uint32
// Super block revisions.
const (
diff --git a/pkg/sentry/fs/ext/disklayout/superblock_old.go b/pkg/sentry/fs/ext/disklayout/superblock_old.go
index c74953610..aada8b550 100644
--- a/pkg/sentry/fs/ext/disklayout/superblock_old.go
+++ b/pkg/sentry/fs/ext/disklayout/superblock_old.go
@@ -44,6 +44,9 @@ type SuperBlockOld struct {
DefResGID uint16
}
+// Compiles only if SuperBlockOld implements SuperBlock.
+var _ SuperBlock = (*SuperBlockOld)(nil)
+
// InodesCount implements SuperBlock.InodesCount.
func (sb *SuperBlockOld) InodesCount() uint32 { return sb.InodesCountRaw }