Sign in to follow this  
starnamer

How to get harddisk hardware serial number from EVC 4.0?

Recommended Posts

starnamer    122
Hi, I need to extract the hardware serial number (not the file system volume serial number) of an IDE harddisk attached to an embedded device motherboard running Windows CE.NET 4.10 for a software licensing feature. I need to write the program in EVC++ 4.0. I have come across numerous sample programs on the internet but they are written for the Win32 desktop platform and they cannot work on the device. The general approach seems to be to open a handle to the disk device (eg DSK0:) using CreateFile and then call a few DeviceIoControl calls to get the serial number. However, when I tried to do so, the deviceiocontrol function calls failed with error codes of 50 which I think it means ERROR_NOT_SUPPORTED. It should mean that the IOCTL codes were not defined in the device driver. So, I like to ask if anyone knows what are the commonly defined IOCTL codes for the Windows CE.NET 4.10 atapi.dll (presumably device driver for the hdd and other ATA devices)? Also, any sample codes to get the serial number out? Thanks in advance. Charles

Share this post


Link to post
Share on other sites
starnamer    122
Its IDE (or Parallel ATA). I downloaded a draft version of ATA/ATAPI-6 specs from www.ata-atapi.com. It does say about the structure of the hdd drive details including the serial number and what I/O command to call to get it. However, the i/o command uses the old MSDOS inb, outb (in byte, out byte) functions which Windows CE.NET does not support. CE.NET seems to only support calling I/O at the device driver level using DeviceIoControl API and the IO control codes (as see in some PC samples) don't correspond directly to any DOS I/O commands. Moreover, I don have the device driver (atapi.dll) source codes, which by right will tell us what IO codes are published thru the header files. Its with the OEM which created the OS image.

You might say, "why don u check with the OEM?" We did that and they haven got back to us yet. I was thinking if this atapi.dll device driver is a generic one that there are a standard set of codes pple use and that anyone has them off-hand.

Charles

Share this post


Link to post
Share on other sites
nmi    978
BTW which IOCTL did you try ?

Here is IOCTL_DISK_DEVICE_INFO for Windows CE 5.0 and here the IOCTL_DISK_GET_STORAGEID for Windows CE 3.0.

Maybe you should also take a look into the header: Diskio.h

Share this post


Link to post
Share on other sites
starnamer    122
Quote:
Original post by nmi
BTW which IOCTL did you try ?

Here is IOCTL_DISK_DEVICE_INFO for Windows CE 5.0 and here the IOCTL_DISK_GET_STORAGEID for Windows CE 3.0.

Maybe you should also take a look into the header: Diskio.h


I have tried the following ioctl codes. The 1st 3 are found in the disk32id.cpp sample by Lynn McGuire which can be found at http://www.winsim.com/diskid32/diskid32.html.

IOCTL_SCSI_MINIPORT
DFP_GET_VERSION
DFP_RECEIVE_DRIVE_DATA
IOCTL_DISK_GET_STORAGEID

IOCTL_DISK_DEVICE_INFO don't seem to return any serial number info in the DEVICE_INFO structure according to the msdn. IOCTL_DISK_GET_STORAGEID seems to be the closes I can get but it failed with an error of 50.

Heres a snippet of the sample code I tried:

//////////////////////////////////////////////////////////////
HANDLE hDisk = CreateFile(_T("DSK1:"), GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);

if (!hDisk) return -1;

PSTORAGE_IDENTIFICATION pStoreInfo = (PSTORAGE_IDENTIFICATION) new BYTE[3000];
if (!pStoreInfo) {
CloseHandle(hDisk);
return -1;
}

DWORD dwBytesRet;

if (!DeviceIoControl(hDisk, IOCTL_DISK_GET_STORAGEID, NULL, 0, pStoreInfo, 3000, &dwBytesRet, NULL)) {
delete [] pStoreInfo;
CloseHandle(hDisk);
return -1;
}
//////////////////////////////////////////////////////////////

The createfile call succeeded but failed at the deviceiocontrol call.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this