FAT_IOCTL_SET_ATTRIBUTES(2const)
π FAT_IOCTL_SET_ATTRIBUTES π
okay bestie, so this is a <pink>2const</pink> page β that means it's one of those lil' constant-focused man pages, not a whole syscall. and today's topic?? file attributes on FAT filesystems. yes, the same FAT from your USB stick. we're getting and setting those attribute bits like the absolute icon you are π
β¨ NAME β¨
FAT_IOCTL_GET_ATTRIBUTES, FAT_IOCTL_SET_ATTRIBUTES β get and set file attributes in a FAT filesystem π¦
π LIBRARY π
Standard C library (libc, -lc) β the classic, no cap.
πΈ SYNOPSIS πΈ
#include <linux/msdos_fs.h> /* Definition of FAT_* and
ATTR_* constants */
#include <sys/ioctl.h>
int ioctl(int fd, FAT_IOCTL_GET_ATTRIBUTES, uint32_t *attr);
int ioctl(int fd, FAT_IOCTL_SET_ATTRIBUTES, uint32_t *attr);
like, look at that. two ioctls, one attr pointer. it's giving minimalist queen β¨
π DESCRIPTION π
so here's the tea π β files and directories living on a FAT filesystem each carry around an attribute bit mask. you can read it with FAT_IOCTL_GET_ATTRIBUTES and write it with FAT_IOCTL_SET_ATTRIBUTES. simple as.
the fd argument is a file descriptor for a file or a directory. and get this β it is sufficient to create that file descriptor by calling open(2) with the O_RDONLY flag. so yes, read-only open and you can still set attributes. no cap, that's genuinely how it works π«Ά
the attr argument is a pointer to a bit mask. and the bits of that bit mask are... drumroll please π₯
ATTR_ROβ this bit says the file or directory is read-only. πATTR_HIDDENβ this bit says the file or directory is hidden. sneaky lil' thing.ATTR_SYSβ this bit says the file is a system file. main character energy, but system edition.ATTR_VOLUMEβ this bit says the file is a volume label. π heads up tho: this attribute is read-only.ATTR_DIRβ this bit says this is a directory. also read-only, so don't come for it πATTR_ARCHβ this bit indicates that this file or directory should be archived. it gets set when a file is created or modified, and it gets reset by an archiving system. the archiving system's lil' todo list basically β
and the zero value ATTR_NONE can be used to indicate that no attribute bit is set. literally the "nothing here" option π§
π₯ RETURN VALUE π₯
- on success,
0is returned. slay. - on error,
-1is returned, anderrnois set to indicate the error. π
π STANDARDS π
Linux. that's it. that's the standard. π
β HISTORY β
Linux 2.6.12. old enough to be iconic, young enough to still serve.
π EXAMPLES π
okay so this next part is so fun β the following program demonstrates the usage of ioctl(2) to manipulate file attributes. it reads and displays the archive attribute of a file. then, after inverting the value of that attribute, it reads and displays the attribute again. a little glow-up-and-check moment β¨
and the following was recorded when applying the program for the file /mnt/user/foo:
# ./toggle_fat_archive_flag /mnt/user/foo
Archive flag is set
Toggling archive flag
Archive flag is not set
πΈ Program source (toggle_fat_archive_flag.c) πΈ
#include <fcntl.h>
#include <linux/msdos_fs.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <unistd.h>
/*
* Read file attributes of a file on a FAT filesystem.
* Output the state of the archive flag.
*/
static uint32_t
readattr(int fd)
{
int ret;
uint32_t attr;
ret = ioctl(fd, FAT_IOCTL_GET_ATTRIBUTES, &attr);
if (ret == -1) {
perror("ioctl");
exit(EXIT_FAILURE);
}
if (attr & ATTR_ARCH)
printf("Archive flag is set\n");
else
printf("Archive flag is not set\n");
return attr;
}
int
main(int argc, char *argv[])
{
int fd;
int ret;
uint32_t attr;
if (argc != 2) {
printf("Usage: %s FILENAME\n", argv[0]);
exit(EXIT_FAILURE);
}
fd = open(argv[1], O_RDONLY);
if (fd == -1) {
perror("open");
exit(EXIT_FAILURE);
}
/*
* Read and display the FAT file attributes.
*/
attr = readattr(fd);
/*
* Invert archive attribute.
*/
printf("Toggling archive flag\n");
attr ^= ATTR_ARCH;
/*
* Write the changed FAT file attributes.
*/
ret = ioctl(fd, FAT_IOCTL_SET_ATTRIBUTES, &attr);
if (ret == -1) {
perror("ioctl");
exit(EXIT_FAILURE);
}
/*
* Read and display the FAT file attributes.
*/
readattr(fd);
close(fd);
exit(EXIT_SUCCESS);
}
like?? the ^= ATTR_ARCH XOR toggle?? that's the whole trick and it ate π₯
π¦ SEE ALSO π¦
and that's the whole page bestie π this was Linux man-pages 6.20, dated 2025-05-17, and honestly?? iconic of it to be this cute about bit masks. go forth and toggle ur archive flags, iykyk β¨ππ
π¦ 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