How to format diskette without using ? 
Author Message
 How to format diskette without using ?

I'd like to write two functions: quickFormatDiskette() and
fullFormatDiskette() which will perform the same action as a: /q

and a:

respectively, except there should be no user input and nothing
displayed on the screen.  Any errors detected during the format should
be caught, and the solution should work on both Win95 and NT4.  You
can assume that the floppy drive is A: and will only be used for
1.44MB diskettes.  I'd also prefer to avoid using the
program entirely if possible.

I've discovered SHFormatDrive() (an undocumented function in
shell32.dll) which will format a diskette, but the problem is it puts
up a dialog box (e.g. check this box if you want a quick format)
whereas I want an automatic non-interactive solution.

There's DeviceIoControl() which I think should be able to format a
diskette by setting dwIoControlCode to IOCTL_DISK_FORMAT_TRACKS and in
the FORMAT_PARAMETERS structure, setting media type to F3_1Pt44_512,
but I'm not sure what values to use for StartCylinderNumber,
EndCylinderNumber. StartHeadNumber or EndHeadNumber (also in

I imagine DeviceIoControl() would allow a full (slow) format, but not
a quick format.  And a quick format is essential for the project I'm
working on.

The method I am currently using is quite hideous as it relies on
knowledge of certain prompts in the program.  I call a
batch file FormatDiskette.bat with two parameters; the first is either
-q or -f (quick or full), and the second is the name of an error file
which gets created if fails.

There is also a text file called FormatDiskette.txt which contains the
5 characters <CR><LF>n<CR><LF>.  This is used as input to the program.

    rem FormatDiskette.bat - format a diskette

    if z%1 == z-q goto arg1ok
    if z%1 == z-f goto arg1ok
    goto usage

    if z%2 == z goto usage
    if z%3 == z goto ok

    echo FormatDiskette [-q or -f] errorfile
    goto end

    rem *** Ensure error file does not exist
    if exist %2 del %2
    if not exist %2 goto ok001
    echo Unable to delete error file %2
    goto end

    rem *** Ensure input file for format exists
    if exist FormatDiskette.txt goto ok002
    echo FormatDiskette.txt must exist in the current directory.
    echo Current directory is:
    goto error

    if z%1 == z-q goto quick
    format a: /v:"" /u < FormatDiskette.txt
    if errorlevel 1 goto error
    goto end

    format a: /v:"" /u /q < FormatDiskette.txt
    if not errorlevel 1 goto end

    rem *** Create error file
    echo off > %2



Sat, 03 Mar 2001 03:00:00 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Source code to format a diskette?

2. Format diskette in Turbo C

3. Programically format a diskette - how?

4. Asking for C source to format MSDOS diskettes

5. Asking for C source to format a MSDOS diskette

6. Programically format a diskette - how?

7. Format a diskette

8. How to format a diskette under Win

9. formatting long strings using sprintf() without including tabs or newlines

10. Changing .MAT data format to binary format

11. ELF format to OMF386 format

12. Help: Re-format HTML format


Powered by phpBB® Forum Software