Initial commit
Proof-of-concept implementation. Bugs will occur.
This commit is contained in:
9
vendor/github.com/hanwen/go-fuse/v2/internal/fallocate/fallocate.go
generated
vendored
Normal file
9
vendor/github.com/hanwen/go-fuse/v2/internal/fallocate/fallocate.go
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
package fallocate
|
||||
|
||||
// Fallocate is a wrapper around fallocate syscall.
|
||||
// On Linux, it is a wrapper around fallocate(2).
|
||||
// On Darwin, it is a wrapper around fnctl(2).
|
||||
// On FreeBSD, it is a wrapper around posix_fallocate(2).
|
||||
func Fallocate(fd int, mode uint32, off int64, len int64) (err error) {
|
||||
return fallocate(fd, mode, off, len)
|
||||
}
|
||||
56
vendor/github.com/hanwen/go-fuse/v2/internal/fallocate/fallocate_darwin.go
generated
vendored
Normal file
56
vendor/github.com/hanwen/go-fuse/v2/internal/fallocate/fallocate_darwin.go
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
package fallocate
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func fallocate(fd int, mode uint32, off int64, len int64) error {
|
||||
// TODO: Handle `mode` parameter.
|
||||
_ = mode
|
||||
|
||||
// From `man fcntl` on OSX:
|
||||
// The F_PREALLOCATE command operates on the following structure:
|
||||
//
|
||||
// typedef struct fstore {
|
||||
// u_int32_t fst_flags; /* IN: flags word */
|
||||
// int fst_posmode; /* IN: indicates offset field */
|
||||
// off_t fst_offset; /* IN: start of the region */
|
||||
// off_t fst_length; /* IN: size of the region */
|
||||
// off_t fst_bytesalloc; /* OUT: number of bytes allocated */
|
||||
// } fstore_t;
|
||||
//
|
||||
// The flags (fst_flags) for the F_PREALLOCATE command are as follows:
|
||||
//
|
||||
// F_ALLOCATECONTIG Allocate contiguous space.
|
||||
//
|
||||
// F_ALLOCATEALL Allocate all requested space or no space at all.
|
||||
//
|
||||
// The position modes (fst_posmode) for the F_PREALLOCATE command indicate how to use the offset field. The modes are as fol-
|
||||
// lows:
|
||||
//
|
||||
// F_PEOFPOSMODE Allocate from the physical end of file.
|
||||
//
|
||||
// F_VOLPOSMODE Allocate from the volume offset.
|
||||
|
||||
k := struct {
|
||||
Flags uint32 // u_int32_t
|
||||
Posmode int64 // int
|
||||
Offset int64 // off_t
|
||||
Length int64 // off_t
|
||||
Bytesalloc int64 // off_t
|
||||
}{
|
||||
0,
|
||||
0,
|
||||
int64(off),
|
||||
int64(len),
|
||||
0,
|
||||
}
|
||||
_, _, errno := unix.Syscall(syscall.SYS_FCNTL, uintptr(fd), uintptr(unix.F_PREALLOCATE), uintptr(unsafe.Pointer(&k)))
|
||||
if errno != 0 {
|
||||
return errno
|
||||
}
|
||||
return nil
|
||||
}
|
||||
15
vendor/github.com/hanwen/go-fuse/v2/internal/fallocate/fallocate_freebsd.go
generated
vendored
Normal file
15
vendor/github.com/hanwen/go-fuse/v2/internal/fallocate/fallocate_freebsd.go
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
package fallocate
|
||||
|
||||
import (
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func fallocate(fd int, mode uint32, off int64, len int64) error {
|
||||
// Ignore mode
|
||||
_ = mode
|
||||
ret, _, _ := unix.Syscall(unix.SYS_POSIX_FALLOCATE, uintptr(fd), uintptr(off), uintptr(len))
|
||||
if ret != 0 {
|
||||
return unix.Errno(ret)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
7
vendor/github.com/hanwen/go-fuse/v2/internal/fallocate/fallocate_linux.go
generated
vendored
Normal file
7
vendor/github.com/hanwen/go-fuse/v2/internal/fallocate/fallocate_linux.go
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
package fallocate
|
||||
|
||||
import "golang.org/x/sys/unix"
|
||||
|
||||
func fallocate(fd int, mode uint32, off int64, len int64) error {
|
||||
return unix.Fallocate(fd, mode, off, len)
|
||||
}
|
||||
Reference in New Issue
Block a user