Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 10 additions & 19 deletions example/loopback/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"path"
"runtime/pprof"
"syscall"
"time"

"github.com/hanwen/go-fuse/v2/fs"
"github.com/hanwen/go-fuse/v2/fuse"
Expand Down Expand Up @@ -92,24 +91,16 @@ func main() {
log.Fatalf("NewLoopbackRoot(%s): %v\n", orig, err)
}

sec := time.Second
opts := &fs.Options{
// The timeout options are to be compatible with libfuse defaults,
// making benchmarking easier.
AttrTimeout: &sec,
EntryTimeout: &sec,

NullPermissions: true, // Leave file permissions on "000" files as-is

MountOptions: fuse.MountOptions{
AllowOther: *other,
Debug: *debug,
DirectMount: *directmount,
DirectMountStrict: *directmountstrict,
IDMappedMount: *idmap,
FsName: orig, // First column in "df -T": original dir
Name: "loopback", // Second column in "df -T" will be shown as "fuse." + Name
},
opts := fs.DefaultOptions()
opts.NullPermissions = true // Leave file permissions on "000" files as-is
opts.MountOptions = fuse.MountOptions{
AllowOther: *other,
Debug: *debug,
DirectMount: *directmount,
DirectMountStrict: *directmountstrict,
IDMappedMount: *idmap,
FsName: orig, // First column in "df -T": original dir
Name: "loopback", // Second column in "df -T" will be shown as "fuse." + Name
}
if opts.AllowOther {
// Make the kernel check file permissions for us
Expand Down
9 changes: 2 additions & 7 deletions example/multizip/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"fmt"
"os"
"path/filepath"
"time"

"github.com/hanwen/go-fuse/v2/fs"
"github.com/hanwen/go-fuse/v2/zipfs"
Expand All @@ -30,13 +29,9 @@ func main() {
}

root := &zipfs.MultiZipFs{}
sec := time.Second
opts := fs.Options{
EntryTimeout: &sec,
AttrTimeout: &sec,
}
opts := fs.DefaultOptions()
opts.Debug = *debug
server, err := fs.Mount(flag.Arg(0), root, &opts)
server, err := fs.Mount(flag.Arg(0), root, opts)
if err != nil {
fmt.Printf("Mount fail: %v\n", err)
os.Exit(1)
Expand Down
6 changes: 1 addition & 5 deletions example/winfs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,7 @@ func main() {
Path: orig,
}

sec := time.Second
opts := &fs.Options{
AttrTimeout: &sec,
EntryTimeout: &sec,
}
opts := fs.DefaultOptions()
opts.Debug = *debug
opts.MountOptions.Options = append(opts.MountOptions.Options, "fsname="+orig)
opts.MountOptions.Name = "winfs"
Expand Down
17 changes: 7 additions & 10 deletions fs/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"runtime/debug"
"sync"
"syscall"
"time"

"github.com/hanwen/go-fuse/v2/fuse"
"github.com/hanwen/go-fuse/v2/internal"
Expand Down Expand Up @@ -286,24 +285,22 @@ func (b *rawBridge) setAttrTimeout(out *fuse.AttrOut) {

// NewNodeFS creates a node based filesystem based on the
// InodeEmbedder instance for the root of the tree.
// If nil is given as opts, default settings are
// applied, which are 1 second entry and attribute timeout.
func NewNodeFS(root InodeEmbedder, opts *Options) fuse.RawFileSystem {
if opts == nil {
opts = DefaultOptions()
}
bridge := &rawBridge{
automaticIno: opts.FirstAutomaticIno,
server: opts.ServerCallbacks,
nextNodeId: 2, // the root node has nodeid 1
stableAttrs: make(map[StableAttr]*Inode),
options: *opts,
}

if bridge.automaticIno == 0 {
bridge.automaticIno = 1 << 63
}

if opts != nil {
bridge.options = *opts
} else {
oneSec := time.Second
bridge.options.EntryTimeout = &oneSec
bridge.options.AttrTimeout = &oneSec
bridge.automaticIno = DefaultOptions().FirstAutomaticIno
}

stableAttr := StableAttr{
Expand Down
5 changes: 5 additions & 0 deletions fs/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,8 @@ func TestNegativeLookupCache(t *testing.T) {
}
}
}

// NewNodeFS should not crash with opts=nil
func TestNewNodeFSNilOpts(t *testing.T) {
NewNodeFS(&Inode{}, nil)
}
19 changes: 19 additions & 0 deletions fs/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,22 @@
// license that can be found in the LICENSE file.

package fs

import (
"time"
)

// DefaultOptions returns the default Options that are used when
// nil is passed for *Options.
//
// When you do want to set something in Options, get the defaults
// from this function and adjust as required.
func DefaultOptions() *Options {
oneSec := time.Second
return &Options{
// libfuse also uses one second per default
EntryTimeout: &oneSec,
AttrTimeout: &oneSec,
FirstAutomaticIno: 1 << 63,
}
}
3 changes: 1 addition & 2 deletions fs/dir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,7 @@ func (n *syncNode) OpendirHandle(ctx context.Context, flags uint32) (FileHandle,

func TestFsyncDir(t *testing.T) {
root := &syncNode{}
opts := Options{}
mnt, _ := testMount(t, root, &opts)
mnt, _ := testMount(t, root, nil)

fd, err := syscall.Open(mnt, syscall.O_DIRECTORY, 0)
if err != nil {
Expand Down
6 changes: 1 addition & 5 deletions fs/interrupt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ func (o *interruptOps) Open(ctx context.Context, flags uint32) (FileHandle, uint
func TestInterrupt(t *testing.T) {
root := &interruptRoot{}

oneSec := time.Second
mntDir, server := testMount(t, root, &Options{
EntryTimeout: &oneSec,
AttrTimeout: &oneSec,
})
mntDir, server := testMount(t, root, DefaultOptions())

cmd := exec.Command("cat", mntDir+"/file")
if err := cmd.Start(); err != nil {
Expand Down
7 changes: 1 addition & 6 deletions fs/loopback_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"sync"
"syscall"
"testing"
"time"
"unsafe"

"github.com/hanwen/go-fuse/v2/fuse"
Expand Down Expand Up @@ -287,11 +286,7 @@ func TestParallelDiropsHang(t *testing.T) {
if err != nil {
t.Fatalf("NewLoopbackRoot(%s): %v\n", orig, err)
}
sec := time.Second
opts := &Options{
AttrTimeout: &sec,
EntryTimeout: &sec,
}
opts := DefaultOptions()
opts.Debug = testutil.VerboseTest()

rawFS := NewNodeFS(loopbackRoot, opts)
Expand Down
16 changes: 5 additions & 11 deletions fs/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
package fs

import (
"time"

"github.com/hanwen/go-fuse/v2/fuse"
)

Expand All @@ -15,16 +13,12 @@ import (
// fuse.NewServer. If nil is given as options, default settings are
// applied, which are 1 second entry and attribute timeout.
func Mount(dir string, root InodeEmbedder, options *Options) (*fuse.Server, error) {
if options == nil {
oneSec := time.Second
options = &Options{
EntryTimeout: &oneSec,
AttrTimeout: &oneSec,
}
}

rawFS := NewNodeFS(root, options)
server, err := fuse.NewServer(rawFS, dir, &options.MountOptions)
var mountOptions *fuse.MountOptions
if options != nil {
mountOptions = &options.MountOptions
}
server, err := fuse.NewServer(rawFS, dir, mountOptions)
if err != nil {
return nil, err
}
Expand Down
7 changes: 1 addition & 6 deletions fs/windows_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"log"
"sync"
"syscall"
"time"

"github.com/hanwen/go-fuse/v2/fs"
"github.com/hanwen/go-fuse/v2/fuse"
Expand Down Expand Up @@ -107,11 +106,7 @@ func Example_loopbackReuse() {
Path: origDir,
}

sec := time.Second
opts := &fs.Options{
AttrTimeout: &sec,
EntryTimeout: &sec,
}
opts := fs.DefaultOptions()

root := &WindowsNode{
LoopbackNode: &fs.LoopbackNode{
Expand Down
Loading