1

The binary file is located on a USB key used as a dongle.

I need to get a unique identifier from the key. VendorID + DeviceID is out of the question because they may be the same if the USB key's models are the same.

Using Windows, I use a the function GetVolumeInformation() which gives me a serial number that is changed eachtime the device is formated (not a problem).

Using Unix, to get the same serial number, I need to read the corresponding mount file in the /dev/ directory. But this operation requieres a root access, or at least I need to be part of a specific group.

The unique identifier could be different than the serial number found on Win32 systems. But it must be different for each USB key I will use for delivery.

Any ideas ?

perelo
  • 465
  • 5
  • 14
  • `Vendor_ID+Product_ID+USB_SerialNumber` is unique. `VID+PID` obviously is the same if the USB key models are the same, by definition of "same model". – MSalters May 15 '12 at 08:49
  • `GetVolumeInformation()` gives the serial number of the filesystem on the USB key, not the serial number of the USB key. More can be found the these duplicates: http://stackoverflow.com/q/4327032/79455 and http://stackoverflow.com/q/2432759/79455 – rve May 15 '12 at 09:25

3 Answers3

1

You can look in /dev/disk/by-uuid/ directory. There are symlinks to device nodes, and symlinks names is the IDs of partitions.

ArtifTh
  • 11
  • 2
0

Here's some ideas:

  • Is the device auto-mounted on the system? If so, it might get mounted with its device name by the automounter, and the mount command will tell you the device name. E.g. something gets mounted to /media/ABCD-1234 then ABCD-1234 is the device name as provided in the partition table.
  • In the /sys filesystem exists some information regarding the device. One is the size, for each partition. You could put several partitions on the device and use one unformatted partition (which will not get mounted) with a specific size. Then the size of that partition would be your serial number, available e.g. by /sys/block/sdb/sdb1/size, which is world-readable.
mistalee
  • 881
  • 6
  • 14
  • The mountpoint name is not reliable, if the user manualy mount the device, the program is down... For the size of a partition, the user may (by mistake?) modify it or something. – perelo May 23 '12 at 09:25
0

I have managed to retrieve the serial number by getting the /dev file using df command

Than used this code and modified it a little bit :

USB-drive serial number under linux C++

3rd answer (Orwellophile's)

I'm not sure this will work on every Unix systems, but it is fine for now.

Community
  • 1
  • 1
perelo
  • 465
  • 5
  • 14