Debian Codegraph @

upstream/debian-trixie/man2/FAT_IOCTL_SET_ATTRIBUTES.2const

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