Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go-fuse
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go-fuse
Commits
44cba9c3
Commit
44cba9c3
authored
Apr 07, 2024
by
lch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
internal: add unified function to fallocate
Change-Id: I2b80c97a8b7bd4e93085ba6fe4a0bf2a852db78e
parent
905b26f1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
87 additions
and
0 deletions
+87
-0
internal/fallocate/fallocate.go
internal/fallocate/fallocate.go
+9
-0
internal/fallocate/fallocate_darwin.go
internal/fallocate/fallocate_darwin.go
+56
-0
internal/fallocate/fallocate_freebsd.go
internal/fallocate/fallocate_freebsd.go
+15
-0
internal/fallocate/fallocate_linux.go
internal/fallocate/fallocate_linux.go
+7
-0
No files found.
internal/fallocate/fallocate.go
0 → 100644
View file @
44cba9c3
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
)
}
internal/fallocate/fallocate_darwin.go
0 → 100644
View file @
44cba9c3
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
}
internal/fallocate/fallocate_freebsd.go
0 → 100644
View file @
44cba9c3
package
fallocate
import
(
"golang.org/x/sys/unix"
)
func
fallocate
(
fd
int
,
mode
uint32
,
off
int64
,
len
int64
)
error
{
// Ignore mode
_
=
mode
_
,
_
,
errno
:=
unix
.
Syscall
(
unix
.
SYS_POSIX_FALLOCATE
,
uintptr
(
fd
),
uintptr
(
off
),
uintptr
(
len
))
if
errno
!=
0
{
return
errno
}
return
nil
}
internal/fallocate/fallocate_linux.go
0 → 100644
View file @
44cba9c3
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
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment