LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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, 07:39 AM   #1
Xeratul
Senior Member
 
Registered: Jun 2006
Location: UNIX
Distribution: FreeBSD
Posts: 2,657

Rep: Reputation: 255Reputation: 255Reputation: 255
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 07:41 AM.
 
Old 08-04-2017, 07:58 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

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

Original Poster
Rep: Reputation: 255Reputation: 255Reputation: 255
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, 08:16 AM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

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

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

Original Poster
Rep: Reputation: 255Reputation: 255Reputation: 255
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 08:34 AM.
 
  


Reply



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 07:20 AM
Can two different device drivers use the same low level bus driver? anuragccsu Linux - Embedded & Single-board computer 1 04-28-2011 02: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 07:38 PM
Low level access to USB device Recursion Linux - Hardware 5 12-01-2009 09:21 PM
Low level formatting.... Santorres Linux - General 1 02-02-2004 07:50 AM

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

All times are GMT -5. The time now is 04:09 PM.

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
Open Source Consulting | Domain Registration