From 1f81865847e637d27d5c64e7f0dcecf2641c3c04 Mon Sep 17 00:00:00 2001 From: Christian Kemper Date: Sun, 14 Feb 2016 12:24:02 -0800 Subject: [PATCH] set Blocks and BlockSize in Attr using a default blocksize of 512 to address #442. --- fuse/file.go | 5 +++++ fuse/file_test.go | 1 + 2 files changed, 6 insertions(+) diff --git a/fuse/file.go b/fuse/file.go index 998ea822c..60e206fd5 100644 --- a/fuse/file.go +++ b/fuse/file.go @@ -15,6 +15,9 @@ import ( "golang.org/x/net/context" ) +// The default block size to report in stat +const blockSize = 512 + // Statically ensure that *file implements the given interface var _ = fs.HandleReader(&file{}) var _ = fs.HandleReleaser(&file{}) @@ -67,6 +70,8 @@ func (f *file) Attr(ctx context.Context, a *fuse.Attr) error { a.Inode = f.node.Inode a.Mode = f.node.Mode a.Size = f.node.Size + a.Blocks = (f.node.Size / blockSize) + 1 + a.BlockSize = blockSize if !f.ownerIsRoot { a.Uid = f.node.UID diff --git a/fuse/file_test.go b/fuse/file_test.go index 10668ea82..7abeac7c2 100644 --- a/fuse/file_test.go +++ b/fuse/file_test.go @@ -132,6 +132,7 @@ func TestFuseFile(t *testing.T) { Equals(t, node.Inode, attr.Inode) Equals(t, node.Mode, attr.Mode) Equals(t, node.Size, attr.Size) + Equals(t, (node.Size/uint64(attr.BlockSize))+1, attr.Blocks) for i, test := range offsetReadsTests { b := memfile[test.offset : test.offset+test.length]