none
WinCE6: Change volume format from exFAT to TFAT dont work RRS feed

  • Question

  • Hi all,

    In a BPS I have developed, I have create a function to be able to switch a storage volume between exFAT and TFAT format. I have do this to test file system performance.

    Here a code extract, which show how I format the volume

     

    hFatUtil = LoadLibrary(L"FATUTIL.DLL");
    if(hFatUtil == NULL)
    {
        RETAILMSG(TRUE, (L"%s:: Error loading FATUTIL.DLL !!\r\n", __WFUNCTION__));
        errCode = GetLastError();
        goto exit_func;
    }
    
    pfnFormatVolume = (PFN_FORMATVOLUME)GetProcAddress(hFatUtil, TEXT("FormatVolume"));
    
    hStore = OpenStore(ceVolumeInfo.szStoreName);
    if(hStore != INVALID_HANDLE_VALUE)
    {
        HANDLE hPartition;
        
        hPartition = OpenPartition(hStore, ceVolumeInfo.szPartitionName);
        if(hPartition != INVALID_HANDLE_VALUE)
        {
            if(DismountPartition(hPartition))
            {
                FORMAT_OPTIONS fo;
                DWORD rc;
                DISK_INFO di;
                DWORD dwBytes;
    
    
                fo.dwClusSize = 4 * 1024;
                fo.dwFatVersion = 64;
                fo.dwNumFats = 2;
                fo.dwRootEntries = 512;
    
                fo.dwFlags = 0;
                //fo.dwFlags |= FATUTIL_FULL_FORMAT;
                fo.dwFlags |= FATUTIL_DISABLE_MOUNT_CHK;
                fo.dwFlags |= FATUTIL_FORMAT_EXFAT;
                if(bFormatAsTfat)
                {
                    RETAILMSG( 1, (L"%s: Format TFAT\n", __WFUNCTION__));
                    fo.dwFlags |= FATUTIL_FORMAT_TFAT;                    
                }
                else
                {
                    RETAILMSG( 1, (L"%s: Format exFAT\n", __WFUNCTION__));
                }
    
                // read disk information
                if (!DeviceIoControl(hPartition, DISK_IOCTL_GETINFO, &di, sizeof(DISK_INFO), &di, sizeof(DISK_INFO), &dwBytes, NULL))
                {
                    RETAILMSG(TRUE, (L"%s:: Error DeviceIoControl() => IDS_COULD_NOT_GET_PART_INFO\r\n", __WFUNCTION__));
                }
                else
                {
                    // formating
                    rc = pfnFormatVolume(hPartition, &di, &fo, FormatProgress, NULL);
                    RETAILMSG( 1, (L"\r\n"));
                    if(ERROR_SUCCESS != rc)
                    {
                        RETAILMSG( 1, (L"%s: Format Failed\n", __WFUNCTION__));
                        errCode = GetLastError();
                        CloseHandle(hPartition);
                        goto exit_func;
                    }
                }
                MountPartition(hPartition);
            }
            else
            {
                RETAILMSG(TRUE, (L"%s: Error dismounting Partition\r\n", __WFUNCTION__));
                errCode = GetLastError();
                CloseHandle(hPartition);
    
                goto exit_func;
            }
    
            CloseHandle(hPartition);
    
        }
        else
        {
            RETAILMSG(TRUE, (L"%s: Error opening Partition\r\n", __WFUNCTION__));
            FormatLowLevel();
            errCode = GetLastError();
            goto exit_func;
        }
    
    }
    else
    {
        RETAILMSG(TRUE, (L"%s: Error opening Store\r\n", __WFUNCTION__));
        FormatLowLevel();
        goto exit_func;
    }
    
    


    Note: I have removed the FATUTIL_FULL_FORMAT flag, because with this flag the format routine ends with an error!

    When I format from TFAT to exFAT, it seems to work well.

    When I format form exFAT to TFAT, at the begin the storage seems to work but, after some file operations (copy, create, rename, etc.) the contents of the storage is corrupt. The files have the correct size, but the content of the file isn't valid.

    When I format the storage with Windows CE Storage Manager:

    • full format ends without error
    • the TFAT partition isn't corrupted during file operations

     

    I have also seen, that when I do a "low level" format (erasing Nand Flash blocks) and use "AutoFormat" in registry, the TFAT partition is also valid after Windows CE formats the partition during startup, but when I switch from TFAT => exFAT => TFAT with my routine, the contents will be corrupted after some file operations.

    What's wrong with my code?

    I need help !

    Best regards

    Fabrice

     

    Monday, January 16, 2012 8:23 AM