none
Windows CompactEmbedded2013: FormatStore() failed with ERROR_NOT_SUPPORTED (errno:50) RRS feed

  • Question

  • Wenn calling FormatStore() for a SD-Card with this small function:

    {

    HANDLEhStore;

    hStore = OpenStore(

    pwcDeviceName);

    if(INVALID_HANDLE_VALUE!= hStore)

    {

    if(DismountStore(hStore))

    {

    if(TRUE== FormatStore(hStore))

    {

    RETAILMSG( TRUE, (_T( "%s%s Format device '%s' successful.\r\n"),

      

    MODUL_NAME, FUNC_NAME, pwcDeviceName));

    }

    else


    {

    RETAILMSG( TRUE, (_T( "%s%s ERROR -> Could not format device '%s' (errno:%d).\r\n"),

      

    MODUL_NAME, FUNC_NAME, pwcDeviceName, GetLastError()));

    }

    }

    else


    {

    RETAILMSG( TRUE, (_T( "%s%s ERROR -> Could not dismount device '%s'.\r\n"),

      

    MODUL_NAME, FUNC_NAME, pwcDeviceName));

    }

            CloseHandle(hStore);

    }

    else


    {

    RETAILMSG( TRUE, (_T( "%s%s ERROR -> Could not open device '%s' (errno:%d)\r\n"),

      

    MODUL_NAME, FUNC_NAME, pwcDeviceName, GetLastError()));

    }

    return;

    }

    I get the following error traces and the Format fails:

    PID:00400002 TID:03A70026 SDMemory: GetDeviceInfo - Profile = SDHCMemory, length = 22
    PID:00400002 TID:03A70026 SDemory: GetDeviceInfo - RegQueryValueEx(Profile) returned 2
    PID:00400002 TID:03A70026 Partition PART00  NumSectors=7744512

    Any ideas?

    Tx Markus

    Wednesday, July 16, 2014 10:46 AM

