FAT_IOCTL_GET_VOLUME_ID(2const)
π FAT_IOCTL_GET_VOLUME_ID(2const) π
okay so bestie, welcome to this 2const manual page, literally the cutest lil corner of the Linux man-pages β¨ (a 2const page is like a lil sidekick page for a specific constant, not a whole syscall, iykyk)
πΈ 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> /* Definition of FAT_* constants */
#include <sys/ioctl.h>
int ioctl(int fd, FAT_IOCTL_GET_VOLUME_ID, uint32_t *id);
π DESCRIPTION π
so FAT filesystems are identified by a volume ID. iconic. and you can read that volume ID with FAT_IOCTL_GET_VOLUME_ID. that's literally the whole job, no cap π«Ά
the fd argument can be a file descriptor for any file or directory of the filesystem. you don't need anything fancy β it's sufficient to create the file descriptor by calling open(2) with the O_RDONLY flag. lowkey the easiest setup ever.
the id argument is a pointer to the field that will get 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);
so cute, so tidy, two lil 16-bit halves holding hands π
π₯ RETURN VALUE π₯
- on success,
0is returned β slay β¨ - on error,
-1is returned, anderrnois set to indicate the error π
π STANDARDS π
Linux. (periodt.)
π¦ HISTORY π¦
Linux 3.11.
π EXAMPLES π
the following program demonstrates the use of ioctl(2) to display the volume ID of a FAT filesystem. main character energy fr fr.
the following output was recorded when applying the program for directory /mnt/user:
$ ./display_fat_volume_id /mnt/user
Volume ID 6443-6241
π Program 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[])
{
int fd;
int ret;
uint32_t id;
if (argc != 2) {
printf("Usage: %s FILENAME\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\n", id >> 16, id & 0xFFFF);
close(fd);
exit(EXIT_SUCCESS);
}
π SEE ALSO π
not me being obsessed with a filesystem magic number, but here we are π
and that's the whole page bestie!! this gem is from Linux man-pages 6.20, dated 2025-05-17 β mwah, go read your FAT volume IDs responsibly π§π
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: Linux-man-pages-copyleft
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms