summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/fs/ext/inode.go
diff options
context:
space:
mode:
authorAyush Ranjan <ayushranjan@google.com>2019-07-30 19:42:50 -0700
committergVisor bot <gvisor-bot@google.com>2019-07-30 19:43:59 -0700
commit5afa642deb190dbacee225d05f58de69f775d3f3 (patch)
treea086d06ea3193f72770f5ca7620dfc8979e9d531 /pkg/sentry/fs/ext/inode.go
parent9fbe984dc13f1af42bf3a73b696f7358794dd2d4 (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/inode.go')
-rw-r--r--pkg/sentry/fs/ext/inode.go24
1 files changed, 16 insertions, 8 deletions
diff --git a/pkg/sentry/fs/ext/inode.go b/pkg/sentry/fs/ext/inode.go
index 00e022953..364980e4c 100644
--- a/pkg/sentry/fs/ext/inode.go
+++ b/pkg/sentry/fs/ext/inode.go
@@ -46,6 +46,12 @@ type inode struct {
// identify inodes within the ext filesystem.
inodeNum uint32
+ // dev represents the underlying device. Same as filesystem.dev.
+ dev io.ReaderAt
+
+ // blkSize is the fs data block size. Same as filesystem.sb.BlockSize().
+ blkSize uint64
+
// diskInode gives us access to the inode struct on disk. Immutable.
diskInode disklayout.Inode
@@ -86,12 +92,12 @@ func (in *inode) decRef(fs *filesystem) {
// newInode is the inode constructor. Reads the inode off disk. Identifies
// inodes based on the absolute inode number on disk.
-func newInode(ctx context.Context, dev io.ReaderAt, sb disklayout.SuperBlock, bgs []disklayout.BlockGroup, inodeNum uint32) (*inode, error) {
+func newInode(ctx context.Context, fs *filesystem, inodeNum uint32) (*inode, error) {
if inodeNum == 0 {
panic("inode number 0 on ext filesystems is not possible")
}
- inodeRecordSize := sb.InodeSize()
+ inodeRecordSize := fs.sb.InodeSize()
var diskInode disklayout.Inode
if inodeRecordSize == disklayout.OldInodeSize {
diskInode = &disklayout.InodeOld{}
@@ -100,12 +106,12 @@ func newInode(ctx context.Context, dev io.ReaderAt, sb disklayout.SuperBlock, bg
}
// Calculate where the inode is actually placed.
- inodesPerGrp := sb.InodesPerGroup()
- blkSize := sb.BlockSize()
- inodeTableOff := bgs[getBGNum(inodeNum, inodesPerGrp)].InodeTable() * blkSize
+ inodesPerGrp := fs.sb.InodesPerGroup()
+ blkSize := fs.sb.BlockSize()
+ inodeTableOff := fs.bgs[getBGNum(inodeNum, inodesPerGrp)].InodeTable() * blkSize
inodeOff := inodeTableOff + uint64(uint32(inodeRecordSize)*getBGOff(inodeNum, inodesPerGrp))
- if err := readFromDisk(dev, int64(inodeOff), diskInode); err != nil {
+ if err := readFromDisk(fs.dev, int64(inodeOff), diskInode); err != nil {
return nil, err
}
@@ -113,18 +119,20 @@ func newInode(ctx context.Context, dev io.ReaderAt, sb disklayout.SuperBlock, bg
inode := inode{
refs: 1,
inodeNum: inodeNum,
+ dev: fs.dev,
+ blkSize: blkSize,
diskInode: diskInode,
}
switch diskInode.Mode().FileType() {
case linux.ModeSymlink:
- f, err := newSymlink(dev, blkSize, inode)
+ f, err := newSymlink(inode)
if err != nil {
return nil, err
}
return &f.inode, nil
case linux.ModeRegular:
- f, err := newRegularFile(dev, blkSize, inode)
+ f, err := newRegularFile(inode)
if err != nil {
return nil, err
}