summaryrefslogblamecommitdiffstats
path: root/private/utils/rdisk/floppyop.c
blob: 1195aab97b805c6b22cb026d705f1f0c6571bcb3 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888























































































































































































































































































































































































































































































































































































































































































































































































































































































































                                                                                                                                 
/*++

Copyright (c) 1992  Microsoft Corporation

Module Name:

    restore.c

Abstract:

    Code to handle interfacing with fmifs.dll for formatting and copying
    floppy disks.

Author:

    Ted Miller (tedm) 28-July-1992

Revision History:

--*/

#include "precomp.h"
#pragma hdrstop

VOID
FmifsThread(
    IN PVOID Arguments
    );



/*
**  Purpose:
**      To center a dialog on the desktop window.
**  Arguments:
**      hdlg:      Handle to the dialog being centered
**  Returns:
**      fTrue:     Centering succeeded.
**      fFalse:    Error condition.
**
****************************************************************************/

BOOL
FCenterDialogOnDesktop(
    HWND hdlg
    )

{

   RECT DesktopRect, DlgRect;
   BOOL bStatus;
   HWND hwMaster ;
   POINT pt,
         ptCtr,
         ptMax,
         ptDlgSize ;
   LONG l ;

   ptMax.x = GetSystemMetrics( SM_CXFULLSCREEN ) ;
   ptMax.y = GetSystemMetrics( SM_CYFULLSCREEN ) ;

   //
   // Determine area of shell and of dlg
   //
   // Center dialog over the "pseudo parent" if there is one.
   //

//   hwMaster = hwPseudoParent
//            ? hwPseudoParent
//            : GetDesktopWindow() ;
    hwMaster = GetDesktopWindow() ;

   if ( ! GetWindowRect( hwMaster, & DesktopRect ) )
       return FALSE ;

   if ( ! GetWindowRect( hdlg, & DlgRect ) )
       return FALSE ;

   ptDlgSize.x = DlgRect.right - DlgRect.left ;
   ptDlgSize.y = DlgRect.bottom - DlgRect.top ;

   //  Attempt to center our dialog on top of the "master" window.

   ptCtr.x = DesktopRect.left + ((DesktopRect.right  - DesktopRect.left) / 2) ;
   ptCtr.y = DesktopRect.top  + ((DesktopRect.bottom - DesktopRect.top)  / 2) ;
   pt.x = ptCtr.x - (ptDlgSize.x / 2) ;
   pt.y = ptCtr.y - (ptDlgSize.y / 2) ;

   //  Force upper left corner back onto screen if necessary.

   if ( pt.x < 0 )
       pt.x = 0 ;
   if ( pt.y < 0 )
       pt.y = 0 ;

   //  Now check to see if the dialog is getting clipped
   //  to the right or bottom.

   if ( (l = pt.x + ptDlgSize.x) > ptMax.x )
      pt.x -= l - ptMax.x ;
   if ( (l = pt.y + ptDlgSize.y) > ptMax.y )
      pt.y -= l - ptMax.y ;

   if ( pt.x < 0 )
        pt.x = 0 ;
   if ( pt.y < 0 )
        pt.y = 0 ;

   //
   // center the dialog window in the shell window.  Specify:
   //
   // SWP_NOSIZE     : To ignore the cx,cy params given
   // SWP_NOZORDER   : To ignore the HwndInsert after parameter and retain the
   //                  current z ordering.
   // SWP_NOACTIVATE : To not activate the window.
   //

   bStatus = SetWindowPos
                 (
                 hdlg,
                 (HWND) NULL,
                 pt.x,
                 pt.y,
                 0,
                 0,
                 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE
                 );

   //
   // return Status of operation
   //

   return(bStatus);

}


typedef enum _FLOPPY_OPERATION {
    FloppyOpFormat,
#ifdef FLOPPY_COPY
    FloppyOpDiskcopy,
#endif
    FloppyOpMaximum
} FLOPPY_OPERATION, *PFLOPPY_OPERATION;


typedef struct _FLOPPY_OPERATION_PARAMS {

    FLOPPY_OPERATION    Operation;
    WCHAR               DriveLetter;
    FMIFS_MEDIA_TYPE    MediaType;
    UINT                CaptionResId;
    UINT                GeneralFailureResId;
    UINT                SrcDiskPromptResId;
    UINT                DstDiskPromptResId;

} FLOPPY_OPERATION_PARAMS, *PFLOPPY_OPERATION_PARAMS;


#define     WM_FMIFS_CALLBACK       (WM_USER+137)

BOOL
ProgressDlgProc(
    IN HWND   hdlg,
    IN UINT   Msg,
    IN WPARAM wParam,
    IN LONG   lParam
    );

BOOLEAN
FmifsCallbackRoutine(
    IN FMIFS_PACKET_TYPE PacketType,
    IN DWORD             PacketLength,
    IN PVOID             PacketAddress
    );


HMODULE                  FmifsModule;

PFMIFS_FORMAT_ROUTINE    FmifsFormat;
#ifdef FLOPPY_COPY
PFMIFS_DISKCOPY_ROUTINE  FmifsDiskCopy;
#endif
PFMIFS_QSUPMEDIA_ROUTINE FmifsQuerySupportedMedia;

HWND ProgressDialog;

BOOL
InitializeFloppySup(
    VOID
    )

/*++

Routine Description:

    Initialize the floppy-disk support package for formatting and diskcopying.
    Load the fmifs dll.

Arguments:

    None.

Return Value:

    TRUE if initialization succeeded.  FALSE otherwise.  It is the caller's
    responsibility to put up a msg box informing the user of the error.

--*/

{
    ProgressDialog = NULL;

    if(FmifsModule) {
        // already initialized
        return(TRUE);
    }

    //
    // Load the fmifs dll.
    //

    if((FmifsModule = LoadLibrary(TEXT("fmifs"))) == NULL) {

        return(FALSE);
    }

    //
    // Get the addresses of relevent entry points.
    //

    FmifsFormat = (PFMIFS_FORMAT_ROUTINE)GetProcAddress( FmifsModule,
                                                         (LPCSTR)"Format"
                                                       );

#ifdef FLOPPY_COPY
    FmifsDiskCopy = (PFMIFS_DISKCOPY_ROUTINE)GetProcAddress( FmifsModule,
                                                             TEXT("DiskCopy")
                                                           );
#endif

    FmifsQuerySupportedMedia = (PFMIFS_QSUPMEDIA_ROUTINE)GetProcAddress( FmifsModule,
                                                                         (LPCSTR)"QuerySupportedMedia"
                                                                       );


    if((FmifsFormat              == NULL)
#ifdef FLOPPY_COPY
    || (FmifsDiskCopy            == NULL)
#endif
    || (FmifsQuerySupportedMedia == NULL))
    {
        FreeLibrary(FmifsModule);
        FmifsModule = NULL;

        return(FALSE);
    }

    return(TRUE);
}


VOID
TerminateFloppySup(
    VOID
    )

/*++

Routine Description:

    Terminate the floppy-disk support package for formatting and diskcopying.

Arguments:

    None.

Return Value:

    None.

--*/

{
    FreeLibrary(FmifsModule);
    FmifsModule = NULL;
}



BOOL
FormatFloppyDisk(
    IN  WCHAR  DriveLetter,
    IN  HWND  hwndOwner,
    OUT PBOOL Fatal
    )

/*++

Routine Description:

    Top-level routine to format a floppy in the given drive.  A floppy
    disk must already be in the drive or this routine will fail.

    This routine also makes sure that the drive can handle 1.2 or 1.44 meg
    disks (ie fail if low-density drive) and format to one of those two
    densities (ie, no 20.8 scsi flopticals).

Arguments:

    DriveLetter - supplies drive letter of drive to format, A-Z or a-z.

    hwndOwner - supplies handle of window that is to own the progress dlg.

    Fatal - see below.

Return Value:

    TRUE if the format succeeded.
    FALSE if not.  In this case, the Fatal flag will be filled in
        appropriately -- the user should be allowed to retry in this case.

--*/

{
    BOOL                    Flag;
    WCHAR                   WideName[3];
    DWORD                   cMediaTypes;
    PFMIFS_MEDIA_TYPE       MediaTypes;
    FMIFS_MEDIA_TYPE        MediaType;
    FLOPPY_OPERATION_PARAMS FloppyOp;

    *Fatal = TRUE;

    //
    // Determine which format to use (1.2 or 1.44). First determine how big
    // we need the array of supported types to be, then allocate an array of
    // that size and call QuerySupportedMedia.
    //

    WideName[0] = (WCHAR)DriveLetter;   // BUGBUG check this
    WideName[1] = L':';
    WideName[2] = 0;

    Flag = FmifsQuerySupportedMedia( WideName,
                                     NULL,
                                     0,
                                     &cMediaTypes
                                   );

    if(Flag == FALSE) {
        *Fatal = FALSE; //allow retry
        DisplayMsgBox(hwndOwner,
                      IDS_CANTDETERMINEFLOPTYPE,
                      MB_OK | MB_ICONEXCLAMATION,
                      _szApplicationName);
        return(FALSE);
    }

    while((MediaTypes = (PFMIFS_MEDIA_TYPE)LocalAlloc(LMEM_FIXED,cMediaTypes * sizeof(FMIFS_MEDIA_TYPE))) == NULL) {
        //
        // BUGBUG -
        //
        // if(!FHandleOOM(hwndOwner)) {
        //     return(FALSE);
        // }
    }

    Flag = FmifsQuerySupportedMedia( WideName,
                                     MediaTypes,
                                     cMediaTypes,
                                     &cMediaTypes
                                   );

    if(Flag == FALSE) {
        *Fatal = FALSE; //allow retry
        LocalFree(MediaTypes);
        DisplayMsgBox(hwndOwner,
                      IDS_CANTDETERMINEFLOPTYPE | MB_ICONEXCLAMATION,
                      MB_OK,
                      _szApplicationName);
        return(FALSE);
    }


    //
    // Zeroth entry is the highest capacity
    //

    switch(*MediaTypes) {

    case FmMediaF5_1Pt2_512:     // 5.25", 1.2MB,  512 bytes/sector

        MediaType = FmMediaF5_1Pt2_512;
        break;

    case FmMediaF3_1Pt44_512:    // 3.5",  1.44MB, 512 bytes/sector

        MediaType = FmMediaF3_1Pt44_512;
        break;

    case FmMediaF3_2Pt88_512:    // 3.5",  2.88MB, 512 bytes/sector
        {
            WCHAR   VolumeNameBuffer[MAX_PATH + 1];
            DWORD   VolumeSerialNumber;
            DWORD   MaximumComponentLength;
            DWORD   FileSystemFlags;
            WCHAR   FileSystemName[128];
            UINT    ErrorMode;

            //
            //  If the disk drive is a 2.88 Mb drive, then find out if the disk is formatted
            //  as a 2.88 Mb disk. If it is, then reformat the disk as a 2.88 Mb disk, otherwise,
            //  reformat it as a 1.44 Mb disk
            //

            //
            //  Initially, assume that the disk format is 1.44 Mb
            //
            MediaType = FmMediaF3_1Pt44_512;

            //
            //  Find out whether or not the floppy should be formatted as a 2.88 Mb disk
            //
            ErrorMode = SetErrorMode( SEM_FAILCRITICALERRORS );
            if( GetVolumeInformation( (LPWSTR)L"A:\\",
                                      VolumeNameBuffer,
                                      sizeof( VolumeNameBuffer ) / sizeof( WCHAR ),
                                      &VolumeSerialNumber,
                                      &MaximumComponentLength,
                                      &FileSystemFlags,
                                      FileSystemName,
                                      sizeof( FileSystemName ) / sizeof( WCHAR ) ) &&
                ( _wcsicmp( FileSystemName, (LPWSTR)L"RAW" ) != 0 )
              ) {

                //
                //  The disk is formatted. Check if it is formatted as a 2.88 Mb disk
                //
                DWORD           BytesReturned;
                DISK_GEOMETRY   DiskGeometry;
                HANDLE          hDevice;


                if( ( hDevice = CreateFile( L"\\\\.\\A:",
                                            GENERIC_READ,
                                            FILE_SHARE_READ | FILE_SHARE_WRITE,
                                            NULL,
                                            OPEN_EXISTING,
                                            0,
                                            NULL ) ) != INVALID_HANDLE_VALUE ) {
                    if( DeviceIoControl( hDevice,
                                         IOCTL_DISK_GET_DRIVE_GEOMETRY,
                                         NULL,
                                         0,
                                         &DiskGeometry,
                                         sizeof( DISK_GEOMETRY),
                                         &BytesReturned,
                                         NULL ) &&
                        ( DiskGeometry.MediaType == F3_2Pt88_512 )
                      ) {
                            //
                            //  The disk is a 2.88 Mb
                            //
                            MediaType = FmMediaF3_2Pt88_512;
                    }
                    CloseHandle( hDevice );
                }
            }
            SetErrorMode( ErrorMode );
        }
        break;

    case FmMediaF3_120M_512:     // 3.5", 120M Floppy
        //
        // We get this back *only* if there is a 120MB floppy
        // actually in the drive right now.
        //
        // For SUR disallow these.
        //
        DisplayMsgBox(hwndOwner,
                      IDS_HUGEFLOPPYNOTSUPPORTED,
                      MB_OK | MB_ICONEXCLAMATION,
                      _szApplicationName);

        LocalFree(MediaTypes);
        *Fatal = FALSE; //allow retry
        return(FALSE);

    case FmMediaF3_20Pt8_512:    // 3.5",  20.8MB, 512 bytes/sector

#if i386
    {
        DWORD i;

        //
        // Look for a compatibility mode
        //

        for(i=1; i<cMediaTypes; i++) {

            if((MediaTypes[i] == FmMediaF5_1Pt2_512)
            || (MediaTypes[i] == FmMediaF3_1Pt44_512))
            {
                MediaType = MediaTypes[i];
                break;
            }
        }

        if(i < cMediaTypes) {
            break;
        }
    }
        // fall through

#else
        //
        // On an ARC machine, use whatever floppies the user has since
        // we aren't required to boot from it.
        //

        MediaType = *MediaTypes;
        break;
#endif

    case FmMediaF5_160_512:      // 5.25", 160KB,  512 bytes/sector
    case FmMediaF5_180_512:      // 5.25", 180KB,  512 bytes/sector
    case FmMediaF5_320_512:      // 5.25", 320KB,  512 bytes/sector
    case FmMediaF5_320_1024:     // 5.25", 320KB,  1024 bytes/sector
    case FmMediaF5_360_512:      // 5.25", 360KB,  512 bytes/sector
    case FmMediaF3_720_512:      // 3.5",  720KB,  512 bytes/sector
    case FmMediaRemovable:       // Removable media other than floppy
    case FmMediaFixed:
    case FmMediaUnknown:
    default:

        DisplayMsgBox(hwndOwner,
                      IDS_BADFLOPPYTYPE,
                      MB_OK | MB_ICONEXCLAMATION);
        LocalFree(MediaTypes);

        //
        // Unknown can be returned in the case where the drive is an ATAPI floppy
        // and there's no media in the drive. Allow retry.
        //
        if(*MediaTypes == FmMediaUnknown) {
            *Fatal = FALSE;
        }

        return(FALSE);
    }

    LocalFree(MediaTypes);

    //
    // Start the modal dialog that will display the progress indicator.
    //

    FloppyOp.MediaType = MediaType;
    FloppyOp.DriveLetter = (WCHAR)DriveLetter;
    FloppyOp.Operation = FloppyOpFormat;
    FloppyOp.CaptionResId = IDS_FORMATTINGDISK;
    FloppyOp.GeneralFailureResId = IDS_FORMATGENERALFAILURE;

    Flag = DialogBoxParam( GetModuleHandle(NULL),
                           MAKEINTRESOURCE( IDD_PROGRESS2 ), // TEXT("Progress2"),
                           hwndOwner,
                           ProgressDlgProc,
                           (LONG)&FloppyOp
                         );

    *Fatal = FALSE;

    return(Flag);
}

