Debian Codegraph @

upstream/debian-unstable/man2/FAT_IOCTL_GET_VOLUME_ID.2const

raw
1 .\" Copyright, the authors of the Linux man-pages project
2 .\"
3 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
4 .\"
5 .TH FAT_IOCTL_GET_VOLUME_ID 2const 2025-05-17 "Linux man-pages 6.18"
6 .SH NAME
7 FAT_IOCTL_GET_VOLUME_ID
8 \-
9 read the volume ID in a FAT filesystem
10 .SH LIBRARY
11 Standard C library
12 .RI ( libc ,\~ \-lc )
13 .SH SYNOPSIS
14 .nf
15 .BR "#include <linux/msdos_fs.h>" " /* Definition of " FAT_* " constants */"
16 .B #include <sys/ioctl.h>
17 .P
18 .BI "int ioctl(int " fd ", FAT_IOCTL_GET_VOLUME_ID, uint32_t *" id );
19 .fi
20 .SH DESCRIPTION
21 FAT filesystems are identified by a volume ID.
22 The volume ID can be read with
23 .BR FAT_IOCTL_GET_VOLUME_ID .
24 .P
25 The
26 .I fd
27 argument can be a file descriptor for any file or directory of the
28 filesystem.
29 It is sufficient to create the file descriptor by calling
30 .BR open (2)
31 with the
32 .B O_RDONLY
33 flag.
34 .P
35 The
36 .I id
37 argument is a pointer to the field that will be filled with the volume ID.
38 Typically the volume ID is displayed to the user as a group of two
39 16-bit fields:
40 .P
41 .in +4n
42 .EX
43 printf("Volume ID %04x\-%04x\[rs]n", id >> 16, id & 0xFFFF);
44 .EE
45 .in
46 .SH RETURN VALUE
47 On success,
48 0 is returned.
49 On error, \-1 is returned, and
50 .I errno
51 is set to indicate the error.
52 .SH STANDARDS
53 Linux.
54 .SH HISTORY
55 Linux 3.11.
56 .\" commit 6e5b93ee55d401f1619092fb675b57c28c9ed7ec
57 .SH EXAMPLES
58 The following program demonstrates the use of
59 .BR ioctl (2)
60 to display the volume ID of a FAT filesystem.
61 .P
62 The following output was recorded when applying the program for
63 directory
64 .IR /mnt/user :
65 .P
66 .in +4n
67 .EX
68 $ ./display_fat_volume_id /mnt/user
69 Volume ID 6443\-6241
70 .EE
71 .in
72 .SS Program source (display_fat_volume_id.c)
73 \&
74 .\" SRC BEGIN (display_fat_volume_id.c)
75 .EX
76 #include <fcntl.h>
77 #include <linux/msdos_fs.h>
78 #include <stdint.h>
79 #include <stdio.h>
80 #include <stdlib.h>
81 #include <sys/ioctl.h>
82 #include <unistd.h>
83 \&
84 int
85 main(int argc, char *argv[])
86 {
87 int fd;
88 int ret;
89 uint32_t id;
90 \&
91 if (argc != 2) {
92 printf("Usage: %s FILENAME\[rs]n", argv[0]);
93 exit(EXIT_FAILURE);
94 }
95 \&
96 fd = open(argv[1], O_RDONLY);
97 if (fd == \-1) {
98 perror("open");
99 exit(EXIT_FAILURE);
100 }
101 \&
102 /*
103 * Read volume ID.
104 */
105 ret = ioctl(fd, FAT_IOCTL_GET_VOLUME_ID, &id);
106 if (ret == \-1) {
107 perror("ioctl");
108 exit(EXIT_FAILURE);
109 }
110 \&
111 /*
112 * Format the output as two groups of 16 bits each.
113 */
114 printf("Volume ID %04x\-%04x\[rs]n", id >> 16, id & 0xFFFF);
115 \&
116 close(fd);
117 \&
118 exit(EXIT_SUCCESS);
119 }
120 .EE
121 .\" SRC END
122 .SH SEE ALSO
123 .BR ioctl (2),
124 .BR ioctl_fat (2)