All replies

  • Call GetStoreInfo on the hStore, then check the dwPartitionCount. If it is not 0 it means the SD card is already formatted and partitioned. You can then use FindFirst/NextPartition to enumerate the partitions and do whatever you need to do (delete the partitions, or format the partitions using OpenPartition and FormatPartitionEx).

    You can't call FormatStore on a store containing partitions, that's why you get the error.

    Note that after formatting the store or partition, you still have to format the volume (using FormatVolumeEx) to create a filesystem on the partition or store.


    Good luck,

    Michel Verhagen, eMVP
    Check out my blog: http://guruce.com/blog

    GuruCE
    Microsoft Embedded Partner
    http://guruce.com
    Consultancy, training and development services.

    Thursday, July 17, 2014 1:40 AM
    Moderator
  • Hi Michel,

    your approach with DeletePartition() did also not work:

    I try it now first with FormatStore() which fails (same as already posted):
    SDMemory: GetDeviceInfo - Profile = SDMemory, length = 18
    SDemory: GetDeviceInfo - RegQueryValueEx(Profile) returned 2
    Partition PART00  NumSectors=3862528
    PartTool:FormatDeviceFormatStore: ERROR -> Could not format device 'DSK2:' (errno:50).

    then with DeletePartition() did it also not work
    PartTool:FormatDeviceDeletePartition: Start deleting partiton 'PART00' on device 'DSK2:'
    PartTool:FormatDeviceDeletePartition: ERROR -> Failed deleting partiton 'PART00' on device 'DSK2:' (errno:31)
    PartTool:formatDevice: ERROR --> Unable to format the device!

    I call DeletePartition like this:
    fRet = DeletePartition(hStore, sPartInfo.szPartitionName);

    I have also NAND-flash on my EvalBoard and here the FormatStore() works perfect. Also when I have multiple partitions on it. What here did not work when I use DeletePartition(), because there are not only FAT-partitions inside the NAND, but also BOOT-partitions and here DeletePartition() fails.

    So finally I think you are not right with your statemanet that FormatStore() could not be called on a store which contains partitions.

    So my Problem is still not solved :-(

    Further ideas?

    Tx Markus

    Thursday, July 17, 2014 7:18 AM
  • Additional info:

    The FormatStore() function works also perfect for a USB-stick. I have only the problems with the SD-Card!

    What also puzzles me are the traces from my Problem from the Registry. Why is there printed out

    SDemory: GetDeviceInfo - RegQueryValueEx(Profile) returned 2

    SDemory and not SDMemory.

    Can the Problem perhaps be lockated in the registry?

    Regards

    Markus

    Thursday, July 17, 2014 7:39 AM
  • Hmmm... There may be something strange with your SD card driver then...

    I've got code here that does exactly what I described and it works perfectly fine. I may not have been right on the FormatStore not working when there are partitions, but it seemed a logical explanation (I did not try it).

    Here's the sequence I use:

    OpenStore
    GetStoreInfo
    if (partition count == 0)
       DismountStore
       FormatStore
       GetStoreInfo
       CreatePartitionEx(.., .. ,.., storeInfo.snBiggestPartCreatable)
       OpenPartition
       FormatPartitionEx
       GetPartitionInfo
       DismountPartition
       FormatVolumeEx
       MountPartition
       GetPartitionInfo
    else
       FindFirstPartition
       OpenPartition
       FormatPartitionEx
       GetPartitionInfo
       DismountPartition
       FormatVolumeEx
       MountPartition
       GetPartitionInfo
       FindNextPartition (repeat)
    CloseHandle(hStore)

    I use the above sequence to format a store whether it has partitions or not. This works in our BSP for SD, uSD, MMC and NAND, so if that doesn't work for you I'd suggest stepping through the filesystem code to figure out where exactly it fails.

    You don't have the write-protect tab set to lock on your SD card by any chance?

    Can you format stores using the storage manager control panel applet? If that also doesn't work there's simply something wrong in your driver or HW (card?)


    Good luck,

    Michel Verhagen, eMVP
    Check out my blog: http://guruce.com/blog

    GuruCE
    Microsoft Embedded Partner
    http://guruce.com
    Consultancy, training and development services.


    Thursday, July 17, 2014 7:42 AM
    Moderator
  • Hi,

    no I don´t have set the write-protect tab.

    I have also a WinEC7 here and tried it on the board with the storage manage control Panel Applet and this Fails also.

    Can there perhaps be something wrong in my System configuration? I use the Standard Host Controller (SYSGEN_SDHC_STANDARD) and the SD Host Controller from the BSP (BSP_SDHC)? Is this a host Controller too much or are both necessary?

    Markus

    Thursday, July 17, 2014 8:05 AM
  • Don't set SYSGEN_SDHC_STANDARD, that's the old SDBus driver. Use SYSGEN_SDBUS (and SYSGEN_SD_MEMORY) instead.

    BSP_SDHC is the board specific part of the SDHC components. You need both.


    Good luck,

    Michel Verhagen, eMVP
    Check out my blog: http://guruce.com/blog

    GuruCE
    Microsoft Embedded Partner
    http://guruce.com
    Consultancy, training and development services.


    Thursday, July 17, 2014 8:10 AM
    Moderator
  • Removing SYSGEN_SDHC_STANDARD changes nothing.

    Tx for the tips until here.

    So my Problem is still open...

    Markus

    Thursday, July 17, 2014 10:31 AM
  • What BSP are you using? Which processor?

    My next advice would be; contact the BSP developers.


    Good luck,

    Michel Verhagen, eMVP
    Check out my blog: http://guruce.com/blog

    GuruCE
    Microsoft Embedded Partner
    http://guruce.com
    Consultancy, training and development services.

    Thursday, July 17, 2014 10:39 AM
    Moderator
  • Hi,

    in the meantime I have found out where the problem comes from and how you could get out of this situation.

    How it Comes to this Problem:

    Just insert a blank SD-Card or USB-Stick in the target (there have to be no partitons on the device)

    When you insert the device WinCE creates a strange new partiton on it from type FAT16 (0x04). This Partition can not be mounted or erased any more. On the target you are lost with this device. It is no longer useable. Also the storage Manager Applet could not delete this device any more.

    How you could get out if this Situation:

    Take the device and Format it with the PC-Tool "SDFormatter" and you will have your device back. Also in the target it is now useable again. When you insert it back on the target you could see, that the partiton type has changed and you could work again with this device.

    WinCE seems to write on inserting of an empty device some Strange data on the device, which makes it no longer useable. So perhaps some guys from MSFT can give us a detailed declaration for this Problem.

    I leave this Topic open, because I could only Show how this Problem occurs, but not how we came in this Situation.

    Wednesday, July 23, 2014 2:01 PM
  • I see the same issue.  In my case, I cannot remove the SD media from WinCE device, so moving it to a PC to fix it is not an option.

    The problem appears to be that the card was formatted with a FAT partition boot sector at sector 0 instead of an MBR:

    000000h   EB 58 90 4D 53 44 4F 53 35 2E 30 00 02 08 7E 09 02 00 00 00 00 F8 00 00 3F 00 FF 00 00 00 00 00 00 80 ED 00 41 3B 00 00   .X.MSDOS5.0...~.........?...........A;..
    000028h   00 00 00 00 02 00 00 00 01 00 06 00 00 00 00 00 00 00 00 00 00 00 00 00 80 00 29 69 53 69 AA 4E 4F 20 4E 41 4D 45 20 20   ..........................)iSi.NO NAME  
    000050h   20 20 46 41 54 33 32 20 20 20 33 C9 8E D1 BC F4 7B 8E C1 8E D9 BD 00 7C 88 4E 02 8A 56 40 B4 41 BB AA 55 CD 13 72 10 81     FAT32   3.....{......|.N..V@.A..U..r..
    000078h   FB 55 AA 75 0A F6 C1 01 74 05 FE 46 02 EB 2D 8A 56 40 B4 08 CD 13 73 05 B9 FF FF 8A F1 66 0F B6 C6 40 66 0F B6 D1 80 E2   .U.u....t..F..-.V@....s......f...@f.....
    0000A0h   3F F7 E2 86 CD C0 ED 06 41 66 0F B7 C9 66 F7 E1 66 89 46 F8 83 7E 16 00 75 38 83 7E 2A 00 77 32 66 8B 46 1C 66 83 C0 0C   ?.......Af...f..f.F..~..u8.~*.w2f.F.f...
    0000C8h   BB 00 80 B9 01 00 E8 2B 00 E9 2C 03 A0 FA 7D B4 7D 8B F0 AC 84 C0 74 17 3C FF 74 09 B4 0E BB 07 00 CD 10 EB EE A0 FB 7D   .......+..,...}.}.....t.<.t............}
    0000F0h   EB E5 A0 F9 7D EB E0 98 CD 16 CD 19 66 60 80 7E 02 00 0F 84 20 00 66 6A 00 66 50 06 53 66 68 10 00 01 00 B4 42 8A 56 40   ....}.......f`.~.... .fj.fP.Sfh.....B.V@
    000118h   8B F4 CD 13 66 58 66 58 66 58 66 58 EB 33 66 3B 46 F8 72 03 F9 EB 2A 66 33 D2 66 0F B7 4E 18 66 F7 F1 FE C2 8A CA 66 8B   ....fXfXfXfX.3f;F.r...*f3.f..N.f......f.
    000140h   D0 66 C1 EA 10 F7 76 1A 86 D6 8A 56 40 8A E8 C0 E4 06 0A CC B8 01 02 CD 13 66 61 0F 82 75 FF 81 C3 00 02 66 40 49 75 94   .f....v....V@............fa..u.....f@Iu.
    000168h   C3 42 4F 4F 54 4D 47 52 20 20 20 20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   .BOOTMGR    ............................
    000190h   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0D 0A 52 65 6D 6F 76 65 20 64 69 73   ..............................Remove dis
    0001B8h   6B 73 20 6F 72 20 6F 74 68 65 72 20 6D 65 64 69 61 2E FF 0D 0A 44 69 73 6B 20 65 72 72 6F 72 FF 0D 0A 50 72 65 73 73 20   ks or other media....Disk error...Press 
    0001E0h   61 6E 79 20 6B 65 79 20 74 6F 20 72 65 73 74 61 72 74 0D 0A 00 00 00 00 00 AC CB D8 00 00 55 AA                           any key to restart............U.
    

    When CE is mounting this store, mspart.dll's GetDosPartitions fails with ERROR_INVALID_DATA (helper.cpp) due to finding invalid partition data (that would be in an MBR).  The StoreManager then attempts to use the 'null' partition driver to mount the partition.  The null partition driver supplies an empty DeletePartition function (with error return 0x31, ERROR_GEN_FAILURE). This null partition driver also supplies similar empty/error functions for creating, renaming, setting attributes, setting size, etc.

    So it appears that WinCE is incapable of managing partitions on a store without an MBR, except for being able to actually mount a partition and the filesystem (in my case, type 0x4 (FAT16)).

    There's probably a solution here based on writing a valid empty MBR directly to sector 0 of the store, then restarting WinCE (forcing a re-load of the store that will employ mspart.dll).

    - Wil

    Wednesday, June 7, 2017 4:29 PM
  • Take a look at:

    http://geekswithblogs.net/BruceEitman/archive/2010/08/29/windows-ce-formatting-tfat.aspx

    It worked when I wrote it in 2010.



    Bruce Eitman (eMVP)
    Senior Engineer
    Bruce.Eitman AT Eurotech DOT com
    My BLOG http://geekswithblogs.net/bruceeitman
    I work for Eurotech

    Thursday, June 8, 2017 2:47 PM
    Moderator