How get uuid of a device/partition in linux programatically?

牧云@^-^@ 提交于 2019-12-04 05:18:51

The general approach would be:

  • find out what device your / is on by parsing /etc/mtab for example
  • go through the /dev/disks/by-uuid directory (using opendir/readdir/closedir) and find which one points to that device.

See the readlink function for getting the target of a symbolic link. You'll find plenty of code examples for parsing text files on this site or with your favorite search engine.

Since blkid already does it, you could also just see how it works and pilfer the solution, if you abide by util-linux's license (GPLv2).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!