7 Replies - 813 Views - Last Post: 01 April 2013 - 06:41 PM Rate Topic: -----

#1 Ryuuji  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 31-March 13

Getting Device Interface Protocol (SCSI or ATA protocol)

Posted 31 March 2013 - 06:39 PM

Hi guys!

I need help. I need to know drive's protocol.

For example I have 3 drives:
SATA Drive
PCIe Drive
FC Drive

How can i get their device interface protocol? ATA or SCSI? before I go sending commands using deviocontrol function to those drives.

Thanks in advance
Is This A Good Question/Topic? 0
  • +

Replies To: Getting Device Interface Protocol (SCSI or ATA protocol)

#2 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3589
  • View blog
  • Posts: 11,158
  • Joined: 05-May 12

Re: Getting Device Interface Protocol (SCSI or ATA protocol)

Posted 31 March 2013 - 07:36 PM

What platform? Windows? Linux?
Was This Post Helpful? 0
  • +
  • -

#3 Ryuuji  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 31-March 13

Re: Getting Device Interface Protocol (SCSI or ATA protocol)

Posted 31 March 2013 - 08:10 PM

Windows
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3589
  • View blog
  • Posts: 11,158
  • Joined: 05-May 12

Re: Getting Device Interface Protocol (SCSI or ATA protocol)

Posted 31 March 2013 - 08:22 PM

Quick and dirty way: Interrogate WMI Win32_Disk and look at InterfaceType string. Alternately, you can parse the Caption string. So far all the current shipping device drivers say "ATA Device" or "SCSI Device" as part of their caption:
http://msdn.microsof...2(v=vs.85).aspx
Was This Post Helpful? 0
  • +
  • -

#5 Ryuuji  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 31-March 13

Re: Getting Device Interface Protocol (SCSI or ATA protocol)

Posted 31 March 2013 - 08:36 PM

Hi Sir, Thanks for your help but can you also help me how to use this class. :) or any example using this class. Thanks a lot.
Was This Post Helpful? 0
  • +
  • -

#6 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3589
  • View blog
  • Posts: 11,158
  • Joined: 05-May 12

Re: Getting Device Interface Protocol (SCSI or ATA protocol)

Posted 31 March 2013 - 08:48 PM

I figured that if you knew enough to be calling DevIoControl() calls, you already familiar with the way MSDN is laid out. On the left hand side on the navigation bar, you would have found a topic a few levels above the "Reference" section which always leads to a section that has an overview followed by sections about how to use an API in term of the big picture instead of the low level details.

Anyway here's a link to help you out: http://msdn.microsof...4(v=vs.85).aspx
Was This Post Helpful? 0
  • +
  • -

#7 snoopy11  Icon User is online

  • Engineering ● Software
  • member icon

Reputation: 802
  • View blog
  • Posts: 2,360
  • Joined: 20-March 10

Re: Getting Device Interface Protocol (SCSI or ATA protocol)

Posted 01 April 2013 - 07:05 AM

Asked here as well

http://www.qtcentre....col%29?p=241790

Not exactly what you need but I wrote this program that uses Win32_LogicalDisk class

#define _WIN32_DCOM
#include <iostream>
using namespace std;
#include <comdef.h>
#include <Wbemidl.h>

#pragma comment(lib, "wbemuuid.lib")


string Avail[5] = {"Read/Write","Readable","Writeable","Unknown","Write Once"};
string Drive[7] = {"Unknown","No Root Directory","Removable Disk (USB)","Local Disk","Network Drive","CD/DVD Drive","RAM Disk"};
string Media[23] = {"Unknown","5 1/4 inch Floppy 1.2MB","3.5 inch Floppy 1.44MB","3.5 inch Floppy 2.88MB","3.5 inch Floppy 20.8MB",
	"3.5 inch Floppy 730KB","5 1/4 inch Floppy 360KB","5 1/4 inch Floppy","5 1/4 inch Floppy","5 1/4 inch Floppy","5 1/4 inch Floppy",
	"Removable Media","Fixed Hard Disk","3.5 inch Floppy","3.5 inch Floppy","5 1/4 inch Floppy","5 1/4 inch Floppy","3.5 inch Floppy",
	"3.5 inch Floppy","5 1/4 inch Floppy","3.5 inch Floppy","3.5 inch Floppy","8 inch Floppy"};

