Windows CE: Displaying Disk Information

Windows CE: Displaying Disk Information
Created by on 11/20/2010 10:54:27 PM

  


To expand on my Serial Debug Port Menu (Windows CE: Serial Debug Menu Summary), I decided to add a Disk Viewer. The Disk Viewer enumerates the disks and partitions to display information about them.   This can be a useful tool if you have a headless system and can’t access the Control Panel.

The systems doesn’t really have information about disks, instead it has Stores. To find the stores, use FindFirstStore() and FindNextStore() which function much like the other functions that I have already used, like FindFirstDevice().   The following function, DisplayDisks(), uses FindFirstStore() and FindNextStore() to enumerate the stores, display information about the stores and finally call DisplayPartions() .

VOID DisplayDisks()

{

    STOREINFO si = {0};

    HANDLE hFind = INVALID_HANDLE_VALUE;

    DWORD dwCurrentSel = 0;

                HANDLE hStore;

               

    si.cbSize = sizeof(STOREINFO);

    // enumerate first store

    hFind = FindFirstStore(&si);

   

    if(INVALID_HANDLE_VALUE != hFind)

    {

        do

        {

                                                RETAILMSG( 1, (TEXT("Device Name %s\n"), si.szDeviceName ));

                                                RETAILMSG( 1, (TEXT("Name %s\n"), si.szStoreName ));

                                                RETAILMSG( 1, (TEXT("Class %s\n"), si.dwDeviceClass == STORAGE_DEVICE_CLASS_BLOCK ?

                                                                TEXT("STORAGE_DEVICE_CLASS_BLOCK") :

                                                                TEXT("STORAGE_DEVICE_CLASS_MULTIMEDIA") ));

                                                RETAILMSG( 1, (TEXT("Type ")));

                                                switch( si.dwDeviceType )

                                                {

                                                                case STORAGE_DEVICE_TYPE_PCIIDE:

                                                                                RETAILMSG( 1, (TEXT("STORAGE_DEVICE_TYPE_PCIIDE\n")));

                                                                                break;

                                                                case STORAGE_DEVICE_TYPE_FLASH:

                                                                                RETAILMSG( 1, (TEXT("STORAGE_DEVICE_TYPE_FLASH\n")));

                                                                                break;

                                                                case STORAGE_DEVICE_TYPE_ATA:

                                                                                RETAILMSG( 1, (TEXT("STORAGE_DEVICE_TYPE_ATA\n")));

                                                                                break;

                                                                case STORAGE_DEVICE_TYPE_ATAPI:

                                                                                RETAILMSG( 1, (TEXT("STORAGE_DEVICE_TYPE_ATAPI\n")));

                                                                                break;

                                                                case STORAGE_DEVICE_TYPE_PCCARD:

                                                                                RETAILMSG( 1, (TEXT("STORAGE_DEVICE_TYPE_PCCARD\n")));

                                                                                break;

                                                                case STORAGE_DEVICE_TYPE_CFCARD:

                                                                                RETAILMSG( 1, (TEXT("STORAGE_DEVICE_TYPE_CFCARD\n")));

                                                                                break;

                                                                case STORAGE_DEVICE_TYPE_SRAM:

                                                                                RETAILMSG( 1, (TEXT("STORAGE_DEVICE_TYPE_SRAM\n")));

                                                                                break;

                                                                case STORAGE_DEVICE_TYPE_DVD:

                                                                                RETAILMSG( 1, (TEXT("STORAGE_DEVICE_TYPE_DVD\n")));

                                                                                break;

                                                                case STORAGE_DEVICE_TYPE_CDROM:

                                                                                RETAILMSG( 1, (TEXT("STORAGE_DEVICE_TYPE_CDROM\n")));

                                                                                break;

                                                                case STORAGE_DEVICE_TYPE_USB:

                                                                                RETAILMSG( 1, (TEXT("STORAGE_DEVICE_TYPE_USB\n")));

                                                                                break;

                                                                case STORAGE_DEVICE_TYPE_1394:

                                                                                RETAILMSG( 1, (TEXT("STORAGE_DEVICE_TYPE_1394\n")));

                                                                                break;

                                                                case STORAGE_DEVICE_TYPE_DOC:

                                                                                RETAILMSG( 1, (TEXT("STORAGE_DEVICE_TYPE_DOC\n")));

                                                                                break;

                                                                case STORAGE_DEVICE_TYPE_UNKNOWN:

                                                                                RETAILMSG( 1, (TEXT("STORAGE_DEVICE_TYPE_UNKNOWN\n")));

                                                                                break;

                                                                case STORAGE_DEVICE_TYPE_REMOVABLE_DRIVE:

                                                                                RETAILMSG( 1, (TEXT("STORAGE_DEVICE_TYPE_REMOVABLE_DRIVE\n")));

                                                                                break;

                                                                case STORAGE_DEVICE_TYPE_REMOVABLE_MEDIA:

                                                                                RETAILMSG( 1, (TEXT("STORAGE_DEVICE_TYPE_REMOVABLE_MEDIA\n")));

                                                                                break;

                                                                default:

                                                                                RETAILMSG( 1, (TEXT("Unkown device type 0x%X\n"), si.dwDeviceType));

                                                                                break;

 

                                                }

                                                RETAILMSG( 1, (TEXT("Flags")));

                                                if(si.dwDeviceFlags & STORAGE_DEVICE_FLAG_READWRITE )

                                                                RETAILMSG( 1, (TEXT(" STORAGE_DEVICE_FLAG_READWRITE")));

                                                if(si.dwDeviceFlags & STORAGE_DEVICE_FLAG_READONLY )

                                                                RETAILMSG( 1, (TEXT(" STORAGE_DEVICE_FLAG_READONLY")));

                                                if(si.dwDeviceFlags & STORAGE_DEVICE_FLAG_TRANSACTED )

                                                                RETAILMSG( 1, (TEXT(" STORAGE_DEVICE_FLAG_TRANSACTED")));

                                                if(si.dwDeviceFlags & STORAGE_DEVICE_FLAG_MEDIASENSE )

                                                                RETAILMSG( 1, (TEXT(" STORAGE_DEVICE_FLAG_MEDIASENSE")));

                                                if(si.dwDeviceFlags == 0 )

                                                                RETAILMSG( 1, (TEXT(" None")));

                                                RETAILMSG( 1, (TEXT("\n")));

 

                                                RETAILMSG( 1, (TEXT("Bytes per Sector %d\n"), si.dwBytesPerSector));

                                                RETAILMSG( 1, (TEXT("Attributes")));

                                                if(si.dwAttributes & STORE_ATTRIBUTE_READONLY )

                                                                RETAILMSG( 1, (TEXT(" STORE_ATTRIBUTE_READONLY")));

                                                if(si.dwAttributes & STORE_ATTRIBUTE_REMOVABLE )

                                                                RETAILMSG( 1, (TEXT(" STORE_ATTRIBUTE_REMOVABLE")));

                                                if(si.dwAttributes & STORE_ATTRIBUTE_UNFORMATTED )

                                                                RETAILMSG( 1, (TEXT(" STORE_ATTRIBUTE_UNFORMATTED")));

                                                if(si.dwAttributes & STORE_ATTRIBUTE_AUTOFORMAT )

                                                                RETAILMSG( 1, (TEXT(" STORE_ATTRIBUTE_AUTOFORMAT")));

                                                if(si.dwAttributes & STORE_ATTRIBUTE_AUTOPART )

                                                                RETAILMSG( 1, (TEXT(" STORE_ATTRIBUTE_AUTOPART")));

                                                if(si.dwAttributes & STORE_ATTRIBUTE_AUTOMOUNT )

                                                                RETAILMSG( 1, (TEXT(" STORE_ATTRIBUTE_AUTOMOUNT")));

                                                if(si.dwAttributes == 0 )

                                                                RETAILMSG( 1, (TEXT(" None")));

                                                RETAILMSG( 1, (TEXT("\n")));

                                               

                                                RETAILMSG( 1, (TEXT("Partition Count %d\n"), si.dwPartitionCount));

                                                RETAILMSG( 1, (TEXT("Mount Count %d\n"), si.dwMountCount));

 

                                               

                                                hStore = OpenStore( si.szDeviceName );             

 

                                                if( hStore )

                                                {

                                                                DisplayPartions( hStore );

                                                                CloseHandle(hStore);

                                                }

                                                else

                                                                RETAILMSG(1, (TEXT("OpenSelectedStore failed\n")));

        }

        while(FindNextStore(hFind, &si));

        FindClose(hFind);

    }

}

The output from DisplayDisks() looks like:

Device Name DSK2:

Name PCMCIA/Compact Flash Device

Class STORAGE_DEVICE_CLASS_MULTIMEDIA

Type Unkown device type 0x0

Flags None

Bytes per Sector 512

Attributes None

Partition Count 1

Mount Count 1

DisplayDisks() calls on DisplayPartions() to enumerate the disk partitions and display the partition information.

void DisplayPartions( HANDLE hStore )

{

                HANDLE hFind = INVALID_HANDLE_VALUE;

                HANDLE hPartition = INVALID_HANDLE_VALUE;

                PARTINFO partInfo = {0};

 

                partInfo.cbSize = sizeof(PARTINFO);

                hFind = FindFirstPartition(hStore, &partInfo);

 

                if(INVALID_HANDLE_VALUE != hFind)

                {             

                                do

                                {

                                                if(PARTITION_ATTRIBUTE_MOUNTED & partInfo.dwAttributes)

                                                {

                                                                RETAILMSG( 1, (TEXT("\t\tPartition Name %s\n"), partInfo.szPartitionName ));

                                                                RETAILMSG( 1, (TEXT("\t\tSize %d\n"), partInfo.cbSize ));

                                                                RETAILMSG( 1, (TEXT("\t\tFile System %s\n"), partInfo.szFileSys ));

                                                                RETAILMSG( 1, (TEXT("\t\tVolume Name %s\n"), partInfo.szVolumeName ));

                                                                RETAILMSG( 1, (TEXT("\t\tNumber of Sectors %d\n"), partInfo.snNumSectors ));

                                                                RETAILMSG( 1, (TEXT("\t\tAttributes")));

                                                                if(partInfo.dwAttributes & PARTITION_ATTRIBUTE_EXPENDABLE )

                                                                                RETAILMSG( 1, (TEXT(" PARTITION_ATTRIBUTE_EXPENDABLE")));

                                                                if(partInfo.dwAttributes & PARTITION_ATTRIBUTE_READONLY )

                                                                                RETAILMSG( 1, (TEXT(" PARTITION_ATTRIBUTE_READONLY")));

                                                                if(partInfo.dwAttributes & PARTITION_ATTRIBUTE_BOOT )

                                                                                RETAILMSG( 1, (TEXT(" PARTITION_ATTRIBUTE_BOOT")));

                                                                if(partInfo.dwAttributes & PARTITION_ATTRIBUTE_AUTOFORMAT )

                                                                                RETAILMSG( 1, (TEXT(" PARTITION_ATTRIBUTE_AUTOFORMAT")));

                                                                if(partInfo.dwAttributes & PARTITION_ATTRIBUTE_MOUNTED )

                                                                                RETAILMSG( 1, (TEXT(" PARTITION_ATTRIBUTE_MOUNTED")));

                                                                if(partInfo.dwAttributes == 0 )

                                                                                RETAILMSG( 1, (TEXT(" None")));

                                                                RETAILMSG( 1, (TEXT("\n")));

                                                                {

                                                                                TCHAR *PartTypeString = NULL;

                                                                                DWORD Result;

                                                                                HKEY hKey;

                                                                                DWORD NumBytes = 0;

                                                                                DWORD Type;

                                                                                TCHAR PartType[3];

 

                                                                                // Convert the partion type value to a string

                                                                                wsprintf( PartType, TEXT("%02X"), partInfo.bPartType );

 

                                                                                // Open the Registry Key

                                                                                Result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, (LPCWSTR)TEXT("System\\StorageManager\\PartitionTable"), 0, 0, &hKey);

 

                                                                                if( ERROR_SUCCESS == Result )

                                                                                {

                                                                                                // This is a fake read, all it does is fill in NumBytes with the number of

                                                                                                // bytes in the string value plus the null character.

                                                                                                Result = RegQueryValueEx( hKey, PartType, NULL, &Type, NULL, &NumBytes );

                                                                                                if( NumBytes > 0 )

                                                                                                {

                                                                                                                // Now we know how big the string is allocate and read it

                                                                                                                PartTypeString = (TCHAR *)malloc( NumBytes );

                                                                                                                if( PartTypeString != NULL )

                                                                                                                                Result = RegQueryValueEx( hKey, PartType, NULL, &Type, (LPBYTE)PartTypeString, &NumBytes );

                                                                                                                RETAILMSG( 1, (TEXT("\t\tPartion Type %s\n"), PartTypeString ));

                                                                                                                free( PartTypeString );

                                                                                                }

                                                                                                else

                                                                                                                RETAILMSG( 1, (TEXT("\t\tPartion Type not found\n")));

                                                                                                RegCloseKey( hKey );

                                                                                }

                                                                }

                                                }

                                }

                                while(FindNextPartition(hFind, &partInfo));

                                FindClose(hFind);

                }

                CloseHandle(hStore);

}

While writing this, I discovered that unlike what the documentation says about bPartType, the macros that define the partition types don’t actually exist. But, the information is in the registry in HKEY_LOCAL_MACHINE\System\StorageManager\PartitionTable. So I reused the code in my post about reading registry strings (Windows CE: Reading a String from the Registry) to read the partition names from the registry.

---------------------------------------------------------------------------------------------------------------------------------

 

Note:  This article is written by Bruce Eitman, and is posted to the Embedded101 site with Bruce’s permission.

 

 

Copyright © 2010 – Bruce Eitman – All Rights Reserved

http://geekswithblogs.net/BruceEitman/

Embedded101 Articles

Click to Expand/Collapse Groups
Skip Navigation Links.
Collapse Windows Embedded Compact (CE)Windows Embedded Compact (CE)
Collapse Compact 7Compact 7
Build A Windows Network Projector wi...
Filter Device Drivers
Asynchronous I/O request support
Configure Flash Storage to Launch Co...
CEDriverWiz V2.00: About this releas...
Installing CEDriverWiz for Visual St...
Collapse CE 6.0CE 6.0
Stream Driver with CEDriverWiz rev 0...
Connecting Visual Studio IDE to CE 6...
Windows CE: Save and Restore the Re...
Windows CE: Stream Interface Driver...
Windows CE: Persisting Registry Chan...
Windows CE: Enhanced BusEnum
Windows CE: Soft Reset
Windows CE: Reading a String from th...
Windows CE: Displaying Disk Informa...
Windows CE: Formatting TFAT
Windows CE: C# Application to Format...
Hive-Based Registry for CE 6.0
AutoLaunch for CE 6.0
Configure Flash Storage to Launch Co...
CEDriverWiz V2.00: About this releas...
Installing CEDriverWiz for Visual St...
Collapse CE 5.0CE 5.0
Configure Flash Storage to Launch Co...
Collapse Platform Builder & OS DesignPlatform Builder & OS Design
Platform Builder: Automatically Flus...
Windows CE: Enhanced BusEnum
Windows CE: Soft Reset
Windows CE: Displaying Disk Informa...
Build A Windows Network Projector wi...
CEDriverWiz V2.00: About this releas...
Installing CEDriverWiz for Visual St...
Collapse BSP, OAL & BootloaderBSP, OAL & Bootloader
Windows CE 6.0: User Mode KernelIoC...
Windows CE: Displaying Disk Informa...
Collapse RegistryRegistry
Platform Builder: Automatically Flus...
Windows CE: Save and Restore the Re...
Windows CE: Stream Interface Driver...
Windows CE: Persisting Registry Chan...
Windows CE: Reading a String from th...
Hive-Based Registry for CE 6.0
Collapse Device DriverDevice Driver
Stream Driver with CEDriverWiz rev 0...
Windows CE: Stream Interface Driver...
Windows CE: Enhanced BusEnum
CEDriverWiz V2.00: About this releas...
Installing CEDriverWiz for Visual St...
Collapse File SystemFile System
Windows CE: Formatting TFAT
Windows CE: C# Application to Format...
Collapse Application DevelopmentApplication Development
Connecting Visual Studio IDE to CE 6...
Windows CE: Persisting Registry Chan...
Windows CE: Reading a String from th...
Windows CE: Formatting TFAT
Windows CE: C# Application to Format...
AutoLaunch for CE 6.0
Windows CE: Stream Interface Driver ...
IBW & ICE
Stream Driver with CEDriverWiz rev 0...
Connecting Visual Studio IDE to CE 6...
Platform Builder: Automatically Flus...
Windows CE: Save and Restore the Re...
Windows CE: Stream Interface Driver...
Windows CE: Persisting Registry Chan...
Windows CE: Enhanced BusEnum
Windows CE: Reading a String from th...
Windows CE: Displaying Disk Informa...
Windows CE: Formatting TFAT
Windows CE: C# Application to Format...
Build A Windows Network Projector wi...
Hive-Based Registry for CE 6.0
AutoLaunch for CE 6.0
Hello all
Filter Device Drivers
Asynchronous I/O request support
Configure Flash Storage to Launch Co...
CEDriverWiz Version 2.00 User Manual
CEDriverWiz V2.00: About this releas...
Installing CEDriverWiz for Visual St...
CEDriverWiz Version 2.00: An Example
CEDriverWiz Version 2.00: Using the ...
Collapse Windows Embedded StandardWindows Embedded Standard
WES7
WES-2009
Windows XP Embedded
Target Designer
Enhanced Write Filter
Collapse NET Compact FrameworkNET Compact Framework
Windows CE: C# Application to Format...
Windows Phone 7
Misc.
Turkish porno izle video site in rokettubeporno izle