I was looking at libblkid and was confused about the documentation. Could someone provide me with an example of how I could find the UUID of a root linux partition using this library?
I was looking at libblkid and was confused about the documentation. Could someone provide
Share
It’s pretty much as simple as the manual makes it look: you create a probe structure, initialize it, ask it for some information, and then free it. And you can combine the first two steps into one. This is a working program:
blkid_probe_lookup_valuesetsuuidto point to a string that belongs to theprstructure, which is why the argument is of typeconst char *. If you needed to, you could copy it to achar *that you manage on your own, but for just passing toprintf, that’s not needed. The fourth argument toblkid_probe_lookup_valuelets you get the length of the returned value in case you need that as well. There are some subtle differences betweenblkid_do_probe,blkid_do_safeprobe, andblkid_do_fullprobe, but in cases where the device has a known filesystem and you just want to pull the UUID out of it, taking the first result fromblkid_do_probeshould do.