From 13055278f56b941be0ea1ff4eb4840d88fba7e37 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Sun, 4 Aug 2019 13:45:10 +0200 Subject: [PATCH] Force -noprealloc on Btrfs Preallocation on Btrfs is broken ( https://github.com/rfjakob/gocryptfs/issues/395 , https://lore.kernel.org/linux-btrfs/CAPv9Zmk46As_P9Gyf_icET53xRda63h7iC1meES9xbdDEt9qow@mail.gmail.com/ ) and slow ( https://github.com/rfjakob/gocryptfs/issues/63 ). --- mount.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/mount.go b/mount.go index 6c94240..8163df0 100644 --- a/mount.go +++ b/mount.go @@ -19,6 +19,8 @@ import ( "syscall" "time" + "golang.org/x/sys/unix" + "github.com/hanwen/go-fuse/fuse" "github.com/hanwen/go-fuse/fuse/nodefs" "github.com/hanwen/go-fuse/fuse/pathfs" @@ -95,6 +97,18 @@ func doMount(args *argContainer) { } }() } + // Preallocation on Btrfs is broken ( https://github.com/rfjakob/gocryptfs/issues/395 ) + // and slow ( https://github.com/rfjakob/gocryptfs/issues/63 ). + if !args.noprealloc { + var st unix.Statfs_t + err = unix.Statfs(args.cipherdir, &st) + if err == nil && st.Type == unix.BTRFS_SUPER_MAGIC { + tlog.Info.Printf(tlog.ColorYellow + + "Btrfs detected, forcing -noprealloc. See https://github.com/rfjakob/gocryptfs/issues/395 for why." + + tlog.ColorReset) + args.noprealloc = true + } + } // We cannot use JSON for pretty-printing as the fields are unexported tlog.Debug.Printf("cli args: %#v", args) // Initialize gocryptfs (read config file, ask for password, ...)