8 type filehandle struct {
14 unreaddirs []os.FileInfo
17 func (f *filehandle) Read(p []byte) (n int, err error) {
19 return 0, ErrWriteOnlyMode
22 defer f.inode.RUnlock()
23 n, f.ptr, err = f.inode.Read(p, f.ptr)
27 func (f *filehandle) Seek(off int64, whence int) (pos int64, err error) {
28 size := f.inode.Size()
39 return f.ptr.off, ErrNegativeOffset
41 if ptr.off != f.ptr.off {
43 // force filenode to recompute f.ptr fields on next
50 func (f *filehandle) Truncate(size int64) error {
51 return f.inode.Truncate(size)
54 func (f *filehandle) Write(p []byte) (n int, err error) {
56 return 0, ErrReadOnlyFile
59 defer f.inode.Unlock()
60 if fn, ok := f.inode.(*filenode); ok && f.append {
62 off: fn.fileinfo.size,
63 segmentIdx: len(fn.segments),
65 repacked: fn.repacked,
68 n, f.ptr, err = f.inode.Write(p, f.ptr)
72 func (f *filehandle) Readdir(count int) ([]os.FileInfo, error) {
74 return nil, ErrInvalidOperation
77 return f.inode.Readdir(), nil
79 if f.unreaddirs == nil {
80 f.unreaddirs = f.inode.Readdir()
82 if len(f.unreaddirs) == 0 {
85 if count > len(f.unreaddirs) {
86 count = len(f.unreaddirs)
88 ret := f.unreaddirs[:count]
89 f.unreaddirs = f.unreaddirs[count:]
93 func (f *filehandle) Stat() (os.FileInfo, error) {
94 return f.inode.FileInfo(), nil
97 func (f *filehandle) Close() error {
101 func (f *filehandle) Sync() error {
102 // Sync the containing filesystem.