SqlPipe.cpp
// Transfer data from virtualDevice to backupfile or vice-versa
Transfer data from virtualDevice to backupfile or vice-versa
Transfer data from virtualDevice to backupfile or vice - versa
HRESULT performTransfer(IClientVirtualDevice* virtualDevice, FILE* backupfile)
{
	VDC_Command *   cmd;
	DWORD           completionCode;
	DWORD           bytesTransferred;
	HRESULT         hr;
	DWORD           totalBytes = 0;
	while (SUCCEEDED (hr = virtualDevice->GetCommand(3 * 60 * 1000, &cmd)))
	{
		bytesTransferred = 0;
		switch (cmd->commandCode)
		{
		case VDC_Read:
			while(bytesTransferred < cmd->size)
				bytesTransferred += fread(cmd->buffer + bytesTransferred, 1, cmd->size - bytesTransferred, backupfile);
			totalBytes += bytesTransferred;
			log(L"%d bytes read                               \r", totalBytes);
			cmd->size = bytesTransferred;
			completionCode = ERROR_SUCCESS;
			break;
		case VDC_Write:
			while(bytesTransferred < cmd->size)
				bytesTransferred += fwrite(cmd->buffer + bytesTransferred, 1, cmd->size - bytesTransferred, backupfile);
			totalBytes += bytesTransferred;
			log(L"%d bytes written\r", totalBytes);
			completionCode = ERROR_SUCCESS;
			break;
		case VDC_Flush:
			completionCode = ERROR_SUCCESS;
			break;
		case VDC_ClearError:
			log(L"\nVDC_ClearError\n");
			completionCode = ERROR_SUCCESS;
			break;
		default:
			completionCode = ERROR_NOT_SUPPORTED;
		}
		hr = virtualDevice->CompleteCommand(cmd, completionCode, bytesTransferred, 0);
		if (FAILED(hr))
		{
			err(L"\nvirtualDevice->CompleteCommand failed: %s\n", (TCHAR*)errorMessage(hr));
			return hr;
		}
	}
	log(L"\n");
	if (hr != VD_E_CLOSE)
	{
		err(L"virtualDevice->GetCommand failed: ");
		if (hr == VD_E_TIMEOUT)
			err(L" timeout awaiting data.\n");
		else if (hr == VD_E_ABORT)
			err(L" transfer was aborted.\n");
		else
			err(L"%s\n", (TCHAR*)errorMessage(hr));
		return hr;
	}
	return NOERROR;
}
HRESULT performTransfer ( IClientVirtualDevice * virtualDevice , FILE * backupfile ) { VDC_Command * cmd ; DWORD completionCode ; DWORD bytesTransferred ; HRESULT hr ; DWORD totalBytes = 0 ; while ( SUCCEEDED ( hr = virtualDevice -> GetCommand ( 3 * 60 * 1000 , & cmd ) ) ) { bytesTransferred = 0 ; switch ( cmd -> commandCode ) { case VDC_Read : while ( bytesTransferred < cmd -> size ) bytesTransferred += fread ( cmd -> buffer + bytesTransferred , 1 , cmd -> size - bytesTransferred , backupfile ) ; totalBytes += bytesTransferred ; log ( L" \r " , totalBytes ) ; cmd -> size = bytesTransferred ; completionCode = ERROR_SUCCESS ; break ; case VDC_Write : while ( bytesTransferred < cmd -> size ) bytesTransferred += fwrite ( cmd -> buffer + bytesTransferred , 1 , cmd -> size - bytesTransferred , backupfile ) ; totalBytes += bytesTransferred ; log ( L" \r " , totalBytes ) ; completionCode = ERROR_SUCCESS ; break ; case VDC_Flush : completionCode = ERROR_SUCCESS ; break ; case VDC_ClearError : log ( L" \n \n " ) ; completionCode = ERROR_SUCCESS ; break ; default : completionCode = ERROR_NOT_SUPPORTED ; } hr = virtualDevice -> CompleteCommand ( cmd , completionCode , bytesTransferred , 0 ) ; if ( FAILED ( hr ) ) { err ( L" \n \n " , ( TCHAR * ) errorMessage ( hr ) ) ; return hr ; } } log ( L" \n " ) ; if ( hr != VD_E_CLOSE ) { err ( L" " ) ; if ( hr == VD_E_TIMEOUT ) err ( L" \n " ) ; else if ( hr == VD_E_ABORT ) err ( L" \n " ) ; else err ( L" \n " , ( TCHAR * ) errorMessage ( hr ) ) ; return hr ; } return NOERROR ; }
Transfer data from virtualDevice to backupfile or vice-versa
Transfer data from virtualDevice to backupfile or vice - versa
//log(L">command %d, size %d\n", cmd->commandCode, cmd->size); //log(L"VDC_Write - size: %d\r\n", cmd->size); //log(L"\nVDC_Flush %d\n", cmd->size); //Debug::WriteLine("VDC_ClearError"); // If command is unknown...