Compact Flash Card Serial Number?

Last post 11-28-2007 19:22 by Anonymous. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 07-28-2004 9:40

    Compact Flash Card Serial Number?


    Does anyone know a way to get the serial number off a compact flash card?

    ---
    Those who live by the sword, get shot by those who don’t.
  • 01-21-2005 0:11 In reply to

    Re: Compact Flash Card Serial Number?

    I've been trying to get the serial number of a compact flash card on a Windows CE 4.2 device using EVC++ 4.0, using IOCTL_DISK_GET_STORAGEID and the STORAGE_IDENTIFICATION structure it populates. (relevant MSDN Pages linked below)

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceddk40/html/_wceddk_ioctl_disk_get_storageid.asp
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceddk40/html/_wceddk_storage_identification.asp

    The following code produces the following result

    <result>

    the message box at the end returns the follow value as the serial, minus the inverted comma's

    " 04A38A1CA33A3100A5"

    I know for a fact that the serial number of the CF-Card is -> Volume Serial Number : 0xc7019d4

    second result gathered by using xp shell command -> "fsutil fsinfo volumeinfo g:\" (where g:\ is my local CF-Card Drive

    </result>

    <Code>

    #include "stdafx.h"
    #include <windows.h>
    #include <winioctl.h>

    #define IOCTL_DISK_BASE FILE_DEVICE_DISK
    #define IOCTL_DISK_GET_STORAGEID CTL_CODE(IOCTL_DISK_BASE, 0x709, METHOD_BUFFERED, FILE_ANY_ACCESS)

    typedef struct _STORAGE_IDENTIFICATION {

    DWORD dwSize;
    DWORD dwFlags;
    DWORD dwManufactureIDOffset;
    DWORD dwSerialNumOffset;

    } STORAGE_IDENTIFICATION, *PSTORAGE_IDENTIFICATION;


    #define MANUFACTUREID_INVALID 0x01
    #define SERIALNUM_INVALID 0x02

    int WINAPI WinMain( HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPTSTR lpCmdLine,
    int nCmdShow)
    {

    HANDLE hDisk = CreateFile(_T("\\PCMCIA-CF Card\\Vol:"), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
    if (!hDisk) return -1;

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

    DWORD dwBytesRet;

    if (!DeviceIoControl(hDisk, IOCTL_DISK_GET_STORAGEID, NULL, 0, pStoreInfo, 100, &dwBytesRet, NULL)) { //3000 changed to 46
    DWORD err = GetLastError();
    delete [] pStoreInfo;
    CloseHandle(hDisk);
    return -1;
    }

    TCHAR tStr[200];
    if (dwBytesRet)
    {
    unsigned char *SerialNo=(((BYTE *)pStoreInfo)+pStoreInfo->dwSerialNumOffset);
    int i =0;
    while (SerialNo[i]!=0 && i < (int)(dwBytesRet-pStoreInfo->dwSerialNumOffset))
    {
    tStr[i] = (TCHAR)SerialNo[i];
    i++;
    }
    tStr[i] = 0;
    }

    delete [] pStoreInfo;
    CloseHandle(hDisk);

    MessageBox(NULL, tStr, _T("HDD Serial No"), MB_OK);
    return 0;
    }
    </Code>

    <ReleventInfo>

    On running the pStoreInfo structure fills with the following data

    DWORD dwSize; = 46
    DWORD dwFlags; = 0
    DWORD dwManufactureIDOffset; = 16
    DWORD dwSerialNumOffset; = 25

    </ReleventInfo>

    Please could anyone point out if I'm doing something stupid, or provide an explanation as to why this code behaves in this manner.
    Any commentary or advise is welcome

    Regards,
    Bm

    ---
    Those who live by the sword, get shot by those who don’t.
  • 01-28-2005 4:03 In reply to

    Re: Compact Flash Card Serial Number?

    With regards to the values that fill the STORAGE_IDENTIFICATION structure during debugging.

    DWORD dwSize; = 46
    DWORD dwFlags; = 0
    DWORD dwManufactureIDOffset; = 16
    DWORD dwSerialNumOffset; = 25

    Now. I'd like to quote the MSDN pages.

    From the IOCTL_DISK_GET_STORAGEID page:
    "For Advanced Technology Attachment (ATA) disk devices, the identifiers consist of 20 bytes for a manufacturer identifier string, and also 10 bytes for the serial number of the disk."

    You might be saying that a CF-Card isn't an ATA disc. I'm not a 100% sure, but the filename of the driver that loads when the disc is inserted is called "ATADISK.DLL"

    If you look at the offsets provided by the populated structure, something is seriously wrong with either the way the code is interacting with the device, or the MSDN pages are incorrect? (highly unlikly, but still posible)

    I've read through 38 separate posts (all of them) through google groups concerning the IOCTL_DISK_GET_STORAGEID call. Not a single person that I can find has actually got it to work properly...

    The serial number of a removable card should be easier to get than this :(

    Can anybody render any insights.

    Regards,
    Bm

    ---
    Those who live by the sword, get shot by those who don’t.
  • 03-18-2005 9:02 In reply to

    Re: Compact Flash Card Serial Number?

    If you're getting those offsets then you're fine and everything worked. You simply need to read the string that has been placed at that offset.

    Now, I'm very curious if anyone has gotten these calls to work on 2002... I can only get this to work with WinCE 3.0, 2003.

    Today is the best day of my life. I remember everything that happened yesterday and there is still tomorrow to look forward to.
  • 07-18-2007 13:30 In reply to

    Re: Compact Flash Card Serial Number?

    Can anyone tell me if other forms of flash memory also have serial numbers. Things like MMC, SD, SMC, MagicGate, etc. Do all of these devices obey the ATA ID command?

    Thanks
  • 11-28-2007 19:22 In reply to

    Re: Compact Flash Card Serial Number?

    can anyone tell me,
    How can I set the \\PCMCIA-CF Card\\Vol:

    thanks

    I test the code

    set the \\PCMCIA-CF Card\\Vol: to DSK1:

    I can run it, but I get the

    dwSize; 47
    dwFlags; 0
    dwManufactureIDOffset; 16
    dwSerialNumOffset; 0

Page 1 of 1 (6 items)