home *** CD-ROM | disk | FTP | other *** search
/ The Best of Mecomp Multimedia 2 / MECOMP-CD-II.iso / amiga / tools / system / format64 / source / dofullformat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-20  |  5.4 KB  |  198 lines

  1. #include <exec/types.h>
  2. #include <exec/exec.h>
  3. #include <intuition/intuition.h>
  4. #include <dos/dos.h>
  5. #include <dos/filehandler.h>
  6. #include <workbench/startup.h>
  7. #include <libraries/gadtools.h>
  8. #include <workbench/icon.h>
  9. #include <devices/trackdisk.h>
  10. #include <dos/rdargs.h>
  11.  
  12. #include <proto/exec.h>
  13. #include <proto/intuition.h>
  14. #include <proto/dos.h>
  15. #include <proto/gadtools.h>
  16. #include <proto/icon.h>
  17. #include <proto/graphics.h>
  18.  
  19. #include "Format.h"
  20. #include "string.h"
  21. #include "stdio.h"
  22.  
  23. /* External symbols */
  24.  
  25. extern BOOL FFS = FALSE;
  26. extern BOOL QuickFmt = FALSE;
  27. extern BOOL Verify = TRUE;
  28. extern BOOL Icon = TRUE;
  29. extern struct Library *ibase = NULL;
  30. extern struct Library *gbase = NULL;
  31. extern struct Library *GadToolsBase = NULL;
  32. extern struct Library *IconBase = NULL;
  33. extern BPTR StdErr = NULL;
  34. extern LONG args[6] = { NULL,NULL,0,0,0,0 };
  35. extern struct WBStartup *WBenchMsg;
  36.  
  37. /* Internal prototypes for this specific C file.*/
  38.  
  39. BOOL checkfor64bitcommandset(struct IOStdReq *io);
  40. void nsd_add(ULONG *bf, ULONG value1, ULONG value2);
  41.  
  42. /*This function does a full (low-level) format of a disk*/
  43. BOOL doFullFormat(DriveLayout *layout,char *statString,char *devName,
  44.              struct IOExtTD *io1)
  45.     {
  46.    ULONG nsdbuffer[2], nsdbuffer2[2];
  47.    ULONG trackSize, numTracks, i, track;
  48.     UWORD formatcommand = TD_FORMAT, verifycommand = CMD_READ;
  49.    int c;
  50.    UBYTE error=2, *write = NULL;
  51.    BOOL errorB = FALSE, command64 = FALSE;
  52.  
  53.    /*Get the size of a track (#surfaces*#blocks*#longwordsPerTrack*4*/
  54.    trackSize=layout->surfaces*layout->blockSize*4*layout->BPT;
  55.  
  56.     command64 = checkfor64bitcommandset((struct IOStdReq *)io1);
  57.     if (command64 == TRUE)
  58.         {
  59.         formatcommand = NSCMD_TD_FORMAT64;
  60.         verifycommand = NSCMD_TD_READ64;
  61.         }
  62.  
  63.     nsdbuffer[0] = 0; nsdbuffer[1] = 0;
  64.  
  65.    /*Allocate enough memory for one track*/
  66.    write = (UBYTE*)AllocMem(trackSize, layout->memType|MEMF_CLEAR);
  67.    if (write != NULL)
  68.         {
  69.       /*Initialize the IORequest*/
  70. //      io1->iotd_Req.io_Data=write;
  71.  //     io1->iotd_Req.io_Length=trackSize;
  72.  
  73.  
  74.       /*Get the starting byte position in the volume*/
  75.         for (i=0; i<layout->lowCyl; i++)
  76.             nsd_add((ULONG*)&nsdbuffer, nsdbuffer[1], trackSize);
  77.  
  78.         nsdbuffer2[0] = nsdbuffer[0];
  79.         nsdbuffer2[1] = nsdbuffer[1];
  80.  
  81.         for (i=layout->lowCyl; i<layout->highCyl; i++)
  82.             nsd_add((ULONG*)&nsdbuffer2, nsdbuffer2[1], trackSize);
  83.  
  84. //    printf("start: %u %u end: %u %u\n",
  85. //        nsdbuffer[0], nsdbuffer[1],
  86. //        nsdbuffer2[0], nsdbuffer2[1]);
  87.  
  88.         if (nsdbuffer2[0] != 0)
  89.             if (command64 == FALSE)
  90.                 {
  91.                 printError("You are trying to format beyond 4GB border although\nyour device does not support 64 bit commands. Due to this\nfact, format operation is aborted in order to save your drive.", NULL, NULL);
  92.                 FreeMem(write, trackSize);
  93.                 return(FALSE);
  94.                 }
  95.             else
  96.                 {
  97.                 formatcommand = NSCMD_TD_FORMAT64;
  98.                 verifycommand = NSCMD_TD_READ64;
  99.                 }
  100.  
  101.       numTracks=layout->highCyl-layout->lowCyl+1;
  102.  
  103.       /*Clear the status window*/
  104.       error=(updateStatWindow(" ",0)) ? 0 : error;
  105.  
  106.       /*For each track*/
  107.       for(track=0;track<numTracks && error!=0;track++)
  108.             {
  109.             /*Setup to format the disk*/
  110.             io1->iotd_Req.io_Data    = write;
  111.             io1->iotd_Req.io_Length  = trackSize;
  112.             io1->iotd_Req.io_Command = formatcommand;
  113.             io1->iotd_Req.io_Actual  = (ULONG)nsdbuffer[0];
  114.             io1->iotd_Req.io_Offset  = (ULONG)nsdbuffer[1];
  115. /*
  116.             printf("%u %u %u %u command $%lx\n",
  117.                 nsdbuffer[0],
  118.                 io1->iotd_Req.io_Actual,
  119.                 nsdbuffer[1],
  120.                 io1->iotd_Req.io_Offset,
  121.                 io1->iotd_Req.io_Command);
  122. */
  123.             /*Update the status window*/
  124.             sprintf(statString, "Formatting cylinder %ld, %ld to go  ",
  125.                 track+layout->lowCyl, numTracks-track-1);
  126.  
  127.             error = (updateStatWindow(statString,track*1000/numTracks)) ?0:error;
  128.  
  129.             /*If the user didnt press Stop*/
  130.             if(error != 0)
  131.                 {
  132.                 error = (DoIO((struct IORequest *)io1)) ? 0 : error;
  133.                 if(error == 0)
  134.                     {
  135.                     printError("\nA formatting error occured",NULL,NULL);
  136.                     errorB = TRUE;
  137.                     }
  138.                 }
  139.  
  140.             /*If we're suppossed to verify, and the user didn't press 'Stop'*/
  141.             if(Verify == TRUE && error != 0)
  142.                 {
  143.                 /*Setup the same IORequest to do a read*/
  144.                 io1->iotd_Req.io_Data    = write;
  145.                 io1->iotd_Req.io_Length  = trackSize;
  146.                 io1->iotd_Req.io_Command = verifycommand;
  147.                 io1->iotd_Req.io_Actual  = (ULONG)nsdbuffer[0];
  148.                 io1->iotd_Req.io_Offset  = (ULONG)nsdbuffer[1];
  149.  
  150.                 /*Update the status*/
  151.                 sprintf(statString, "Verifying  cylinder %ld, %ld to go  ",
  152.                     track+layout->lowCyl, numTracks-track-1);
  153.  
  154.                 error = (updateStatWindow(statString,
  155.                     ( (1+(track*2))*1000)/(2*numTracks) )) ? 0 : error;
  156.  
  157.  
  158.                 /*If the user hasnt pressed Stop*/
  159.                 if(error != 0)
  160.                     {
  161.                     error = (DoIO((struct IORequest *)io1)) ? 0 : error;
  162.                     if (error == 0)
  163.                         {
  164.                         printError("\nA verify error occurred",NULL,NULL);
  165.                         errorB=TRUE;
  166.                         }
  167.                     }
  168.  
  169.                 /*Check the data that was read back.*/
  170.                 if (error != 0)
  171.                     if (errorB == FALSE)
  172.                         for(c=0; c<trackSize; c++)
  173.                             {
  174.                             if (write[c] != 0)
  175.                                 {
  176.                                 errorB = TRUE;
  177.                                 printError("\nA verify error occurred",NULL,NULL);
  178.                                 break;
  179.                                 }
  180.                             write[c]=0;
  181.                             }
  182.                 } /* End of Verify */
  183.  
  184.             if (error == 0 || errorB == TRUE) break;
  185.             else { error = 2; errorB = FALSE;
  186.                    nsd_add((ULONG*)&nsdbuffer, nsdbuffer[1], trackSize); }
  187.  
  188.             } /* End format loop */
  189.  
  190.         /*Were done, so free the track memory*/
  191.         FreeMem(write,trackSize);
  192.         if (error == 0 || errorB == TRUE) return(FALSE);
  193.         }
  194.    else printError("Couldn't allocate write buffer",NULL,NULL);
  195.  
  196.    return(TRUE);
  197.     }
  198.