Results 1 to 2 of 2
Hi..Friends,
I am very much new to Linux programming. My question is Is there any way to read UUID of a device or partition in linux programatically. Is there any ...
- 03-13-2011 #1Just Joined!
- Join Date
- Mar 2011
- Posts
- 1
How get uuid of a device/partition in linux programatically?
Hi..Friends,
I am very much new to Linux programming. My question is Is there any way to read UUID of a device or partition in linux programatically. Is there any c/c++ API for user-space applications. I found some commands "sudo vol_id --uuid /dev/sda1", "sudo blkid", "ls -l /dev/disk/by-uuid/". But all are commands which we need to run in terminal. But i need to achieve this from a c/c++ program. Can some one help me in this problem.(FYI: I need to read uuid of root filesystem ("/") where Linux has been installed.)
Thank you in advance.
- 03-13-2011 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
These two headers (and the associated libraries) have functions that may work for you:
There may be better options, but I don't know what they would be offhand.Code:/usr/include/hal/libhal-storage.h const char *libhal_volume_get_partition_uuid(LibHalVolume *volume); const char *libhal_volume_get_uuid(LibHalVolume *volume); /usr/include/glib-2.0/gio/gmount.h char *g_mount_get_uuid(GMount *mount);Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote