Possible Duplicate:
How to get drive label in Linux using C from userspace
How can I obtain label of a disk by its file name (/dev/sda1, e.g.) in a program written in C/C++?
Possible Duplicate:
How to get drive label in Linux using C from userspace
How can I obtain label of a disk by its file name (/dev/sda1, e.g.) in a program written in C/C++?
You can code the C or C++ equivalent of this command:
find -L /dev/disk/by-label -inum $(stat -c %i /dev/sda1) -print
That is, stat()
the device file you care about and remember its inode number. Iterate over all of the files in /dev/disk/by-label, and stat()
each of them. When the inode number matches, then the name of the matched file is the label of that disk.
If it were me, I'd code the above algorithm in C++, using Boost.Filesystem.