Getting HDD serial in kernel space
Hello.
I had a necessity to get HDD serial number in my kernel module. In user space I can do it so:
fd = open( "/dev/sda", O_RDONLY|O_NONBLOCK );
ioctl( fd, HDIO_GET_IDENTITY, &id );
printf( "Serial: %s", id.serial_no );How can I do it in kernel space (it is one hdd in machine, plugged with SATA)?
Quoted 11 lines · On Sat, 14 Nov 2009 14:34:54 +0300 Andrey Polovov <[email protected]>…
Hello.
I had a necessity to get HDD serial number in my kernel module. In user space I can do it so:
fd = open( "/dev/sda", O_RDONLY|O_NONBLOCK ); ioctl( fd, HDIO_GET_IDENTITY, &id ); printf( "Serial: %s", id.serial_no );How can I do it in kernel space (it is one hdd in machine, plugged with SATA)?
The identity when probed is all in the struct ata_device, although be aware that it may not be unique per device and also that hotplug means you need to be careful how you access it. Now and then you meet a device where the serial number changes randomly each boot just to really annoy.
What are you actually trying to do ?
Andrey Polovov:
Quoted 2 lines
How can I do it in kernel space (it is one hdd in machine, plugged with SATA)?
What I need is a small piece of code that can help me in getting a list (ata_device array?) of plugged HDDs and their serial numbers.
Quoted 7 lines · On Sun, 15 Nov 2009 17:03:56 +0300 Andrey Polovov <[email protected]>…
Andrey Polovov:
Quoted 2 lines
How can I do it in kernel space (it is one hdd in machine, plugged with SATA)?
What I need is a small piece of code that can help me in getting a list (
ata_devicearray?) of plugged HDDs and their serial numbers.
That wasn't the question I asked. The question I asked is "what are you trying to do". You request seems rather odd, especially to try and do in kernel space, so if we understood what you were trying to do it might make more sense and easier to suggest the best way to approach it.
Alan