int main(int argc, char **argv)
{
    HRESULT hres;
	
    // Step 1: --------------------------------------------------
    // Initialize COM. ------------------------------------------

    hres =  CoInitializeEx(0, COINIT_MULTITHREADED); 
    if (FAILED(hres))
    {
        cout << "Failed to initialize COM library. Error code = 0x" 
            << hex << hres << endl;
        return 1;                  // Program has failed.
    }

    // Step 2: --------------------------------------------------
    // Set general COM security levels --------------------------
    // Note: If you are using Windows 2000, you need to specify -
    // the default authentication credentials for a user by using
    // a SOLE_AUTHENTICATION_LIST structure in the pAuthList ----
    // parameter of CoInitializeSecurity ------------------------

    hres =  CoInitializeSecurity(
        NULL, 
        -1,                          // COM authentication
        NULL,                        // Authentication services
        NULL,                        // Reserved
        RPC_C_AUTHN_LEVEL_DEFAULT,   // Default authentication 
        RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation  
        NULL,                        // Authentication info
        EOAC_NONE,                   // Additional capabilities 
        NULL                         // Reserved
        );

                      
    if (FAILED(hres))
    {
        cout << "Failed to initialize security. Error code = 0x" 
            << hex << hres << endl;
        CoUninitialize();
        return 1;                    // Program has failed.
    }
    
    // Step 3: ---------------------------------------------------
    // Obtain the initial locator to WMI -------------------------

    IWbemLocator *pLoc = NULL;

    hres = CoCreateInstance(
        CLSID_WbemLocator,             
        0, 
        CLSCTX_INPROC_SERVER, 
        IID_IWbemLocator, (LPVOID *) &pLoc);
 
    if (FAILED(hres))
    {
        cout << "Failed to create IWbemLocator object."
            << " Err code = 0x"
            << hex << hres << endl;
        CoUninitialize();
        return 1;                 // Program has failed.
    }

    // Step 4: -----------------------------------------------------
    // Connect to WMI through the IWbemLocator::ConnectServer method

    IWbemServices *pSvc = NULL;
	
    // Connect to the root\cimv2 namespace with
    // the current user and obtain pointer pSvc
    // to make IWbemServices calls.
    hres = pLoc->ConnectServer(
         _bstr_t(L"ROOT\\CIMV2"), // Object path of WMI namespace
         NULL,                    // User name. NULL = current user
         NULL,                    // User password. NULL = current
         0,                       // Locale. NULL indicates current
         NULL,                    // Security flags.
         0,                       // Authority (for example, Kerberos)
         0,                       // Context object 
         &pSvc                    // pointer to IWbemServices proxy
         );
    
    if (FAILED(hres))
    {
        cout << "Could not connect. Error code = 0x" 
             << hex << hres << endl;
        pLoc->Release();     
        CoUninitialize();
        return 1;                // Program has failed.
    }

    cout << "Connected to ROOT\\CIMV2 WMI namespace" << endl;


    // Step 5: --------------------------------------------------
    // Set security levels on the proxy -------------------------

    hres = CoSetProxyBlanket(
       pSvc,                        // Indicates the proxy to set
       RPC_C_AUTHN_WINNT,           // RPC_C_AUTHN_xxx
       RPC_C_AUTHZ_NONE,            // RPC_C_AUTHZ_xxx
       NULL,                        // Server principal name 
       RPC_C_AUTHN_LEVEL_CALL,      // RPC_C_AUTHN_LEVEL_xxx 
       RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx
       NULL,                        // client identity
       EOAC_NONE                    // proxy capabilities 
    );

    if (FAILED(hres))
    {
        cout << "Could not set proxy blanket. Error code = 0x" 
            << hex << hres << endl;
        pSvc->Release();
        pLoc->Release();     
        CoUninitialize();
        return 1;               // Program has failed.
    }

    // Step 6: --------------------------------------------------
    // Use the IWbemServices pointer to make requests of WMI ----

    // For example, get the name of the operating system
    IEnumWbemClassObject* pEnumerator = NULL;
    hres = pSvc->ExecQuery(
        bstr_t("WQL"), 
        bstr_t("SELECT * FROM Win32_LogicalDisk"),
        WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, 
        NULL,
        &pEnumerator);
    
    if (FAILED(hres))
    {
        cout << "Query for Logical Disk failed."
            << " Error code = 0x" 
            << hex << hres << endl;
        pSvc->Release();
        pLoc->Release();
        CoUninitialize();
        return 1;               // Program has failed.
    }

    // Step 7: -------------------------------------------------
    // Get the data from the query in step 6 -------------------
 
    IWbemClassObject *pclsObj;
    ULONG uReturn = 0;
   
    while (pEnumerator)
    {
        HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, 
            &pclsObj, &uReturn);

        if(0 == uReturn)
        {
            break;
        }

        VARIANT vtProp;
		UINT32 numerator;
		
        // Get the value of the Name property
        hr = pclsObj->Get(L"Name", 0, &vtProp, 0, 0);
        wcout << "Disk Drive: " << vtProp.bstrVal << endl;
		
		 hr = pclsObj->Get(L"MediaType", 0, &vtProp, 0, 0);
		 numerator = vtProp.bVal;
		 if(numerator>=0&&numerator<23)
		 cout << " MediaType: " << Media[numerator].c_str() << endl;
		 else
		 cout << " MediaType: USB Stick "<< endl;

		 hr = pclsObj->Get(L"DriveType", 0, &vtProp, 0, 0);
		 numerator = vtProp.bVal;
		 cout << " DriveType: " << Drive[numerator].c_str() << endl;

         hr = pclsObj->Get(L"Access", 0, &vtProp, 0, 0);
		 numerator= vtProp.bVal;
		 if(numerator>=0&&numerator<5)
		 cout << " Access: " <<Avail[numerator].c_str()<< endl;
		 else
	     cout << " Access: No Disk in Drive"<< endl;
         VariantClear(&vtProp);
		
        
    }

    // Cleanup
    // ========
    
    pSvc->Release();
    pLoc->Release();
    pEnumerator->Release();
    pclsObj->Release();
    CoUninitialize();

	cin.ignore();
	cin.get();
    return 0;   // Program successfully completed.
	
}



What you need to do is modify the above program for

Win32_DiskDrive class

found here

http://msdn.microsof...v=vs.85%29.aspx

but it should be fairly easy to do that.

Regards

Snoopy.
Was This Post Helpful? 0
  • +
  • -

#8 Ryuuji  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 31-March 13

Re: Getting Device Interface Protocol (SCSI or ATA protocol)

Posted 01 April 2013 - 06:41 PM

Thanks a lot guys. I'll try this code. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1