What is the difference between FS_IOC_GETFLAGS and FS_IOC_FSGETXATTR ioctl commands? What flags do both return?
2 Answers
In the Linux context, FS_IOC_GETFLAGS and FS_IOC_FSGETXATTR both retrieve inode flags.
GETFLAGS is the older ioctl, and comes originally from ext2 (again, in Linux); it manipulates a 32-bit value and has thus limited expansion capabilities — there aren’t many unused bits available.
FSGETXATTR comes from XFS, and was recently (2016) moved from XFS to the shared VFS layer. It uses a data structure, struct fsxattr, which allows for more values and more expansion.
Both of these, and the meanings of the data they return, are defined in linux/fs.h. The GETFLAGS flags are additionally documented in ioctl_iflags(2). Common values between the two correspond mostly to GETFLAGS flags which were historically supported by XFS: “append only”, “no atime updates”, “no dump”, “immutable”, and “synchronous updates”.
Note that in both cases support varies from one file system to another, and some flags aren’t actually supported at all.
- Thank you, Stephen. Great explanation. One question more, how to set these xflags via linux cli?Sameer Khurd– Sameer Khurd2018-06-08 13:23:10 +00:00Commented Jun 8, 2018 at 13:23
- Two CLI tools supports
fsxattr-specific flags, as far as I’m aware:chattrallows setting project-related flags, andxfs_fsrallows settings XFS flags (but only on XFS). Some tools (Docker, Ceph...) supportfsxattrflags internally, but I don’t know whether they allow manipulating them externally.Stephen Kitt– Stephen Kitt2018-06-08 14:25:21 +00:00Commented Jun 8, 2018 at 14:25
FS_IOC_GETFLAGS is an interface to access BSD style file flags. It just uses a much worse interface than *BSD, since you need to open the file in order to get access. *BSD has these informations in struct stat, so if you like to get the related information in /dev/ entries on Linux, you may cause a tape drive to rewind it's medium.
FS_IOC_FSGETXATTRis a similar but apparently incompatible interface from XFS that seems to be supported by ext4 as well since September 2015.
Conclusion: both interfaces are badly designed since they need to open the file in order to get access. The maintainers do not seem to care about their interfaces since they do not inform important users like star which is able to back up and restore the flags from the FS_IOC_GETFLAGSinterface.
- Not sure who’s downvoting these answers... Do you have a pointer to the extended attribute proposal in question?Stephen Kitt– Stephen Kitt2018-06-08 14:32:35 +00:00Commented Jun 8, 2018 at 14:32
- Hi, I fixed my text, it seems that I was mistaken since the name of the second call is very similar to the withdrawn xattr interface. There seem to be some people who follow me and downvote all my answers. This was the POSIX.1e ACL draft. You may try: simson.net/ref/1997/posix_1003.1e-990310.pdfschily– schily2018-06-08 14:53:42 +00:00Commented Jun 8, 2018 at 14:53
- Thanks, I wondered if you were referring to POSIX.1e. The difference in interfaces between the BSDs and Linux is indeed unfortunate...Stephen Kitt– Stephen Kitt2018-06-08 15:01:17 +00:00Commented Jun 8, 2018 at 15:01
- well, Linux could fix the interface without becoming incompatible to older Linux versions: It would just need to implement and document that an open() with the open flag
O_SEARCHbut withoutO_RDONLYorO_WRONLYwill be allowed to issue aFS_IOC_GETFLAGSiotcl()but will not cause any side effects in theopen()call.O_SEARCHhas been introduced in POSIX from my proposal similar to an open method from UNOS that did not havestat()but onlyfstat().schily– schily2018-06-08 15:07:09 +00:00Commented Jun 8, 2018 at 15:07