Debian Codegraph @

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