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 the O_APPEND flag. And if you slap this on a directory, it forbids removing files from that directory (via unlink(), 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 with CAP_LINUX_IMMUTABLE can 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 is btrfs(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 the mount(2) MS_DIRSYNC option, 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 with CAP_LINUX_IMMUTABLE can set or clear this attribute. Main character energy, honestly.
  • FS_JOURNAL_DATA_FL 'j' β€” enable journaling of file data on ext3(5) and ext4(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 the mount(2) MS_NOATIME flag, 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. See chattr(1) and btrfs(5).
  • FS_NODUMP_FL 'd' β€” don't include this file in backups made using dump(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 the O_SYNC flag). For directories, it has the same effect as FS_DIRSYNC_FL.
  • FS_TOPDIR_FL 'T' β€” mark a directory for special treatment under the Orlov block-allocation strategy. See chattr(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 are FS_TOPDIR_FL, which is not inheritable, and FS_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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms