initial check in
This commit is contained in:
8
testDeviceIOWin32/stdafx.cpp
Normal file
8
testDeviceIOWin32/stdafx.cpp
Normal file
@@ -0,0 +1,8 @@
|
||||
// stdafx.cpp : source file that includes just the standard includes
|
||||
// testDeviceIOWin32.pch will be the pre-compiled header
|
||||
// stdafx.obj will contain the pre-compiled type information
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
// TODO: reference any additional headers you need in STDAFX.H
|
||||
// and not in this file
|
||||
23
testDeviceIOWin32/stdafx.h
Normal file
23
testDeviceIOWin32/stdafx.h
Normal file
@@ -0,0 +1,23 @@
|
||||
// stdafx.h : include file for standard system include files,
|
||||
// or project specific include files that are used frequently, but
|
||||
// are changed infrequently
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef _WIN32_WINNT // Allow use of features specific to Windows XP or later.
|
||||
#define _WIN32_WINNT 0x0501 // Change this to the appropriate value to target other versions of Windows.
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <tchar.h>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
|
||||
#include <windows.h>
|
||||
#include <winioctl.h>
|
||||
#include <ntddcdrm.h>
|
||||
|
||||
|
||||
|
||||
// TODO: reference additional headers your program requires here
|
||||
699
testDeviceIOWin32/testDeviceIOWin32.cpp
Normal file
699
testDeviceIOWin32/testDeviceIOWin32.cpp
Normal file
@@ -0,0 +1,699 @@
|
||||
// testDeviceIOWin32.cpp : Defines the entry point for the console application.
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <tchar.h>
|
||||
#include <iostream>
|
||||
|
||||
#include <windows.h>
|
||||
#include <winioctl.h>
|
||||
#include <ntddcdrm.h>
|
||||
|
||||
/*
|
||||
CD
|
||||
Every byte == 14bit (EFM) ??
|
||||
Small Frame == 588bit == 24 byte <== this is the unit of read. Can't read smaller portions.
|
||||
+-----------+------------+--------------+-----------+--------------+-----------+
|
||||
| Sync code | Subchannel | Main Channel | CIRC code | Main Channel | CIRC code |
|
||||
| | byte | data | | data | |
|
||||
bit | 24+3 | 14+3 | 12x(14+3) | 4x(14+3) | 12x(14+3) | 4x(14+3) |
|
||||
+-----------+------------+--------------+-----------+--------------+-----------+
|
||||
|
||||
Frame == 98 Small Frames == 2352 bytes <== this is reachable form soft.
|
||||
+98 byte of subchannel ( 2 sync bytes + 96 bytes of data )
|
||||
The first 2 small frames containe sync bytes and then the rest of small frames
|
||||
containe data bytes.
|
||||
|
||||
|
||||
Session == Lead-in + Program Area + Lead-out
|
||||
Lead-in == TOC in Q-Subchannel
|
||||
Program Area == Logical Tracks (at least containes one logical track)
|
||||
|
||||
|
||||
Address format is MSF (Minute/Second/Frame) M=60*S S=75*F
|
||||
1 Audio Sec = 4(Stereo 16bit)*44100(Hz)=176400 byte = 75 * 2352 byte = 75 Frame
|
||||
0<= F <= 74
|
||||
0<= S <= 59
|
||||
0<= M <= 99
|
||||
|
||||
|
||||
*/
|
||||
|
||||
enum {
|
||||
ADDR_SEC2FRAME = 75,
|
||||
ADDR_MIN2SEC = 60,
|
||||
|
||||
CTRL_COPYPROT_MASK = 0x02, // 0010
|
||||
CTRL_TYPE_MASK = 0x0C, // 1100
|
||||
CTRL_AUDIO2CH_TRACK = 0x00, //
|
||||
CTRL_DATA_TRACK = 0x04, //
|
||||
CTRL_AUDIO4CH_TRACK = 0x06, //
|
||||
CTRL_RESERVED_TRACK = 0x0C, //
|
||||
CTRL_DATA_INCREMENTAL = 0x01, //
|
||||
CTRL_AUDIO_50_15 = 0x01, //
|
||||
|
||||
FRAME_DATA = 2352,
|
||||
|
||||
};
|
||||
|
||||
#define MAXIMUM_NUMBER_TRACKS 100
|
||||
#define NSECTORS 13
|
||||
#define UNDERSAMPLING 1
|
||||
#define CB_CDDASECTOR 2368
|
||||
#define CB_QSUBCHANNEL 16
|
||||
#define CB_CDROMSECTOR 2048
|
||||
#define CB_AUDIO (CB_CDDASECTOR-CB_QSUBCHANNEL)
|
||||
|
||||
/* The code of interest is in the subroutine GetDriveGeometry. The
|
||||
code in main shows how to interpret the results of the call. */
|
||||
|
||||
class device
|
||||
{
|
||||
protected:
|
||||
|
||||
// Handle to the drive to be examined.
|
||||
HANDLE hDevice;
|
||||
|
||||
DISK_GEOMETRY dg;
|
||||
CDROM_TOC toc;
|
||||
|
||||
bool m_bLocked;
|
||||
|
||||
public:
|
||||
|
||||
device()
|
||||
{
|
||||
hDevice = INVALID_HANDLE_VALUE;
|
||||
m_bLocked = false;
|
||||
}
|
||||
|
||||
~device()
|
||||
{
|
||||
if ( hDevice != INVALID_HANDLE_VALUE )
|
||||
{
|
||||
if ( m_bLocked )
|
||||
storageMediaUnlock();
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
bool create( const TCHAR* pszDevice )
|
||||
{
|
||||
hDevice = ::CreateFile(pszDevice, // drive to open
|
||||
GENERIC_READ |
|
||||
GENERIC_WRITE , // no access to the drive
|
||||
FILE_SHARE_READ | // share mode
|
||||
FILE_SHARE_WRITE,
|
||||
NULL, // default security attributes
|
||||
OPEN_EXISTING, // disposition
|
||||
0, // file attributes
|
||||
NULL); // do not copy file attributes
|
||||
if (hDevice == INVALID_HANDLE_VALUE) // cannot open the drive
|
||||
{
|
||||
printErr("CreateFile");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool close()
|
||||
{
|
||||
if ( hDevice != INVALID_HANDLE_VALUE )
|
||||
{
|
||||
::CloseHandle(hDevice);
|
||||
hDevice = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void printErr( char* szMsg = "" )
|
||||
{
|
||||
printf ("%s Error %ld. ", szMsg, GetLastError ());
|
||||
|
||||
char szMsgBfr[ 1024 ];
|
||||
::FormatMessageA(
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL,
|
||||
GetLastError (),
|
||||
0, // Default language
|
||||
szMsgBfr,
|
||||
sizeof( szMsgBfr ),
|
||||
NULL );
|
||||
szMsgBfr[sizeof( szMsgBfr )-1] = 0;
|
||||
|
||||
puts ( szMsgBfr );
|
||||
}
|
||||
|
||||
bool diskGetDriveGeometry()
|
||||
{
|
||||
DWORD junk; // discard results
|
||||
|
||||
printf("IOCTL_DISK_GET_DRIVE_GEOMETRY\n");
|
||||
if ( !DeviceIoControl( hDevice, // device to be queried
|
||||
IOCTL_DISK_GET_DRIVE_GEOMETRY, // operation to perform
|
||||
NULL, 0, // no input buffer
|
||||
&dg, sizeof(dg), // output buffer
|
||||
&junk, // # bytes returned
|
||||
(LPOVERLAPPED) NULL) ) // synchronous I/O
|
||||
{
|
||||
printErr("");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("MediaType = %d\n", dg.MediaType);
|
||||
printf("Cylinders = %I64d\n", dg.Cylinders);
|
||||
printf("Tracks/cylinder = %ld\n", (ULONG) dg.TracksPerCylinder);
|
||||
printf("Sectors/track = %ld\n", (ULONG) dg.SectorsPerTrack);
|
||||
printf("Bytes/sector = %ld\n", (ULONG) dg.BytesPerSector);
|
||||
|
||||
ULONGLONG DiskSize = dg.Cylinders.QuadPart * (ULONG)dg.TracksPerCylinder *
|
||||
(ULONG)dg.SectorsPerTrack * (ULONG)dg.BytesPerSector;
|
||||
printf("Disk size = %I64d (Bytes) = %I64d (Gb)\n", DiskSize,
|
||||
DiskSize / (1024 * 1024 * 1024));
|
||||
}
|
||||
puts("");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool diskGetCacheInformation()
|
||||
{
|
||||
DWORD junk; // discard results
|
||||
DISK_CACHE_INFORMATION dci;
|
||||
|
||||
printf("IOCTL_DISK_GET_CACHE_INFORMATION\n");
|
||||
if ( !DeviceIoControl( hDevice, // device to be queried
|
||||
IOCTL_DISK_GET_CACHE_INFORMATION, // operation to perform
|
||||
NULL, 0, // no input buffer
|
||||
&dci, sizeof(dci), // output buffer
|
||||
&junk, // # bytes returned
|
||||
(LPOVERLAPPED) NULL) ) // synchronous I/O
|
||||
{
|
||||
printErr("");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("ParametersSavable = %d\n", dci.ParametersSavable);
|
||||
printf("ReadCacheEnabled = %d\n", dci.ReadCacheEnabled);
|
||||
printf("WriteCacheEnabled = %d\n", dci.WriteCacheEnabled);
|
||||
printf("ReadRetentionPriority = %d\n", dci.ReadRetentionPriority);
|
||||
printf("WriteRetentionPriority = %d\n", dci.WriteRetentionPriority);
|
||||
printf("DisablePrefetchTransferLength = %d\n", dci.DisablePrefetchTransferLength);
|
||||
if ( dci.PrefetchScalar )
|
||||
{
|
||||
printf("ScalarPrefetch.Minimum = %d\n", dci.ScalarPrefetch.Minimum);
|
||||
printf("ScalarPrefetch.Maximum = %d\n", dci.ScalarPrefetch.Maximum);
|
||||
printf("ScalarPrefetch.MaximumBlocks = %d\n", dci.ScalarPrefetch.MaximumBlocks);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("BlockPrefetch.Minimum = %d\n", dci.BlockPrefetch.Minimum);
|
||||
printf("BlockPrefetch.Maximum = %d\n", dci.BlockPrefetch.Maximum);
|
||||
}
|
||||
}
|
||||
puts("");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool diskPerformance()
|
||||
{
|
||||
DWORD junk; // discard results
|
||||
DISK_PERFORMANCE dp;
|
||||
|
||||
printf("IOCTL_DISK_PERFORMANCE\n");
|
||||
if ( !DeviceIoControl( hDevice, // device to be queried
|
||||
IOCTL_DISK_PERFORMANCE, // operation to perform
|
||||
NULL, 0, // no input buffer
|
||||
&dp, sizeof(dp), // output buffer
|
||||
&junk, // # bytes returned
|
||||
(LPOVERLAPPED) NULL) ) // synchronous I/O
|
||||
{
|
||||
printErr("");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("BytesRead = %I64d\n", dp.BytesRead);
|
||||
printf("BytesWritten = %I64d\n", dp.BytesWritten);
|
||||
printf("ReadTime = %I64d\n", dp.ReadTime);
|
||||
printf("WriteTime = %I64d\n", dp.WriteTime);
|
||||
printf("IdleTime = %I64d\n", dp.IdleTime);
|
||||
printf("ReadCount = %d\n", dp.ReadCount);
|
||||
printf("WriteCount = %d\n", dp.WriteCount);
|
||||
printf("QueueDepth = %d\n", dp.QueueDepth);
|
||||
printf("SplitCount = %d\n", dp.SplitCount);
|
||||
printf("QueryTime = %I64d\n", dp.QueryTime);
|
||||
printf("StorageDeviceNumber = %d\n", dp.StorageDeviceNumber);
|
||||
printf("StorageManagerName = %c%c%c%c%c%c%c%c\n",
|
||||
dp.StorageManagerName[0], dp.StorageManagerName[1],
|
||||
dp.StorageManagerName[2], dp.StorageManagerName[3],
|
||||
dp.StorageManagerName[4], dp.StorageManagerName[5],
|
||||
dp.StorageManagerName[6], dp.StorageManagerName[7]);
|
||||
}
|
||||
puts("");
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
printf("IOCTL_DISK_PERFORMANCE_OFF\n");
|
||||
if ( !DeviceIoControl( hDevice, // device to be queried
|
||||
IOCTL_DISK_PERFORMANCE_OFF, // operation to perform
|
||||
NULL, 0, // no input buffer
|
||||
0, 0, // output buffer
|
||||
&junk, // # bytes returned
|
||||
(LPOVERLAPPED) NULL) ) // synchronous I/O
|
||||
{
|
||||
printErr("");
|
||||
return false;
|
||||
}
|
||||
puts("");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool diskVerify()
|
||||
{
|
||||
DWORD junk; // discard results
|
||||
VERIFY_INFORMATION vi;
|
||||
|
||||
printf("IOCTL_DISK_VERIFY\n");
|
||||
vi.StartingOffset.QuadPart = 0;
|
||||
vi.Length = 2048;
|
||||
if ( !DeviceIoControl( hDevice, // device to be queried
|
||||
IOCTL_DISK_VERIFY, // operation to perform
|
||||
&vi, sizeof(vi), // no input buffer
|
||||
0, 0, // output buffer
|
||||
&junk, // # bytes returned
|
||||
(LPOVERLAPPED) NULL) ) // synchronous I/O
|
||||
{
|
||||
printErr("");
|
||||
return false;
|
||||
}
|
||||
puts("");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool storageMediaLock()
|
||||
{
|
||||
DWORD junk; // discard results
|
||||
PREVENT_MEDIA_REMOVAL pmr;
|
||||
pmr.PreventMediaRemoval = 1;
|
||||
|
||||
printf("IOCTL_STORAGE_MEDIA_REMOVAL lock\n");
|
||||
if ( !::DeviceIoControl( hDevice,
|
||||
IOCTL_STORAGE_MEDIA_REMOVAL,
|
||||
&pmr, sizeof( pmr ),
|
||||
0, 0,
|
||||
&junk,
|
||||
(LPOVERLAPPED)0 ) )
|
||||
{
|
||||
printErr("");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_bLocked = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool storageMediaUnlock()
|
||||
{
|
||||
DWORD junk; // discard results
|
||||
PREVENT_MEDIA_REMOVAL pmr;
|
||||
pmr.PreventMediaRemoval = 0;
|
||||
|
||||
printf("IOCTL_STORAGE_MEDIA_REMOVAL unlock\n");
|
||||
if ( !::DeviceIoControl( hDevice,
|
||||
IOCTL_STORAGE_MEDIA_REMOVAL,
|
||||
&pmr, sizeof( pmr ),
|
||||
0, 0,
|
||||
&junk,
|
||||
(LPOVERLAPPED)0 ) )
|
||||
{
|
||||
printErr("");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_bLocked = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool storageLoadMedia()
|
||||
{
|
||||
DWORD junk; // discard results
|
||||
|
||||
printf("IOCTL_STORAGE_LOAD_MEDIA\n");
|
||||
if ( !::DeviceIoControl( hDevice,
|
||||
IOCTL_STORAGE_LOAD_MEDIA,
|
||||
0, 0,
|
||||
0, 0,
|
||||
&junk,
|
||||
(LPOVERLAPPED)0 ) )
|
||||
{
|
||||
printErr("");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// printf("");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool storageCheckVerify()
|
||||
{
|
||||
DWORD junk; // discard results
|
||||
|
||||
printf("IOCTL_STORAGE_CHECK_VERIFY\n");
|
||||
if ( !::DeviceIoControl( hDevice,
|
||||
IOCTL_STORAGE_CHECK_VERIFY,
|
||||
0, 0,
|
||||
0, 0,
|
||||
&junk,
|
||||
(LPOVERLAPPED)0 ) )
|
||||
{
|
||||
printErr("");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// printf("");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool storageEjectMedia()
|
||||
{
|
||||
DWORD junk; // discard results
|
||||
|
||||
printf("IOCTL_STORAGE_EJECT_MEDIA\n");
|
||||
if ( !::DeviceIoControl( hDevice,
|
||||
IOCTL_STORAGE_EJECT_MEDIA,
|
||||
0, 0,
|
||||
0, 0,
|
||||
&junk,
|
||||
(LPOVERLAPPED)0 ) )
|
||||
{
|
||||
printErr("");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// printf("");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool storageReadCapacity()
|
||||
{
|
||||
// 2003
|
||||
#if 0
|
||||
DWORD junk; // discard results
|
||||
|
||||
STORAGE_READ_CAPACITY src;
|
||||
printf("IOCTL_STORAGE_READ_CAPACITY\n");
|
||||
if ( !DeviceIoControl( hDevice, // device to be queried
|
||||
IOCTL_STORAGE_READ_CAPACITY, // operation to perform
|
||||
NULL, 0, // no input buffer
|
||||
&src, sizeof(src), // output buffer
|
||||
&junk, // # bytes returned
|
||||
(LPOVERLAPPED) NULL) ) // synchronous I/O
|
||||
{
|
||||
printErr("");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Version = %d\n", src.Version);
|
||||
printf("Size = %d\n", src.Size);
|
||||
printf("BlockLength = %d\n", src.BlockLength);
|
||||
printf("NumberOfBlocks = %I64d\n", dg.NumberOfBlocks);
|
||||
printf("DiskLength = %I64d\n", dg.DiskLength);
|
||||
}
|
||||
puts("");
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cdromDiskInfo()
|
||||
{
|
||||
#if 0
|
||||
DWORD junk; // discard results
|
||||
printf("IOCTL_CDROM_DISC_INFO\n");
|
||||
CDROM_DISCINFO cdi;
|
||||
if ( !DeviceIoControl( hDevice, // device to be queried
|
||||
IOCTL_CDROM_DISC_INFO, // operation to perform
|
||||
0, 0, // no input buffer
|
||||
&cdi, sizeof( cdi ), // output buffer
|
||||
&junk, // # bytes returned
|
||||
(LPOVERLAPPED) NULL) ) // synchronous I/O
|
||||
{
|
||||
printErr("");
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Reserved = %I64d\n", cdi.Reserved );
|
||||
printf("FirstTrack = %I64d\n", cdi.FirstTrack );
|
||||
printf("LastTrack = %I64d\n", cdi.LastTrack );
|
||||
printf("LastTrack = %I64d\n", cdi.LeadOutTrackAddr );
|
||||
printf("FirstSession = %I64d\n", cdi.FirstSession );
|
||||
printf("LastSession = %I64d\n", cdi.LastSession );
|
||||
printf("ReqSession = %I64d\n", cdi.ReqSession );
|
||||
printf("RetSession = %I64d\n", cdi.RetSession );
|
||||
printf("LogicStartAddr = %I64d\n", cdi.LogicStartAddr );
|
||||
}
|
||||
puts("");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
bool cdromReadTOC()
|
||||
{
|
||||
DWORD junk; // discard results
|
||||
printf("IOCTL_CDROM_READ_TOC\n");
|
||||
|
||||
if ( !::DeviceIoControl( hDevice,
|
||||
IOCTL_CDROM_READ_TOC,
|
||||
0, 0,
|
||||
&toc, sizeof(toc),
|
||||
&junk,
|
||||
(LPOVERLAPPED)0 ) )
|
||||
{
|
||||
printErr("");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Length = " << (USHORT&)toc.Length << std::endl;
|
||||
std::cout << "FirstTrack = " << int(toc.FirstTrack) << std::endl;
|
||||
std::cout << "LastTrack = " << int(toc.LastTrack) << std::endl;
|
||||
for ( int i = 0; i < (toc.LastTrack - toc.FirstTrack +1); ++i )
|
||||
{
|
||||
std::cout << "track " << i << " {" << std::endl;
|
||||
|
||||
if ( toc.TrackData[i].Control & CTRL_COPYPROT_MASK )
|
||||
std::cout << " No copy protection" << std::endl;
|
||||
else
|
||||
std::cout << " Copy protected" << std::endl;
|
||||
|
||||
int n = toc.TrackData[i].Control & CTRL_TYPE_MASK;
|
||||
if ( n == CTRL_AUDIO2CH_TRACK )
|
||||
std::cout << " 2 channel audio track" << std::endl;
|
||||
else if ( n == CTRL_AUDIO4CH_TRACK )
|
||||
std::cout << " 4 channel audio track" << std::endl;
|
||||
else if ( n == CTRL_DATA_TRACK )
|
||||
std::cout << " Data track" << std::endl;
|
||||
else
|
||||
std::cout << " Unknown type of track" << std::endl;
|
||||
|
||||
if ( n == CTRL_DATA_TRACK )
|
||||
{
|
||||
if ( toc.TrackData[i].Control & CTRL_DATA_INCREMENTAL )
|
||||
std::cout << " Incremental record" << std::endl;
|
||||
else
|
||||
std::cout << " Continuous record" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( toc.TrackData[i].Control & CTRL_AUDIO_50_15 )
|
||||
std::cout << " Predistortion 50/15 mks" << std::endl;
|
||||
else
|
||||
std::cout << " No predistortion" << std::endl;
|
||||
}
|
||||
|
||||
std::cout << " Adr = " << int(toc.TrackData[i].Adr) << std::endl;
|
||||
std::cout << " TrackNumber = " << int(toc.TrackData[i].TrackNumber) << std::endl;
|
||||
std::cout << " Address[0] = " << int(toc.TrackData[i].Address[0]) << std::endl;
|
||||
std::cout << " Minute = " << int(toc.TrackData[i].Address[1]) << std::endl;
|
||||
std::cout << " Second = " << int(toc.TrackData[i].Address[2]) << std::endl;
|
||||
std::cout << " Frame = " << int(toc.TrackData[i].Address[3]) << std::endl;
|
||||
std::cout << " Start Sector = " << toc.TrackData[i].Address[1] * ADDR_MIN2SEC * ADDR_SEC2FRAME
|
||||
+ toc.TrackData[i].Address[2] * ADDR_SEC2FRAME
|
||||
+ toc.TrackData[i].Address[3] << std::endl;
|
||||
std::cout << "}" << std::endl;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual int cdromRawRead( int sector, int num, char* buf, int buf_size );
|
||||
|
||||
};
|
||||
|
||||
int device::cdromRawRead( int sector, int num, char* buf, int buf_size )
|
||||
{
|
||||
DWORD nBytsRead = 0;
|
||||
|
||||
RAW_READ_INFO rri;
|
||||
// rri.TrackMode = CDDA;
|
||||
rri.TrackMode = YellowMode2;
|
||||
rri.SectorCount = num;
|
||||
rri.DiskOffset.QuadPart = sector*CB_CDROMSECTOR;
|
||||
|
||||
memset ( buf, 0, buf_size );
|
||||
|
||||
#if 1
|
||||
// std::cout << "IOCTL_CDROM_RAW_READ" << std::endl;
|
||||
if ( !::DeviceIoControl( hDevice,
|
||||
IOCTL_CDROM_RAW_READ,
|
||||
&rri, sizeof(rri),
|
||||
buf, buf_size,
|
||||
&nBytsRead,
|
||||
(LPOVERLAPPED)0 ) )
|
||||
{
|
||||
int i = 0;
|
||||
char tmp[32];
|
||||
|
||||
for ( ; i < buf_size && !buf[i]; ++i );
|
||||
if ( i < buf_size )
|
||||
_snprintf( tmp, sizeof( tmp), "Sector %d buf!=0", sector );
|
||||
else
|
||||
_snprintf( tmp, sizeof( tmp), "Sector %d", sector );
|
||||
|
||||
printErr( tmp );
|
||||
return false;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
#if 0
|
||||
std::cout << " Read " << nBytsRead << " bytes" << std::endl;
|
||||
const int cCol = 16;
|
||||
for ( int i = 0; i < int(nBytsRead) ; )
|
||||
{
|
||||
int k = i;
|
||||
for ( int j = 0; j < cCol && k < int(nBytsRead); ++k, ++j )
|
||||
{
|
||||
std::cout << std::hex << (((unsigned)( buf[k] ) >> 4) & 0xF ) << ((unsigned)( buf[k] ) & 0x0F ) << " ";
|
||||
}
|
||||
|
||||
for ( int j = 0; j < cCol && i < int(nBytsRead); ++i, ++j )
|
||||
{
|
||||
if ( 32 < buf[i] && buf[i] < 255 )
|
||||
std::cout << buf[i];
|
||||
else
|
||||
std::cout << ' ';
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// CB_CDROMSECTOR
|
||||
#if 0
|
||||
if (m_bTocValid && ((sector + NumSectors) <= GetEndSector(m_TOC.LastTrack)))
|
||||
{
|
||||
RAW_READ_INFO rri;
|
||||
rri.TrackMode = CDDA;
|
||||
rri.SectorCount = (DWORD)NumSectors;
|
||||
rri.DiskOffset.QuadPart = sector*CB_CDROMSECTOR;
|
||||
|
||||
DWORD charsRead = 0;
|
||||
if (::DeviceIoControl(m_hDrive, IOCTL_CDROM_RAW_READ, &rri, sizeof(rri), Buffer, (DWORD)NumSectors * CB_AUDIO, &charsRead, NULL) != 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
#endif
|
||||
return nBytsRead;
|
||||
}
|
||||
|
||||
|
||||
int _tmain(int argc, _TCHAR* argv[])
|
||||
{
|
||||
//TCHAR szDevice[] = L"\\\\.\\PhysicalDrive0";
|
||||
//TCHAR szDevice[] = L"\\\\.\\PhysicalDrive2";
|
||||
TCHAR szDevice[] = L"\\\\.\\E:";
|
||||
|
||||
FILE* f = fopen( "dump.txt", "wb" );
|
||||
|
||||
device d;
|
||||
|
||||
if ( !d.create( szDevice ) )
|
||||
{
|
||||
std::cerr << "Cannot open device." << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ( !d.storageCheckVerify() )
|
||||
{
|
||||
std::cerr << "Media is not accessable." << std::endl;
|
||||
return 2;
|
||||
}
|
||||
|
||||
if ( !d.storageMediaLock() )
|
||||
{
|
||||
std::cerr << "Cannot lock the media." << std::endl;
|
||||
return 3;
|
||||
}
|
||||
|
||||
// d.diskGetDriveGeometry();
|
||||
// d.storageReadCapacity();
|
||||
// d.diskGetCacheInformation();
|
||||
// d.diskPerformance();
|
||||
|
||||
// d.cdromDiskInfo();
|
||||
d.cdromReadTOC();
|
||||
|
||||
const int nStart = 000;
|
||||
const int nAmount = nStart + 350000;
|
||||
int i = nStart;
|
||||
char buf[ 2*FRAME_DATA ];
|
||||
for ( ; i < nAmount; ++i )
|
||||
{
|
||||
int n = d.cdromRawRead( i, 1, buf, sizeof( buf ) );
|
||||
// fwrite( buf, 1, n, f );
|
||||
}
|
||||
|
||||
d.storageMediaUnlock();
|
||||
d.storageMediaUnlock();
|
||||
d.storageMediaUnlock();
|
||||
d.storageMediaUnlock();
|
||||
d.storageMediaUnlock();
|
||||
d.storageMediaUnlock();
|
||||
|
||||
// d.storageEjectMedia();
|
||||
|
||||
d.close();
|
||||
|
||||
fclose( f );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
20
testDeviceIOWin32/testDeviceIOWin32.sln
Normal file
20
testDeviceIOWin32/testDeviceIOWin32.sln
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 9.00
|
||||
# Visual Studio 2005
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testDeviceIOWin32", "testDeviceIOWin32.vcproj", "{E94938D0-9C6D-4792-824D-919AC911027C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{E94938D0-9C6D-4792-824D-919AC911027C}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{E94938D0-9C6D-4792-824D-919AC911027C}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{E94938D0-9C6D-4792-824D-919AC911027C}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{E94938D0-9C6D-4792-824D-919AC911027C}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
225
testDeviceIOWin32/testDeviceIOWin32.vcproj
Normal file
225
testDeviceIOWin32/testDeviceIOWin32.vcproj
Normal file
@@ -0,0 +1,225 @@
|
||||
<?xml version="1.0" encoding="windows-1251"?>
|
||||
<VisualStudioProject
|
||||
ProjectType="Visual C++"
|
||||
Version="8.00"
|
||||
Name="testDeviceIOWin32"
|
||||
ProjectGUID="{E94938D0-9C6D-4792-824D-919AC911027C}"
|
||||
RootNamespace="testDeviceIOWin32"
|
||||
Keyword="Win32Proj"
|
||||
>
|
||||
<Platforms>
|
||||
<Platform
|
||||
Name="Win32"
|
||||
/>
|
||||
</Platforms>
|
||||
<ToolFiles>
|
||||
</ToolFiles>
|
||||
<Configurations>
|
||||
<Configuration
|
||||
Name="Debug|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
RuntimeLibrary="3"
|
||||
UsePrecompiledHeader="2"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="4"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
LinkIncremental="2"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
<Configuration
|
||||
Name="Release|Win32"
|
||||
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
|
||||
IntermediateDirectory="$(ConfigurationName)"
|
||||
ConfigurationType="1"
|
||||
CharacterSet="1"
|
||||
WholeProgramOptimization="1"
|
||||
>
|
||||
<Tool
|
||||
Name="VCPreBuildEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXMLDataGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebServiceProxyGeneratorTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCMIDLTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
|
||||
RuntimeLibrary="2"
|
||||
UsePrecompiledHeader="2"
|
||||
WarningLevel="3"
|
||||
Detect64BitPortabilityProblems="true"
|
||||
DebugInformationFormat="3"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManagedResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCResourceCompilerTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPreLinkEventTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
OptimizeReferences="2"
|
||||
EnableCOMDATFolding="2"
|
||||
TargetMachine="1"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCALinkTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCManifestTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCXDCMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCBscMakeTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCFxCopTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCAppVerifierTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCWebDeploymentTool"
|
||||
/>
|
||||
<Tool
|
||||
Name="VCPostBuildEventTool"
|
||||
/>
|
||||
</Configuration>
|
||||
</Configurations>
|
||||
<References>
|
||||
</References>
|
||||
<Files>
|
||||
<Filter
|
||||
Name="Source Files"
|
||||
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
|
||||
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\stdafx.cpp"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="1"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
UsePrecompiledHeader="1"
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\testDeviceIOWin32.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Header Files"
|
||||
Filter="h;hpp;hxx;hm;inl;inc;xsd"
|
||||
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\stdafx.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="Resource Files"
|
||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
|
||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
|
||||
>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath=".\ReadMe.txt"
|
||||
>
|
||||
</File>
|
||||
</Files>
|
||||
<Globals>
|
||||
</Globals>
|
||||
</VisualStudioProject>
|
||||
Reference in New Issue
Block a user