fstrim

package
v2.0.32 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 6, 2026 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package fstrim discards unused blocks of a mounted filesystem (the equivalent of the fstrim(8) command).

Index

Constants

View Source
const FITRIM = 0xc0185879

FITRIM is the ioctl number to discard unused blocks of a mounted filesystem.

It is _IOWR('X', 121, struct fstrim_range), where struct fstrim_range is three uint64 fields (24 bytes). This encoding is the same on all architectures using the asm-generic ioctl numbering (amd64, arm64, ...).

Variables

View Source
var ErrNotSupported = errors.New("fstrim is not supported for this filesystem")

ErrNotSupported indicates that the filesystem (or the underlying block device) does not support discarding unused blocks.

Functions

func Fstrim

func Fstrim(path string) (uint64, error)

Fstrim discards unused blocks of the mounted filesystem at the given path.

The path may be the mount point or any file or directory within the mounted filesystem.

It returns the number of bytes discarded as reported by the kernel (the same figure printed by `fstrim -v`; an estimate, not a hardware-confirmed count).

The error is nil on success, ErrNotSupported if the filesystem or the underlying device does not support discard, or another error if the operation failed.

func FstrimFd

func FstrimFd(fd uintptr) (uint64, error)

FstrimFd discards unused blocks of the mounted filesystem identified by the open file descriptor.

The descriptor may refer to the mount point or any file or directory within the mounted filesystem.

See Fstrim for the returned value and errors.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL