FSPACECTL(2)
π FSPACECTL(2) β space management in a file π
okay so bestie, welcome to the fspacectl page from the System Calls Manual β¨ this one's a syscall, it lives in section 2, and it's literally all about managing space inside a file. let's get into it π
β¨ LIBRARY β¨
Standard C Library (libc, -lc) π«Ά
πΈ SYNOPSIS πΈ
#include <fcntl.h>
int
fspacectl(int fd, int cmd, const struct spacectl_range *rqsr, int flags,
struct spacectl_range *rmsr);
π DESCRIPTION π
so fspacectl is a system call that does space management over a file. iconic behavior ngl π
here's the cast of characters, bestie:
fdβ the file descriptor thecmdargument is gonna operate on.rqsrβ points to aspacectl_rangestructure holding the requested operation range.flagsβ controls how the operation behaves.rmsrβ if it's non-NULL, thespacectl_rangestructure it points to gets updated to hold the unprocessed operation range after the system call returns.
so if everything goes great and there's no unprocessed part left in the requested operation range, then rmsr->r_len gets updated to the value 0, and rmsr->r_offset gets updated to be rqsr->r_offset plus the number of bytes zeroed before the end-of-file. cute, right? π
also very important: the file descriptor's file offset is not used or modified by the system call. and yes β both rqsr and rmsr arguments can point to the same structure. slay.
the spacectl_range structure is defined as:
struct spacectl_range {
off_t r_offset;
off_t r_len;
};
the operation specified by the cmd argument may be one of:
SPACECTL_DEALLOCβ zero a region in the file specified by therqsrargument. therqsr->r_offsethas to be a value greater than or equal to0, and therqsr->r_lenhas to be a value greater than0. π«Ά
and listen β if the file system supports hole-punching, file system space deallocation may be performed in the given region. no cap.
the flags argument needs to be the value 0 currently. that's it. that's the whole vibe check π
π₯ RETURN VALUES π₯
upon successful completion, the value 0 is returned π otherwise the value -1 is returned and errno is set to indicate the error π
π ERRORS π
possible failure conditions, bestie β read these, they're important:
[EBADF]β thefdargument is not a valid file descriptor.[EBADF]β thefdargument references a file that was opened without write permission.[EINTR]β a signal was caught during execution.[EINVAL]β thecmdargument is not valid.[EINVAL]β if thecmdargument isSPACECTL_DEALLOC, either therqsr->r_offsetargument was less than zero, or therqsr->r_lenargument was less than or equal to zero.[EINVAL]β the value ofrqsr->r_offset + rqsr->r_lenis greater thanOFF_MAX.[EINVAL]β an invalid or unsupported flag is included inflags.[EINVAL]β a flag included inflagsis not supported by the operation specified by thecmdargument.[EFAULT]β therqsror a non-NULLrmsrargument point outside the process' allocated address space.[EIO]β an I/O error occurred while reading from or writing to a file system.[EINTEGRITY]β corrupted data was detected while reading from the file system.[ENODEV]β thefdargument does not refer to a file that supportsfspacectl.[ENOSPC]β there is insufficient free space remaining on the file system storage media.[ENOTCAPABLE]β the file descriptorfdhas insufficient rights.[ESPIPE]β thefdargument is associated with a pipe or FIFO.
fr fr, two of these are both [EBADF] β that's not a typo on my part, that's exactly how the page lists them π
π SEE ALSO π
creat(2), ftruncate(2), open(2), unlink(2) β go read those too, iykyk π¦
β HISTORY β
the fspacectl system call appeared in FreeBSD 14.0 π
π§ AUTHORS π§
fspacectl and this manual page were written by Ka Ho Ng <khng@FreeBSD.org> under sponsorship from the FreeBSD Foundation. give them their flowers π
and that's the whole page bestie!! π this version's from Debian, dated August 25, 2021, and it's FSPACECTL(2) all day β mwah πβ¨
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- π the page's license: BSD-2-Clause
- Copyright (c) 2021 The FreeBSD Foundation
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms