|
609 | 609 | return pb-dataBuffer;
|
610 | 610 | }
|
611 | 611 |
|
| 612 | + TStdWinError CKryoFluxDevice::UploadTrack(TCylinder cyl,THead head,CTrackReader tr) const{ |
| 613 | + // uploads specified Track to a CAPS-based device (e.g. KryoFlux); returns Windows standard i/o error |
| 614 | + EXCLUSIVELY_LOCK_DEVICE(); |
| 615 | + // - converting the supplied Track to "KFW" data, below streamed directly to KryoFlux |
| 616 | + const DWORD nBytesToWrite=TrackToKfw1( tr ); |
| 617 | + #ifdef _DEBUG |
| 618 | + if (false){ |
| 619 | + CFile f; |
| 620 | + ::CreateDirectory( _T("r:\\kfw"), nullptr ); |
| 621 | + TCHAR kfwName[80]; |
| 622 | + ::wsprintf( kfwName, _T("r:\\kfw\\track%02d-%c.bin"), cyl, '0'+head ); |
| 623 | + f.Open( kfwName, CFile::modeCreate|CFile::modeWrite|CFile::typeBinary|CFile::shareExclusive ); |
| 624 | + f.Write( dataBuffer, nBytesToWrite ); |
| 625 | + f.Close(); |
| 626 | + } |
| 627 | + #endif |
| 628 | + // - clearing i/o pipes |
| 629 | + winusb.ClearIoPipes( KF_EP_BULK_IN, KF_EP_BULK_OUT ); |
| 630 | + // - streaming the "KFW" data to KryoFlux |
| 631 | + SendRequest( TRequest::INDEX_WRITE, 2 ); // waiting for an index? |
| 632 | + if (!SetMotorOn() || !SelectHead(head) || !SeekTo(cyl)) // some Drives require motor to be on before seeking Heads |
| 633 | + return ERROR_NOT_READY; |
| 634 | + SendRequest( TRequest::STREAM, 2 ); // start streaming |
| 635 | + TStdWinError err=WriteFull( dataBuffer, nBytesToWrite ); |
| 636 | + if (err==ERROR_SUCCESS) |
| 637 | + do{ |
| 638 | + if (err=SendRequest( TRequest::RESULT_WRITE )) |
| 639 | + break; |
| 640 | + }while (::strrchr(device.lastRequestResultMsg,'=')[1]=='9'); // TODO: explain why sometimes instead of '0' a return code is '3' but the Track has been written; is it a timeout? if yes, how to solve it? |
| 641 | + SendRequest( TRequest::STREAM, 0 ); // stop streaming |
| 642 | + return err; |
| 643 | + } |
| 644 | + |
612 | 645 | #define ERROR_SAVE_MESSAGE_TEMPLATE _T("Track %02d.%c %s failed")
|
613 | 646 |
|
614 |
| - TStdWinError CKryoFluxDevice::SaveAndVerifyTrack(TCylinder cyl,THead head,const volatile bool &cancelled) const{ |
| 647 | + TStdWinError CCapsBase::SaveTrack(TCylinder cyl,THead head,const volatile bool &cancelled) const{ |
615 | 648 | // saves the specified Track to the inserted Medium; returns Windows standard i/o error
|
616 | 649 | EXCLUSIVELY_LOCK_THIS_IMAGE();
|
617 | 650 | // - Track must already exist from before
|
|
678 | 711 | }
|
679 | 712 | // - pre-compensation of the temporary Track
|
680 | 713 | const CTrackReaderWriter trwCompensated( trw, false );
|
681 |
| - TStdWinError err; |
682 | 714 | if (precompensation.methodVersion!=CPrecompensation::None)
|
683 |
| - if ( err=precompensation.ApplyTo(*this,cyl,head,trwCompensated) ) |
| 715 | + if (const TStdWinError err=precompensation.ApplyTo( *this, cyl, head, trwCompensated )) |
684 | 716 | return err;
|
685 | 717 | // - Drive's head calibration
|
686 |
| - EXCLUSIVELY_LOCK_DEVICE(); |
687 | 718 | if (params.calibrationStepDuringFormatting)
|
688 |
| - if (std::abs(cyl-lastCalibratedCylinder)>>(BYTE)params.doubleTrackStep>=params.calibrationStepDuringFormatting){ |
689 |
| - lastCalibratedCylinder=cyl; |
690 |
| - SeekHeadsHome(); |
691 |
| - } |
| 719 | + if (std::abs(cyl-lastCalibratedCylinder)>>(BYTE)params.doubleTrackStep>=params.calibrationStepDuringFormatting) |
| 720 | + if (const TStdWinError err=SeekHeadsHome()) |
| 721 | + return err; |
| 722 | + else |
| 723 | + lastCalibratedCylinder=cyl; |
692 | 724 | // - writing (and optional verification)
|
| 725 | + TStdWinError err; |
| 726 | + TCHAR msgSavingFailed[80]; |
| 727 | + ::wsprintf( msgSavingFailed, ERROR_SAVE_MESSAGE_TEMPLATE, cyl, '0'+head, _T("saving") ); |
693 | 728 | char nSilentRetrials=4;
|
694 | 729 | do{
|
695 | 730 | if (cancelled)
|
696 | 731 | return ERROR_CANCELLED;
|
697 | 732 | // . consuming one SilentRetrial
|
698 | 733 | nSilentRetrials--;
|
699 |
| - // . converting the temporary Track to "KFW" data, below streamed directly to KryoFlux |
700 |
| - const DWORD nBytesToWrite=TrackToKfw1( trwCompensated ); |
701 |
| - #ifdef _DEBUG |
702 |
| - if (false){ |
703 |
| - CFile f; |
704 |
| - ::CreateDirectory( _T("r:\\kfw"), nullptr ); |
705 |
| - TCHAR kfwName[80]; |
706 |
| - ::wsprintf( kfwName, _T("r:\\kfw\\track%02d-%c.bin"), cyl, '0'+head ); |
707 |
| - f.Open( kfwName, CFile::modeCreate|CFile::modeWrite|CFile::typeBinary|CFile::shareExclusive ); |
708 |
| - f.Write( dataBuffer, nBytesToWrite ); |
709 |
| - f.Close(); |
710 |
| - } |
711 |
| - #endif |
712 |
| - // . clearing i/o pipes |
713 |
| - winusb.ClearIoPipes( KF_EP_BULK_IN, KF_EP_BULK_OUT ); |
714 |
| - // . streaming the "KFW" data to KryoFlux |
715 |
| - SendRequest( TRequest::INDEX_WRITE, 2 ); // waiting for an index? |
716 |
| - if (!SetMotorOn() || !SelectHead(head) || !SeekTo(cyl)) // some Drives require motor to be on before seeking Heads |
717 |
| - return ERROR_NOT_READY; |
718 |
| - SendRequest( TRequest::STREAM, 2 ); // start streaming |
719 |
| - err=WriteFull( dataBuffer, nBytesToWrite ); |
720 |
| - if (err==ERROR_SUCCESS) |
721 |
| - do{ |
722 |
| - if (err=SendRequest( TRequest::RESULT_WRITE )) |
723 |
| - break; |
724 |
| - }while (::strrchr(device.lastRequestResultMsg,'=')[1]=='9'); // TODO: explain why sometimes instead of '0' a return code is '3' but the Track has been written; is it a timeout? if yes, how to solve it? |
725 |
| - SendRequest( TRequest::STREAM, 0 ); // stop streaming |
726 |
| - TCHAR msgSavingFailed[80]; |
727 |
| - ::wsprintf( msgSavingFailed, ERROR_SAVE_MESSAGE_TEMPLATE, cyl, '0'+head, _T("saving") ); |
728 |
| - if (err) // writing to the device failed |
| 734 | + if (err=UploadTrack( cyl, head, trwCompensated )) // writing to the device failed |
729 | 735 | switch (
|
730 | 736 | nSilentRetrials>0 || cancelled
|
731 | 737 | ? IDRETRY
|
|
761 | 767 | }while (err!=ERROR_SUCCESS && err!=ERROR_CONTINUE);
|
762 | 768 | // - (successfully) saved - see TODOs
|
763 | 769 | pit->modified=false;
|
| 770 | + if (err==ERROR_CONTINUE) // if writing errors commanded to ignore ... |
| 771 | + err=ERROR_SUCCESS; // ... then the Track has been saved successfully |
764 | 772 | return err;
|
765 | 773 | }
|
766 | 774 |
|
767 |
| - TStdWinError CKryoFluxDevice::SaveTrack(TCylinder cyl,THead head,const volatile bool &cancelled) const{ |
768 |
| - // saves the specified Track to the inserted Medium; returns Windows standard i/o error |
769 |
| - switch (const TStdWinError err=SaveAndVerifyTrack(cyl,head,cancelled)){ |
770 |
| - case ERROR_SUCCESS: |
771 |
| - case ERROR_CONTINUE: // writing errors ignored |
772 |
| - return ERROR_SUCCESS; |
773 |
| - default: |
774 |
| - return err; |
775 |
| - } |
776 |
| - } |
777 |
| - |
778 | 775 | CImage::CTrackReader CKryoFluxDevice::ReadTrack(TCylinder cyl,THead head) const{
|
779 | 776 | // creates and returns a general description of the specified Track, represented using neutral LogicalTimes
|
780 | 777 | PInternalTrack &rit=internalTracks[cyl][head];
|
|
0 commit comments