Seek implements vfs.FileDescriptionImpl.Allocate.
(ctx context.Context, mode, offset, length uint64)
| 59 | |
| 60 | // Seek implements vfs.FileDescriptionImpl.Allocate. |
| 61 | func (fd *regularFileFD) Allocate(ctx context.Context, mode, offset, length uint64) error { |
| 62 | if mode & ^uint64(linux.FALLOC_FL_KEEP_SIZE|linux.FALLOC_FL_PUNCH_HOLE|linux.FALLOC_FL_ZERO_RANGE) != 0 { |
| 63 | return linuxerr.EOPNOTSUPP |
| 64 | } |
| 65 | in := linux.FUSEFallocateIn{ |
| 66 | Fh: fd.Fh, |
| 67 | Offset: uint64(offset), |
| 68 | Length: uint64(length), |
| 69 | Mode: uint32(mode), |
| 70 | } |
| 71 | i := fd.inode() |
| 72 | if err := i.call(ctx, linux.FUSE_FALLOCATE, &in, nil); err != nil { |
| 73 | return err |
| 74 | } |
| 75 | i.attrMu.Lock() |
| 76 | defer i.attrMu.Unlock() |
| 77 | if uint64(offset+length) > i.size.Load() { |
| 78 | if err := i.reviseAttr(ctx, linux.FUSE_GETATTR_FH, fd.Fh); err != nil { |
| 79 | return err |
| 80 | } |
| 81 | // If the offset after update is still too large, return error. |
| 82 | if uint64(offset) >= i.size.Load() { |
| 83 | return io.EOF |
| 84 | } |
| 85 | } |
| 86 | return nil |
| 87 | } |
| 88 | |
| 89 | // Seek implements vfs.FileDescriptionImpl.Seek. |
| 90 | func (fd *regularFileFD) Seek(ctx context.Context, offset int64, whence int32) (int64, error) { |