Files
tailscale/util/sparse/punch_linux.go
T
James Scott ef1c2a2280 util/sparse: add a sparse file PunchAt method
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]>
2025-02-26 11:25:40 -08:00

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
}