DiskId32 has trouble reading some SATA drives

Discussion in 'Windows Vista Drivers' started by Lynn McGuire, Jan 28, 2008.

  1. Lynn McGuire

    Lynn McGuire Guest

    My DiskId32 tool, http://www.winsim.com/diskid32/diskid32.html ,
    reads hard drive information directly from the hard drive in
    Windows Vista, XP, Win2K, Win9X, etc. DiskId32 works in three
    modes: direct using administrator rights, indirect using the
    scsi bypass and direct using user mode rights. The scsi
    bypass was dropped in Windows server 2003 and Vista. Please
    note that the source code for DiskId32 is there also.

    For some reason, the direct reading of the hard drive using
    user mode rights is failing for some SATA hard drives.
    However, the direct reading of the hard drive works fine in
    administrator mode.

    Specifically, what is failing is the reading of the serial
    number of the hard drive. The identify bank being returned
    by the hard drive is only 121 bytes long and the serial number
    pointer is at position 120 which has a zero in it.

    I would appreciate any insights or thoughts people might have
    for this issue.

    Thanks,
    Lynn
     
    Lynn McGuire, Jan 28, 2008
    #1
    1. Advertisements

  2. number of the hard drive. The identify bank being returned
    What API are you using to get this BLOB? SMART_RCV_DRIVE_DATA?
     
    Maxim S. Shatskih, Jan 29, 2008
    #2
    1. Advertisements

  3. Lynn McGuire

    Lynn McGuire Guest

    number of the hard drive. The identify bank being returned
    Here is the code:

    STORAGE_PROPERTY_QUERY query;
    DWORD cbBytesReturned = 0;
    char buffer [10000];

    memset ((void *) & query, 0, sizeof (query));
    query.PropertyId = StorageDeviceProperty;
    query.QueryType = PropertyStandardQuery;

    memset (buffer, 0, sizeof (buffer));

    if ( DeviceIoControl (hPhysicalDriveIOCTL, IOCTL_STORAGE_QUERY_PROPERTY,
    & query,
    sizeof (query),
    & buffer,
    sizeof (buffer),
    & cbBytesReturned, NULL) )

    cbBytesReturned is 121 bytes long for these particular SATA drives.

    This code is contained in the function ReadPhysicalDriveInNTWithZeroRights.

    Thanks,
    Lynn
     
    Lynn McGuire, Jan 29, 2008
    #3
  4. What API are you using to get this BLOB? SMART_RCV_DRIVE_DATA?
    IOCTL_SCSI_MINIPORT/SMART_RCV_DRIVE_DATA works since NT4 up to 2003, probably
    in Vista too.

    This IOCTL returns the ATA IDENTIFY data, and works even on SMARTless ancient
    disk drives.

    I have some tiny command-line app with source I can share which does this.
     
    Maxim S. Shatskih, Jan 29, 2008
    #4
  5. Lynn McGuire

    Lynn McGuire Guest

    What API are you using to get this BLOB? SMART_RCV_DRIVE_DATA?
    If you look at my ReadIdeDriveAsScsiDriveInNT function, it uses:
    memset (buffer, 0, sizeof (buffer));
    p -> HeaderLength = sizeof (SRB_IO_CONTROL);
    p -> Timeout = 10000;
    p -> Length = SENDIDLENGTH;
    p -> ControlCode = IOCTL_SCSI_MINIPORT_IDENTIFY;
    strncpy ((char *) p -> Signature, "SCSIDISK", 8);
    pin -> irDriveRegs.bCommandReg = IDE_ATA_IDENTIFY;
    pin -> bDriveNumber = drive;
    if (DeviceIoControl (hScsiDriveIOCTL, IOCTL_SCSI_MINIPORT,
    buffer,
    sizeof (SRB_IO_CONTROL) +
    sizeof (SENDCMDINPARAMS) - 1,
    buffer,
    sizeof (SRB_IO_CONTROL) + SENDIDLENGTH,
    &dummy, NULL))

    Is this the same as SMART_RCV_DRIVE_DATA ?

    IOCTL_SCSI_MINIPORT support was dropped in Windows Server 2003,
    right ? And Vista also since Windows Sever 2003 is the basis
    for the Vista code ?

    Thanks,
    Lynn
     
    Lynn McGuire, Jan 29, 2008
    #5
  6. Is this the same as SMART_RCV_DRIVE_DATA ?

    No.
    Don't think so.

    BTW - I was wrong, SMART_RCV_DRIVE_DATA is not IOCTL_SCSI_MINIPORT but is an
    IOCTL itself - DeviceIoControl(hDevice, SMART_RCV_DRIVE_DATA,

    My code works on 2003.
     
    Maxim S. Shatskih, Jan 29, 2008
    #6
  7. Lynn McGuire

    Lynn McGuire Guest

    BTW - I was wrong, SMART_RCV_DRIVE_DATA is not IOCTL_SCSI_MINIPORT but is an
    Could you post the code please ?

    Thanks,
    Lynn
     
    Lynn McGuire, Jan 29, 2008
    #7
  8. Lynn McGuire

    Lynn McGuire Guest

    BTW - I was wrong, SMART_RCV_DRIVE_DATA is not IOCTL_SCSI_MINIPORT but
    Yes, I added the code to my DiskId32 tool. However,
    SMART_RCV_DRIVE_DATA requires administrator access. It does
    not work in limited user mode (like the SCSI bypass). Yes,
    it works the same way in Vista also.

    So, does anyone know how to get the hard drive information
    in limited user mode in Windows Server 2003 and Vista for
    some SATA hard drives ?

    Is there a new IDE bypass in Windows Server 2003 / Vista like
    there used to be a SCSI bypass in Windows NT, 2K, XP ?

    Thanks,
    Lynn
     
    Lynn McGuire, Jan 29, 2008
    #8
  9. Lynn McGuire

    David Craig Guest

    If you are going to expand the utility for serial numbers on the weirder
    storage stacks, such as 1394 and USB, how about for flash memory too? It
    would be interesting to see if it can return that correctly. I don't think
    I have ever seen a general purpose utility that can get those serial
    numbers, though some special purpose utilities for a particular form of
    flash memory can do so.
     
    David Craig, Jan 29, 2008
    #9
  10. Lynn McGuire

    Lynn McGuire Guest

    If you are going to expand the utility for serial numbers on the weirder
    I really dont have an interest in those. If someone wants to
    forward me the code then I will try to incorporate it when I
    get the time though.

    Thanks,
    Lynn
     
    Lynn McGuire, Jan 30, 2008
    #10
  11. How SCSIPORT forms the serial number value for
    IOCTL_STORAGE_QUERY_PROPERTY? from VPD INQUIRY?

    And how ATAPI does this? from IDENTIFY data?
     
    Maxim S. Shatskih, Jan 30, 2008
    #11
  12. Lynn McGuire

    Lynn McGuire Guest

    How SCSIPORT forms the serial number value for
    Looking at ReadIdeDriveAsScsiDriveInNT in DiskId32,
    http://www.winsim.com/diskid32/diskid32.html ,
    the following code is found:

    sprintf (driveName, "\\\\.\\Scsi%d:", controller);
    hScsiDriveIOCTL = CreateFile (driveName,
    GENERIC_READ | GENERIC_WRITE,
    FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
    OPEN_EXISTING, 0, NULL);
    if (hScsiDriveIOCTL != INVALID_HANDLE_VALUE)
    {
    int drive = 0;
    for (drive = 0; drive < 2; drive++)
    {
    char buffer [sizeof (SRB_IO_CONTROL) + SENDIDLENGTH];
    SRB_IO_CONTROL *p = (SRB_IO_CONTROL *) buffer;
    SENDCMDINPARAMS *pin =
    (SENDCMDINPARAMS *) (buffer + sizeof (SRB_IO_CONTROL));
    DWORD dummy;
    memset (buffer, 0, sizeof (buffer));
    p -> HeaderLength = sizeof (SRB_IO_CONTROL);
    p -> Timeout = 10000;
    p -> Length = SENDIDLENGTH;
    p -> ControlCode = IOCTL_SCSI_MINIPORT_IDENTIFY;
    strncpy ((char *) p -> Signature, "SCSIDISK", 8);
    pin -> irDriveRegs.bCommandReg = IDE_ATA_IDENTIFY;
    pin -> bDriveNumber = drive;
    if (DeviceIoControl (hScsiDriveIOCTL, IOCTL_SCSI_MINIPORT,
    buffer,
    sizeof (SRB_IO_CONTROL) +
    sizeof (SENDCMDINPARAMS) - 1,
    buffer,
    sizeof (SRB_IO_CONTROL) + SENDIDLENGTH,
    &dummy, NULL))
    Yes !
    {
    SENDCMDOUTPARAMS *pOut =
    (SENDCMDOUTPARAMS *) (buffer + sizeof (SRB_IO_CONTROL));
    IDSECTOR *pId = (IDSECTOR *) (pOut -> bBuffer);
    if (pId -> sModelNumber [0])
    {
    DWORD diskdata [256];
    int ijk = 0;
    USHORT *pIdSector = (USHORT *) pId;

    for (ijk = 0; ijk < 256; ijk++)
    diskdata [ijk] = pIdSector [ijk];

    PrintIdeInfo (controller * 2 + drive, diskdata);

    done = TRUE;
    }
    }

    Thanks,
    Lynn
     
    Lynn McGuire, Jan 30, 2008
    #12
  13. Lynn McGuire

    Lynn McGuire Guest

    How SCSIPORT forms the serial number value for
    Did I answer the question that you were asking ?

    My question is, can I use the new IDE bypass to get
    get the IDENTITY info from the hard drive with only
    user rights ?

    Thanks,
    Lynn
     
    Lynn McGuire, Jan 31, 2008
    #13
  14. You could do it through a service and then pass it back to the application
    via a pipe, but that may be more effort than it is worth.
     
    Gary G. Little, Jan 31, 2008
    #14
  15. I'm not sure it is secure for this information to be available to
    unprivileged users, my guess is that a hole was fixed in Vista. Of course,
    that's doubly annoying because even administrators now have to elevate your
    system information tool, but that is more secure.
     
    Ben Voigt [C++ MVP], Jan 31, 2008
    #15
  16. Lynn McGuire

    Lynn McGuire Guest

    My question is, can I use the new IDE bypass to get
    Actually, my DiskId32 tool works for all PATA hard
    drives and most SATA drives in Windows Server 2003
    and Vista with only user rights mode. It is only
    failing on some Western Digital SATA hard drives for
    some weird reason. If it was a security hole fix
    then the job was not finished.

    Thanks,
    Lynn
     
    Lynn McGuire, Jan 31, 2008
    #16
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.