How to get harddisk hardware serial number from EVC 4.0?

Started by
5 comments, last by starnamer 19 years, 4 months ago
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
Astronomy HubThe International Astronomy and Space Forum CommunityWhere Astronomers and Space-Minded Enthusiasts Meethttp://astro.jconserv.net
Advertisement
Do you use ATA or SATA ?

Maybe you want to get the ATA specification from www.t13.org
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
Astronomy HubThe International Astronomy and Space Forum CommunityWhere Astronomers and Space-Minded Enthusiasts Meethttp://astro.jconserv.net
here is a macro which generates IOCTL codes

or check this page of the msdn

hope that helps
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
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.
Astronomy HubThe International Astronomy and Space Forum CommunityWhere Astronomers and Space-Minded Enthusiasts Meethttp://astro.jconserv.net
Ok. Got my bug fixed. The problem lies with my IOCTL definition. Defined using a wrong code value. Here's the reference I found.

http://groups.google.com.sg/groups?hl=en&lr=&selm=EhsU8.381%24M5.21189%40nasal.pacific.net.au

It worked now. Thanks for ur advice anyway.

Starnamer
Astronomy HubThe International Astronomy and Space Forum CommunityWhere Astronomers and Space-Minded Enthusiasts Meethttp://astro.jconserv.net

This topic is closed to new replies.

Advertisement