Seek implements vfs.FileDescriptionImpl.Seek.
(ctx context.Context, offset int64, whence int32)
| 88 | |
| 89 | // Seek implements vfs.FileDescriptionImpl.Seek. |
| 90 | func (fd *regularFileFD) Seek(ctx context.Context, offset int64, whence int32) (int64, error) { |
| 91 | fd.offMu.Lock() |
| 92 | defer fd.offMu.Unlock() |
| 93 | inode := fd.inode() |
| 94 | inode.attrMu.Lock() |
| 95 | defer inode.attrMu.Unlock() |
| 96 | switch whence { |
| 97 | case linux.SEEK_SET: |
| 98 | // use offset as specified |
| 99 | case linux.SEEK_CUR: |
| 100 | offset += fd.off |
| 101 | case linux.SEEK_END: |
| 102 | offset += int64(inode.size.Load()) |
| 103 | default: |
| 104 | return 0, linuxerr.EINVAL |
| 105 | } |
| 106 | if offset < 0 { |
| 107 | return 0, linuxerr.EINVAL |
| 108 | } |
| 109 | fd.off = offset |
| 110 | return offset, nil |
| 111 | } |
| 112 | |
| 113 | // PRead implements vfs.FileDescriptionImpl.PRead. |
| 114 | func (fd *regularFileFD) PRead(ctx context.Context, dst usermem.IOSequence, offset int64, opts vfs.ReadOptions) (int64, error) { |