mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Implement Seek in verity fs
PiperOrigin-RevId: 338847417
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user