88 return ! m_hhDrive.
IsNull();
107 m_hhDrive = ::CreateFile(
CStr::Fmt(_T(
"\\\\.\\PhysicalDrive%d"), driveNo),
108 GENERIC_READ | GENERIC_WRITE,
109 FILE_SHARE_READ | FILE_SHARE_WRITE,
113 return ! m_hhDrive.
IsNull();
126 m_hhDrive = ::CreateFile(
CStr::Fmt(_T(
"\\\\.\\%c:"), driveLetter),
127 GENERIC_READ | GENERIC_WRITE,
132 return ! m_hhDrive.
IsNull();
153 return !! ::DeviceIoControl(m_hhDrive, IOCTL_DISK_UPDATE_PROPERTIES, NULL, 0, NULL, 0, &d, NULL);
164 return !! ::DeviceIoControl(m_hhDrive, FSCTL_DISMOUNT_VOLUME, NULL, 0, NULL, 0, &d, NULL);
175 return !! ::DeviceIoControl(m_hhDrive, FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0, &d, NULL);
186 return !! ::DeviceIoControl(m_hhDrive, FSCTL_UNLOCK_VOLUME, NULL, 0, NULL, 0, &d, NULL);
200 ::SetLastError(ERROR_ACCESS_DENIED);
203 CCdbInfo tmp(0, SCSI_IOCTL_DATA_UNSPECIFIED);
204 tmp.SetCdb(cdb, m_timeout);
205 return m_SendCdb(tmp);
221 ::SetLastError(ERROR_ACCESS_DENIED);
225 CCdbInfo tmp(l,
static_cast<BYTE
>((l > 0) ? SCSI_IOCTL_DATA_OUT : SCSI_IOCTL_DATA_UNSPECIFIED));
226 tmp.SetCdb(cdb, m_timeout);
231 return m_SendCdb(tmp);
248 ::SetLastError(ERROR_ACCESS_DENIED);
251 CCdbInfo tmp(readSize, SCSI_IOCTL_DATA_IN);
252 tmp.SetCdb(cdb, m_timeout);
253 int r = m_SendCdb(tmp);
273 BYTE cdb[6] = {0x1A,
_BIT(3), pc, 0, 4, 0};
275 if ( r == 0 && _d.
GetSize() >= 4 )
277 cdb[1] =
static_cast<BYTE
>((isWithBd && _d.
At(3) == 8) ? 0 :
_BIT(3));
278 cdb[4] =
static_cast<BYTE
>(4 + _d.
At(3) + _d.
At(0));
293 BYTE cdb[6] = {0x12, 0, 0, 0, 8, 0};
297 cdb[4] =
static_cast<BYTE
>(5 + _d.
At(4));
311 BYTE cdb[6] = {0, 0, 0, 0, 0, 0};
324 BYTE cdb[6] = {0x1B, 1, 0, 0, b, 0};
338 BYTE cdb[10] = {0x25, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
343 BYTE* p =
reinterpret_cast<BYTE*
>(vb.
GetBuffer());
344 _blockAddress = p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3];
345 _blockLength = p[4] << 24 | p[5] << 16 | p[6] << 8 | p[7];
361 BYTE cdb[10] = {0x2A, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
362 cdb[2] =
static_cast<BYTE
>(ba >> 24);
363 cdb[3] =
static_cast<BYTE
>(ba >> 16);
364 cdb[4] =
static_cast<BYTE
>(ba >> 8);
365 cdb[5] =
static_cast<BYTE
>(ba);
367 cdb[7] =
static_cast<BYTE
>(l >> 8);
368 cdb[8] =
static_cast<BYTE
>(l);
396 const char* p =
reinterpret_cast<const char*
>(vb.
ReferBuffer());
451 return (vb[2] &
_BIT(7)) == 0;
464 CWorkMem w(
sizeof(DISK_GEOMETRY_EX) +
sizeof(DISK_PARTITION_INFO) +
sizeof(DISK_DETECTION_INFO));
466 DWORD returnedBytes = 0;
467 BOOL r = ::DeviceIoControl(
469 DISK_GEOMETRY_EX* pGeometry =
reinterpret_cast<DISK_GEOMETRY_EX*
>(w.
Ref());
472 LONGLONG ll = pGeometry->DiskSize.QuadPart;
484 CWorkMem w(
sizeof(DISK_GEOMETRY_EX) +
sizeof(DISK_PARTITION_INFO) +
sizeof(DISK_DETECTION_INFO));
486 DWORD returnedBytes = 0;
487 BOOL r = ::DeviceIoControl(
489 DISK_GEOMETRY_EX* pGeometry =
reinterpret_cast<DISK_GEOMETRY_EX*
>(w.
Ref());
490 _g = pGeometry->Geometry;
511 r.QuadPart = llOffset;
512 r.LowPart = ::SetFilePointer(
GetSafeHandle(), r.LowPart, &r.HighPart, seek);
513 if ( r.LowPart == INVALID_SET_FILE_POINTER )
515 if ( ::GetLastError() != NO_ERROR )
531 virtual size_t Read(
size_t size, LPVOID _P)
const
549 virtual void Write(
size_t size, LPCVOID P)
551 if ( size >= ULONG_MAX )
557 DWORD dwError = boRc ? 0 : ::GetLastError();
558 if ( ! boRc || size != dwWrite )
577 struct TScsiPassThroughEx
579 SCSI_PASS_THROUGH spt;
591 CCdbInfo(
size_t size, BYTE bMode) : m_work(0)
593 m_size =
sizeof(TScsiPassThroughEx) + size;
595 TScsiPassThroughEx* P =
reinterpret_cast<TScsiPassThroughEx*
>(m_work.
Ref());
596 ::ZeroMemory(P, m_size);
597 P->spt.Length =
sizeof(SCSI_PASS_THROUGH);
599 P->spt.SenseInfoLength = 32;
600 P->spt.DataIn = bMode;
601 P->spt.DataTransferLength =
static_cast<ULONG
>(size);
602 P->spt.TimeOutValue = 2;
605 P->spt.DataBufferOffset =
sizeof(TScsiPassThroughEx);
607 P->spt.SenseInfoOffset = offsetof(TScsiPassThroughEx, abSense);
612 TScsiPassThroughEx* P =
reinterpret_cast<TScsiPassThroughEx*
>(m_work.
Ref());
613 P->spt.CdbLength =
static_cast<BYTE
>(cdb.
GetSize());
615 P->spt.TimeOutValue = timeout;
618 TScsiPassThroughEx* Ref(
void)
620 return reinterpret_cast<TScsiPassThroughEx*
>(m_work.
Ref());
625 return m_work.
Ref() +
sizeof(TScsiPassThroughEx);
628 size_t GetLength(
void)
635 template<
typename TYP>
643 template<
typename T> CArrayAdapterT(
const T& t)
644 : _super(), m_pcType(static_cast<const TYP*>(t)), m_size(sizeof(T) / sizeof(TYP)) {}
646 virtual size_t GetSize(
void)
const {
return m_size; }
648 virtual const TYP* ReferBuffer(
void)
const {
return m_pcType; }
658 int m_SendCdb(CCdbInfo& cdb)
661 TScsiPassThroughEx* P = cdb.Ref();
662 BOOL r = ::DeviceIoControl(m_hhDrive,
663 IOCTL_SCSI_PASS_THROUGH,
671 if ( r && P->spt.ScsiStatus != 0 )
673 m_sense.
KEY =
static_cast<BYTE
>(P->abSense[2] & 0x0F);
674 if ( P->abSense[7] >= 0x0A )
676 m_sense.
ASC = P->abSense[12];
677 m_sense.
ASCQ = P->abSense[13];
679 return P->spt.ScsiStatus;
687 mutable CStr m_vendorId;
int SendCommandWithWritePhase(const ISequenceCollectionT< BYTE > &cdb, const ISequenceCollectionT< BYTE > &data)
[送信] CDB送信(書込みフェーズ付).
bool GetVendorId(CStr &_id, bool withRevision=false) const
[取得] ベンダID 取得.
int Send_TestUnit(void)
[送信] TEST UNIT CDB送信.
bool Update()
[設定] アップデート.
virtual size_t Read(size_t size, LPVOID _P) const
[取得] 読み込み
int Send_Inquiry(ICollectionT< BYTE > &_d)
[送信] INQUIRY CDB送信.
int SendCommandWithReadPhase(ICollectionT< BYTE > &_d, const ISequenceCollectionT< BYTE > &cdb, int readSize)
[送信] CDB送信(読込みフェーズ付).
int Send_Write10(DWORD ba, const ISequenceCollectionT< BYTE > &d, DWORD div=512)
[送信] Write(10) CDB送信.
HANDLE GetSafeHandle(void) const
[取得] ハンドル取得.
virtual LONGLONG GetSize(void) const
[取得] サイズ取得.
virtual bool CanRead(void) const
[確認] 読み込み可能か?
int SendCommand(const ISequenceCollectionT< BYTE > &cdb)
[送信] CDB送信.
bool IsOpened(void) const
[確認] オープン済み?
virtual LPCTSTR GetOpenName(void) const
[取得] オープン名取得.
CDriveCommander(void)
コンストラクタ
int Send_ModeSense(ICollectionT< BYTE > &_d, BYTE pc, bool isWithBd=false)
[送信] MODESENSE CDB送信.
virtual LONGLONG Seek(LONGLONG llOffset, ESeekMode seek=TOP) const
[操作] シーク.
const TSenseData & GetSense(void) const
[取得] センスデータ取得
virtual void Close(void)
[操作] クローズ
bool GetGeometry(DISK_GEOMETRY &_g) const
[取得] GEOMETRY 取得.
virtual void Write(size_t size, LPCVOID P)
[保存] 書き込み
virtual void SetEnd(void)
[設定] EOFを指定.
bool LockVolume(void)
[設定] Lock Volume.
int Send_StartStop(BYTE b=2)
[送信] STARTSTOP CDB送信.
bool OpenDrive(DWORD driveNo)
[操作] オープン.
bool OpenLetter(TCHAR driveLetter)
[操作] オープン.
bool DismountVolume()
[設定] Dismount Volume.
virtual bool CanWrite(void) const
[確認] 書込み可能か?
bool UnlockVolume(void)
[設定] Unlock Volume.
int Send_ReadCapacity(DWORD &_blockAddress, DWORD &_blockLength)
[送信] Read Capacity CDB送信.
bool IsNull(void) const
[確認] NULLチェック
static CStrT Fmt(const TCHAR *lpszFormat,...)
[作成] 書式付き文字列作成
CStrT & SetFromLeft(const TYP *lpText, size_t iLen)
[代入] 文字数制限代入.
virtual size_t GetSize(void) const
[取得] サイズ取得
TYP * GetBuffer(size_t size=0)
[操作] データアドレス取得
virtual const TYP * ReferBuffer(void) const
[取得] データアドレス取得
size_t GetSize(void) const
[取得] サイズ取得
void Fill(const TYP &other)
[設定] 全情報代入.
void Resize(size_t l)
[設定] サイズ再設定
const TYP * Ref(void) const
[取得] ポインタ取得
DWORD ToDword(LPCSTR lpsz, int iBase=10)
[変換] INT変換(ASCII/SJIS用).
void MemCopy(T *_pDst, const void *pSrc, size_t len)
[複製] メモリコピー
BYTE ASCQ
SCSI Additional Sense Code Qualifier
void Clear(void)
[消去] 全情報クリア
BYTE ASC
SCSI Additional Sense Code
virtual size_t CopyElements(size_t size, const TYP *P=NULL)
[設定] コピー.
virtual const TYP & At(INDEX index) const =0
[取得] 要素の参照取得.
virtual size_t GetSize(void) const =0
[取得] 要素数取得.
virtual const TYP * ReferBuffer(void) const =0
[取得] データアドレス取得.
virtual size_t GetSize(void) const =0
[取得] 要素数取得.