NAME
FAT_IOCTL_GET_VOLUME_ID - read the volume ID in a FAT filesystem
LIBRARY
Standard C library (libc, -lc)
SYNOPSIS
#include <linux/msdos_fs.h>\n /* Definition of \nFAT_*\n constants */
\n#include <sys/ioctl.h>int ioctl(int \nfd\n, FAT_IOCTL_GET_VOLUME_ID, uint32_t *\nid\n);DESCRIPTION
FAT filesystems are identified by a volume ID. The volume ID can be read with FAT_IOCTL_GET_VOLUME_ID.
The 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 open(2) with the O_RDONLY flag.
The 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:
printf("Volume ID %04x-%04x\n", id >> 16, id & 0xFFFF);RETURN VALUE
On success, 0 is returned. On error, -1 is returned, and errno is set to indicate the error.
STANDARDS
Linux.
HISTORY
Linux 3.11.
EXAMPLES
The following program demonstrates the use of ioctl(2) to display the volume ID of a FAT filesystem.
The following output was recorded when applying the program for directory /mnt/user:
$ ./display_fat_volume_id /mnt/user
Volume ID 6443-6241Program source (display_fat_volume_id.c)
#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[])
{
\n
int fd;
\n
int ret;
\n
uint32_t id;
\n
if (argc != 2) {
\n
printf("Usage: %s FILENAME\n", argv[0]);
\n
exit(EXIT_FAILURE);
\n
}
\n
fd = open(argv[1], O_RDONLY);
\n
if (fd == -1) {
\n
perror("open");
\n
exit(EXIT_FAILURE);
\n
}
\n
/*
\n
* Read volume ID.
\n
*/
\n
ret = ioctl(fd, FAT_IOCTL_GET_VOLUME_ID, &id);
\n
if (ret == -1) {
\n
perror("ioctl");
\n
exit(EXIT_FAILURE);
\n
}
\n
/*
\n
* Format the output as two groups of 16 bits each.
\n
*/
\n
printf("Volume ID %04x-%04x\n", id >> 16, id & 0xFFFF);
\n
close(fd);
\n
exit(EXIT_SUCCESS);
}SEE ALSO
ioctl(2), ioctl_fat(2)