ioctl_fslabel(2)

✨ ioctl_fslabel β€” get or set a filesystem label ✨

okay bestie, so this one lives in the System Calls Manual section (that's the (2) on ioctl_fslabel(2), iykyk) πŸ’…


🌸 LIBRARY 🌸

Standard C library (libc, -lc) β€” the classic, the icon, the one you already have linked 🫢


πŸŽ€ SYNOPSIS πŸŽ€

#include <linux/fs.h>       /* Definition of *FSLABEL* constants */
#include <sys/ioctl.h>

int ioctl(int fd, FS_IOC_GETFSLABEL, char label[FSLABEL_MAX]);
int ioctl(int fd, FS_IOC_SETFSLABEL, char label[FSLABEL_MAX]);

like, two whole flavors of ioctl call, one for reading the label and one for writing it. slay ✨


πŸ¦‹ DESCRIPTION πŸ¦‹

so if your filesystem is one of those girlies that supports online label manipulation, these ioctl(2) operations are how you get or set the filesystem label for the filesystem that fd is living on πŸ’–

the FS_IOC_SETFSLABEL operation requires privilege β€” specifically CAP_SYS_ADMIN. so no, you can't just waltz in there and rename things without the juice πŸ”₯


πŸ’« RETURN VALUE πŸ’«

  • On success, zero is returned. periodt. πŸ’…
  • On error, -1 comes back, and errno gets set to tell you exactly what went wrong. it's giving "read the error, bestie" 😭

🌈 ERRORS 🌈

possible errors include (but are not limited to) the following β€” so don't come for me if you get something else, the list is open-ended fr fr:

  • EFAULT β€” label references an inaccessible memory area. like, that memory said "not today" πŸ™ˆ
  • EINVAL β€” the specified label exceeds the maximum label length for the filesystem. too long, girl, trim it βœ‚οΈ
  • ENOTTY β€” this can appear if the filesystem does not support online label manipulation. the vibe check failed πŸ’€
  • EPERM β€” the calling process does not have sufficient permissions to set the label. you don't have the clearance, babes 🚫

πŸ‘‘ STANDARDS πŸ‘‘

Linux. that's it, that's the standard. πŸ’œ


🧚 HISTORY 🧚

  • Linux 4.18. ✨
  • They were previously known as BTRFS_IOC_GET_FSLABEL and BTRFS_IOC_SETFSLABEL, and were private to Btrfs. glow-up arc complete πŸ¦‹

πŸ’… NOTES πŸ’…

okay this part matters so listen up:

  • the maximum string length for this interface is FSLABEL_MAX, including the terminating null byte ('\0').
  • filesystems have differing maximum label lengths, which may or may not include the terminating null. so like, don't assume, every fs has its own rules 🌸
  • the string provided to FS_IOC_SETFSLABEL must always be null-terminated.
  • the string returned by FS_IOC_GETFSLABEL will always be null-terminated. she's reliable like that 🫢
not me being the friend who reminds you about null terminators at 2am 😭 but bestie, the terminator is not optional.

⭐ SEE ALSO ⭐


and that's the whole page, no cap πŸ’– go forth and label your filesystems, main character πŸ’…βœ¨

this was brought to you by Linux man-pages 6.7, dated 2023-10-31 β€” mwah, kisses, see you in the next man page πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from