Hi @alex.tx, thanks for replying.
I am able to format the USB drive with TexFAT using the StorageManager applet. When I do that I am then able to use CeGetVolumeInfo()
in my code and confirm that the CE_VOLUME_TRANSACTION_SAFE
flag is set. This makes me think that my OS image does support TexFAT. I am using version 1.8 of the CE7 image for iMX6.
The link you sent for FormatVolume()
sounds promising but the header file formatdisk.h
does not seem to be part of the BSP and so I can’t compile my code if I try to use that function.
Reading the links you sent me did make me think of a few more things to try which did allow me to get this to work! I was doing this before, but MountPartition()
was failing:
HANDLE hStore = OpenStore(storeName);
HANDLE hPartitionSearch = FindFirstPartition(hStore, &partInfo);
HANDLE hPartition = OpenPartition(hStore, partInfo.szPartitionName);
DismountPartition(hPartition);
FormatPartition(hPartition);
MountPartition(hPartition);
I realized that what I need to do is this instead:
HANDLE hStore = OpenStore(storeName);
DismountStore(hStore);
FormatStore(hStore);
CreatePartition(hStore, ...);
When I did it that way the new partition is automatically mounted and appears in the file system. I also figured out that I was able to specify TexFAT by adding registry entries to [HKLM\SYSTEM\StorageManager\FATFS].
Here is the full code which checks to see if TexFAT is enabled and if it is not enabled then it reformats using TexFAT, in case someone else finds this discussion in the future and needs the same thing. After doing this the CE_VOLUME_TRANSACTION_SAFE
is set and if I insert the USB drive into my PC I can see that file system was changed from FAT32 to exFAT. So I think this is working.
// Call CeGetVolumeInfo() to see if the CE_VOLUME_TRANSACTION_SAFE flag is set
// If the flag is set then USB drive is already using either the TFAT or TexFAT file system
CE_VOLUME_INFO ceVolumeInfo;
memset(&ceVolumeInfo, 0, sizeof(CE_VOLUME_INFO));
ceVolumeInfo.cbSize = sizeof(CE_VOLUME_INFO);
BOOL success = CeGetVolumeInfo(L"\\USB HD", CeVolumeInfoLevelStandard, &ceVolumeInfo);
BOOL transactionSafe = FALSE;
if (success)
{
transactionSafe = ceVolumeInfo.dwFlags & CE_VOLUME_TRANSACTION_SAFE;
if (!transactionSafe)
{
// Change the file system to TexFAT by reformatting the USB drive
STOREINFO storeInfo;
memset(&storeInfo, 0, sizeof(STOREINFO));
storeInfo.cbSize = sizeof(STOREINFO);
HANDLE hStoreSearch = FindFirstStore(&storeInfo);
if (hStoreSearch != INVALID_HANDLE_VALUE)
{
BOOL success;
do
{
if (storeInfo.dwDeviceType & STORAGE_DEVICE_TYPE_USB)
{
HANDLE hStore = OpenStore(storeInfo.szDeviceName);
if (hStore != INVALID_HANDLE_VALUE)
{
if (DismountStore(hStore))
{
// Specify that we want TexFAT by setting two registry keys
HKEY hKey;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"SYSTEM\\StorageManager\\FATFS", 0, KEY_READ, &hKey) == ERROR_SUCCESS)
{
DWORD data = 1;
DWORD size = sizeof(DWORD);
if ((RegSetValueEx(hKey, L"FormatExFat", NULL, REG_DWORD, (byte*)&data, size) == ERROR_SUCCESS) &&
(RegSetValueEx(hKey, L"FormatTFat", NULL, REG_DWORD, (byte*)&data, size) == ERROR_SUCCESS))
{
if (FormatStore(hStore))
{
// If I use CreatePartition() then the new partition appears in the WinCE Storage Manager as type 0x0B, which is FAT32
// But using CHKDSK on Windows 11 I can see that the drive is actually using exFAT
// Using CreatePartitionEx() allows me to specify the partition type as 0x07, which is exFAT
// This makes the partition look correct in Storage Manager but does not seem to have any other effect
// I cannot find a #define for the partition type in the BSP
if (CreatePartitionEx(hStore, L"MyPart", 0x07, storeInfo.snNumSectors))
{
printf("Success!\n");
}
}
}
RegCloseKey(hKey);
}
}
CloseHandle(hStore);
}
}
success = FindNextStore(hStoreSearch, &storeInfo);
} while (success);
FindCloseStore(hStoreSearch);
}
}
}