Commit f2ddeec4 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

fs: set Blksize and Blocks automatically based on Size

Change-Id: I272909148667e1f0246914ef7fdd1052bf3b5bc3
parent ba605e54
...@@ -222,7 +222,8 @@ type NodeAccesser interface { ...@@ -222,7 +222,8 @@ type NodeAccesser interface {
// FOPEN_DIRECTIO, Size should be set so it can be read correctly. If // FOPEN_DIRECTIO, Size should be set so it can be read correctly. If
// returning zeroed permissions, the default behavior is to change the // returning zeroed permissions, the default behavior is to change the
// mode of 0755 (directory) or 0644 (files). This can be switched off // mode of 0755 (directory) or 0644 (files). This can be switched off
// with the Options.NullPermissions setting. // with the Options.NullPermissions setting. If blksize is unset, 4096
// is assumed, and the 'blocks' field is set accordingly.
type NodeGetattrer interface { type NodeGetattrer interface {
Getattr(ctx context.Context, f FileHandle, out *fuse.AttrOut) syscall.Errno Getattr(ctx context.Context, f FileHandle, out *fuse.AttrOut) syscall.Errno
} }
......
...@@ -159,6 +159,7 @@ func (b *rawBridge) setAttr(out *fuse.Attr) { ...@@ -159,6 +159,7 @@ func (b *rawBridge) setAttr(out *fuse.Attr) {
if b.options.GID != 0 && out.Gid == 0 { if b.options.GID != 0 && out.Gid == 0 {
out.Gid = b.options.GID out.Gid = b.options.GID
} }
setBlocks(out)
} }
func (b *rawBridge) setAttrTimeout(out *fuse.AttrOut) { func (b *rawBridge) setAttrTimeout(out *fuse.AttrOut) {
...@@ -244,7 +245,6 @@ func (b *rawBridge) Lookup(cancel <-chan struct{}, header *fuse.InHeader, name s ...@@ -244,7 +245,6 @@ func (b *rawBridge) Lookup(cancel <-chan struct{}, header *fuse.InHeader, name s
child.setEntryOut(out) child.setEntryOut(out)
b.addNewChild(parent, name, child, nil, 0, out) b.addNewChild(parent, name, child, nil, 0, out)
b.setEntryOutTimeout(out) b.setEntryOutTimeout(out)
return fuse.OK return fuse.OK
} }
......
// Copyright 2019 the Go-FUSE Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package fs
import "github.com/hanwen/go-fuse/v2/fuse"
func setBlocks(out *fuse.Attr) {
}
...@@ -30,3 +30,13 @@ func (f *loopbackFile) utimens(a *time.Time, m *time.Time) syscall.Errno { ...@@ -30,3 +30,13 @@ func (f *loopbackFile) utimens(a *time.Time, m *time.Time) syscall.Errno {
err := futimens(int(f.fd), &ts) err := futimens(int(f.fd), &ts)
return ToErrno(err) return ToErrno(err)
} }
func setBlocks(out *fuse.Attr) {
if out.Blksize > 0 {
return
}
out.Blksize = 4096
pages := (out.Size + 4095) / 4096
out.Blocks = pages * 8
}
...@@ -56,7 +56,6 @@ func (n *loopbackNode) Statfs(ctx context.Context, out *fuse.StatfsOut) syscall. ...@@ -56,7 +56,6 @@ func (n *loopbackNode) Statfs(ctx context.Context, out *fuse.StatfsOut) syscall.
} }
func (n *loopbackRoot) Getattr(ctx context.Context, f FileHandle, out *fuse.AttrOut) syscall.Errno { func (n *loopbackRoot) Getattr(ctx context.Context, f FileHandle, out *fuse.AttrOut) syscall.Errno {
st := syscall.Stat_t{} st := syscall.Stat_t{}
err := syscall.Stat(n.rootPath, &st) err := syscall.Stat(n.rootPath, &st)
if err != nil { if err != nil {
......
...@@ -96,6 +96,10 @@ func TestDataFile(t *testing.T) { ...@@ -96,6 +96,10 @@ func TestDataFile(t *testing.T) {
t.Errorf("got mode %o, want %o", st.Mode, want) t.Errorf("got mode %o, want %o", st.Mode, want)
} }
if st.Size != int64(len(want)) || st.Blocks != 8 || st.Blksize != 4096 {
t.Errorf("got %#v, want sz = %d, 8 blocks, 4096 blocksize", st, len(want))
}
fd, err := syscall.Open(mntDir+"/file", syscall.O_RDONLY, 0) fd, err := syscall.Open(mntDir+"/file", syscall.O_RDONLY, 0)
if err != nil { if err != nil {
t.Fatalf("Open: %v", err) t.Fatalf("Open: %v", err)
......
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