FS_IOC_SETFLAGS(2const)
π FS_IOC_SETFLAGS(2const) β aka bestie, let's talk inode flags π
Okay so this is a Linux manual page, section 2const (that's the constants-flavored corner of the ioctl(2) universe, iykyk). Grab a strawberry drink π and let's get into it, because this one is genuinely so useful and I am obsessed.
β¨ NAME β¨
FS_IOC_GETFLAGS, FS_IOC_SETFLAGS β the ioctl() operations for inode flags. That's it, that's the whole vibe. π¦
πΈ SYNOPSIS πΈ
#include <linux/fs.h> /* Definition of FS_* constants */
#include <sys/ioctl.h>
int ioctl(int fd, FS_IOC_GETFLAGS, int *attr);
int ioctl(int fd, FS_IOC_SETFLAGS, const int *attr);
no cap, that's the whole API. two calls. iconic. π
π DESCRIPTION π
So like, a bunch of Linux filesystems have this concept called inode flags β extra attributes that literally change how files and directories behave. Not a permissions thing, not an ownership thing, justβ¦ vibes that the filesystem respects. And you can get them and set them with two ioctl(2) operations, bestie:
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' */
See how that works?? You read the current bitmask out with FS_IOC_GETFLAGS, you OR in the bit you want with attr |= ..., and you push it back with FS_IOC_SETFLAGS. That's the whole loop. Chef's kiss. π
Now if you're not trying to hand-write ioctls in C like some kind of gremlin, the shell commands lsattr(1) and chattr(1) are literally just friendly frontends to these two operations β they let you look at and change the inode flags on a file. Use them, bestie. Your wrists will thank you. π
Here's every flag that's supported, shown with the letter that lsattr(1) and chattr(1) use to represent it:
FS_APPEND_FL'a'β the file can only be opened with theO_APPENDflag. And if you slap this on a directory, it forbids removing files from that directory (viaunlink(),rename(), and all their little friends). And yes β this restriction applies even to the superuser, so don't come at me with "but I'm root". You're not that girl. Only a privileged process withCAP_LINUX_IMMUTABLEcan set or clear this attribute.FS_COMPR_FL'c'β store the file compressed on disk. Lowkey most mainstream filesystem implementations do not support this flag; one exception isbtrfs(5). So likeβ¦ check before you get your hopes up.FS_DIRSYNC_FL'D'(since Linux 2.6.0) β write directory changes synchronously to disk. Semantics are equivalent to themount(2)MS_DIRSYNCoption, but per-directory instead of whole-mount. This flag can be applied only to directories. β¨FS_IMMUTABLE_FL'i'β the file is immutable, meaning no changes are permitted to file contents or metadata (permissions, timestamps, ownership, link count, and so on). And yeah β this applies even to the superuser, so it is not playing around. Only a privileged process withCAP_LINUX_IMMUTABLEcan set or clear this attribute. Main character energy, honestly.FS_JOURNAL_DATA_FL'j'β enable journaling of file data onext3(5)andext4(5)filesystems. If your filesystem is journaling in ordered or writeback mode, a privileged (CAP_SYS_RESOURCE) process can set this flag to turn on data-update journaling for one specific file. Per-file journaling, we love to see it.FS_NOATIME_FL'A'β don't update the file's last access time when the file is accessed. This can give you actual I/O performance benefits for apps that simply do not care about that timestamp being accurate. It's like themount(2)MS_NOATIMEflag, but per-file. ποΈFS_NOCOW_FL'C'(since Linux 2.6.39) β the file will not be subject to copy-on-write updates. This flag has an effect only 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). That's the whole thing.FS_NOTAIL_FL't'β supported only on Reiserfs. It disables the Reiserfs tail-packing feature, which tries to pack small files (and the final fragment of larger files) into the same disk block as the file metadata. Niche, but valid. πFS_PROJINHERIT_FL'P'(since Linux 4.5) β inherit the quota project ID. Files and subdirectories will inherit the project ID of the directory. This flag can be applied only to directories.FS_SECRM_FL's'β mark the file for secure deletion. Heads up: this feature is not implemented by any filesystem, because securely erasing a file from a recording medium is surprisingly difficult. So it's givingβ¦ decorative. π«FS_SYNC_FL'S'β make file updates synchronous. For files, this makes all writes synchronous (as though every open of the file used theO_SYNCflag). For directories, it has the same effect asFS_DIRSYNC_FL.FS_TOPDIR_FL'T'β mark a directory for special treatment under the Orlov block-allocation strategy. Seechattr(1)for the details. This flag can be applied only to directories, and it has an effect only for ext2, ext3, and ext4.FS_UNRM_FL'u'β allow the file to be undeleted if it's deleted. Plot twist: this feature is not implemented by any filesystem, since it's possible to implement file-recovery mechanisms outside the kernel. So againβ¦ cute idea, no implementation. π
Important inheritance tea: in most cases, when any of the flags above is set on a directory, that flag gets inherited by files and subdirectories created inside it. The exceptions areFS_TOPDIR_FL, which is not inheritable, andFS_DIRSYNC_FL, which is inherited only by subdirectories. Write that down. π
π STANDARDS π
Linux. Yeah. That's the standard. It's a Linux thing, bestie.
π NOTES π
Okay, this one matters, so listen up: 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 owner, no capability, no flag changes. Periodt. π«
π«Ά SEE ALSO π«Ά
ioctl(2), chattr(1), lsattr(1), mount(2), btrfs(5), ext4(5), xfs(5), xattr(7), mount(8)
Later, bestie!! This lil love letter to inode flags comes to you straight from Linux man-pages 6.20, dated 2026-02-08, and it's filed under FS_IOC_SETFLAGS(2const). Go set some flags responsibly. πΈβ¨π¦
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: Linux-man-pages-copyleft
- Copyright 2017, 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