Results 1 to 8 of 8

Thread: [RESOLVED] FAT32 Quick Format above 32gb

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2024
    Posts
    81

    Resolved [RESOLVED] FAT32 Quick Format above 32gb

    Using VB6

    Must use FAT32 file system for a device using a USB thumb drive now above 32gb. Need to make a "quick format" via code as a fast way to "erase" the drive. Currently shelling out to a batch file running in the command (DOS-like) system.

    I can format above 32gb but no syntax variation I can find in the "Format" command will allow the /q option with return error indicating "FAT32 cannot be used above 32gb" yet there is no problem doing a complete and successful format of a 64gb drive without the /q option.

    Is my only option using a batch file to teletype to into DiskPart? If so how do I find the disk number beforehand? I find nothing in either VB or the FileSystemObject to return a simple integer value of a drive to correspond with that in the DiskPart interface.

    Thanks for any suggestions/assistance.

  2. #2
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,758

    Re: FAT32 Quick Format above 32gb

    https://github.com/usbtool/formatusb...format_fat32.c

    It's not simple because there are no ready-made API calls to use. In sources above they resort to DeviceIoControl and directly writing sectors to disk.

    Btw, I guess you can shell their formatusb_x64.exe too.

    cheers,
    </wqw>

  3. #3
    Hyperactive Member -Franky-'s Avatar
    Join Date
    Dec 2022
    Location
    Bremen Germany
    Posts
    371

    Re: FAT32 Quick Format above 32gb

    A long time ago I programmed something together from various links. It's not perfect, but it works.
    Code in a module
    Code:
    Option Explicit
    
    
    ' https://github.com/microsoft/winfile/blob/master/src/fmifs.h
    ' http://read.pudn.com/downloads153/sourcecode/windows/system/670288/FORMAT/FORMAT.C__.htm
    
    
    Public Const API_FALSE As Long = &H0&
    Public Const API_TRUE As Long = &H1&
    
    
    Public Enum CLUSTER_SIZE
        FMIFS_SizeDefault = 0
        FMIFS_Size512 = 512
        FMIFS_Size1K = 1024
        FMIFS_Size2K = 2048
        FMIFS_Size4K = 4096
        FMIFS_Size8K = 8192
        FMIFS_Size16K = 16384
        FMIFS_Size32K = 32768
        FMIFS_Size64K = 65536
        FMIFS_Size128K = 131072
        FMIFS_Size256K = 262144
    End Enum
    
    
    Public Enum MEDIA_TYPE
        FMIFS_MediaUnknown = 0      ' Format is unknown
        FMIFS_MediaRemovable = 11   ' Removable media other than floppy.
        FMIFS_MediaFixed = 12       ' Fixed hard disk media.
    End Enum
    
    
    Public Enum CALLBACK_COMMAND
        FMIFS_PROGRESS = &H0
        FMIFS_DONE_WITH_STRUCTURE = &H1
        FMIFS_INCOMPATIBLE_FILE_SYSTEM = &H3
        FMIFS_ACCESS_DENIED = &H6
        FMIFS_MEDIA_WRITE_PROTECTED = &H7
        FMIFS_VOLUME_IN_USE = &H8
        FMIFS_CANT_QUICK_FORMAT = &H9
        FMIFS_DONE = &HB
        FMIFS_BAD_LABEL = &HC
        FMIFS_OUTPUT = &HE
        FMIFS_STRUCTURE_PROGRESS = &HF
        FMIFS_CLUSTER_SIZE_TOO_SMALL = &H10
        FMIFS_CLUSTER_SIZE_TOO_BIG = &H11
        FMIFS_VOLUME_TOO_SMALL = &H12
        FMIFS_VOLUME_TOO_BIG = &H13
        FMIFS_NO_MEDIA_IN_DRIVE = &H14
        FMIFS_DEVICE_NOT_READY = &H18
        FMIFS_CHECKDISK_PROGRESS = &H19
        FMIFS_READ_ONLY_MODE = &H20
    End Enum
    
    
    'Public Type FORMAT_VOL_PARAMETERS
    ''29          BOOL bDevice;
    ''30          BOOL hiddenVol;
    ''31          char *volumePath;
    ''32          unsigned __int64 size;
    ''33          unsigned __int64 hiddenVolHostSize;
    ''34          int ea;
    ''35          int pkcs5;
    ''36          uint32 headerFlags;
    ''37          int fileSystem;
    ''38          unsigned int clusterSize;
    ''39          BOOL sparseFileSwitch;
    ''40          BOOL quickFormat;
    ''41          DWORD sectorSize;
    ''42          int *realClusterSize;
    ''43          Password *password;
    ''44          int pim;
    ''45          HWND hwndDlg;
    ''46          BOOL bForceOperation;
    ''47          BOOL bGuiMode;
    'End Type
                             
    Public Declare Sub CopyMemory Lib "kernel32" _
                       Alias "RtlMoveMemory" ( _
                       ByRef Destination As Any, _
                       ByRef Source As Any, _
                       ByVal Length As Long)
                       
    Public Declare Function FormatEx Lib "fmifs.dll" ( _
                            ByVal DriveRoot As Long, _
                            ByVal MediaType As MEDIA_TYPE, _
                            ByVal FileSystemName As Long, _
                            ByVal VolumeLabel As Long, _
                            ByVal QuickFormat As Long, _
                            ByVal ClusterSize As CLUSTER_SIZE, _
                            ByVal Callback As Long) As Long
                            
    Public Function FormatExCallback(ByVal Command As CALLBACK_COMMAND, _
                                     ByVal Modifier As Long, _
                                     ByVal Argument As Long) As Long
        
        Dim lngPercent As Long
        
        'Debug.Print Command, Modifier, Argument
        
        Select Case Command
            
            Case CALLBACK_COMMAND.FMIFS_PROGRESS
                Call CopyMemory(lngPercent, ByVal Argument, 4)
                Debug.Print "Percent completed: " & CStr(lngPercent)
            
            Case CALLBACK_COMMAND.FMIFS_OUTPUT
                Debug.Print "Output: " & CStr(Argument)
            
            Case CALLBACK_COMMAND.FMIFS_DONE
                Debug.Print "Done: " & CStr(Argument)
                
        End Select
        
        FormatExCallback = API_TRUE
        
    End Function
    The call itself:
    Code:
    Option Explicit
    
    
    Private Sub Command1_Click()
        
        Debug.Print FormatEx(StrPtr("G:"), FMIFS_MediaRemovable, _
                             StrPtr("FAT32"), StrPtr("SomeLabel"), _
                             API_TRUE, FMIFS_SizeDefault, _
                             AddressOf FormatExCallback)
    
    
    End Sub
    Drive G: is a USB stick for me. NTFS can also be specified instead of FAT32.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Mar 2024
    Posts
    81

    Re: FAT32 Quick Format above 32gb

    Thank you @wqweto

    Didn't think it would be easy (to automate) as I'd spent quite a bit of time searching and researching. It's nothing for me to quick format using DiskPart or other partition utility program but I intend to distribute this program (not commercially however) and want to keep things as simple as possible for the user.

    The program is for use with a specific brand of modern solenoid player piano that unlike the others is designed to use "everyone's" player piano music.

    At present I'm "erasing" the thumb drive with a shell to simply use del[ete] and RmDir recursively and "quietly" with the appropriate switches. Much faster than a full format but not like AOEMI and probably DiskPart can do a "quick" format.

    I'll mark as "resolved" even though I'm likely to keep looking for a better solution.

  5. #5
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,758

    Re: [RESOLVED] FAT32 Quick Format above 32gb

    @-Franky-: Declare Function FormatEx Lib "fmifs" is a nice find I didn't know it was accessible. Should make providing a Format utility trivial incl. quick format.

    cheers,
    </wqw>

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Mar 2024
    Posts
    81

    Re: [RESOLVED] FAT32 Quick Format above 32gb

    The second post wasn't there when I first looked and I hadn't fully studied that FormatEx function provided in the first. It reminded me of some of the crazy batch files we had to use and write in the early days of DOS. I'll certainly look into it some more once I have it and all of the associated routines refined from their "works for me" semi-automated sequence into something suitable for use by others.

  7. #7
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    6,820

    Re: [RESOLVED] FAT32 Quick Format above 32gb

    There's also the Virtual Disk Service COM interfaces; e.g. IVdsVolumeMF::Format.

    These aren't in oleexp yet but I'm working on adding them for the next version. Will release it as soon as I'm done with them since I just added BITS and DirectML since the last release already.

  8. #8
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,758

    Re: [RESOLVED] FAT32 Quick Format above 32gb

    Btw, formatting a logical drive happens *after* partitioning the physical disk i.e. using DeviceIoControl with IOCTL_DISK_SET_DRIVE_LAYOUT_EX and IOCTL_DISK_SET_PARTITION_INFO_EX might be prerequisite to calling either of the Format methods.

    There is no complete sample how to format a completely blank USB/HDD drive on VBF which would be nice submission to CodeBank.

    cheers,
    </wqw>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width