LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-04-2017, 08:39 AM   #1
Xeratul
Senior Member
 
Registered: Jun 2006
Location: UNIX
Distribution: FreeBSD
Posts: 2,357

Rep: Reputation: 213Reputation: 213Reputation: 213
Get UUID of a device (without using blkid.h) using low-level C language?


Hello,

It is possible to get the UUID of an harddisk with blkid, which is a library to look in infos about devices.

There is here possible way using this library.
https://stackoverflow.com/questions/...ion-infomation

However this is not a code which can be universal and largely portable:
Code:
~$ gcc -o getuuid getuuid.c -lblkid
getuuid.c:4:25: fatal error: blkid/blkid.h: No such file or directory
 #include <blkid/blkid.h>
                         ^
compilation terminated.
Would you know a possible alternative to get UUID of a device (without using blkid.h) using low-level C language?

thank you

Last edited by Xeratul; 08-04-2017 at 08:41 AM.
 
Old 08-04-2017, 08:58 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,317

Rep: Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008
Install package libblkid-dev
Or use popen("/sbin/blkid", "r")
 
Old 08-04-2017, 09:06 AM   #3
Xeratul
Senior Member
 
Registered: Jun 2006
Location: UNIX
Distribution: FreeBSD
Posts: 2,357

Original Poster
Rep: Reputation: 213Reputation: 213Reputation: 213
Quote:
Originally Posted by NevemTeve View Post
Install package libblkid-dev
Or use popen("/sbin/blkid", "r")
Thank you but it is not portable on any machines. It shall work on any Unix platform, without the devel libraries of blkid.
 
Old 08-04-2017, 09:16 AM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 15,996

Rep: Reputation: 2219Reputation: 2219Reputation: 2219Reputation: 2219Reputation: 2219Reputation: 2219Reputation: 2219Reputation: 2219Reputation: 2219Reputation: 2219Reputation: 2219
Hard disk devices don't have UUIDs
 
1 members found this post helpful.
Old 08-04-2017, 09:19 AM   #5
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,317

Rep: Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008Reputation: 1008
use popen("/sbin/blkid", "r")
 
Old 08-04-2017, 09:29 AM   #6
Xeratul
Senior Member
 
Registered: Jun 2006
Location: UNIX
Distribution: FreeBSD
Posts: 2,357

Original Poster
Rep: Reputation: 213Reputation: 213Reputation: 213
Quote:
Originally Posted by syg00 View Post
Hard disk devices don't have UUIDs
+1

Good point... https://social.technet.microsoft.com...m=winservergen

interesting

However MS Windows seems to have also a sort of UID

Windows developers are stating from above link as follows:
Quote:
Every hard disk has a unique ID stored in the hard disk. This is used to identify the hard disk. This is a 128-bit universally unique identifier (UUID). This field is used to associate a parent hard disk image with its differencing hard disk image(s).
Mountvol gives guid for the formated partion and VHD can have more than one of those.
(Visual C++ to get GUID)

Last edited by Xeratul; 08-04-2017 at 09:34 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
blkid/blkid.h: No such file or directory sundanat Linux - Hardware 4 05-24-2015 08:20 AM
Can two different device drivers use the same low level bus driver? anuragccsu Linux - Embedded & Single-board computer 1 04-28-2011 03:08 PM
[SOLVED] How to mount by-uuid if the device won't show in /dev/disk/by-uuid untill after blkid /dev/sd* ? masmddr Linux - General 4 01-10-2011 08:38 PM
Low level access to USB device Recursion Linux - Hardware 5 12-01-2009 10:21 PM
Low level formatting.... Santorres Linux - General 1 02-02-2004 08:50 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration