Disable media poll using IOCTL_STORAGE_MCN_CONTROL fails

I’m trying to prevent Windows from polling a tape device while a firmware upgrade is performed. The only way I think this can be done from an application is by sending a DeviceIoControl to the device using the IOCTL_STORAGE_MCN_CONTROL parameter.

When I try to run my code on a tape device, the call to disable media polling succeeds but the drive continues to receive Test Unit Ready commands. When I try to enable media polling, the call fails with a NT error 16H, which would suggest that the command isn’t valid for this device. My question is, which driver is responsible for implementing this IOCTL? Is it the device specific tape driver, or a lower layer? When I try all this on CD/DVD devices I get an error 57H. I’m at a loss…

Below is a quick-and-dirty example of the code I’m using to test this. Any comments are very welcome…

Thanks,
Rob

#include <stdio.h>
#include <windows.h>
#include

void vErrOut(int byExit, char pchText);

int main(int argc, char **argv)
{
BOOL Poll;
DWORD bytes, status;
HANDLE h;

printf(“PnP Poll V%.2f – By R. Turk \n\n”, VERSION);
if((argc != 3) || (strlen(argv[2]) != 1) ) {
vErrOut(1, “Usage : pnppoll device [1 or 0]”);
}

h = CreateFile( argv[1], 0,
0,
//FILE_SHARE_READ | FILE_SHARE_WRITE ,
NULL, OPEN_EXISTING, 0, NULL);
if(h == INVALID_HANDLE_VALUE) {
printf(“Cannot obtain a handle to %s\n”, argv[1]);
vErrOut(2, “Stopped”);
}

switch(argv[2][0]) {
case ‘0’:
printf(“Trying to switch polling off\n”);
Poll = TRUE;
break;
case ‘1’:
printf(“Trying to switch polling on\n”);
Poll = FALSE;
break;
default:
vErrOut(4, “Parameter 2 is invalid, use 0 or 1 only”);
}
/

* Try to control the PNP polling on the specified device.
* See: http://msdn2.microsoft.com/en-us/library/aa363415.aspx
*/
status = DeviceIoControl( h, IOCTL_STORAGE_MCN_CONTROL,
&Poll, sizeof(BOOL), // Input params
NULL, 0, // Output params
&bytes, NULL);
if(!status) {
printf(“Unable to set/reset PnP on %s, error = %xH\n”, argv[1], GetLastError());
vErrOut(3, “Stopped”);
}
printf(“OK\n”);
CloseHandle(h);
return 0;
}

void vErrOut(int byExit, char *pchText)
{
printf(“\n%s\n”, pchText);
exit(byExit);
}</windows.h></stdio.h>

Look at the sources in DDK\src\storage\class. These are the system drivers
that handle this.

wrote in message news:xxxxx@ntdev…
> I’m trying to prevent Windows from polling a tape device while a firmware
> upgrade is performed. The only way I think this can be done from an
> application is by sending a DeviceIoControl to the device using the
> IOCTL_STORAGE_MCN_CONTROL parameter.
>
> When I try to run my code on a tape device, the call to disable media
> polling succeeds but the drive continues to receive Test Unit Ready
> commands. When I try to enable media polling, the call fails with a NT
> error 16H, which would suggest that the command isn’t valid for this
> device. My question is, which driver is responsible for implementing this
> IOCTL? Is it the device specific tape driver, or a lower layer? When I try
> all this on CD/DVD devices I get an error 57H. I’m at a loss…
>
> Below is a quick-and-dirty example of the code I’m using to test this. Any
> comments are very welcome…
>
> Thanks,
> Rob
> ==
> #include <stdio.h>
> #include <windows.h>
> #include
>
> void vErrOut(int byExit, char pchText);
>
> int main(int argc, char **argv)
> {
> BOOL Poll;
> DWORD bytes, status;
> HANDLE h;
>
> printf(“PnP Poll V%.2f – By R. Turk \n\n”, VERSION);
> if((argc != 3) || (strlen(argv[2]) != 1) ) {
> vErrOut(1, “Usage : pnppoll device [1 or 0]”);
> }
>
> h = CreateFile( argv[1], 0,
> 0,
> //FILE_SHARE_READ | FILE_SHARE_WRITE ,
> NULL, OPEN_EXISTING, 0, NULL);
> if(h == INVALID_HANDLE_VALUE) {
> printf(“Cannot obtain a handle to %s\n”, argv[1]);
> vErrOut(2, “Stopped”);
> }
>
> switch(argv[2][0]) {
> case ‘0’:
> printf(“Trying to switch polling off\n”);
> Poll = TRUE;
> break;
> case ‘1’:
> printf(“Trying to switch polling on\n”);
> Poll = FALSE;
> break;
> default:
> vErrOut(4, “Parameter 2 is invalid, use 0 or 1 only”);
> }
> /

> * Try to control the PNP polling on the specified device.
> * See: http://msdn2.microsoft.com/en-us/library/aa363415.aspx
> */
> status = DeviceIoControl( h, IOCTL_STORAGE_MCN_CONTROL,
> &Poll, sizeof(BOOL), // Input params
> NULL, 0, // Output params
> &bytes, NULL);
> if(!status) {
> printf(“Unable to set/reset PnP on %s, error = %xH\n”, argv[1],
> GetLastError());
> vErrOut(3, “Stopped”);
> }
> printf(“OK\n”);
> CloseHandle(h);
> return 0;
> }
>
> void vErrOut(int byExit, char *pchText)
> {
> printf(“\n%s\n”, pchText);
> exit(byExit);
> }
>
></windows.h></stdio.h>