Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

local: preallocate files on linux with fallocate(2)

Nick Craig-Wood9fa8c959ee33
diff --git a/backend/local/preallocate_other.go b/backend/local/preallocate_other.go
index 7afff5e29..fb71cad59 100644
--- a/backend/local/preallocate_other.go
+++ b/backend/local/preallocate_other.go
@@ -1,4 +1,4 @@
-//+build !windows
+//+build !windows,!linux
package local
diff --git a/backend/local/preallocate_unix.go b/backend/local/preallocate_unix.go
new file mode 100644
index 000000000..f7208ab0b
--- /dev/null
+++ b/backend/local/preallocate_unix.go
@@ -0,0 +1,22 @@
+//+build linux
+
+package local
+
+import (
+ "os"
+
+ "golang.org/x/sys/unix"
+)
+
+// preAllocate the file for performance reasons
+func preAllocate(size int64, out *os.File) error {
+ if size <= 0 {
+ return nil
+ }
+ err := unix.Fallocate(int(out.Fd()), unix.FALLOC_FL_KEEP_SIZE, 0, size)
+ // FIXME could be doing something here
+ // if err == unix.ENOSPC {
+ // log.Printf("No space")
+ // }
+ return err
+}