#ifdef FLOPPY_COPY
BOOL
CopyFloppyDisk(
    IN CHAR  DriveLetter,
    IN HWND  hwndOwner,
    IN DWORD SourceDiskPromptId,
    IN DWORD TargetDiskPromptId
    )

/*++

Routine Description:

    Top-level routine to copy a floppy in the given drive (src and dst
    both in this drive).  A floppy disk must already be in the drive or
    this routine will fail.

Arguments:

    DriveLetter - supplies drive letter of drive to copy (A-Z or a-z)

    hwndOwner - supplies handle of window that is to own the progress dlg.

    SourceDiskPromptId - supplies the resource id of the prompt to display
        when prompting for the source diskette

    TargetDiskPromptId - supplies the resource id of the prompt to display
        when prompting for the target diskette

Return Value:

    TRUE if the operation succeeded, FALSE if not.

--*/

{
    BOOL                    Flag;
    FLOPPY_OPERATION_PARAMS FloppyOp;

    FloppyOp.DriveLetter = (WCHAR)DriveLetter;
    FloppyOp.Operation = FloppyOpDiskcopy;
    FloppyOp.CaptionResId = IDS_COPYINGDISK;
    FloppyOp.GeneralFailureResId = IDS_COPYGENERALFAILURE;
    FloppyOp.SrcDiskPromptResId = SourceDiskPromptId;
    FloppyOp.DstDiskPromptResId = TargetDiskPromptId;

    Flag = DialogBoxParam( GetModuleHandle(NULL),
                           TEXT("Progress2"),
                           hwndOwner,
                           ProgressDlgProc,
                           (LONG)&FloppyOp
                         );

    return(Flag);
}
#endif

BOOL
ProgressDlgProc(
    IN HWND   hdlg,
    IN UINT   Msg,
    IN WPARAM wParam,
    IN LONG   lParam
    )
{
    static PFLOPPY_OPERATION_PARAMS FloppyOp;
    static WCHAR WideDriveName[3];
    static BOOL OpSucceeded;
    PVOID PacketAddress;
    FMIFS_PACKET_TYPE PacketType;
    WCHAR  Buffer[256];
    DWORD                   ThreadId;

    switch(Msg) {

    case WM_INITDIALOG:

        FloppyOp = (PFLOPPY_OPERATION_PARAMS)lParam;
        WideDriveName[0] = FloppyOp->DriveLetter;
        WideDriveName[1] = L':';
        WideDriveName[2] = 0;

        ProgressDialog = hdlg;

        //
        // set up range for percentage (0-100) display
        //
        SendDlgItemMessage(hdlg,ID_BAR,PBM_SETRANGE,0,MAKELPARAM(0,GAUGE_BAR_RANGE));

        //
        // Set the caption
        //

        LoadString(_hModule,FloppyOp->CaptionResId,Buffer,sizeof(Buffer)/sizeof(WCHAR));
        SetWindowText(hdlg,Buffer);

        OpSucceeded = TRUE;

        // center the dialog relative to the parent window
        //
        //  BUGBUG - commented out
        //
        FCenterDialogOnDesktop(hdlg);

        CreateThread( NULL,
                      1024,
                      ( LPTHREAD_START_ROUTINE )FmifsThread,
                      FloppyOp,
                      0,
                      &ThreadId );



        break;

    case AP_TASK_COMPLETED:

        SendDlgItemMessage( hdlg,
                            ID_BAR,
                            PBM_SETPOS,
                            GAUGE_BAR_RANGE,
                            0L
                          );
        PostMessage( hdlg,
                     AP_TERMINATE_DIALOG,
                     0,
                     0 );
        break;

    case AP_TERMINATE_DIALOG:

        EndDialog(hdlg, OpSucceeded);
        break;


    case WM_FMIFS_CALLBACK:

        //
        // The callback routine is telling us something.
        // wParam = packet type
        // lParam = packet address
        //

        PacketType    = wParam;
        PacketAddress = (PVOID)lParam;

        switch(PacketType) {

        case FmIfsPercentCompleted:

            //
            // update gas gauge
            //

            SendDlgItemMessage( hdlg,
                                ID_BAR,
                                PBM_SETPOS,
                                (GAUGE_BAR_RANGE * ((PFMIFS_PERCENT_COMPLETE_INFORMATION)PacketAddress)->PercentCompleted) / 100,
                                0L
                              );
            break;

        case FmIfsFinished:

            {
                BOOLEAN b;

                //
                // update gas gauge (100% complete)
                //

                SendDlgItemMessage( hdlg,
                                    ID_BAR,
                                    PBM_SETPOS,
                                    GAUGE_BAR_RANGE,
                                    0L
                                  );

                b = ((PFMIFS_FINISHED_INFORMATION)PacketAddress)->Success;

                //
                // If the operation failed but the user hasn't already been
                // informed, inform him.
                //

                if(OpSucceeded && !b) {
                    OpSucceeded = FALSE;
                    DisplayMsgBox( hdlg,
                                   FloppyOp->GeneralFailureResId,
                                   MB_OK | MB_ICONEXCLAMATION,
                                   _szApplicationName
                                 );

                }
            }
            break;

        case FmIfsFormatReport:         // ignore

            break;

#ifdef FLOPPY_COPY
        case FmIfsInsertDisk:

            if(FloppyOp->Operation == FloppyOpDiskcopy) {
                switch(((PFMIFS_INSERT_DISK_INFORMATION)PacketAddress)->DiskType) {
                case DISK_TYPE_SOURCE:
                    ResId = FloppyOp->SrcDiskPromptResId;
                    break;
                case DISK_TYPE_TARGET:
                    ResId = FloppyOp->DstDiskPromptResId;
                    break;
                default:
                    return(TRUE);
                }
                xMsgBox(hdlg,IDS_INSERTDISKETTE,ResId,MB_OK,FloppyOp->DriveLetter);
            }
            break;

        case FmIfsFormattingDestination:

            // BUGBUG do something
            break;
#endif

        case FmIfsMediaWriteProtected:

            DisplayMsgBox(hdlg,IDS_FLOPPYWRITEPROT,MB_OK | MB_ICONEXCLAMATION);
            OpSucceeded = FALSE;
            break;

        case FmIfsIoError:

            DisplayMsgBox(hdlg,IDS_FLOPPYIOERR,MB_OK | MB_ICONEXCLAMATION);
            OpSucceeded = FALSE;
            break;

        case FmIfsHiddenStatus:     // ignore

            break;

        default:

            DisplayMsgBox(hdlg,IDS_FLOPPYUNKERR,MB_OK | MB_ICONEXCLAMATION);
            OpSucceeded = FALSE;
            break;
        }
        break;

    default:

        return(FALSE);
    }

    return(TRUE);
}


BOOLEAN
FmifsCallbackRoutine(
    IN FMIFS_PACKET_TYPE PacketType,
    IN DWORD             PacketLength,
    IN PVOID             PacketAddress
    )
{
    UNREFERENCED_PARAMETER(PacketLength);
    //
    // Package up the callback and send it on to the progress dialog.
    // wParam = packet type
    // lParam = packet address
    //

    SendMessage( ProgressDialog,
                 WM_FMIFS_CALLBACK,
                 PacketType,
                 (LONG)PacketAddress
               );

    return(TRUE);       // keep going
}

VOID
FmifsThread(
    IN PVOID Arguments
    )

{
    PFLOPPY_OPERATION_PARAMS FloppyOp;
    WCHAR                    WideDriveName[3];


    FloppyOp = ( PFLOPPY_OPERATION_PARAMS )Arguments;
    WideDriveName[0] = FloppyOp->DriveLetter;
    WideDriveName[1] = L':';
    WideDriveName[2] = 0;

    FmifsFormat( WideDriveName,
               FloppyOp->MediaType,
                 L"fat",
                 L"",
                 FALSE,                 // not quick format
                 FmifsCallbackRoutine
               );

    SendMessage( ProgressDialog,
                 AP_TASK_COMPLETED,
                 0,
                 0L
               );

    ExitThread(0);
}