本文整理汇总了C++中DeviceIoControl函数的典型用法代码示例。如果您正苦于以下问题:C++ DeviceIoControl函数的具体用法?C++ DeviceIoControl怎么用?C++ DeviceIoControl使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DeviceIoControl函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int
main(int argc, char **argv)
{
LARGE_INTEGER FileSize;
HANDLE hFile;
char cSuffix;
BOOL bSetSparse = FALSE;
DWORD dw;
if (argc == 4)
if (strcmpi(argv[1], "-s") == 0)
{
bSetSparse = TRUE;
argc--;
argv++;
}
if (argc != 3)
{
puts("CHSIZE32.EXE - freeware by Olof Lagerkvist.\r\n"
"http://www.ltr-data.se [email protected]\r\n"
"Utility to change size of an existing file, or create a new file with specified"
"size.\r\n"
"\n"
"Syntax:\r\n"
"\n"
"CHSIZE32 [-s] file size[K|M|G|T]\r\n"
"\n"
"-s Set sparse attribute.");
return 0;
}
switch (sscanf(argv[2], "%I64i%c", &FileSize, &cSuffix))
{
case 2:
switch (cSuffix)
{
case 0:
break;
case 'T': case 't':
FileSize.QuadPart <<= 10;
case 'G': case 'g':
FileSize.QuadPart <<= 10;
case 'M': case 'm':
FileSize.QuadPart <<= 10;
case 'K': case 'k':
FileSize.QuadPart <<= 10;
break;
default:
fprintf(stderr, "Unknown size extension: %c\n", cSuffix);
return 1;
}
case 1:
break;
default:
fprintf(stderr, "Expected file size, got \"%s\"\n", argv[2]);
return 1;
}
hFile = CreateFile(argv[1], GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS,
FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
win_perror(argv[1]);
return 1;
}
if (bSetSparse)
if (!DeviceIoControl(hFile, FSCTL_SET_SPARSE, NULL, 0, NULL, 0, &dw, NULL))
win_perror("Error setting sparse attribute");
if ((SetFilePointer(hFile, FileSize.LowPart, &FileSize.HighPart,
FILE_BEGIN) == 0xFFFFFFFF) ?
(GetLastError() != NO_ERROR) : FALSE)
{
win_perror(NULL);
return 1;
}
if (SetEndOfFile(hFile))
return 0;
win_perror(NULL);
return 1;
}
示例2: main
//.........这里部分代码省略.........
if(srbType == 1)
{
ZeroMemory(&sptwb_ex,sizeof(SCSI_PASS_THROUGH_WITH_BUFFERS_EX));
sptwb_ex.spt.Version = 0;
sptwb_ex.spt.Length = sizeof(SCSI_PASS_THROUGH_EX);
sptwb_ex.spt.ScsiStatus = 0;
sptwb_ex.spt.CdbLength = CDB6GENERIC_LENGTH;
sptwb_ex.spt.StorAddressLength = sizeof(STOR_ADDR_BTL8);
sptwb_ex.spt.SenseInfoLength = SPT_SENSE_LENGTH;
sptwb_ex.spt.DataOutTransferLength = 0;
sptwb_ex.spt.DataInTransferLength = 192;
sptwb_ex.spt.DataDirection = SCSI_IOCTL_DATA_IN;
sptwb_ex.spt.TimeOutValue = 2;
sptwb_ex.spt.StorAddressOffset =
offsetof(SCSI_PASS_THROUGH_WITH_BUFFERS_EX,StorAddress);
sptwb_ex.StorAddress.Type = STOR_ADDRESS_TYPE_BTL8;
sptwb_ex.StorAddress.Port = 0;
sptwb_ex.StorAddress.AddressLength = STOR_ADDR_BTL8_ADDRESS_LENGTH;
sptwb_ex.StorAddress.Path = 0;
sptwb_ex.StorAddress.Target = 1;
sptwb_ex.StorAddress.Lun = 0;
sptwb_ex.spt.SenseInfoOffset =
offsetof(SCSI_PASS_THROUGH_WITH_BUFFERS_EX,ucSenseBuf);
sptwb_ex.spt.DataOutBufferOffset = 0;
sptwb_ex.spt.DataInBufferOffset =
offsetof(SCSI_PASS_THROUGH_WITH_BUFFERS_EX,ucDataBuf);
sptwb_ex.spt.Cdb[0] = SCSIOP_MODE_SENSE;
sptwb_ex.spt.Cdb[2] = MODE_SENSE_RETURN_ALL;
sptwb_ex.spt.Cdb[4] = 192;
length = offsetof(SCSI_PASS_THROUGH_WITH_BUFFERS_EX,ucDataBuf) +
sptwb_ex.spt.DataInTransferLength;
status = DeviceIoControl(fileHandle,
IOCTL_SCSI_PASS_THROUGH_EX,
&sptwb_ex,
sizeof(SCSI_PASS_THROUGH_WITH_BUFFERS_EX),
&sptwb_ex,
length,
&returned,
FALSE);
PrintStatusResultsEx(status,returned,&sptwb_ex,length);
}
else
{
ZeroMemory(&sptwb,sizeof(SCSI_PASS_THROUGH_WITH_BUFFERS));
sptwb.spt.Length = sizeof(SCSI_PASS_THROUGH);
sptwb.spt.PathId = 0;
sptwb.spt.TargetId = 1;
sptwb.spt.Lun = 0;
sptwb.spt.CdbLength = CDB6GENERIC_LENGTH;
sptwb.spt.SenseInfoLength = SPT_SENSE_LENGTH;
sptwb.spt.DataIn = SCSI_IOCTL_DATA_IN;
sptwb.spt.DataTransferLength = 192;
sptwb.spt.TimeOutValue = 2;
sptwb.spt.DataBufferOffset =
offsetof(SCSI_PASS_THROUGH_WITH_BUFFERS,ucDataBuf);
sptwb.spt.SenseInfoOffset =
offsetof(SCSI_PASS_THROUGH_WITH_BUFFERS,ucSenseBuf);
sptwb.spt.Cdb[0] = SCSIOP_MODE_SENSE;
sptwb.spt.Cdb[2] = MODE_SENSE_RETURN_ALL;
sptwb.spt.Cdb[4] = 192;
length = offsetof(SCSI_PASS_THROUGH_WITH_BUFFERS,ucDataBuf) +
sptwb.spt.DataTransferLength;
示例3: GetCommModemStatus
/***********************************************************************
* GetCommModemStatus ([email protected])
*
* Obtains the four control register bits if supported by the hardware.
*
* PARAMS
*
* hFile [in] The communications device
* lpModemStat [out] The control register bits
*
* RETURNS
*
* True if the communications handle was good and for hardware that
* control register access, false otherwise.
*/
BOOL WINAPI GetCommModemStatus(HANDLE hFile, LPDWORD lpModemStat)
{
DWORD dwBytesReturned;
return DeviceIoControl(hFile, IOCTL_SERIAL_GET_MODEMSTATUS,
NULL, 0, lpModemStat, sizeof(DWORD), &dwBytesReturned, NULL);
}
示例4: DetectAlreadyConnectedDevices
//.........这里部分代码省略.........
if (!bResult)
{
if (dwError == ERROR_NO_MORE_DEVICES || dwError == ERROR_NO_MORE_ITEMS)
break;
}
/*
Get the required size for the
PSP_DEVICE_INTERFACE_DETAIL_DATA
structure
*/
bResult = SetupDiGetDeviceInterfaceDetail(
hDevInfo,
&spDeviceInterfaceData,
NULL,
0,
&dwRequiredSize,
NULL
);
/*
Allocate that required size
*/
if (!bResult)
{
if (ERROR_INSUFFICIENT_BUFFER == GetLastError())
{
pspDeviceInterfaceDetailData = new SP_DEVICE_INTERFACE_DETAIL_DATA[dwRequiredSize];//(PSP_DEVICE_INTERFACE_DETAIL_DATA)LocalAlloc(LPTR, dwRequiredSize);
pspDeviceInterfaceDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
}
else
break;
}
/*
Get the details on that device
*/
bResult = SetupDiGetDeviceInterfaceDetail(
hDevInfo,
&spDeviceInterfaceData,
pspDeviceInterfaceDetailData,
dwRequiredSize,
NULL,
NULL
);
if (bResult)
{
STORAGE_DEVICE_NUMBER storageDeviceNumber;
ZeroMemory(&storageDeviceNumber, sizeof(STORAGE_DEVICE_NUMBER));
storageDeviceNumber.DeviceNumber = 0;
DWORD dwSize = 0;
/*
Get the device handle
*/
HANDLE hDrive = CreateFile(
pspDeviceInterfaceDetailData->DevicePath,
GENERIC_READ,
FILE_SHARE_READ |
FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
0
);
if (hDrive != INVALID_HANDLE_VALUE)
{
/*
Get the device number
*/
bResult = DeviceIoControl(
hDrive,
IOCTL_STORAGE_GET_DEVICE_NUMBER,
NULL,
0,
&storageDeviceNumber,
sizeof(storageDeviceNumber),
&dwSize,
NULL
);
if (bResult)
{
char cDrive = GetVolumeLabelByDiskNumber(storageDeviceNumber.DeviceNumber);
if (cDrive)
{
int iIndex = cDrive - 'A';
printf("%c:\\ will be watched\n", cDrive);
tpThreads[iIndex] = new ThreadObject(Inspection, (LPVOID)cDrive);
tpThreads[iIndex]->Start();
}
}
}
CloseHandle(hDrive);
}
delete pspDeviceInterfaceDetailData;
}
}
}
SetupDiDestroyDeviceInfoList(hDevInfo);
}
示例5: if
void CMBR::setType()
{
#if 1
PARTITION_INFORMATION_EX partinfo;
DWORD read = 0;
HANDLE hDevice = m_hDevice;
if (!DeviceIoControl(hDevice, IOCTL_DISK_GET_PARTITION_INFO_EX, NULL, 0, &partinfo, sizeof(partinfo), &read, NULL))
throw "Cannot get partititon information";
m_partsize = partinfo.PartitionLength.QuadPart / geometry.BytesPerSector;
if (partinfo.PartitionStyle == PARTITION_STYLE_MBR)
{
SET_PARTITION_INFORMATION_EX setinfo;
setinfo.PartitionStyle = partinfo.PartitionStyle;
setinfo.Mbr.PartitionType = 0x13;
//if (!DeviceIoControl(hDevice, IOCTL_DISK_SET_PARTITION_INFO_EX, &setinfo, sizeof(setinfo), NULL, 0, &read, NULL))
//throw "Could not set partition type";
}
else if (partinfo.PartitionStyle == PARTITION_STYLE_GPT)
{
SET_PARTITION_INFORMATION_EX setinfo;
setinfo.PartitionStyle = partinfo.PartitionStyle;
setinfo.Gpt = partinfo.Gpt;
setinfo.Gpt.PartitionType = CFS64GUID;
if (!DeviceIoControl(hDevice, IOCTL_DISK_SET_PARTITION_INFO_EX, &setinfo, sizeof(setinfo), NULL, 0, &read, NULL))
throw "Could not set partition type";
}
else
throw "Unknown partitioning scheme";
#else
MBR thembr;
UINT64 RECORDLBA = 0;
try {
m_pPhysRawDisk->read(0, &thembr, 512);
}
catch (char* e)
{
//Probably native 4K, we can continue;
goto fullGPT;
}
//GPT support
if (thembr.entries[0].sysid == 0xEE)
{
fullGPT:
throw "GPT support is buggy";
//full GPT, we just need to search GPT tables
GPTheader* header = (GPTheader*)new BYTE[geometry.BytesPerSector];
GPTheader& theheader = *header;
m_pPhysRawDisk->read(1, &theheader, geometry.BytesPerSector);
BYTE* fullarray = new BYTE[theheader.partitionArrayLength*theheader.partitionEntrySize + geometry.BytesPerSector];
ZeroMemory(fullarray, theheader.partitionArrayLength*theheader.partitionEntrySize + geometry.BytesPerSector);
m_pPhysRawDisk->read(theheader.partitionArrayLBA, fullarray, ((theheader.partitionArrayLength*theheader.partitionEntrySize + geometry.BytesPerSector - 1) / geometry.BytesPerSector) * geometry.BytesPerSector);
GPTentry* theentry = (GPTentry*)fullarray;
bool bFound = false;
for (int n = 0; n < theheader.partitionArrayLength; n++)
{
theentry = (GPTentry*)&fullarray[n*theheader.partitionEntrySize];
if (theentry->firstLBA <= extents.Extents[0].StartingOffset.QuadPart / geometry.BytesPerSector && theentry->lastLBA >= extents.Extents[0].StartingOffset.QuadPart / geometry.BytesPerSector)
{
//We found our entry, set it as CFS64
bFound = true;
theentry->type = CFS64GUID;
break;
}
}
if (!bFound)
throw "Coud not find partition entry";
DWORD initcrc = crc32(0, NULL, 0);
theheader.partitionArrayCRC = crc32(initcrc, fullarray, theheader.partitionArrayLength*theheader.partitionEntrySize);
m_pPhysRawDisk->write(theheader.partitionArrayLBA, fullarray, ((theheader.partitionArrayLength*theheader.partitionEntrySize + geometry.BytesPerSector - 1) / geometry.BytesPerSector) * geometry.BytesPerSector);
m_pPhysRawDisk->write(theheader.lastUsableLBA + 1, fullarray, ((theheader.partitionArrayLength*theheader.partitionEntrySize + geometry.BytesPerSector - 1) / geometry.BytesPerSector) * geometry.BytesPerSector);
m_pPhysRawDisk->write(1, &theheader, geometry.BytesPerSector);
m_pPhysRawDisk->write(theheader.backupLBA, &theheader, geometry.BytesPerSector);
delete[] fullarray;
delete[] header;
return;
}
//GPT Hybrid support
if (thembr.entries[0].sysid == 0xED)
{
throw "GPT support is buggy";
//We need to set type of GPT partition AND MBR partition (if it is there)
GPTheader* header = (GPTheader*)new BYTE[geometry.BytesPerSector];
GPTheader& theheader = *header;
m_pPhysRawDisk->read(1, &theheader, geometry.BytesPerSector);
BYTE* fullarray = new BYTE[theheader.partitionArrayLength*theheader.partitionEntrySize + geometry.BytesPerSector];
ZeroMemory(fullarray, theheader.partitionArrayLength*theheader.partitionEntrySize + geometry.BytesPerSector);
m_pPhysRawDisk->read(theheader.partitionArrayLBA, fullarray, ((theheader.partitionArrayLength*theheader.partitionEntrySize + geometry.BytesPerSector - 1) / geometry.BytesPerSector) * geometry.BytesPerSector);
GPTentry* theentry = (GPTentry*)fullarray;
bool bFound = false;
for (int n = 0; n < theheader.partitionArrayLength; n++)
{
theentry = (GPTentry*)&fullarray[n*theheader.partitionEntrySize];
if (theentry->firstLBA <= extents.Extents[0].StartingOffset.QuadPart / geometry.BytesPerSector && theentry->lastLBA >= extents.Extents[0].StartingOffset.QuadPart / geometry.BytesPerSector)
{
//We found our entry, set it as CFS64
bFound = true;
theentry->type = CFS64GUID;
break;
}
}
//.........这里部分代码省略.........
示例6: TCFormatVolume
//.........这里部分代码省略.........
FALSE);
if (nStatus != 0)
{
burn (header, sizeof (header));
VirtualUnlock (header, sizeof (header));
return nStatus;
}
begin_format:
if (volParams->bDevice)
{
/* Device-hosted volume */
DWORD dwResult;
int nPass;
if (FakeDosNameForDevice (volParams->volumePath, dosDev, sizeof(dosDev), devName, sizeof(devName), FALSE) != 0)
return ERR_OS_ERROR;
if (IsDeviceMounted (devName))
{
if ((dev = DismountDrive (devName, volParams->volumePath)) == INVALID_HANDLE_VALUE)
{
Error ("FORMAT_CANT_DISMOUNT_FILESYS", hwndDlg);
nStatus = ERR_DONT_REPORT;
goto error;
}
/* Gain "raw" access to the partition (it contains a live filesystem and the filesystem driver
would otherwise prevent us from writing to hidden sectors). */
if (!DeviceIoControl (dev,
FSCTL_ALLOW_EXTENDED_DASD_IO,
NULL,
0,
NULL,
0,
&dwResult,
NULL))
{
bFailedRequiredDASD = TRUE;
}
}
else if (IsOSAtLeast (WIN_VISTA) && driveLetter == -1)
{
// Windows Vista doesn't allow overwriting sectors belonging to an unformatted partition
// to which no drive letter has been assigned under the system. This problem can be worked
// around by assigning a drive letter to the partition temporarily.
char szDriveLetter[] = { 'A', ':', 0 };
char rootPath[] = { 'A', ':', '\\', 0 };
char uniqVolName[MAX_PATH+1] = { 0 };
int tmpDriveLetter = -1;
BOOL bResult = FALSE;
tmpDriveLetter = GetFirstAvailableDrive ();
if (tmpDriveLetter != -1)
{
rootPath[0] += (char) tmpDriveLetter;
szDriveLetter[0] += (char) tmpDriveLetter;
if (DefineDosDevice (DDD_RAW_TARGET_PATH, szDriveLetter, volParams->volumePath))
{
示例7: Read
int Read(HANDLE fileHandle,unsigned long blockNumber,char *buffer,int size)
{
int status,result,blocks;
DWORD returned;
SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER commandBuffer;
ZeroMemory(&commandBuffer,sizeof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER));
/* set up the command */
commandBuffer.sptd.Length = sizeof(SCSI_PASS_THROUGH_DIRECT);
commandBuffer.sptd.SenseInfoLength = sizeof(SENSE_DATA);
commandBuffer.sptd.DataIn = SCSI_IOCTL_DATA_IN;
commandBuffer.sptd.DataTransferLength = size*512;
commandBuffer.sptd.TimeOutValue = 60;
commandBuffer.sptd.DataBuffer = buffer;
commandBuffer.sptd.SenseInfoOffset = offsetof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER,senseData);
/* now the command itself */
commandBuffer.sptd.CdbLength = 10;
commandBuffer.sptd.Cdb[0] = READ_10;
commandBuffer.sptd.Cdb[1] = (0 | DPO_LOAD_IN_CACHE | FUA_USE_CACHE | RA_ACTUAL_ADDRESS);
commandBuffer.sptd.Cdb[2] = GetByte4(blockNumber);
commandBuffer.sptd.Cdb[3] = GetByte3(blockNumber);
commandBuffer.sptd.Cdb[4] = GetByte2(blockNumber);
commandBuffer.sptd.Cdb[5] = GetByte1(blockNumber);
commandBuffer.sptd.Cdb[6] = 0;
commandBuffer.sptd.Cdb[7] = GetByte2(size);
commandBuffer.sptd.Cdb[8] = GetByte1(size);
commandBuffer.sptd.Cdb[9] = 0; /* control field (allways zero) */
/* lets send the command */
status = DeviceIoControl(fileHandle,
IOCTL_SCSI_PASS_THROUGH_DIRECT,
&commandBuffer,
sizeof(SCSI_PASS_THROUGH_DIRECT),
&commandBuffer,
sizeof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
&returned,
NULL);
/* status of the command */
if ((status && commandBuffer.sptd.ScsiStatus != 0) || !status)
{
printf("read failed.\n");
printf("Sense: %2x ASC: %2x ASCQ: %2x status: %d\n",
commandBuffer.senseData.sense_key,
commandBuffer.senseData.ASC,
commandBuffer.senseData.ASCQ,
GetLastError());
result = 0;
/* save the result code */
memcpy(&lastSenseCode,&commandBuffer.senseData,sizeof(SENSE_DATA));
return result;
}else{
return 1;
}
}
示例8: SPTIExecSCSICommand
/*
* Converts ASPI-style SRB to SCSI Pass Through IOCTL
*/
DWORD SPTIExecSCSICommand( LPSRB_ExecSCSICmd lpsrb, BOOL bBeenHereBefore )
{
BOOLEAN status;
SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER swb;
ULONG length, returned;
//BYTE i;
BYTE idx;
idx = SPTIGetDeviceIndex( lpsrb->SRB_HaID, lpsrb->SRB_Target, lpsrb->SRB_Lun );
if ( idx == 0 )
{
lpsrb->SRB_Status = SS_ERR;
return SS_ERR;
}
if ( lpsrb->CDBByte[0] == 0x12 ) // is it an INQUIRY?
{
lpsrb->SRB_Status = SS_COMP;
memcpy( lpsrb->SRB_BufPointer, sptiglobal.drive[idx].inqData, 36 );
return SS_COMP;
}
if ( sptiglobal.drive[idx].hDevice == INVALID_HANDLE_VALUE )
sptiglobal.drive[idx].hDevice = GetFileHandle( sptiglobal.drive[idx].driveLetter );
ZeroMemory( &swb, sizeof(swb) );
swb.spt.Length = sizeof(SCSI_PASS_THROUGH);
swb.spt.CdbLength = lpsrb->SRB_CDBLen;
if ( lpsrb->SRB_Flags & SRB_DIR_IN )
swb.spt.DataIn = SCSI_IOCTL_DATA_IN;
else if ( lpsrb->SRB_Flags & SRB_DIR_OUT )
swb.spt.DataIn = SCSI_IOCTL_DATA_OUT;
else
swb.spt.DataIn = SCSI_IOCTL_DATA_UNSPECIFIED;
swb.spt.DataTransferLength = lpsrb->SRB_BufLen;
swb.spt.TimeOutValue = 5;
swb.spt.DataBuffer = lpsrb->SRB_BufPointer;
swb.spt.SenseInfoOffset =
offsetof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf );
memcpy( swb.spt.Cdb, lpsrb->CDBByte, lpsrb->SRB_CDBLen );
length = sizeof(swb);
#ifdef _DEBUG_SCSIPT
dbprintf( "AKRip32: SPTIExecSCSICmd: calling DeviceIoControl()\n" );
dbprintf( " : cmd == 0x%02X\n", swb.spt.Cdb[0] );
#endif
status = DeviceIoControl( sptiglobal.drive[idx].hDevice,
IOCTL_SCSI_PASS_THROUGH_DIRECT,
&swb,
length,
&swb,
length,
&returned,
NULL );
if ( status )
{
lpsrb->SRB_Status = SS_COMP;
#ifdef _DEBUG_SCSIPT
OutputDebugString( " : SRB_Status == SS_COMP" );
#endif
}
else
{
DWORD dwErrCode;
lpsrb->SRB_Status = SS_ERR;
lpsrb->SRB_TargStat = 0x0004;
dwErrCode = GetLastError();
#ifdef _DEBUG_SCSIPT
dbprintf( " : error == %d handle == %08X\n", dwErrCode, sptiglobal.drive[idx].hDevice );
#endif
/*
* KLUDGE ALERT! KLUDGE ALERT! KLUDGE ALERT!
* Whenever a disk changer switches disks, it may render the device
* handle invalid. We try to catch these errors here and recover
* from them.
*/
if ( !bBeenHereBefore &&
((dwErrCode == ERROR_MEDIA_CHANGED) || (dwErrCode == ERROR_INVALID_HANDLE)) )
{
if ( dwErrCode != ERROR_INVALID_HANDLE )
CloseHandle( sptiglobal.drive[idx].hDevice );
SPT_GetDriveInformation( idx, &sptiglobal.drive[idx] );
#ifdef _DEBUG_SCSIPT
dbprintf( "AKRip32: SPTIExecSCSICommand: Retrying after ERROR_MEDIA_CHANGED\n" );
#endif
return SPTIExecSCSICommand( lpsrb, TRUE );
}
}
return lpsrb->SRB_Status;
}
示例9: GetDriveLetter
/*
* Returns the first drive letter for a volume located on the drive identified by DriveIndex
* TODO: should we return all the drive letters?
*/
char GetDriveLetter(DWORD DriveIndex)
{
DWORD size;
BOOL r;
STORAGE_DEVICE_NUMBER_REDEF device_number = {0};
UINT drive_type;
HANDLE hDrive = INVALID_HANDLE_VALUE;
char *drive, drives[26*4]; /* "D:\", "E:\", etc. */
char logical_drive[] = "\\\\.\\#:";
char drive_letter = ' ';
CheckDriveIndex(DriveIndex);
size = GetLogicalDriveStringsA(sizeof(drives), drives);
if (size == 0) {
uprintf("GetLogicalDriveStrings failed: %s\n", WindowsErrorString());
goto out;
}
if (size > sizeof(drives)) {
uprintf("GetLogicalDriveStrings: buffer too small (required %d vs %d)\n", size, sizeof(drives));
goto out;
}
for (drive = drives ;*drive; drive += safe_strlen(drive)+1) {
if (!isalpha(*drive))
continue;
*drive = (char)toupper((int)*drive);
if (*drive < 'C') {
continue;
}
/* IOCTL_STORAGE_GET_DEVICE_NUMBER's STORAGE_DEVICE_NUMBER.DeviceNumber is
not unique! An HDD, a DVD and probably other drives can have the same
value there => Use GetDriveType() to filter out unwanted devices.
See https://github.com/pbatard/rufus/issues/32 for details. */
drive_type = GetDriveTypeA(drive);
// NB: the HP utility allows drive_type == DRIVE_FIXED, which we don't allow by default
// Using Alt-F in Rufus does enable listing, but this mode is unsupported.
if ((drive_type != DRIVE_REMOVABLE) && ((!enable_fixed_disks) || (drive_type != DRIVE_FIXED)))
continue;
safe_sprintf(logical_drive, sizeof(logical_drive), "\\\\.\\%c:", drive[0]);
hDrive = CreateFileA(logical_drive, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
if (hDrive == INVALID_HANDLE_VALUE) {
uprintf("Warning: could not open drive %c: %s\n", drive[0], WindowsErrorString());
continue;
}
r = DeviceIoControl(hDrive, IOCTL_STORAGE_GET_DEVICE_NUMBER, NULL,
0, &device_number, sizeof(device_number), &size, NULL);
safe_closehandle(hDrive);
if ((!r) || (size <= 0)) {
uprintf("Could not get device number for device %s: %s\n",
logical_drive, WindowsErrorString());
} else if (device_number.DeviceNumber == DriveIndex) {
drive_letter = *drive;
break;
}
}
out:
return drive_letter;
}
示例10: GetDrivePartitionData
/*
* Fill the drive properties (size, FS, etc)
*/
BOOL GetDrivePartitionData(DWORD DriveIndex, char* FileSystemName, DWORD FileSystemNameSize)
{
BOOL r;
HANDLE hPhysical;
DWORD size;
BYTE geometry[128], layout[1024], part_type;
void* disk_geometry = (void*)geometry;
void* drive_layout = (void*)layout;
PDISK_GEOMETRY_EX DiskGeometry = (PDISK_GEOMETRY_EX)disk_geometry;
PDRIVE_LAYOUT_INFORMATION_EX DriveLayout = (PDRIVE_LAYOUT_INFORMATION_EX)drive_layout;
char* volume_name;
char tmp[256];
DWORD i, nb_partitions = 0;
hPhysical = GetPhysicalHandle(DriveIndex, FALSE, FALSE);
if (hPhysical == INVALID_HANDLE_VALUE)
return FALSE;
r = DeviceIoControl(hPhysical, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX,
NULL, 0, geometry, sizeof(geometry), &size, NULL);
if (!r || size <= 0) {
uprintf("Could not get geometry for drive #%d: %s\n", DriveIndex, WindowsErrorString());
safe_closehandle(hPhysical);
return FALSE;
}
SelectedDrive.DiskSize = DiskGeometry->DiskSize.QuadPart;
memcpy(&SelectedDrive.Geometry, &DiskGeometry->Geometry, sizeof(DISK_GEOMETRY));
uprintf("Sector Size: %d bytes\n", DiskGeometry->Geometry.BytesPerSector);
uprintf("Cylinders: %lld, TracksPerCylinder: %d, SectorsPerTrack: %d\n",
DiskGeometry->Geometry.Cylinders, DiskGeometry->Geometry.TracksPerCylinder, DiskGeometry->Geometry.SectorsPerTrack);
r = DeviceIoControl(hPhysical, IOCTL_DISK_GET_DRIVE_LAYOUT_EX,
NULL, 0, layout, sizeof(layout), &size, NULL );
if (!r || size <= 0) {
uprintf("Could not get layout for drive #d: %s\n", DriveIndex, WindowsErrorString());
return FALSE;
}
switch (DriveLayout->PartitionStyle) {
case PARTITION_STYLE_MBR:
SelectedDrive.PartitionType = PARTITION_STYLE_MBR;
for (i=0; i<DriveLayout->PartitionCount; i++) {
if (DriveLayout->PartitionEntry[i].Mbr.PartitionType != PARTITION_ENTRY_UNUSED) {
nb_partitions++;
}
}
uprintf("Partition type: MBR, NB Partitions: %d\n", nb_partitions);
SelectedDrive.has_mbr_uefi_marker = (DriveLayout->Mbr.Signature == MBR_UEFI_MARKER);
uprintf("Disk ID: 0x%08X %s\n", DriveLayout->Mbr.Signature, SelectedDrive.has_mbr_uefi_marker?"(UEFI target)":"");
for (i=0; i<DriveLayout->PartitionCount; i++) {
if (DriveLayout->PartitionEntry[i].Mbr.PartitionType != PARTITION_ENTRY_UNUSED) {
uprintf("Partition %d:\n", DriveLayout->PartitionEntry[i].PartitionNumber);
part_type = DriveLayout->PartitionEntry[i].Mbr.PartitionType;
uprintf(" Type: %s (0x%02x)\r\n Size: %s (%lld bytes)\r\n Start Sector: %d, Boot: %s, Recognized: %s\n",
GetPartitionType(part_type), part_type, SizeToHumanReadable(DriveLayout->PartitionEntry[i].PartitionLength),
DriveLayout->PartitionEntry[i].PartitionLength, DriveLayout->PartitionEntry[i].Mbr.HiddenSectors,
DriveLayout->PartitionEntry[i].Mbr.BootIndicator?"Yes":"No",
DriveLayout->PartitionEntry[i].Mbr.RecognizedPartition?"Yes":"No");
if (part_type == 0xee) // Flag a protective MBR for non GPT platforms (XP)
SelectedDrive.has_protective_mbr = TRUE;
}
}
break;
case PARTITION_STYLE_GPT:
SelectedDrive.PartitionType = PARTITION_STYLE_GPT;
uprintf("Partition type: GPT, NB Partitions: %d\n", DriveLayout->PartitionCount);
uprintf("Disk GUID: %s\n", GuidToString(&DriveLayout->Gpt.DiskId));
uprintf("Max parts: %d, Start Offset: %lld, Usable = %lld bytes\n",
DriveLayout->Gpt.MaxPartitionCount, DriveLayout->Gpt.StartingUsableOffset.QuadPart, DriveLayout->Gpt.UsableLength.QuadPart);
for (i=0; i<DriveLayout->PartitionCount; i++) {
nb_partitions++;
tmp[0] = 0;
wchar_to_utf8_no_alloc(DriveLayout->PartitionEntry[i].Gpt.Name, tmp, sizeof(tmp));
uprintf("Partition %d:\r\n Type: %s\r\n Name: '%s'\n", DriveLayout->PartitionEntry[i].PartitionNumber,
GuidToString(&DriveLayout->PartitionEntry[i].Gpt.PartitionType), tmp);
uprintf(" ID: %s\r\n Size: %s (%lld bytes)\r\n Start Sector: %lld, Attributes: 0x%016llX\n",
GuidToString(&DriveLayout->PartitionEntry[i].Gpt.PartitionId), SizeToHumanReadable(DriveLayout->PartitionEntry[i].PartitionLength),
DriveLayout->PartitionEntry[i].PartitionLength, DriveLayout->PartitionEntry[i].StartingOffset.QuadPart / DiskGeometry->Geometry.BytesPerSector,
DriveLayout->PartitionEntry[i].Gpt.Attributes);
}
break;
default:
SelectedDrive.PartitionType = PARTITION_STYLE_MBR;
uprintf("Partition type: RAW\n");
break;
}
safe_closehandle(hPhysical);
// Populate the filesystem data
volume_name = GetLogicalName(DriveIndex, TRUE);
if ((volume_name == NULL) || (!GetVolumeInformationA(volume_name, NULL, 0, NULL, NULL, NULL, FileSystemName, FileSystemNameSize))) {
uprintf("Did not get volume information for disk 0x%02x\n", DriveIndex);
FileSystemName[0] = 0;
}
safe_free(volume_name);
return TRUE;
//.........这里部分代码省略.........
示例11: xnUSBOpenEndPoint
XN_C_API XnStatus xnUSBOpenEndPoint(XN_USB_DEV_HANDLE pDevHandle, XnUInt16 nEndPointID, XnUSBEndPointType nEPType, XnUSBDirectionType nDirType, XN_USB_EP_HANDLE* pEPHandlePtr)
{
// Local variables
XnBool bResult = TRUE;
XnStatus nRetVal = XN_STATUS_OK;
XnInt32 nRetBytes = 0;
XnChar pConfigDescBuf[MAX_CONFIG_DESC_SIZE];
XnChar* pBuf = NULL;
PUSB_CONFIGURATION_DESCRIPTOR pUSBConfigDesc = NULL;
PUSB_INTERFACE_DESCRIPTOR pUSBInterfaceDesc = NULL;
PUSB_ENDPOINT_DESCRIPTOR pUSBEndPointDesc = NULL;
XN_USB_EP_HANDLE pEPHandle = NULL;
XnChar cpPipeID[3];
// Validate xnUSB
XN_VALIDATE_USB_INIT();
XN_VALIDATE_USB_PDEV_HANDLE(pDevHandle);
// Validate the input/output pointers
XN_VALIDATE_OUTPUT_PTR(pEPHandlePtr);
// Allocate a new xnUSB EP handle
XN_VALIDATE_ALIGNED_CALLOC(*pEPHandlePtr, xnUSBEPHandle, 1, XN_DEFAULT_MEM_ALIGN);
pEPHandle = *pEPHandlePtr;
// Read the config descriptor
bResult = DeviceIoControl(pDevHandle->hUSBDevHandle, IOCTL_PSDRV_GET_CONFIG_DESCRIPTOR, pConfigDescBuf, sizeof(pConfigDescBuf), pConfigDescBuf, sizeof(pConfigDescBuf), (PULONG)&nRetBytes, NULL);
if (bResult)
{
XnUInt32 nIFIdx = 0;
UCHAR nEPIdx = 0;
XnUInt32 nUBBEPType = 0;
XnUInt32 nCurrIF = 0;
pBuf = pConfigDescBuf;
pUSBConfigDesc = (PUSB_CONFIGURATION_DESCRIPTOR)pBuf;
pBuf += pUSBConfigDesc->bLength;
// Scan all the interfaces
do {
pUSBInterfaceDesc = (PUSB_INTERFACE_DESCRIPTOR)pBuf;
pBuf += pUSBInterfaceDesc->bLength;
// Scan all the endpoints
for (nEPIdx = 0; nEPIdx < pUSBInterfaceDesc->bNumEndpoints; nEPIdx++)
{
pUSBEndPointDesc = (PUSB_ENDPOINT_DESCRIPTOR)pBuf;
// Is this the EP we're looking for?
if ((pUSBEndPointDesc->bEndpointAddress == nEndPointID) && (pDevHandle->nAltInterface == nCurrIF))
{
// Get the EP type
nUBBEPType = pUSBEndPointDesc->bmAttributes & USB_ENDPOINT_TYPE_MASK;
// Verify that the EP type matches the requested EP
if (nEPType == XN_USB_EP_BULK)
{
if (nUBBEPType != USB_ENDPOINT_TYPE_BULK)
{
XN_ALIGNED_FREE_AND_NULL(pEPHandle);
return (XN_STATUS_USB_WRONG_ENDPOINT_TYPE);
}
}
else if (nEPType == XN_USB_EP_INTERRUPT)
{
if (nUBBEPType != USB_ENDPOINT_TYPE_INTERRUPT)
{
XN_ALIGNED_FREE_AND_NULL(pEPHandle);
return (XN_STATUS_USB_WRONG_ENDPOINT_TYPE);
}
}
else if (nEPType == XN_USB_EP_ISOCHRONOUS)
{
if (nUBBEPType != USB_ENDPOINT_TYPE_ISOCHRONOUS)
{
XN_ALIGNED_FREE_AND_NULL(pEPHandle);
return (XN_STATUS_USB_WRONG_ENDPOINT_TYPE);
}
}
else
{
XN_ALIGNED_FREE_AND_NULL(pEPHandle);
return (XN_STATUS_USB_UNKNOWN_ENDPOINT_TYPE);
}
// Verify that the EP direction matches the requested direction
if (nDirType == XN_USB_DIRECTION_IN)
{
if (USB_ENDPOINT_DIRECTION_IN(pUSBEndPointDesc->bEndpointAddress) == FALSE)
{
XN_ALIGNED_FREE_AND_NULL(pEPHandle);
return (XN_STATUS_USB_WRONG_ENDPOINT_DIRECTION);
}
}
else if (nDirType == XN_USB_DIRECTION_OUT)
{
if (USB_ENDPOINT_DIRECTION_OUT(pUSBEndPointDesc->bEndpointAddress) == FALSE)
//.........这里部分代码省略.........
示例12: GetLogicalName
// Return the first GUID volume name for the associated drive or NULL if not found
// See http://msdn.microsoft.com/en-us/library/cc542456.aspx
// The returned string is allocated and must be freed
// TODO: a drive may have multiple volumes - should we handle those?
char* GetLogicalName(DWORD DriveIndex, BOOL bKeepTrailingBackslash)
{
BOOL success = FALSE;
char volume_name[MAX_PATH];
HANDLE hDrive = INVALID_HANDLE_VALUE, hVolume = INVALID_HANDLE_VALUE;
size_t len;
char path[MAX_PATH];
VOLUME_DISK_EXTENTS DiskExtents;
DWORD size;
UINT drive_type;
int i, j;
static const char* ignore_device[] = { "\\Device\\CdRom", "\\Device\\Floppy" };
CheckDriveIndex(DriveIndex);
for (i=0; hDrive == INVALID_HANDLE_VALUE; i++) {
if (i == 0) {
hVolume = FindFirstVolumeA(volume_name, sizeof(volume_name));
if (hVolume == INVALID_HANDLE_VALUE) {
uprintf("Could not access first GUID volume: %s\n", WindowsErrorString());
goto out;
}
} else {
if (!FindNextVolumeA(hVolume, volume_name, sizeof(volume_name))) {
if (GetLastError() != ERROR_NO_MORE_FILES) {
uprintf("Could not access next GUID volume: %s\n", WindowsErrorString());
}
goto out;
}
}
// Sanity checks
len = safe_strlen(volume_name);
if ((len <= 1) || (safe_strnicmp(volume_name, "\\\\?\\", 4) != 0) || (volume_name[len-1] != '\\')) {
uprintf("'%s' is not a GUID volume name\n", volume_name);
continue;
}
drive_type = GetDriveTypeA(volume_name);
// NB: the HP utility allows drive_type == DRIVE_FIXED, which we don't allow by default
// Using Alt-F in Rufus does enable listing, but this mode is unsupported.
if ((drive_type != DRIVE_REMOVABLE) && ((!enable_fixed_disks) || (drive_type != DRIVE_FIXED)))
continue;
volume_name[len-1] = 0;
if (QueryDosDeviceA(&volume_name[4], path, sizeof(path)) == 0) {
uprintf("Failed to get device path for GUID volume '%s': %s\n", volume_name, WindowsErrorString());
continue;
}
for (j=0; (j<ARRAYSIZE(ignore_device)) &&
(safe_strnicmp(path, ignore_device[j], safe_strlen(ignore_device[j])) != 0); j++);
if (j < ARRAYSIZE(ignore_device)) {
uprintf("Skipping GUID volume for '%s'\n", path);
continue;
}
// If we can't have FILE_SHARE_WRITE, forget it
hDrive = CreateFileA(volume_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0);
if (hDrive == INVALID_HANDLE_VALUE) {
uprintf("Could not open GUID volume '%s': %s\n", volume_name, WindowsErrorString());
continue;
}
if ((!DeviceIoControl(hDrive, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, NULL, 0,
&DiskExtents, sizeof(DiskExtents), &size, NULL)) || (size <= 0)) {
uprintf("Could not get Disk Extents: %s\n", WindowsErrorString());
safe_closehandle(hDrive);
continue;
}
safe_closehandle(hDrive);
if ((DiskExtents.NumberOfDiskExtents >= 1) && (DiskExtents.Extents[0].DiskNumber == DriveIndex)) {
if (bKeepTrailingBackslash)
volume_name[len-1] = '\\';
success = TRUE;
break;
}
}
out:
if (hVolume != INVALID_HANDLE_VALUE)
FindVolumeClose(hVolume);
return (success)?safe_strdup(volume_name):NULL;
}
示例13: ioctl_ReadSectors
/****************************************************************************
* ioctl_ReadSector: Read VCD or CDDA sectors
****************************************************************************/
int ioctl_ReadSectors( vlc_object_t *p_this, const vcddev_t *p_vcddev,
int i_sector, uint8_t *p_buffer, int i_nb, int i_type )
{
uint8_t *p_block;
int i;
if( i_type == VCD_TYPE )
p_block = malloc( VCD_SECTOR_SIZE * i_nb );
else
p_block = p_buffer;
if( p_vcddev->i_vcdimage_handle != -1 )
{
/*
* vcd image mode
*/
if( lseek( p_vcddev->i_vcdimage_handle, i_sector * VCD_SECTOR_SIZE,
SEEK_SET ) == -1 )
{
msg_Err( p_this, "Could not lseek to sector %d", i_sector );
goto error;
}
if( read( p_vcddev->i_vcdimage_handle, p_block, VCD_SECTOR_SIZE * i_nb)
== -1 )
{
msg_Err( p_this, "Could not read sector %d", i_sector );
goto error;
}
}
else
{
/*
* vcd device mode
*/
#if defined( __APPLE__ )
dk_cd_read_t cd_read;
memset( &cd_read, 0, sizeof(cd_read) );
cd_read.offset = i_sector * VCD_SECTOR_SIZE;
cd_read.sectorArea = kCDSectorAreaSync | kCDSectorAreaHeader |
kCDSectorAreaSubHeader | kCDSectorAreaUser |
kCDSectorAreaAuxiliary;
cd_read.sectorType = kCDSectorTypeUnknown;
cd_read.buffer = p_block;
cd_read.bufferLength = VCD_SECTOR_SIZE * i_nb;
if( ioctl( p_vcddev->i_device_handle, DKIOCCDREAD, &cd_read ) == -1 )
{
msg_Err( p_this, "could not read block %d", i_sector );
goto error;
}
#elif defined( _WIN32 )
DWORD dwBytesReturned;
RAW_READ_INFO cdrom_raw;
/* Initialize CDROM_RAW_READ structure */
cdrom_raw.DiskOffset.QuadPart = CD_SECTOR_SIZE * i_sector;
cdrom_raw.SectorCount = i_nb;
cdrom_raw.TrackMode = i_type == VCD_TYPE ? XAForm2 : CDDA;
if( DeviceIoControl( p_vcddev->h_device_handle, IOCTL_CDROM_RAW_READ,
&cdrom_raw, sizeof(RAW_READ_INFO), p_block,
VCD_SECTOR_SIZE * i_nb, &dwBytesReturned,
NULL ) == 0 )
{
if( i_type == VCD_TYPE )
{
/* Retry in YellowMode2 */
cdrom_raw.TrackMode = YellowMode2;
if( DeviceIoControl( p_vcddev->h_device_handle,
IOCTL_CDROM_RAW_READ, &cdrom_raw,
sizeof(RAW_READ_INFO), p_block,
VCD_SECTOR_SIZE * i_nb, &dwBytesReturned,
NULL ) == 0 )
goto error;
}
else return -1;
}
#elif defined( __OS2__ )
cdrom_readlong_t readlong = {{'C', 'D', '0', '1'}, };
ULONG param_len;
ULONG data_len;
ULONG rc;
readlong.addr_mode = 0; /* LBA mode */
readlong.sectors = i_nb;
readlong.start = i_sector;
//.........这里部分代码省略.........
示例14: ioctl_GetTracksMap
/*****************************************************************************
* ioctl_GetTracksMap: Read the Table of Content, fill in the pp_sectors map
* if pp_sectors is not null and return the number of
* tracks available.
*****************************************************************************/
int ioctl_GetTracksMap( vlc_object_t *p_this, const vcddev_t *p_vcddev,
int **pp_sectors )
{
int i_tracks = 0;
if( p_vcddev->i_vcdimage_handle != -1 )
{
/*
* vcd image mode
*/
i_tracks = p_vcddev->i_tracks;
if( pp_sectors )
{
*pp_sectors = calloc( i_tracks + 1, sizeof(**pp_sectors) );
if( *pp_sectors == NULL )
return 0;
memcpy( *pp_sectors, p_vcddev->p_sectors,
(i_tracks + 1) * sizeof(**pp_sectors) );
}
return i_tracks;
}
else
{
/*
* vcd device mode
*/
#if defined( __APPLE__ )
CDTOC *pTOC;
int i_descriptors;
if( ( pTOC = darwin_getTOC( p_this, p_vcddev ) ) == NULL )
{
msg_Err( p_this, "failed to get the TOC" );
return 0;
}
i_descriptors = CDTOCGetDescriptorCount( pTOC );
i_tracks = darwin_getNumberOfTracks( pTOC, i_descriptors );
if( pp_sectors )
{
int i, i_leadout = -1;
CDTOCDescriptor *pTrackDescriptors;
u_char track;
*pp_sectors = calloc( i_tracks + 1, sizeof(**pp_sectors) );
if( *pp_sectors == NULL )
{
darwin_freeTOC( pTOC );
return 0;
}
pTrackDescriptors = pTOC->descriptors;
for( i_tracks = 0, i = 0; i < i_descriptors; i++ )
{
track = pTrackDescriptors[i].point;
if( track == 0xA2 )
i_leadout = i;
if( track > CD_MAX_TRACK_NO || track < CD_MIN_TRACK_NO )
continue;
(*pp_sectors)[i_tracks++] =
CDConvertMSFToLBA( pTrackDescriptors[i].p );
}
if( i_leadout == -1 )
{
msg_Err( p_this, "leadout not found" );
free( *pp_sectors );
darwin_freeTOC( pTOC );
return 0;
}
/* set leadout sector */
(*pp_sectors)[i_tracks] =
CDConvertMSFToLBA( pTrackDescriptors[i_leadout].p );
}
darwin_freeTOC( pTOC );
#elif defined( _WIN32 )
DWORD dwBytesReturned;
CDROM_TOC cdrom_toc;
if( DeviceIoControl( p_vcddev->h_device_handle, IOCTL_CDROM_READ_TOC,
NULL, 0, &cdrom_toc, sizeof(CDROM_TOC),
//.........这里部分代码省略.........
示例15: LsBusCtlPlugInEx
LSBUSCTLAPI BOOL WINAPI
LsBusCtlPlugInEx(
ULONG SlotNo,
ULONG MaxRequestBlocks,
HANDLE hEvent,
HANDLE hAlarmEvent)
{
BOOL fSuccess = FALSE;
HANDLE hDevice = INVALID_HANDLE_VALUE;
DWORD cbReturned = 0;
DWORD err;
PBUSENUM_PLUGIN_HARDWARE_EX pLanscsiPluginData;
DWORD cbLanscsiPluginData = 0;
DebugPrint(1, _T("LsBusCtlPlugInEx: Slot %d, MaxRequestBlock %d, hEvent %p, hAlarmEvent %p\n"),
SlotNo, MaxRequestBlocks, hEvent, hAlarmEvent);
hDevice = OpenBusInterface();
if(INVALID_HANDLE_VALUE == hDevice) {
return FALSE;
}
cbLanscsiPluginData = sizeof (BUSENUM_PLUGIN_HARDWARE_EX) +
LSMINIPORT_HARDWARE_IDS_W_SIZE;
pLanscsiPluginData = HeapAlloc(
GetProcessHeap(),
HEAP_ZERO_MEMORY,
cbLanscsiPluginData);
//
// The size field should be set to the sizeof the struct as declared
// and *not* the size of the struct plus the multi_sz
//
pLanscsiPluginData->Size = sizeof(BUSENUM_PLUGIN_HARDWARE_EX);
pLanscsiPluginData->SlotNo = SlotNo;
pLanscsiPluginData->MaxRequestBlocks = MaxRequestBlocks;
pLanscsiPluginData->phEvent = &hEvent;
pLanscsiPluginData->phAlarmEvent = &hAlarmEvent;
CopyMemory(
pLanscsiPluginData->HardwareIDs,
LSMINIPORT_HARDWARE_IDS_W,
LSMINIPORT_HARDWARE_IDS_W_SIZE);
fSuccess = DeviceIoControl (
hDevice,
IOCTL_BUSENUM_PLUGIN_HARDWARE_EX,
pLanscsiPluginData,
cbLanscsiPluginData,
pLanscsiPluginData,
cbLanscsiPluginData,
&cbReturned,
NULL);
if (!fSuccess) {
DebugPrintErrEx(_T("LsBusCtlPlugInEx at slot %d failed: "), SlotNo);
} else {
DebugPrintErrEx(_T("LsBusCtlPlugInEx at slot %d completed successfully.\n"), SlotNo);
}
err = GetLastError();
HeapFree(GetProcessHeap(), 0, pLanscsiPluginData);
CloseHandle(hDevice);
SetLastError(err);
return fSuccess;
}