1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
12 type filehandle struct {
18 unreaddirs []os.FileInfo
21 func (f *filehandle) Read(p []byte) (n int, err error) {
23 return 0, ErrWriteOnlyMode
26 defer f.inode.RUnlock()
27 n, f.ptr, err = f.inode.Read(p, f.ptr)
31 func (f *filehandle) Seek(off int64, whence int) (pos int64, err error) {
32 size := f.inode.Size()
43 return f.ptr.off, ErrNegativeOffset
45 if ptr.off != f.ptr.off {
47 // force filenode to recompute f.ptr fields on next
54 func (f *filehandle) Truncate(size int64) error {
55 return f.inode.Truncate(size)
58 func (f *filehandle) Write(p []byte) (n int, err error) {
60 return 0, ErrReadOnlyFile
63 defer f.inode.Unlock()
64 if fn, ok := f.inode.(*filenode); ok && f.append {
66 off: fn.fileinfo.size,
67 segmentIdx: len(fn.segments),
69 repacked: fn.repacked,
72 n, f.ptr, err = f.inode.Write(p, f.ptr)
76 func (f *filehandle) Readdir(count int) ([]os.FileInfo, error) {
78 return nil, ErrInvalidOperation
81 return f.inode.Readdir()
83 if f.unreaddirs == nil {
85 f.unreaddirs, err = f.inode.Readdir()
90 if len(f.unreaddirs) == 0 {
93 if count > len(f.unreaddirs) {
94 count = len(f.unreaddirs)
96 ret := f.unreaddirs[:count]
97 f.unreaddirs = f.unreaddirs[count:]
101 func (f *filehandle) Stat() (os.FileInfo, error) {
102 return f.inode.FileInfo(), nil
105 func (f *filehandle) Close() error {
109 func (f *filehandle) Sync() error {
110 // Sync the containing filesystem.