File: FAT_IOCTL_SET_ATTRIBUTES.2const

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