mirror of
https://github.com/tailscale/tailscale.git
synced 2026-12-04 23:52:20 -08:00
Adds support for sparse file hole punching in linux, windows, and darwin. Also adds a generic PunchAt method that just writes zeros instead of using the file Punch syscall. Updates tailscale/corp#21363 Signed-off-by: James Scott <[email protected]>
23 lines
507 B
Go
23 lines
507 B
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
//go:build linux
|
|
|
|
// Package sparse contains some helpful generic sparse file functions.
|
|
package sparse
|
|
|
|
import (
|
|
"io/fs"
|
|
"os"
|
|
"syscall"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
func punchAt(fd *os.File, off, size int64) error {
|
|
if err := syscall.Fallocate(int(fd.Fd()), unix.FALLOC_FL_KEEP_SIZE|unix.FALLOC_FL_PUNCH_HOLE, off, size); err != nil {
|
|
return &fs.PathError{Op: "fallocate", Path: fd.Name(), Err: err}
|
|
}
|
|
return nil
|
|
}
|