Implement Seek in verity fs

PiperOrigin-RevId: 338847417
This commit is contained in:
Chong Cai
2020-10-24 12:03:44 -07:00
committed by gVisor bot
parent 4feb5c7c26
commit 73a1863538
2 changed files with 31 additions and 2 deletions
+1
View File
@@ -365,6 +365,7 @@ func (fs *filesystem) verifyStat(ctx context.Context, d *dentry, stat linux.Stat
d.mode = uint32(stat.Mode)
d.uid = stat.UID
d.gid = stat.GID
d.size = uint32(size)
return nil
}
+30 -2
View File
@@ -23,6 +23,7 @@ package verity
import (
"fmt"
"math"
"strconv"
"sync/atomic"
@@ -290,11 +291,12 @@ type dentry struct {
// fs is the owning filesystem. fs is immutable.
fs *filesystem
// mode, uid and gid are the file mode, owner, and group of the file in
// the underlying file system.
// mode, uid, gid and size are the file mode, owner, group, and size of
// the file in the underlying file system.
mode uint32
uid uint32
gid uint32
size uint32
// parent is the dentry corresponding to this dentry's parent directory.
// name is this dentry's name in parent. If this dentry is a filesystem
@@ -550,6 +552,32 @@ func (fd *fileDescription) SetStat(ctx context.Context, opts vfs.SetStatOptions)
return syserror.EPERM
}
// Seek implements vfs.FileDescriptionImpl.Seek.
func (fd *fileDescription) Seek(ctx context.Context, offset int64, whence int32) (int64, error) {
fd.mu.Lock()
defer fd.mu.Unlock()
n := int64(0)
switch whence {
case linux.SEEK_SET:
// use offset as specified
case linux.SEEK_CUR:
n = fd.off
case linux.SEEK_END:
n = int64(fd.d.size)
default:
return 0, syserror.EINVAL
}
if offset > math.MaxInt64-n {
return 0, syserror.EINVAL
}
offset += n
if offset < 0 {
return 0, syserror.EINVAL
}
fd.off = offset
return offset, nil
}
// generateMerkle generates a Merkle tree file for fd. If fd points to a file
// /foo/bar, a Merkle tree file /foo/.merkle.verity.bar is generated. The hash
// of the generated Merkle tree and the data size is returned. If fd points to