2424#include "Progress.h"
2525#include "Random.h"
2626#include "Volumes.h"
27+ #include "Dlgcode.h"
2728
2829void
2930GetFatParams (fatparams * ft )
@@ -255,7 +256,7 @@ static void PutFSInfo (unsigned char *sector, fatparams *ft)
255256
256257
257258int
258- FormatFat (void * hwndDlgPtr , unsigned __int64 startSector , fatparams * ft , void * dev , PCRYPTO_INFO cryptoInfo , BOOL quickFormat , BOOL bDevice )
259+ FormatFat (void * hwndDlgPtr , unsigned __int64 startSector , fatparams * ft , void * dev , PCRYPTO_INFO cryptoInfo , volatile void * volParamsArg )
259260{
260261 int write_buf_cnt = 0 ;
261262 char sector [TC_MAX_VOLUME_SECTOR_SIZE ], * write_buf ;
@@ -267,6 +268,9 @@ FormatFat (void* hwndDlgPtr, unsigned __int64 startSector, fatparams * ft, void
267268 int retVal ;
268269 CRYPTOPP_ALIGN_DATA (16 ) char temporaryKey [MASTER_KEYDATA_SIZE ];
269270 HWND hwndDlg = (HWND ) hwndDlgPtr ;
271+ volatile FORMAT_VOL_PARAMETERS * volParams = (volatile FORMAT_VOL_PARAMETERS * )volParamsArg ;
272+ BOOL quickFormat = volParams -> quickFormat ;
273+ BOOL bDevice = volParams -> bDevice ;
270274
271275 LARGE_INTEGER startOffset ;
272276 LARGE_INTEGER newOffset ;
@@ -292,7 +296,7 @@ FormatFat (void* hwndDlgPtr, unsigned __int64 startSector, fatparams * ft, void
292296
293297 PutBoot (ft , (unsigned char * ) sector );
294298 if (WriteSector (dev , sector , write_buf , & write_buf_cnt , & nSecNo , startSector ,
295- cryptoInfo ) == FALSE)
299+ cryptoInfo , volParams ) == FALSE)
296300 goto fail ;
297301
298302 /* fat32 boot area */
@@ -301,7 +305,7 @@ FormatFat (void* hwndDlgPtr, unsigned __int64 startSector, fatparams * ft, void
301305 /* fsinfo */
302306 PutFSInfo ((unsigned char * ) sector , ft );
303307 if (WriteSector (dev , sector , write_buf , & write_buf_cnt , & nSecNo , startSector ,
304- cryptoInfo ) == FALSE)
308+ cryptoInfo , volParams ) == FALSE)
305309 goto fail ;
306310
307311 /* reserved */
@@ -311,20 +315,20 @@ FormatFat (void* hwndDlgPtr, unsigned __int64 startSector, fatparams * ft, void
311315 sector [508 + 3 ]= 0xaa ; /* TrailSig */
312316 sector [508 + 2 ]= 0x55 ;
313317 if (WriteSector (dev , sector , write_buf , & write_buf_cnt , & nSecNo , startSector ,
314- cryptoInfo ) == FALSE)
318+ cryptoInfo , volParams ) == FALSE)
315319 goto fail ;
316320 }
317321
318322 /* bootsector backup */
319323 memset (sector , 0 , ft -> sector_size );
320324 PutBoot (ft , (unsigned char * ) sector );
321325 if (WriteSector (dev , sector , write_buf , & write_buf_cnt , & nSecNo , startSector ,
322- cryptoInfo ) == FALSE)
326+ cryptoInfo , volParams ) == FALSE)
323327 goto fail ;
324328
325329 PutFSInfo ((unsigned char * ) sector , ft );
326330 if (WriteSector (dev , sector , write_buf , & write_buf_cnt , & nSecNo , startSector ,
327- cryptoInfo ) == FALSE)
331+ cryptoInfo , volParams ) == FALSE)
328332 goto fail ;
329333 }
330334
@@ -333,7 +337,7 @@ FormatFat (void* hwndDlgPtr, unsigned __int64 startSector, fatparams * ft, void
333337 {
334338 memset (sector , 0 , ft -> sector_size );
335339 if (WriteSector (dev , sector , write_buf , & write_buf_cnt , & nSecNo , startSector ,
336- cryptoInfo ) == FALSE)
340+ cryptoInfo , volParams ) == FALSE)
337341 goto fail ;
338342 }
339343
@@ -377,7 +381,7 @@ FormatFat (void* hwndDlgPtr, unsigned __int64 startSector, fatparams * ft, void
377381 }
378382
379383 if (WriteSector (dev , sector , write_buf , & write_buf_cnt , & nSecNo , startSector ,
380- cryptoInfo ) == FALSE)
384+ cryptoInfo , volParams ) == FALSE)
381385 goto fail ;
382386 }
383387 }
@@ -388,7 +392,7 @@ FormatFat (void* hwndDlgPtr, unsigned __int64 startSector, fatparams * ft, void
388392 {
389393 memset (sector , 0 , ft -> sector_size );
390394 if (WriteSector (dev , sector , write_buf , & write_buf_cnt , & nSecNo , startSector ,
391- cryptoInfo ) == FALSE)
395+ cryptoInfo , volParams ) == FALSE)
392396 goto fail ;
393397
394398 }
@@ -452,10 +456,19 @@ FormatFat (void* hwndDlgPtr, unsigned __int64 startSector, fatparams * ft, void
452456 while (x -- )
453457 {
454458 if (WriteSector (dev , sector , write_buf , & write_buf_cnt , & nSecNo , startSector ,
455- cryptoInfo ) == FALSE)
459+ cryptoInfo , volParams ) == FALSE)
456460 goto fail ;
457461 }
458- UpdateProgressBar ((nSecNo - startSector ) * ft -> sector_size );
462+
463+ if (volParams -> progress_callback )
464+ {
465+ // Call the progress callback function if it is set
466+ volParams -> progress_callback ((nSecNo - startSector ) * ft -> sector_size , volParams -> progress_callback_user_data );
467+ }
468+ else
469+ {
470+ UpdateProgressBar ((nSecNo - startSector ) * ft -> sector_size );
471+ }
459472
460473 if (!FlushFormatWriteBuffer (dev , write_buf , & write_buf_cnt , & nSecNo , cryptoInfo ))
461474 {
@@ -498,16 +511,44 @@ FormatFat (void* hwndDlgPtr, unsigned __int64 startSector, fatparams * ft, void
498511 nSecNo ++ ;
499512 num_sectors -= nSkipSectors ;
500513
501- if (UpdateProgressBar ((nSecNo - startSector )* ft -> sector_size ))
502- goto fail ;
514+ if (volParams -> progress_callback )
515+ {
516+ // Call the progress callback function if it is set
517+ if (!volParams -> progress_callback ((nSecNo - startSector ) * ft -> sector_size , volParams -> progress_callback_user_data ))
518+ {
519+ goto fail ;
520+ }
521+ }
522+ else
523+ {
524+ if (UpdateProgressBar ((nSecNo - startSector )* ft -> sector_size ))
525+ goto fail ;
526+ }
527+
503528 }
504529
505530 nSecNo += num_sectors ;
506- UpdateProgressBar ((nSecNo - startSector )* ft -> sector_size );
531+ if (volParams -> progress_callback )
532+ {
533+ // Call the progress callback function if it is set
534+ volParams -> progress_callback ((nSecNo - startSector ) * ft -> sector_size , volParams -> progress_callback_user_data );
535+ }
536+ else
537+ {
538+ UpdateProgressBar ((nSecNo - startSector )* ft -> sector_size );
539+ }
507540 }
508541 else
509542 {
510- UpdateProgressBar ((uint64 ) ft -> num_sectors * ft -> sector_size );
543+ if (volParams -> progress_callback )
544+ {
545+ // Call the progress callback function if it is set
546+ volParams -> progress_callback ((uint64 ) ft -> num_sectors * ft -> sector_size , volParams -> progress_callback_user_data );
547+ }
548+ else
549+ {
550+ UpdateProgressBar ((uint64 ) ft -> num_sectors * ft -> sector_size );
551+ }
511552
512553 if (!FlushFormatWriteBuffer (dev , write_buf , & write_buf_cnt , & nSecNo , cryptoInfo ))
513554 goto fail ;
0 commit comments