FSPACECTL(2)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1

πŸ’– 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 the cmd argument is gonna operate on.
  • rqsr β€” points to a spacectl_range structure holding the requested operation range.
  • flags β€” controls how the operation behaves.
  • rmsr β€” if it's non-NULL, the spacectl_range structure 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 the rqsr argument. the rqsr->r_offset has to be a value greater than or equal to 0, and the rqsr->r_len has to be a value greater than 0. 🫢

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] β€” the fd argument is not a valid file descriptor.
  • [EBADF] β€” the fd argument references a file that was opened without write permission.
  • [EINTR] β€” a signal was caught during execution.
  • [EINVAL] β€” the cmd argument is not valid.
  • [EINVAL] β€” if the cmd argument is SPACECTL_DEALLOC, either the rqsr->r_offset argument was less than zero, or the rqsr->r_len argument was less than or equal to zero.
  • [EINVAL] β€” the value of rqsr->r_offset + rqsr->r_len is greater than OFF_MAX.
  • [EINVAL] β€” an invalid or unsupported flag is included in flags.
  • [EINVAL] β€” a flag included in flags is not supported by the operation specified by the cmd argument.
  • [EFAULT] β€” the rqsr or a non-NULL rmsr argument 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] β€” the fd argument does not refer to a file that supports fspacectl.
  • [ENOSPC] β€” there is insufficient free space remaining on the file system storage media.
  • [ENOTCAPABLE] β€” the file descriptor fd has insufficient rights.
  • [ESPIPE] β€” the fd argument 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