<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>Il 05/01/2019 17:03, Bart ha scritto:<br>
</p>
<blockquote type="cite"
cite="mid:CAMye31xY1k=dOLcR0Asty_AjkGFTS5_T9WVrrty_Jy4d4FpM1Q@mail.gmail.com">
<pre wrap="">I need some function to get a unique ID for a disk.
I need this to identify if my program has accessed this disk previously.
</pre>
</blockquote>
<br>
For that purpose on Linux, out of laziness, I usually just parse the
output of command-line utilities, such as blkid or lsblk.<br>
blkid /devs/sd<i>xy</i> provides an output such as:<br>
<br>
<tt>blkid /dev/sda1<br>
/dev/sda1: LABEL="SYSTEM" UUID="980C041F0C03F6D2" TYPE="ntfs"</tt><tt><br>
</tt><br>
or<tt><br>
<br>
</tt><tt>blkid /dev/sda3<br>
/dev/sda3: UUID="ce9d5b2f-232f-4a87-a75e-70e1386dd134" TYPE="ext4"<br>
</tt><tt></tt><br>
while lsblk can provide either a single partition UUID (/dev/sd<i>xy</i>)
or the UUIDS for all the disk partitions (/dev/sd<i>x</i>):<br>
<tt><br>
sudo lsblk -f /dev/sda3</tt><tt><br>
</tt><tt>NAME FSTYPE LABEL UUID
MOUNTPOINT</tt><tt><br>
</tt><tt>sda3 ext4 ce9d5b2f-232f-4a87-a75e-70e1386dd134
/boot</tt><br>
<br>
or<br>
<tt><br>
sudo lsblk -f /dev/sda</tt><tt><br>
</tt><tt>NAME FSTYPE LABEL
UUID MOUNTPOINT</tt><tt><br>
</tt><tt>sda</tt><tt><br>
</tt><tt>├─sda1 ntfs SYSTEM 980C041F0C03F6D2</tt><tt><br>
</tt><tt>├─sda2 ntfs Windows
5E1043661043446D /media/Windows</tt><tt><br>
</tt><tt>├─sda3 ext4
ce9d5b2f-232f-4a87-a75e-70e1386dd134 /boot</tt><tt><br>
</tt><tt>├─sda4</tt><tt><br>
</tt><tt>├─sda5 ntfs HP_RECOVERY 2CF47035F470037E</tt><tt><br>
</tt><tt>├─sda6 vfat HP_TOOLS 7E18-51AB</tt><tt><br>
</tt><tt>├─sda7 swap
68647ac3-2d0b-4f71-92dd-65220092bab6 [SWAP]</tt><tt><br>
</tt><tt>└─sda8 ext4
4ccb4264-9920-4d2b-a568-bfc5024eafcd /</tt><tt><br>
</tt><tt><br>
</tt>Those utilities are based on the libblkid library, which does
the real job.<br>
If you prefer an approach which doesn't require launching an
executable and parsing its output, you may give a look to the C code
of the sources, find the appropriate API's, and then bind what
required to your Pascal program.<br>
<br>
On Mac OSX you should be able to get the UUID by using diskutil, but
I never tested.<br>
<br>
Giuliano<br>
<pre class="moz-signature" cols="72">--
Do not do to others as you would have them do to you.They might have different tastes.</pre>
</body>
</html>