ioctl_iflags(2)
β¨ ioctl_iflags(2) β the System Calls Manual page, but make it make sense π
okay bestie, so this one is ioctl_iflags, and it lives in section 2 of the manual (that's the system calls section, iykyk). let's get into it π«Ά
πΈ NAME πΈ
ioctl_iflags β the ioctl() operations that deal with inode flags, bestie
π¦ DESCRIPTION π¦
so like, a bunch of Linux filesystems are out here supporting the whole concept of inode flags β these are attributes that literally change the semantics of your files and directories. not just metadata vibes, actual behavior changes. and you can read them and change them with two ioctl(2) operations:
int attr;
fd = open("pathname", ...);
ioctl(fd, FS_IOC_GETFLAGS, &attr); /* Place current flags
in 'attr' */
attr |= FS_NOATIME_FL; /* Tweak returned bit mask */
ioctl(fd, FS_IOC_SETFLAGS, &attr); /* Update flags for inode
referred to by 'fd' */
and if you're not trying to write C at 2am, the shell commands lsattr(1) and chattr(1) are the friendly little interfaces to these same two operations β they let you look at and change the inode flags attached to a file. iconic behavior honestly.
here's the full flag lineup (with the little letter that lsattr(1) and chattr(1) use to show it, because they're extra like that):
FS_APPEND_FL'a'β the file can only be opened with theO_APPENDflag. and yes, this restriction applies even to the superuser. only a privileged process (CAP_LINUX_IMMUTABLE) can set or clear this attribute. no cap. πFS_COMPR_FL'c'β store the file in a compressed format on disk. heads up though: most of the mainstream filesystem implementations do not support this flag. one exception isbtrfs(5).FS_DIRSYNC_FL'D'(since Linux 2.6.0) β write directory changes synchronously to disk. this gives you semantics equivalent to themount(2)MS_DIRSYNCoption, but on a per-directory basis instead of the whole mount. can only be applied to directories. π«FS_IMMUTABLE_FL'i'β the file is immutable: no changes are permitted to the file contents or its metadata (permissions, timestamps, ownership, link count, and so on). and again β this restriction applies even to the superuser. only a privileged process (CAP_LINUX_IMMUTABLE) can set or clear this attribute.FS_JOURNAL_DATA_FL'j'β enable journaling of file data onext3(5)andext4(5)filesystems. on a filesystem that's journaling in ordered or writeback mode, a privileged (CAP_SYS_RESOURCE) process can set this flag to turn on journaling of data updates on a per-file basis.FS_NOATIME_FL'A'β don't update the file's last access time when the file is accessed. this can give you I/O performance benefits for applications that genuinely do not care about the accuracy of that timestamp. it's functionally similar to themount(2)MS_NOATIMEflag, but per-file. slay for your performance. π₯FS_NOCOW_FL'C'(since Linux 2.6.39) β the file will not be subject to copy-on-write updates. this only does anything on filesystems that support copy-on-write semantics, like Btrfs. seechattr(1)andbtrfs(5).FS_NODUMP_FL'd'β don't include this file in backups made usingdump(8).FS_NOTAIL_FL't'β supported only on Reiserfs. it disables the Reiserfs tail-packing feature, which is the thing that tries to pack small files (and the final fragment of larger files) into the same disk block as the file metadata.FS_PROJINHERIT_FL'P'(since Linux 4.5) β inherit the quota project ID. files and subdirectories will inherit the project ID of the directory. can only be applied to directories. π§FS_SECRM_FL's'β mark the file for secure deletion. okay so plot twist: this feature is not implemented by any filesystem, because securely erasing a file from a recording medium is, and I quote, surprisingly difficult. πFS_SYNC_FL'S'β make file updates synchronous. for files, this makes all writes synchronous (as though all opens of the file were done with theO_SYNCflag). for directories, it does the same thing as theFS_DIRSYNC_FLflag.FS_TOPDIR_FL'T'β mark a directory for special treatment under the Orlov block-allocation strategy. seechattr(1)for the details. can only be applied to directories, and only actually has an effect for ext2, ext3, and ext4.FS_UNRM_FL'u'β allow the file to be undeleted if it's deleted. and another plot twist: this feature is not implemented by any filesystem either, since you can totally implement file-recovery mechanisms outside the kernel.
and here's the inheritance tea π΅ β in most cases, when any of the above flags is set on a directory, that flag gets inherited by the files and subdirectories created inside that directory. the exceptions are:
FS_TOPDIR_FL, which is not inheritable at allFS_DIRSYNC_FL, which is inherited only by subdirectories
π STANDARDS π
Linux. that's it, that's the standard. periodt.
π NOTES π
to change a file's inode flags using the FS_IOC_SETFLAGS operation, the effective user ID of the caller must match the owner of the file, or the caller must have the CAP_FOWNER capability. no exceptions bestie.
and this one's important: the type of the argument you pass to the FS_IOC_GETFLAGS and FS_IOC_SETFLAGS operations is int * β notwithstanding the implication in the kernel source file include/uapi/linux/fs.h that the argument is long *. do not get got by that. π
π SEE ALSO π
chattr(1), lsattr(1), mount(2), btrfs(5), ext4(5), xfs(5), xattr(7), mount(8)
and that's the whole page, bestie, you ate that π«Ά this lil writeup came from the Linux man-pages 6.7 release, dated 2023-10-31, and the page itself is ioctl_iflags(2). go touch some inode flags (responsibly). πβ¨πΈ
π¦ where this page comes from
- ubuntu noble: manpages-dev 6.7-2
- π the page's license: Linux-man-pages-copyleft
- Copyright (c) 2017 by Michael Kerrisk <mtk.manpages@gmail.com>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms