Page 1 of 1
Unique ID for removeble hardware
Posted: Fri Oct 07, 2011 2:19 am
by Holus
My OS must be bootable from HDD and USB.
But some hardware (like USB) is easy to remove and replace.
Is there a Unique hardware of the device I boot from so I can check before destroing a USB-stick with OS info. I can make a function that checks if the bootdevice is unpluged and tell te user to put it back. But I want to check-it befor writing to it.
Is there a way to check it's the same device with-out reading from the device (and check some signatures on a sector. (that would be to slow))
I found that INT 0x13 function AH=48 tells me the PCI port that was used for the device. So I think I can check the VENDOR and DEVICE_ID. But I have 10 USB sticks with the same VENDOR and DEVICE_ID. Is there a other way?
Re: Unique ID for removeble hardware
Posted: Fri Oct 07, 2011 2:59 am
by Solar
Holus wrote:I want to check-it befor writing to it.
Is there a way to check it's the same device with-out reading from the device (and check some signatures on a sector. (that would be to slow))
Since you are going to write to it anyway, I don't see why reading the device first would be "too slow"...?
Re: Unique ID for removeble hardware
Posted: Fri Oct 07, 2011 3:29 am
by Holus
Solar wrote: Since you are going to write to it anyway, I don't see why reading the device first would be "too slow"...?
Yes. But I do not want an write action to be 1 read and 1 write action.
Waiting and checking the status 2x. Wait for the IRQ 2x. Process te information 2x.
Is there an other way??
Re: Unique ID for removeble hardware
Posted: Fri Oct 07, 2011 3:54 am
by Combuster
For USB: write a proper driver so you can actually detect plug events.
In general there's a certain amount of time needed for a user to physically switch USB sticks (the same goes for floppy drives where it's generally not possible to tell if it's present), if you haven't written or read the device in the past n seconds then you may want to check the signature again. If the device gets unplugged live, the read or write will return a failure so that you know it's not there.
In other words, there should not be a read for every write
Re: Unique ID for removeble hardware
Posted: Fri Oct 07, 2011 4:38 am
by Holus
Combuster wrote:For USB: write a proper driver so you can actually detect plug events.
In general there's a certain amount of time needed for a user to physically switch USB sticks (the same goes for floppy drives where it's generally not possible to tell if it's present), if you haven't written or read the device in the past n seconds then you may want to check the signature again. If the device gets unplugged live, the read or write will return a failure so that you know it's not there.
In other words, there should not be a read for every write
Thanks. Read 1x on plug-in and detect. That sounds like a nice simple solution.
Is there a unplugsignal to an IRQ?
Re: Unique ID for removeble hardware
Posted: Fri Oct 07, 2011 3:23 pm
by Brendan
Hi,
Holus wrote:Thanks. Read 1x on plug-in and detect. That sounds like a nice simple solution.
What are you reading? If you read a magic signature from a sector, then the user can clone the raw data (e.g. copy the raw data onto other USB sticks), and you won't be able to tell the difference between the clones.
For all USB devices; when a USB device is plugged in you first have to find out what the device is (get the class and subclass codes to determine if it's a storage device or a keyboard or mouse or whatever). To do this you ask the device for a "Device Descriptor". In addition to class and subclass codes, the "Device Descriptor" includes a vendor ID, a product ID and a serial number. The serial number is a string of at least 12 Unicode characters that must be unique for the vendor ID and product ID; and by concatenating "vendor + product + serial" you end up with a globally unique identifier.
Basically, you have to get this data from the device anyway (to determine what sort of device it is), and can use it to determine if the device is the same one.
Note: For hard disks it's slightly similar. You have to get device information (e.g. the "identify device" command), and (for modern drives) this data includes an (up to) 40 byte serial number.
Cheers,
Brendan