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, 0 is returned β€” slay ✨
  • on error, -1 is returned, and errno is 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 πŸ’œ

ioctl(2), ioctl_fat(2)

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