📄 tapewmi.c
字号:
GuidIndex is the index into the list of guids provided when the
device registered
Function specifies which functionality is being enabled or disabled
Enable is TRUE then the function is being enabled else disabled
Return Value:
status
--*/
{
NTSTATUS status = STATUS_SUCCESS;
PCOMMON_DEVICE_EXTENSION commonExtension = DeviceObject->DeviceExtension;
PFUNCTIONAL_DEVICE_EXTENSION fdoExtension = DeviceObject->DeviceExtension;
PAGED_CODE();
//
// We handle only enable\disable tape drive problem warning events,
// query data blocks.
//
if ((Function == EventGeneration) &&
(GuidIndex == TapeDriveProblemWarningGuid)) {
DebugPrint((3,
"TapeWmiFunctionControl : DeviceObject %p, Irp %p, ",
"GuidIndex %d. Event Generation %s\n",
DeviceObject, Irp, GuidIndex,
Enable ? "Enabled" : "Disabled"));
status = TapeEnableDisableDrivePolling(fdoExtension,
Enable,
TAPE_DRIVE_POLLING_PERIOD);
} else if (Function == DataBlockCollection) {
DebugPrint((3,
"TapeWmiFunctionControl : Irp %p - %s DataBlockCollection",
" for Device %p.\n",
Irp, Enable ? "Enable " : "Disable ", DeviceObject));
status = STATUS_SUCCESS;
} else {
DebugPrint((3,
"TapeWmiFunctionControl : Unknown function %d for ",
"Device %p, Irp %p\n",
Function, DeviceObject, Irp));
status = STATUS_INVALID_DEVICE_REQUEST;
}
status = ClassWmiCompleteRequest(DeviceObject,
Irp,
status,
0,
IO_NO_INCREMENT);
return status;
}
NTSTATUS
TapeSetWmiDataBlock(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN ULONG GuidIndex,
IN ULONG BufferSize,
IN PUCHAR Buffer
)
/*+
Routine Description :
This routine is called to set the contents of a datablock.
When the driver is finished setting the buffer, it must call
ClassWmiCompleteRequest to complete the irp. The driver can
return STATUS_PENDING if the irp cannot be completed immediately.
Arguments :
Device object of the device being referred.
Irp is the WMI Irp
GuidIndex is the index of the guid for which the data is being set
BufferSize is the size of the data block
Buffer is the pointer to the data block
Return valus :
NTSTATUS returned by ClassWmiCompleteRequest
STATUS_WMI_READ_ONLY if the datablock cannot be modified.
STATUS_WMI_GUID_NOT_FOUND if an invalid guid index is passed
-*/
{
NTSTATUS status = STATUS_WMI_READ_ONLY;
PAGED_CODE();
DebugPrint((3, "TapeWmiSetBlock : Device %p, Irp %p, GuidIndex %d\n",
DeviceObject, Irp, GuidIndex));
if (GuidIndex > TapeSymbolicNameGuid) {
status = STATUS_WMI_GUID_NOT_FOUND;
}
status = ClassWmiCompleteRequest(DeviceObject,
Irp,
status,
0,
IO_NO_INCREMENT);
DebugPrint((3, "TapeSetWmiDataBlock : Device %p, Irp %p returns %lx\n",
DeviceObject, Irp, status));
return status;
}
NTSTATUS
TapeSetWmiDataItem(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN ULONG GuidIndex,
IN ULONG DataItemId,
IN ULONG BufferSize,
IN PUCHAR Buffer
)
/*++
Routine Description:
This routine is a callback into the driver to query for the contents of
a data block. When the driver has finished filling the data block it
must call ClassWmiCompleteRequest to complete the irp. The driver can
return STATUS_PENDING if the irp cannot be completed immediately.
Arguments:
DeviceObject is the device whose data block is being queried
Irp is the Irp that makes this request
GuidIndex is the index into the list of guids provided when the
device registered
DataItemId has the id of the data item being set
BufferSize has the size of the data item passed
Buffer has the new values for the data item
Return Value:
NTSTATUS returned by ClassWmiCompleteRequest
STATUS_WMI_READ_ONLY if the datablock cannot be modified.
STATUS_WMI_GUID_NOT_FOUND if an invalid guid index is passed
-*/
{
NTSTATUS status = STATUS_WMI_READ_ONLY;
PAGED_CODE();
DebugPrint((3, "TapeSetWmiDataItem, Device %p, Irp %p, GuiIndex %d",
" BufferSize %#x Buffer %p\n",
DeviceObject, Irp,
GuidIndex, DataItemId,
BufferSize, Buffer));
if (GuidIndex > TapeSymbolicNameGuid) {
status = STATUS_WMI_GUID_NOT_FOUND;
}
status = ClassWmiCompleteRequest(DeviceObject,
Irp,
status,
0,
IO_NO_INCREMENT);
DebugPrint((3, "TapeSetWmiDataItem Device %p, Irp %p returns %lx\n",
DeviceObject, Irp, status));
return status;
}
NTSTATUS
TapeEnableDisableDrivePolling(
IN PFUNCTIONAL_DEVICE_EXTENSION fdoExtension,
IN BOOLEAN Enable,
IN ULONG PollingTimeInSeconds
)
/*++
Routine Description:
Enable or disable polling to check for drive problems.
Arguments:
FdoExtension Device extension
Enable TRUE if polling is to be enabled. FALSE otherwise.
PollTimeInSeconds - if 0 then no change to current polling timer
Return Value:
NT Status
--*/
{
NTSTATUS status;
FAILURE_PREDICTION_METHOD failurePredictionMethod;
PAGED_CODE();
//
// Failure prediction is done through IOCTL_STORAGE_PREDICT_FAILURE
//
if (Enable) {
failurePredictionMethod = FailurePredictionIoctl;
} else {
failurePredictionMethod = FailurePredictionNone;
}
status = ClassSetFailurePredictionPoll(fdoExtension,
failurePredictionMethod,
PollingTimeInSeconds);
return status;
}
NTSTATUS
TapeWMIControl(
IN PDEVICE_OBJECT DeviceObject,
IN TAPE_PROCESS_COMMAND_ROUTINE commandRoutine,
OUT PUCHAR Buffer
)
/*++
Routine Description:
This is the class routine to handle WMI requests. It handles all query
requests.
Arguments:
DeviceObject The device object
commandRoutine minidriver routine to call.
Buffer Pointer to the buffer
Return Value:
NT Status
--*/
{
PFUNCTIONAL_DEVICE_EXTENSION fdoExtension = DeviceObject->DeviceExtension;
PTAPE_DATA tapeData= (PTAPE_DATA) (fdoExtension->CommonExtension.DriverData);
PTAPE_INIT_DATA_EX tapeInitData = &tapeData->TapeInitData;
PVOID minitapeExtension = tapeData + 1;
NTSTATUS status = STATUS_SUCCESS;
TAPE_STATUS lastError;
TAPE_STATUS tapeStatus;
ULONG callNumber;
PVOID commandExtension;
ULONG retryFlags;
ULONG numRetries;
SCSI_REQUEST_BLOCK srb;
BOOLEAN writeToDevice;
PAGED_CODE();
//
// Verify if the minidriver supports WMI operations
//
if (commandRoutine == NULL) {
DebugPrint((1,
"TapeWMIControl : DeviceObject %d does not support WMI\n"));
return STATUS_WMI_NOT_SUPPORTED;
}
if (tapeInitData->CommandExtensionSize) {
commandExtension = ExAllocatePool(NonPagedPool,
tapeInitData->CommandExtensionSize);
} else {
commandExtension = NULL;
}
RtlZeroMemory(&srb, sizeof(SCSI_REQUEST_BLOCK));
lastError = TAPE_STATUS_SUCCESS ;
for (callNumber = 0; ;callNumber++) {
srb.TimeOutValue = fdoExtension->TimeOutValue;
srb.SrbFlags = 0;
retryFlags = 0;
tapeStatus = commandRoutine(minitapeExtension,
commandExtension,
Buffer,
&srb,
callNumber,
lastError,
&retryFlags);
lastError = TAPE_STATUS_SUCCESS ;
numRetries = retryFlags & TAPE_RETRY_MASK;
if (tapeStatus == TAPE_STATUS_CHECK_TEST_UNIT_READY) {
PCDB cdb = (PCDB)srb.Cdb;
//
// Prepare SCSI command (CDB)
//
TapeClassZeroMemory(srb.Cdb, MAXIMUM_CDB_SIZE);
srb.CdbLength = CDB6GENERIC_LENGTH;
cdb->CDB6GENERIC.OperationCode = SCSIOP_TEST_UNIT_READY;
srb.DataTransferLength = 0 ;
DebugPrint((3,"Test Unit Ready\n"));
} else if (tapeStatus == TAPE_STATUS_CALLBACK) {
lastError = TAPE_STATUS_CALLBACK ;
continue;
} else if (tapeStatus != TAPE_STATUS_SEND_SRB_AND_CALLBACK) {
break;
}
if (srb.DataBuffer && !srb.DataTransferLength) {
ScsiTapeFreeSrbBuffer(&srb);
}
if (srb.DataBuffer && (srb.SrbFlags & SRB_FLAGS_DATA_OUT)) {
writeToDevice = TRUE;
} else {
writeToDevice = FALSE;
}
for (;;) {
status = ClassSendSrbSynchronous(DeviceObject,
&srb,
srb.DataBuffer,
srb.DataTransferLength,
writeToDevice);
if (NT_SUCCESS(status) ||
(status == STATUS_DATA_OVERRUN)) {
if (status == STATUS_DATA_OVERRUN) {
ULONG allocLen;
PCDB Cdb;
//
// ISSUE: 03/31/2000: nramas
// We use either LOG SENSE or REQUEST SENSE CDB
// in minidrivers. For LogSense, AllocationLength
// is 2 bytes. It is 10 byte CDB.
//
// Currently, if DataOverrun occurs on request sense,
// we don't handle that.
//
if ((srb.CdbLength) == CDB10GENERIC_LENGTH) {
Cdb = (PCDB)(srb.Cdb);
allocLen = Cdb->LOGSENSE.AllocationLength[0];
allocLen <<= 8;
allocLen |= Cdb->LOGSENSE.AllocationLength[1];
DebugPrint((3, "DataXferLen %x, AllocLen %x\n",
srb.DataTransferLength,
allocLen));
if ((srb.DataTransferLength) <= allocLen) {
status = STATUS_SUCCESS;
break;
} else {
DebugPrint((1,
"DataOverrun in TapeWMI routine. Srb %p\n",
&srb));
}
}
} else {
break;
}
}
if (numRetries == 0) {
if (retryFlags & RETURN_ERRORS) {
ScsiTapeNtStatusToTapeStatus(status, &lastError) ;
break ;
}
if (retryFlags & IGNORE_ERRORS) {
break;
}
if (commandExtension) {
ExFreePool(commandExtension);
}
ScsiTapeFreeSrbBuffer(&srb);
return status;
}
numRetries--;
}
}
ScsiTapeFreeSrbBuffer(&srb);
if (commandExtension) {
ExFreePool(commandExtension);
}
if (!ScsiTapeTapeStatusToNtStatus(tapeStatus, &status)) {
status = STATUS_IO_DEVICE_ERROR;
}
return status;
} // end TapeWMIControl
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -