Accessing Files on Other Storage Media (Windows Embedded CE 6.0)

1/6/2010

A Windows Embedded CEā€“based device can store data in ROM or on a separate storage device.

  • Object store directory (ROM)
    You can access a file that is stored in ROM just like any other file: by calling the file API. However, you cannot alter a file that is stored in ROM. ROM-based files are marked with the FILE_ATTRIBUTE_INROM value, which indicates that they are read-only.
    Windows Embedded CE also uses the FILE_ATTRIBUTE_ROMMODULE value to indicate that a file is designated to be executed in ROM, instead of copied to RAM. You cannot use the CreateFile function to open files that are designated with FILE_ATTRIBUTE_ROMMODULE. Instead, use the LoadLibrary and the CreateProcess functions to gain access to the module.
  • Mounted volume directory
    Windows Embedded CE supports storage cards, such as ATA flash cards, and linear flash cards. These cards can have an installed file system that uses the storage space for files and databases. However, a mounted file system must be used in conjunction with an installed file-system driver, such as FAT. After you install a storage card, you can copy database objects between the object store and the mounted volume.
    Windows Embedded CE does not assign a letter label to a storage card in the same manner that a desktop computer assigns a drive letter to a hard disk. Instead, the file driver creates subdirectories in the root directory that represent each partition on each storage card.
    In Windows CE 2.0 and earlier, these directories were given default names, such as Storage Card or PC Card. In Windows CE 2.10 and later, the FAT file-system driver queries the storage card driver for a default name.
    If the storage card driver does not supply a default name, Windows Embedded CE uses Storage Card.

In addition, an object store directory and a mounted volume directory have different file attributes. When properly set by the block driver using IOCTL_DISK_DEVICE_INFO, the dwAttributes member of the STOREINFO structure specifies the attributes of a volume. To access this information, use GetStoreInfo. For example, for a removable storage device, the block driver sets dwAttributes to STORE_ATTRIBUTE_REMOVABLE.

The folder name of a mounted volume corresponds to a partition in the store. Thus, to find the folder name, find the szVolumeName member of the PARTINFO structure.

The following code example shows how to determine whether a folder name is a removable device:

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPreviousInstance, LPWSTR lpCommandLine, int nCommandShow)
{
   STOREINFO si;
   HANDLE hSearchStore, hStore, hSearchPart;
   PARTINFO pi;
   TCHAR FolderName[] = TEXT("MyFolder"); // Name of folder to seek
   BOOL bPartFind;
   DWORD cchDest = MAX_PATH;
   TCHAR szMsg[cchDest]; // String to store the result message
   // Walk through the stores
   si.cbSize = sizeof(STOREINFO);
   hSearchStore = FindFirstStore( &si);    
   if (hSearchStore != INVALID_HANDLE_VALUE) {
      do
      {
         hStore = OpenStore(si.szDeviceName);
         if (hStore != INVALID_HANDLE_VALUE)
         {
            // Get a pointer to STOREINFO
            GetStoreInfo( hStore, &si);
            pi.cbSize = sizeof(PARTINFO);
            // Get a handle for first partition 
            hSearchPart =  FindFirstPartition( hStore, &pi);
            if (hSearchPart != INVALID_HANDLE_VALUE)
            {
               do
               {
                  // Check if folder name matches
                  if(wcscmp (pi.szVolumeName, FolderName) == 0)
                  {
                     if(si.dwAttributes == STORE_ATTRIBUTE_REMOVABLE)
                     {
                        StringCchPrintf(szMsg, cchDest, TEXT("%s is a removable storage device."), pi.szVolumeName);
                        return;
                     }
                     else
                     {
                        StringCchPrintf(szMsg, cchDest, TEXT("%s is not a removable storage device."), pi.szVolumeName);
                        return;
                     }
                  }
                  // Close everything.
               }
               while(FindNextPartition( hSearchPart, &pi));
               FindClose(hSearchPart);
            }
         }
         CloseHandle( hStore);
      }
      while(FindNextStore(hSearchStore, &si));
      FindClose( hSearchStore);
   }
   return 1;
}

See Also

Concepts

Obtaining and Setting File Information
File System Operations