Init V4 community edition (#2265)

* Init V4 community edition

* Init V4 community edition
This commit is contained in:
AaronLiu
2025-04-20 17:31:25 +08:00
committed by GitHub
parent da4e44b77a
commit 21d158db07
597 changed files with 119415 additions and 41692 deletions

View File

@@ -0,0 +1,27 @@
package local
import (
"os"
"syscall"
"unsafe"
)
func Fallocate(file *os.File, offset int64, length int64) error {
var fst syscall.Fstore_t
fst.Flags = syscall.F_ALLOCATECONTIG
fst.Posmode = syscall.F_PREALLOCATE
fst.Offset = 0
fst.Length = offset + length
fst.Bytesalloc = 0
// Check https://lists.apple.com/archives/darwin-dev/2007/Dec/msg00040.html
_, _, err := syscall.Syscall(syscall.SYS_FCNTL, file.Fd(), syscall.F_PREALLOCATE, uintptr(unsafe.Pointer(&fst)))
if err != syscall.Errno(0x0) {
fst.Flags = syscall.F_ALLOCATEALL
// Ignore the return value
_, _, _ = syscall.Syscall(syscall.SYS_FCNTL, file.Fd(), syscall.F_PREALLOCATE, uintptr(unsafe.Pointer(&fst)))
}
return syscall.Ftruncate(int(file.Fd()), fst.Length)
}