‘Identify Device’

advertisement
‘Identify Device’
A mandatory command that allows
device-drivers to query any standard
IDE/ATA hard disk for its parameters
Uses PIO data-in protocol
• Our ‘mbr.c’ driver-module reads sector 0
using a well-documented device protocol
• The IDENTIFY_DEVICE command (0xEC)
uses the same basic protocol, except that
only a 1-bit parameter is needed, to select
the desired device (master=0, slave=1)
• You can quickly modify our ‘mbr.c’ module
to create a ‘hdid.c’ driver for disk-ID info
Some items of interest
• The IDENTIFY-DEVICE command returns
256 words of information (i.e., 512 bytes)
• Words 10-19: Hard Disk’s Serial-Number
(it consists of 20 ASCII characters)
• Words 23-26: Firmware Revision Number
(it consists of 8 ASCII characters)
• Words 27-46: Hard Disk’s Model Number
(it consists of 40 ASCII characters)
Important item: disk’s capacity
• Words 60-61: The total number of sectors
a device-driver can access (32-bit value)
• Allows for disk-capacities up to 2 terabytes
(232 sectors)*(512 bytes/sect) = 241 bytes
210: 1 kilobyte = 1024 bytes
220: 1 megabyte = 1024 kilobytes
230: 1 gigabyte = 1024 megabytes
240: 1 terabyte = 1024 gigabytes
C programming “hints”
unsigned short
idinfo[ 256 ];
unsigned long
n_sectors;
unsigned long long n_bytes;
for (i=0; i<256; i++) idinfo[ i ] = inw( IDE_DATA );
n_sectors = *(unsigned long*)&idinfo[ 60 ];
n_bytes = 512LL * n_sectors;
printf( “disk capacity: %llu bytes ”, n_bytes);
printf( “(= 0x%llX bytes) \n”, n_bytes );
In-class exercise #1
• Copy our ‘mbr.c’ module from the website,
remame it as ‘hdid.c’, then modify a few of
its lines as appropriate, so as to create a
character-mode device-driver for the Hard
Disk’s 256 words of device information
• Use our ‘fileview’ utility to browse through
this device-file (named ‘/dev/hd’), copying
down the number of disk-sectors (in hex)
In-class exercise #2
• Write a short C++ application program that
will display these important items of Hard
Disk information (in appropriate formats):
– Hard Disk’s Serial Number
– Firmware’s Revision Number
– Hard Disk’s Model ID Number
– Number of accessible sectors (hexadecimal)
– Disk’s storage capacity in bytes (decimal)
Download