Commit 5ba6d8c3 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent aba9907d
......@@ -469,9 +469,23 @@ func (bfroot *BigFileRoot) Mkdir(name string, mode uint32, fctx *fuse.Context) (
func (bfdata *BigFileData) GetAttr(out *fuse.Attr, _ nodefs.File, fctx *fuse.Context) fuse.Status {
// XXX locking
bf := bfdata.bigfile
zbf := bfdata.bigfile.zbf
// XXX better ctx = transaction.PutIntoContext(ctx, txn)
ctx, cancel := xcontext.Merge(asctx(fctx), bf.txnCtx)
defer cancel()
size, err := zbf.Size(ctx)
if err != nil {
log.Errorf("%s", err) // XXX errctx
return fuse.EIO // XXX extract EFBIG when it is the cause?
}
out.Mode = fuse.S_IFREG | 0444
out.Size = 111 // FIXME -> zbf.Size() (= zbf.blktab.MaxKey() * zbf.blksize)
out.Size = uint64(size)
// .Blocks
// .Blksize
// FIXME lastChange should cover all bigfile data, not only ZBigFile itself
//mtime := &bfdata.lastChange.Time().Time
......
......@@ -42,6 +42,7 @@ import (
"reflect"
"sort"
"sync"
"syscall"
"golang.org/x/sync/errgroup"
......@@ -402,6 +403,32 @@ func (bf *ZBigFile) LoadBlk(ctx context.Context, blk int64) (_ []byte, err error
return blkdata, nil
}
// Size returns whole file size.
func (bf *ZBigFile) Size(ctx context.Context) (_ int64, err error) {
defer xerr.Contextf(&err, "bigfile %s: size", bf.POid())
err = bf.PActivate(ctx)
if err != nil {
return 0, err
}
defer bf.PDeactivate()
tailblk, ok, err := bf.blktab.MaxKey(ctx)
if err != nil {
return 0, err
}
if !ok {
return 0, nil
}
size := (tailblk + 1) * bf.blksize
if size / bf.blksize != tailblk + 1 {
return 0, syscall.EFBIG // overflow
}
return size, nil
}
// ----------------------------------------
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment