⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aspisnoopdlg.cpp

📁 一个SCSI的Tape设备读写等操作的软件.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	UpdateData (TRUE);
	DWORD code;
	if ((code=m_pASPI->GetPosition  (m_cTapeHost,m_cTapeID,m_cTapeLun,&dwPosition)) != ASPIERR_OK)
		Error (code);
	enableButtons (TRUE);
	CString str;
	str.Format ("Position:%d",dwPosition);
	m_ListBox.AddString (str);
	m_ListBox.AddString ("Get Position finished.");
	m_ListBox.SetTopIndex (m_ListBox.GetCount()-1);
	UpdateData (FALSE);
	TRACE ("ASPIsnoop: Get Position done !\n");
}

void CASPIsnoopDlg::OnSpace() 
{
	m_ListBox.AddString ("Space....");
	enableButtons (FALSE);
	UpdateData (TRUE);
	DWORD code;
	if ((code=m_pASPI->Space  (m_cTapeHost,m_cTapeID,m_cTapeLun,m_bFileSeek ? 0x01 : 0x00,m_nOffset)) != ASPIERR_OK)
		Error (code);
	enableButtons (TRUE);
	SpaceDone();
}
void CASPIsnoopDlg::SpaceDone (void)
{
	CString str;
	m_ListBox.AddString ("Space finished.");
	m_ListBox.SetTopIndex (m_ListBox.GetCount()-1);
	UpdateData (FALSE);
	TRACE ("ASPIsnoop: Space done !\n");
}

void CASPIsnoopDlg::OnCompression() 
{
	DWORD code;
	MPG_compression out,current;

	ZeroMemory (&out,sizeof(MPG_devconf));
	ZeroMemory (&current,sizeof(MPG_devconf));
	UpdateData (TRUE);
	enableButtons (FALSE);
	m_ListBox.AddString ("Mode Select....");
	UpdateData (TRUE);
	//get current device configuration mode-page
	if ((code=m_pASPI->ModeSense  (m_cTapeHost,m_cTapeID,m_cTapeLun,0x0F,0x00,&current,sizeof(MPG_devconf))) != ASPIERR_OK)
		Error (code);
	else
	{
		memcpy (&out.com,&current.com,sizeof(_MPG_compression));
		memcpy (&out.bd,&current.bd,sizeof(BlockDescriptor));
		out.head.buff=current.head.buff;
		out.head.bdsize=current.head.bdsize;
		out.com.dce=m_bCompression;
		if ((code=m_pASPI->ModeSelect (	m_cTapeHost,
										m_cTapeID,
										m_cTapeLun,
										&out,
										sizeof(MPG_devconf))) != ASPIERR_OK)
			Error (code);
	}
	enableButtons (TRUE);
	m_ListBox.AddString ("Mode Select finished.");
	m_ListBox.SetTopIndex (m_ListBox.GetCount()-1);
	UpdateData (FALSE);
}

void CASPIsnoopDlg::OnGetParameters() 
{
	enableButtons (FALSE);
	m_ListBox.AddString ("Mode Sense....");
	m_nIOSize=0xFF;
	if (m_hIOBuffer != NULL)
		GlobalFree (m_hIOBuffer);
	m_hIOBuffer=GlobalAlloc (GHND,m_nIOSize);
	m_pIOBuffer=(char *)GlobalLock (m_hIOBuffer);
	UpdateData (TRUE);
	BYTE page,mode;
	switch (m_cbPage.GetCurSel())
	{
		case 0:	page=0x10;	break;
		case 1:	page=0x11;	break;
		case 2:	page=0x0F;	break;
	}
	mode=m_cbMode.GetCurSel();
	m_pASPI->ModeSense  (	m_cTapeHost,
							m_cTapeID,
							m_cTapeLun,
							page,
							mode,
							m_pIOBuffer,
							m_nIOSize-1);
	enableButtons (TRUE);

	switch (page)
	{
		case 0x10:	DisplayDeviceMP (m_pIOBuffer);		break;
		case 0x11:	DisplayPartitionMP (m_pIOBuffer);	break;
		case 0x0F:	DisplayCompressionMP (m_pIOBuffer);	break;
	}
	m_ListBox.AddString ("Mode Sense finished.");
	m_ListBox.SetTopIndex (m_ListBox.GetCount()-1);
	UpdateData (FALSE);
	TRACE ("ASPIsnoop: Parameters done !\n");
}


void CASPIsnoopDlg::SenseDone (void)
{
	CString str;
	m_ListBox.AddString ("Sense finished.");
	m_ListBox.SetTopIndex (m_ListBox.GetCount()-1);
	UpdateData (FALSE);
	TRACE ("ASPIsnoop: Sense done !\n");
}

void CASPIsnoopDlg::enableButtons (BOOL stat)
{
	m_btnEject.EnableWindow (stat);
	m_btnGetParas.EnableWindow (stat);
	m_btnGetPos.EnableWindow (stat);
	m_btnRead.EnableWindow (stat);
	m_btnWrite.EnableWindow (stat);
	m_btnWriteMark.EnableWindow (stat);
	m_btnRezero.EnableWindow (stat);
	m_btnSeekEOD.EnableWindow (stat);
	m_btnSnoop.EnableWindow (stat);
	m_btnSpace.EnableWindow (stat);
	m_btnReset.EnableWindow (stat);
	m_btnReadLimits.EnableWindow (stat);
}

void CASPIsnoopDlg::OnClear() 
{
	m_ListBox.ResetContent ();
}

void CASPIsnoopDlg::OnSeekeod() 
{
	m_ListBox.AddString ("Seek EOD....");
	enableButtons (FALSE);
	UpdateData (TRUE);
	DWORD code;
	if ((code=m_pASPI->Space  (m_cTapeHost,m_cTapeID,m_cTapeLun,0x03,1)) != ASPIERR_OK)
		Error (code);
	enableButtons (TRUE);
	CString str;
	
	m_ListBox.AddString ("Seek EOD finished.");
	m_ListBox.SetTopIndex (m_ListBox.GetCount()-1);
	UpdateData (FALSE);
	TRACE ("ASPIsnoop: Space done !\n");
}

void CASPIsnoopDlg::OnConfigure() 
{
	CDlgConfig dlg;
	dlg.Setup (m_cTapeHost,m_cTapeID,m_cTapeLun);
	if (dlg.DoModal () == IDOK)
	{
		dlg.Update (&m_cTapeHost,&m_cTapeID,&m_cTapeLun);
		CString		strSection = "Configuration";
		CWinApp*	pApp = AfxGetApp();
		CString		str;
		str.Format ("%d",m_cTapeHost);
		WritePrivateProfileString (strSection,"Host",str,"tapesnoop.ini");
		str.Format ("%d",m_cTapeID);
		WritePrivateProfileString (strSection,"ID",str,"tapesnoop.ini");
		str.Format ("%d",m_cTapeLun);
		WritePrivateProfileString (strSection,"Lun",str,"tapesnoop.ini");
		InitTapeParameters ();
	}
}

BOOL CASPIsnoopDlg::InitTapeParameters (void)
{
	DWORD		code;
	MPG_devconf dev;
	MPG_compression com;
	BOOL		bDone=FALSE;

	//get current parameters
	ZeroMemory (&dev,sizeof(MPG_devconf));
	if ((code=m_pASPI->ModeSense  (	m_cTapeHost,
									m_cTapeID,
									m_cTapeLun,
									0x10,
									0x00,
									&dev,
									sizeof(MPG_devconf))) != ASPIERR_OK)
	{
		MessageBox ("could not get blocksize from tape-device\nusing default size of 512 bytes\n","TapeSnoop",MB_OK|MB_ICONEXCLAMATION);
		m_dwBlkSize=512;
		m_btnCompression.EnableWindow (FALSE);
	}
	else
	{
		bDone=TRUE;
		m_dwBlkSize=(((DWORD)dev.bd.size1)<<16)|(((DWORD)dev.bd.size2)<<8)|dev.bd.size3;
		m_btnCompression.EnableWindow (dev.dev.comp != 0);
	}

	//get current parameters
	ZeroMemory (&com,sizeof(MPG_compression));
	if ((code=m_pASPI->ModeSense  (	m_cTapeHost,
									m_cTapeID,
									m_cTapeLun,
									0x0F,
									0x00,
									&com,
									sizeof(MPG_compression))) != ASPIERR_OK)
	{
		MessageBox ("could not get compression capabilities\nfeature disabled\n","TapeSnoop",MB_OK|MB_ICONEXCLAMATION);
		m_bCompression=FALSE;
	}
	else
	{
		bDone=TRUE;
		m_bCompression=com.com.dce;
	}

	//get changeable parameters
	ZeroMemory (&com,sizeof(MPG_compression));
	if ((code=m_pASPI->ModeSense  (	m_cTapeHost,
									m_cTapeID,
									m_cTapeLun,
									0x0F,
									0x01,
									&com,
									sizeof(MPG_compression))) != ASPIERR_OK)
	{
		MessageBox ("could not get compression capabilities\nfeature disabled\n","TapeSnoop",MB_OK|MB_ICONEXCLAMATION);
		m_btnCompression.EnableWindow (FALSE);
	}
	else
	{
		bDone=TRUE;		
		m_btnCompression.EnableWindow (com.com.dce);
	}

	UpdateData (FALSE);
	return bDone;
}

void CASPIsnoopDlg::OnUpdateBlksize() 
{
	DWORD		code;
	MPG_devconf out;
	MPG_devconf current;

	ZeroMemory (&out,sizeof(MPG_devconf));
	ZeroMemory (&current,sizeof(MPG_devconf));
	UpdateData (TRUE);
	enableButtons (FALSE);
	m_ListBox.AddString ("Mode Select....");
	UpdateData (TRUE);
	//get current device configuration mode-page
	if ((code=m_pASPI->ModeSense  (m_cTapeHost,m_cTapeID,m_cTapeLun,0x10,0x00,&current,sizeof(MPG_devconf))) != ASPIERR_OK)
		Error (code);
	else
	{
		memcpy (&out.dev,&current.dev,sizeof(_MPG_devconf));
		memcpy (&out.bd,&current.bd,sizeof(BlockDescriptor));
		out.head.buff=current.head.buff;
		out.head.bdsize=current.head.bdsize;
		out.bd.size1=(m_dwBlkSize>>16)&0xFF;
		out.bd.size2=(m_dwBlkSize>>8)&0xFF;
		out.bd.size3=m_dwBlkSize&0xFF;
		if ((code=m_pASPI->ModeSelect (	m_cTapeHost,
										m_cTapeID,
										m_cTapeLun,
										&out,
										sizeof(MPG_devconf))) != ASPIERR_OK)
			Error (code);
	}
	enableButtons (TRUE);
	m_ListBox.AddString ("Mode Select finished.");
	m_ListBox.SetTopIndex (m_ListBox.GetCount()-1);
	UpdateData (FALSE);
}

void CASPIsnoopDlg::DisplayDeviceMP (LPVOID pBuffer)
{
	CString		str;
	char		*buff=(char *)pBuffer;
	MPG_devconf	*dp;
	const char	*yes="YES";
	const char	*no="NO";
	const char	*line="---------------------------------------------------------------------------------------------";

	dp=(MPG_devconf *)pBuffer;
	m_ListBox.AddString (line);
	str.Format ("modesize:%02Xh medium:%02Xh speed:%02Xh buffered mode:%s",
		dp->head.modesize,
		dp->head.medium,
		dp->head.speed,
		dp->head.buff ? yes : no);
	m_ListBox.AddString (str);
	str.Format ("write protected:%s descriptor size:%02Xh",
		dp->head.wp ? yes : no,
		dp->head.bdsize);
	m_ListBox.AddString (str);
	m_ListBox.AddString (line);
	str.Format ("density:%02Xh number of blocks:%d blocksize:%d",	
			dp->bd.density,
			(((DWORD)dp->bd.blocks1)<<16)|(((DWORD)dp->bd.blocks2)<<8)|dp->bd.blocks3,
			(((DWORD)dp->bd.size1)<<16)|(((DWORD)dp->bd.size2)<<8)|dp->bd.size3);
	m_ListBox.AddString (str);
	m_ListBox.AddString (line);
	str.Format ("pagecode:%02Xh saveable:%s size:%02Xh format:%02Xh",	dp->dev.pagecode,
																		dp->dev.ps ? yes : no,
																		dp->dev.len,
																		dp->dev.format);
	m_ListBox.AddString (str);
	str.Format ("chg.active format:%s chg.active part.:%s current part.:%02Xh",	
				dp->dev.caf ? yes : no,
				dp->dev.cap ? yes : no,
				dp->dev.partition);
	m_ListBox.AddString (str);
	str.Format ("wr.buff.full.ratio:%02Xh rd.buff.empty ratio:%02Xh write delay:%d",	
				dp->dev.wrratio,
				dp->dev.rdratio,
				(((DWORD)dp->dev.delay1)<<8)|dp->dev.delay2);
	m_ListBox.AddString (str);
	str.Format ("report early-warning:%s recover buffer order:%s",
				dp->dev.rew ? yes : no,
				dp->dev.rbo ? yes : no);
	m_ListBox.AddString (str);
	str.Format ("stop on consecutive filemarks:%d automatic velocity control:%d",
				dp->dev.socf,
				dp->dev.avc);
	m_ListBox.AddString (str);
	str.Format ("read setmarks:%s block ID supported:%s data buffer recovery:%s",	
				dp->dev.rsmk ? yes : no,
				dp->dev.bis ? yes : no,
				dp->dev.dbr ? yes : no);
	m_ListBox.AddString (str);
	str.Format ("gap size:%d buffer size at early warning:%d compression:%02Xh",
				dp->dev.gap,
				(((DWORD)dp->dev.size3)<<16)|(((DWORD)dp->dev.size2)<<8)|(DWORD)dp->dev.size1,
				dp->dev.comp);
	m_ListBox.AddString (str);
	str.Format ("EOD recognition:%s enable EOD gen.:%s sync.at early-warning:%s",
				dp->dev.eod ? yes : no,
				dp->dev.eeg ? yes : no,
				dp->dev.sew ? yes : no);
	m_ListBox.AddString (str);
}

void CASPIsnoopDlg::DisplayPartitionMP (LPVOID pBuffer)
{
	CString str;
	char *buff=(char *)m_pIOBuffer;
	MPG_partition	*pp;
	const char *yes="YES";
	const char *no="NO";
	const char *line="---------------------------------------------------------------------------------------------";

	pp=(MPG_partition *)((char *)m_pIOBuffer);
	m_ListBox.AddString (line);
	str.Format ("modesize:%02Xh medium:%02Xh speed:%02Xh buffered mode:%s",
		pp->head.modesize,
		pp->head.medium,
		pp->head.speed,
		pp->head.buff ? yes : no);
	m_ListBox.AddString (str);
	str.Format ("write protected:%s descriptor size:%02Xh",
		pp->head.wp ? yes : no,
		pp->head.bdsize);
	m_ListBox.AddString (str);
	m_ListBox.AddString (line);
	str.Format ("density:%02Xh number of blocks:%d blocksize:%d",	
		pp->bd.density,
		(((DWORD)pp->bd.blocks1)<<16)|(((DWORD)pp->bd.blocks2)<<8)|pp->bd.blocks3,
		(((DWORD)pp->bd.size1)<<16)|(((DWORD)pp->bd.size2)<<8)|pp->bd.size3);
	m_ListBox.AddString (str);
	m_ListBox.AddString (line);
	str.Format ("pagecode:%02Xh saveable:%s size:%02Xh",	
		pp->par.pagecode,
		pp->par.ps ? yes : no,
		pp->par.len);
	m_ListBox.AddString (str);
	str.Format ("max.partitions:%02Xh part.defined:%02Xh measure unit:%d",
		pp->par.maxadd,
		pp->par.adddef,
		pp->par.psum);		
	m_ListBox.AddString (str);
	str.Format ("initiator defined part.:%s select data part.:%s fixed data part.:%s",
		pp->par.idp ? yes : no,
		pp->par.sdp ? yes : no,
		pp->par.fdp ? yes : no);		
	m_ListBox.AddString (str);

	const char *mes;
	switch (pp->par.psum)
	{
		case 0x00:	mes="Bytes";	break;
		case 0x01:	mes="KB";		break;
		case 0x02:	mes="MB";		break;
		case 0x03:	mes="quarks";	break;
	}
	//str.Format ("media format recognition:%02Xh size:%d%s",pp->par.medrec,(((DWORD)pp->par.size1)<<8)|(DWORD)pp->par.size2,mes);
	str.Format ("media format recognition:%02Xh",pp->par.medrec);
	m_ListBox.AddString (str);
}

void CASPIsnoopDlg::DisplayCompressionMP (LPVOID pBuffer)
{
	CString str;
	char *buff=(char *)m_pIOBuffer;
	MPG_compression *cp;
	const char *yes="YES";
	const char *no="NO";
	const char *line="---------------------------------------------------------------------------------------------";

	cp=(MPG_compression *)((char *)m_pIOBuffer);
	m_ListBox.AddString (line);
	str.Format ("modesize:%02Xh medium:%02Xh speed:%02Xh buffered mode:%s",
		cp->head.modesize,
		cp->head.medium,
		cp->head.speed,
		cp->head.buff ? yes : no);
	m_ListBox.AddString (str);
	str.Format ("write protected:%s descriptor size:%02Xh",
		cp->head.wp ? yes : no,
		cp->head.bdsize);
	m_ListBox.AddString (str);
	m_ListBox.AddString (line);
	str.Format ("density:%02Xh number of blocks:%d blocksize:%d",	
		cp->bd.density,
		(((DWORD)cp->bd.blocks1)<<16)|(((DWORD)cp->bd.blocks2)<<8)|cp->bd.blocks3,
		(((DWORD)cp->bd.size1)<<16)|(((DWORD)cp->bd.size2)<<8)|cp->bd.size3);
	m_ListBox.AddString (str);
	m_ListBox.AddString (line);

	str.Format ("pagecode:%02Xh saveable:%s size:%02Xh",	
		cp->com.pagecode,
		cp->com.ps ? yes : no,
		cp->com.len);
	m_ListBox.AddString (str);
	str.Format ("dcc: %s compression enabled:%s decompression enabled:%s",	
		cp->com.dcc ? yes : no,
		cp->com.dce ? yes : no,
		cp->com.dde ? yes : no);
	m_ListBox.AddString (str);
	str.Format ("red:%d compression algorithm:%04X decompression algorithm:%04X",
		cp->com.red,
		(((DWORD)cp->com.comp_1)<<24)|(((DWORD)cp->com.comp_2)<<16)|(((DWORD)cp->com.comp_3)<<8)|cp->com.comp_4,
		(((DWORD)cp->com.decomp_1)<<24)|(((DWORD)cp->com.decomp_2)<<16)|(((DWORD)cp->com.decomp_3)<<8)|cp->com.decomp_4,
		cp->com.dde ? yes : no);
	m_ListBox.AddString (str);

}

void CASPIsnoopDlg::OnCopy() 
{
	DWORD code;
	CString str,part;
	
	UpdateData (TRUE);
	enableButtons (FALSE);
	m_ListBox.AddString ("Copy....");

	if ((code=m_pASPI->Copy  (	m_cTapeHost,		//
								m_cTapeID,			//
								m_cTapeLun,			//
								m_cTapeID == 0x04 ? 0x03 : 0x04,	//dst id
								0,					//dst lun
								0)) != ASPIERR_OK)
		Error (code);

	UpdateData (TRUE);
	enableButtons (TRUE);

	m_ListBox.AddString ("Copy finished.");
	m_ListBox.SetTopIndex (m_ListBox.GetCount()-1);
	UpdateData (FALSE);
	TRACE ("ASPIsnoop: Copy done !\n");
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -