File: FAT_IOCTL_GET_VOLUME_ID.2const

package info (click to toggle)
manpages 6.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 19,808 kB
  • sloc: sh: 503; python: 222; perl: 165; makefile: 27; lisp: 22
file content (125 lines) | stat: -rw-r--r-- 2,635 bytes parent folder | download
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
.\" Copyright 2014, Heinrich Schuchardt <xypron.glpk@gmx.de>
.\" Copyright 2024, Alejandro Colomar <alx@kernel.org>
.\"
.\" SPDX-License-Identifier: Linux-man-pages-copyleft
.\"
.TH FAT_IOCTL_GET_VOLUME_ID 2const 2024-06-15 "Linux man-pages (unreleased)"
.SH NAME
FAT_IOCTL_GET_VOLUME_ID
\-
read the volume ID in a FAT filesystem
.SH LIBRARY
Standard C library
.RI ( libc ", " \-lc )
.SH SYNOPSIS
.nf
.BR "#include <linux/msdos_fs.h>" "  /* Definition of " FAT_* " constants */"
.B #include <sys/ioctl.h>
.P
.BI "int ioctl(int " fd ", FAT_IOCTL_GET_VOLUME_ID, uint32_t *" id );
.fi
.SH DESCRIPTION
FAT filesystems are identified by a volume ID.
The volume ID can be read with
.BR FAT_IOCTL_GET_VOLUME_ID .
.P
The
.I fd
argument can be a file descriptor for any file or directory of the
filesystem.
It is sufficient to create the file descriptor by calling
.BR open (2)
with the
.B O_RDONLY
flag.
.P
The
.I id
argument is a pointer to the field that will be filled with the volume ID.
Typically the volume ID is displayed to the user as a group of two
16-bit fields:
.P
.in +4n
.EX
printf("Volume ID %04x\-%04x\[rs]n", id >> 16, id & 0xFFFF);
.EE
.in
.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
Linux 3.11.
.\" commit 6e5b93ee55d401f1619092fb675b57c28c9ed7ec
.SH EXAMPLES
The following program demonstrates the use of
.BR ioctl (2)
to display the volume ID of a FAT filesystem.
.P
The following output was recorded when applying the program for
directory
.IR /mnt/user :
.P
.in +4n
.EX
$ ./display_fat_volume_id /mnt/user
Volume ID 6443\-6241
.EE
.in
.SS Program source (display_fat_volume_id.c)
\&
.\" SRC BEGIN (display_fat_volume_id.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>
\&
int
main(int argc, char *argv[])
{
    int       fd;
    int       ret;
    uint32_t  id;
\&
    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 volume ID.
     */
    ret = ioctl(fd, FAT_IOCTL_GET_VOLUME_ID, &id);
    if (ret == \-1) {
        perror("ioctl");
        exit(EXIT_FAILURE);
    }
\&
    /*
     * Format the output as two groups of 16 bits each.
     */
    printf("Volume ID %04x\-%04x\[rs]n", id >> 16, id & 0xFFFF);
\&
    close(fd);
\&
    exit(EXIT_SUCCESS);
}
.EE
.\" SRC END
.SH SEE ALSO
.BR ioctl (2),
.BR ioctl_fat (2)