| 1 |
.\" Copyright 2017, Michael Kerrisk <[email protected]> |
| 2 |
.\" Copyright, the authors of the Linux man-pages project |
| 3 |
.\" |
| 4 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 5 |
.\" |
| 6 |
.TH FS_IOC_SETFLAGS 2const 2026-02-08 "Linux man-pages 6.18" |
| 7 |
.SH NAME |
| 8 |
FS_IOC_GETFLAGS, |
| 9 |
FS_IOC_SETFLAGS |
| 10 |
\- |
| 11 |
ioctl() operations for inode flags |
| 12 |
.SH SYNOPSIS |
| 13 |
.nf |
| 14 |
.BR "#include <linux/fs.h>" " /* Definition of " FS_* " constants */" |
| 15 |
.B #include <sys/ioctl.h> |
| 16 |
.P |
| 17 |
.BI "int ioctl(int " fd ", FS_IOC_GETFLAGS, int *" attr ); |
| 18 |
.BI "int ioctl(int " fd ", FS_IOC_SETFLAGS, const int *" attr ); |
| 19 |
.fi |
| 20 |
.SH DESCRIPTION |
| 21 |
Various Linux filesystems support the notion of |
| 22 |
.IR "inode flags" \[em]attributes |
| 23 |
that modify the semantics of files and directories. |
| 24 |
These flags can be retrieved and modified using two |
| 25 |
.BR ioctl (2) |
| 26 |
operations: |
| 27 |
.P |
| 28 |
.in +4n |
| 29 |
.EX |
| 30 |
int attr; |
| 31 |
fd = open("pathname", ...); |
| 32 |
\& |
| 33 |
ioctl(fd, FS_IOC_GETFLAGS, &attr); /* Place current flags |
| 34 |
in \[aq]attr\[aq] */ |
| 35 |
attr |= FS_NOATIME_FL; /* Tweak returned bit mask */ |
| 36 |
ioctl(fd, FS_IOC_SETFLAGS, &attr); /* Update flags for inode |
| 37 |
referred to by \[aq]fd\[aq] */ |
| 38 |
.EE |
| 39 |
.in |
| 40 |
.P |
| 41 |
The |
| 42 |
.BR lsattr (1) |
| 43 |
and |
| 44 |
.BR chattr (1) |
| 45 |
shell commands provide interfaces to these two operations, |
| 46 |
allowing a user to view and modify the inode flags associated with a file. |
| 47 |
.P |
| 48 |
The following flags are supported |
| 49 |
(shown along with the corresponding letter used to indicate the flag by |
| 50 |
.BR lsattr (1) |
| 51 |
and |
| 52 |
.BR chattr (1)): |
| 53 |
.TP |
| 54 |
.BR FS_APPEND_FL " \[aq]a\[aq]" |
| 55 |
The file can be opened only with the |
| 56 |
.B O_APPEND |
| 57 |
flag. |
| 58 |
If applied to a directory, forbids removing files from the directory |
| 59 |
.RB "(via " unlink "(), " rename "(), and the like)." |
| 60 |
(This restriction applies even to the superuser.) |
| 61 |
Only a privileged process |
| 62 |
.RB ( CAP_LINUX_IMMUTABLE ) |
| 63 |
can set or clear this attribute. |
| 64 |
.TP |
| 65 |
.BR FS_COMPR_FL " \[aq]c\[aq]" |
| 66 |
Store the file in a compressed format on disk. |
| 67 |
This flag is |
| 68 |
.I not |
| 69 |
supported by most of the mainstream filesystem implementations; |
| 70 |
one exception is |
| 71 |
.BR btrfs (5). |
| 72 |
.TP |
| 73 |
.BR FS_DIRSYNC_FL " \[aq]D\[aq] (since Linux 2.6.0)" |
| 74 |
Write directory changes synchronously to disk. |
| 75 |
This flag provides semantics equivalent to the |
| 76 |
.BR mount (2) |
| 77 |
.B MS_DIRSYNC |
| 78 |
option, but on a per-directory basis. |
| 79 |
This flag can be applied only to directories. |
| 80 |
.\" .TP |
| 81 |
.\" .BR FS_EXTENT_FL " \[aq]e\[aq]" |
| 82 |
.\" FIXME Some support on ext4? (EXT4_EXTENTS_FL) |
| 83 |
.TP |
| 84 |
.BR FS_IMMUTABLE_FL " \[aq]i\[aq]" |
| 85 |
The file is immutable: |
| 86 |
no changes are permitted to the file contents or metadata |
| 87 |
(permissions, timestamps, ownership, link count, and so on). |
| 88 |
(This restriction applies even to the superuser.) |
| 89 |
Only a privileged process |
| 90 |
.RB ( CAP_LINUX_IMMUTABLE ) |
| 91 |
can set or clear this attribute. |
| 92 |
.TP |
| 93 |
.BR FS_JOURNAL_DATA_FL " \[aq]j\[aq]" |
| 94 |
Enable journaling of file data on |
| 95 |
.BR ext3 (5) |
| 96 |
and |
| 97 |
.BR ext4 (5) |
| 98 |
filesystems. |
| 99 |
On a filesystem that is journaling in |
| 100 |
.I ordered |
| 101 |
or |
| 102 |
.I writeback |
| 103 |
mode, a privileged |
| 104 |
.RB ( CAP_SYS_RESOURCE ) |
| 105 |
process can set this flag to enable journaling of data updates on |
| 106 |
a per-file basis. |
| 107 |
.TP |
| 108 |
.BR FS_NOATIME_FL " \[aq]A\[aq]" |
| 109 |
Don't update the file last access time when the file is accessed. |
| 110 |
This can provide I/O performance benefits for applications that do not care |
| 111 |
about the accuracy of this timestamp. |
| 112 |
This flag provides functionality similar to the |
| 113 |
.BR mount (2) |
| 114 |
.B MS_NOATIME |
| 115 |
flag, but on a per-file basis. |
| 116 |
.\" .TP |
| 117 |
.\" .BR FS_NOCOMP_FL " \[aq]\[aq]" |
| 118 |
.\" FIXME Support for FS_NOCOMP_FL on Btrfs? |
| 119 |
.TP |
| 120 |
.BR FS_NOCOW_FL " \[aq]C\[aq] (since Linux 2.6.39)" |
| 121 |
The file will not be subject to copy-on-write updates. |
| 122 |
This flag has an effect only on filesystems that support copy-on-write |
| 123 |
semantics, such as Btrfs. |
| 124 |
See |
| 125 |
.BR chattr (1) |
| 126 |
and |
| 127 |
.BR btrfs (5). |
| 128 |
.TP |
| 129 |
.BR FS_NODUMP_FL " \[aq]d\[aq]" |
| 130 |
Don't include this file in backups made using |
| 131 |
.BR dump (8). |
| 132 |
.TP |
| 133 |
.BR FS_NOTAIL_FL " \[aq]t\[aq]" |
| 134 |
This flag is supported only on Reiserfs. |
| 135 |
It disables the Reiserfs tail-packing feature, |
| 136 |
which tries to pack small files (and the final fragment of larger files) |
| 137 |
into the same disk block as the file metadata. |
| 138 |
.TP |
| 139 |
.BR FS_PROJINHERIT_FL " \[aq]P\[aq] (since Linux 4.5)" |
| 140 |
.\" commit 040cb3786d9b25293b8b0b05b90da0f871e1eb9b |
| 141 |
.\" Flag name was added in Linux 4.4 |
| 142 |
.\" FIXME Not currently supported because not in FS_FL_USER_MODIFIABLE? |
| 143 |
Inherit the quota project ID. |
| 144 |
Files and subdirectories will inherit the project ID of the directory. |
| 145 |
This flag can be applied only to directories. |
| 146 |
.TP |
| 147 |
.BR FS_SECRM_FL " \[aq]s\[aq]" |
| 148 |
Mark the file for secure deletion. |
| 149 |
This feature is not implemented by any filesystem, |
| 150 |
since the task of securely erasing a file from a recording medium |
| 151 |
is surprisingly difficult. |
| 152 |
.TP |
| 153 |
.BR FS_SYNC_FL " \[aq]S\[aq]" |
| 154 |
Make file updates synchronous. |
| 155 |
For files, this makes all writes synchronous |
| 156 |
(as though all opens of the file were with the |
| 157 |
.B O_SYNC |
| 158 |
flag). |
| 159 |
For directories, this has the same effect as the |
| 160 |
.B FS_DIRSYNC_FL |
| 161 |
flag. |
| 162 |
.TP |
| 163 |
.BR FS_TOPDIR_FL " \[aq]T\[aq]" |
| 164 |
Mark a directory for special treatment under the Orlov block-allocation |
| 165 |
strategy. |
| 166 |
See |
| 167 |
.BR chattr (1) |
| 168 |
for details. |
| 169 |
This flag can be applied only to directories and |
| 170 |
has an effect only for ext2, ext3, and ext4. |
| 171 |
.TP |
| 172 |
.BR FS_UNRM_FL " \[aq]u\[aq]" |
| 173 |
Allow the file to be undeleted if it is deleted. |
| 174 |
This feature is not implemented by any filesystem, |
| 175 |
since it is possible to implement file-recovery mechanisms outside the kernel. |
| 176 |
.P |
| 177 |
In most cases, |
| 178 |
when any of the above flags is set on a directory, |
| 179 |
the flag is inherited by files and subdirectories |
| 180 |
created inside that directory. |
| 181 |
Exceptions include |
| 182 |
.BR FS_TOPDIR_FL , |
| 183 |
which is not inheritable, and |
| 184 |
.BR FS_DIRSYNC_FL , |
| 185 |
which is inherited only by subdirectories. |
| 186 |
.SH STANDARDS |
| 187 |
Linux. |
| 188 |
.SH NOTES |
| 189 |
In order to change the inode flags of a file using the |
| 190 |
.B FS_IOC_SETFLAGS |
| 191 |
operation, |
| 192 |
the effective user ID of the caller must match the owner of the file, |
| 193 |
or the caller must have the |
| 194 |
.B CAP_FOWNER |
| 195 |
capability. |
| 196 |
.SH SEE ALSO |
| 197 |
.BR ioctl (2), |
| 198 |
.BR chattr (1), |
| 199 |
.BR lsattr (1), |
| 200 |
.BR mount (2), |
| 201 |
.BR btrfs (5), |
| 202 |
.BR ext4 (5), |
| 203 |
.BR xfs (5), |
| 204 |
.BR xattr (7), |
| 205 |
.BR mount (8) |