| 1 |
.\" Copyright, the authors of the Linux man-pages project |
| 2 |
.\" |
| 3 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 4 |
.\" |
| 5 |
.TH FAT_IOCTL_SET_ATTRIBUTES 2const 2025-05-17 "Linux man-pages 6.18" |
| 6 |
.SH NAME |
| 7 |
FAT_IOCTL_GET_ATTRIBUTES, |
| 8 |
FAT_IOCTL_SET_ATTRIBUTES |
| 9 |
\- |
| 10 |
get and set file attributes in a FAT filesystem |
| 11 |
.SH LIBRARY |
| 12 |
Standard C library |
| 13 |
.RI ( libc ,\~ \-lc ) |
| 14 |
.SH SYNOPSIS |
| 15 |
.nf |
| 16 |
.BR "#include <linux/msdos_fs.h>" " /* Definition of " FAT_* " and" |
| 17 |
.RB " " ATTR_* " constants */" |
| 18 |
.B #include <sys/ioctl.h> |
| 19 |
.P |
| 20 |
.BI "int ioctl(int " fd ", FAT_IOCTL_GET_ATTRIBUTES, uint32_t *" attr ); |
| 21 |
.BI "int ioctl(int " fd ", FAT_IOCTL_SET_ATTRIBUTES, uint32_t *" attr ); |
| 22 |
.fi |
| 23 |
.SH DESCRIPTION |
| 24 |
Files and directories in the FAT filesystem possess an attribute bit mask that |
| 25 |
can be read with |
| 26 |
.B FAT_IOCTL_GET_ATTRIBUTES |
| 27 |
and written with |
| 28 |
.BR FAT_IOCTL_SET_ATTRIBUTES . |
| 29 |
.P |
| 30 |
The |
| 31 |
.I fd |
| 32 |
argument contains a file descriptor for a file or directory. |
| 33 |
It is sufficient to create the file descriptor by calling |
| 34 |
.BR open (2) |
| 35 |
with the |
| 36 |
.B O_RDONLY |
| 37 |
flag. |
| 38 |
.P |
| 39 |
The |
| 40 |
.I attr |
| 41 |
argument contains a pointer to a bit mask. |
| 42 |
The bits of the bit mask are: |
| 43 |
.TP |
| 44 |
.B ATTR_RO |
| 45 |
This bit specifies that the file or directory is read-only. |
| 46 |
.TP |
| 47 |
.B ATTR_HIDDEN |
| 48 |
This bit specifies that the file or directory is hidden. |
| 49 |
.TP |
| 50 |
.B ATTR_SYS |
| 51 |
This bit specifies that the file is a system file. |
| 52 |
.TP |
| 53 |
.B ATTR_VOLUME |
| 54 |
This bit specifies that the file is a volume label. |
| 55 |
This attribute is read-only. |
| 56 |
.TP |
| 57 |
.B ATTR_DIR |
| 58 |
This bit specifies that this is a directory. |
| 59 |
This attribute is read-only. |
| 60 |
.TP |
| 61 |
.B ATTR_ARCH |
| 62 |
This bit indicates that this file or directory should be archived. |
| 63 |
It is set when a file is created or modified. |
| 64 |
It is reset by an archiving system. |
| 65 |
.P |
| 66 |
The zero value |
| 67 |
.B ATTR_NONE |
| 68 |
can be used to indicate that no attribute bit is set. |
| 69 |
.SH RETURN VALUE |
| 70 |
On success, |
| 71 |
0 is returned. |
| 72 |
On error, \-1 is returned, and |
| 73 |
.I errno |
| 74 |
is set to indicate the error. |
| 75 |
.SH STANDARDS |
| 76 |
Linux. |
| 77 |
.SH HISTORY |
| 78 |
.\" just before we got Git history |
| 79 |
Linux 2.6.12. |
| 80 |
.SH EXAMPLES |
| 81 |
The following program demonstrates the usage of |
| 82 |
.BR ioctl (2) |
| 83 |
to manipulate file attributes. |
| 84 |
The program reads and displays the archive attribute of a file. |
| 85 |
After inverting the value of the attribute, |
| 86 |
the program reads and displays the attribute again. |
| 87 |
.P |
| 88 |
The following was recorded when applying the program for the file |
| 89 |
.IR /mnt/user/foo : |
| 90 |
.P |
| 91 |
.in +4n |
| 92 |
.EX |
| 93 |
# ./toggle_fat_archive_flag /mnt/user/foo |
| 94 |
Archive flag is set |
| 95 |
Toggling archive flag |
| 96 |
Archive flag is not set |
| 97 |
.EE |
| 98 |
.in |
| 99 |
.SS Program source (toggle_fat_archive_flag.c) |
| 100 |
\& |
| 101 |
.\" SRC BEGIN (toggle_fat_archive_flag.c) |
| 102 |
.EX |
| 103 |
#include <fcntl.h> |
| 104 |
#include <linux/msdos_fs.h> |
| 105 |
#include <stdint.h> |
| 106 |
#include <stdio.h> |
| 107 |
#include <stdlib.h> |
| 108 |
#include <sys/ioctl.h> |
| 109 |
#include <unistd.h> |
| 110 |
\& |
| 111 |
/* |
| 112 |
* Read file attributes of a file on a FAT filesystem. |
| 113 |
* Output the state of the archive flag. |
| 114 |
*/ |
| 115 |
static uint32_t |
| 116 |
readattr(int fd) |
| 117 |
{ |
| 118 |
int ret; |
| 119 |
uint32_t attr; |
| 120 |
\& |
| 121 |
ret = ioctl(fd, FAT_IOCTL_GET_ATTRIBUTES, &attr); |
| 122 |
if (ret == \-1) { |
| 123 |
perror("ioctl"); |
| 124 |
exit(EXIT_FAILURE); |
| 125 |
} |
| 126 |
\& |
| 127 |
if (attr & ATTR_ARCH) |
| 128 |
printf("Archive flag is set\[rs]n"); |
| 129 |
else |
| 130 |
printf("Archive flag is not set\[rs]n"); |
| 131 |
\& |
| 132 |
return attr; |
| 133 |
} |
| 134 |
\& |
| 135 |
int |
| 136 |
main(int argc, char *argv[]) |
| 137 |
{ |
| 138 |
int fd; |
| 139 |
int ret; |
| 140 |
uint32_t attr; |
| 141 |
\& |
| 142 |
if (argc != 2) { |
| 143 |
printf("Usage: %s FILENAME\[rs]n", argv[0]); |
| 144 |
exit(EXIT_FAILURE); |
| 145 |
} |
| 146 |
\& |
| 147 |
fd = open(argv[1], O_RDONLY); |
| 148 |
if (fd == \-1) { |
| 149 |
perror("open"); |
| 150 |
exit(EXIT_FAILURE); |
| 151 |
} |
| 152 |
\& |
| 153 |
/* |
| 154 |
* Read and display the FAT file attributes. |
| 155 |
*/ |
| 156 |
attr = readattr(fd); |
| 157 |
\& |
| 158 |
/* |
| 159 |
* Invert archive attribute. |
| 160 |
*/ |
| 161 |
printf("Toggling archive flag\[rs]n"); |
| 162 |
attr \[ha]= ATTR_ARCH; |
| 163 |
\& |
| 164 |
/* |
| 165 |
* Write the changed FAT file attributes. |
| 166 |
*/ |
| 167 |
ret = ioctl(fd, FAT_IOCTL_SET_ATTRIBUTES, &attr); |
| 168 |
if (ret == \-1) { |
| 169 |
perror("ioctl"); |
| 170 |
exit(EXIT_FAILURE); |
| 171 |
} |
| 172 |
\& |
| 173 |
/* |
| 174 |
* Read and display the FAT file attributes. |
| 175 |
*/ |
| 176 |
readattr(fd); |
| 177 |
\& |
| 178 |
close(fd); |
| 179 |
\& |
| 180 |
exit(EXIT_SUCCESS); |
| 181 |
} |
| 182 |
.EE |
| 183 |
.\" SRC END |
| 184 |
.SH SEE ALSO |
| 185 |
.BR ioctl (2), |
| 186 |
.BR ioctl_fat (2) |