[fpc-pascal] Get "disk" ID
Sven Barth
pascaldragon at googlemail.com
Sun Jan 6 12:55:19 CET 2019
Am Sa., 5. Jan. 2019, 17:05 hat Bart <bartjunk64 at gmail.com> geschrieben:
> Hi,
>
> 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.
>
> On Windows I can retreive the VolumeSerialNr, but how do I do
> something like that in Linux?
> Mind you: the "ID" retrieved does NOT have to be the same for each
> platform.
> (I'ld prefer if the "ID" was some kind of integer.)
>
> So if a disk on Windows returns 1234, it is not a problem if on Linux
> the same disk will return 4567.
> The "ID" retrieved however must remeain the same if the disk is
> removed and inserted at a later point in time (regardless of a reboot
> of the system in the mean time).
> If the disk was formatted before inserting a next time, it will not
> matter if the "ID" changes.
>
> Preferrably the code for linux would also work on MacOSX.
>
Best of course would be to query the serial of the disk itself, we do that
in our software at work, but I don't know right now how exactly that needs
to be done (I think on Linux we go through SysFS).
Alternatively you can use the Disk ID that is located inside the MBR of
both MBR and GPT formatted disks at address 0x1B8 with a size of 4 Byte.
Please note that you need to read from the disk, not the partition for that
and that this won't work with SuperFloppy formatted disks (e.g. common USB
drives are often not partitioned with MBR/GPT, but have a file system
starting at sector zero).
See also: https://en.m.wikipedia.org/wiki/Master_boot_record
Regards,
Sven
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20190106/d6ffe204/attachment.html>
More information about the fpc-pascal
mailing list