Hi, all!

I have to add IRP_MJ_SHUTDOWN handler for
AVStream miniport driver. How should I prevent
device from being removed? Does ks.sys support
some kind of remove lock. If so, how can I acquire
it?

WBR
Igor

Re: AVStream: DispatchShutdown handler by Max

Max
Fri Jul 01 00:17:56 CDT 2005

First, why do you think you need to prevent device removal? And why do you
think you need to handle IRP_MJ_SHUTDOWN?

Anyways to stop AVStream device removal you should implement
KSDEVICE_DISPATCH::QueryRemove. It is a simple delegate for
IRP_MN_QUERY_REMOVE_DEVICE, which is what you should be using to reject
device removal attempt.

-- Max.




"Igor Slewsarev" <slewsarev_no_spam_@nospam.yahoo.com> wrote in message
news:%23f5EIZZfFHA.1472@TK2MSFTNGP12.phx.gbl...
> Hi, all!
>
> I have to add IRP_MJ_SHUTDOWN handler for
> AVStream miniport driver. How should I prevent
> device from being removed? Does ks.sys support
> some kind of remove lock. If so, how can I acquire
> it?
>
> WBR
> Igor
>



Re: AVStream: DispatchShutdown handler by Igor

Igor
Mon Jul 04 05:15:31 CDT 2005

Hi!
Thanks, Max.
>To your question. Can't you use KSDEVICE_DISPATCH::Stop? Note that I've
>never done it myself, but a wild guess is that it should be called on
>shutdown.
No. AFAK PCI device drivers never receive IRP_MN_STOP_DEVICE during
shutdown (this differs from USB and CardBus devices). So I can only operate
with IRP_MN_SET_POWER (of course if I'm a power policy owner).

WBR
Igor



Re: AVStream: DispatchShutdown handler by Igor

Igor
Mon Jul 04 10:21:09 CDT 2005

Hi, Max!

I think, finally I've found a fault safe solution:

a)
NTSTATUS AVStrMiniDeviceStart(...)
{
m_StopRequested = false;
IoRegisterShutdownNotification(KsDevice->FunctionalDeviceObject);
//...
}
b)
NTSTATUS AVStrMiniDeviceQueryStop(...) // also QueryRemove
{
// DeviceMutex is already held by ks.sys
m_StopRequested = true;
IoUnregisterShutdownNotification(KsDevice->FunctionalDeviceObject);
// ...
}
c)
NTSTATUS AVStrMiniDeviceCancelStop(...)
{
m_StopRequested = false;
IoRegisterShutdownNotification(KsDevice->FunctionalDeviceObject);
// ...
}
d)
VOID AVStrMiniDeviceStop(...) // also spurious Remove (or surprise remove?)
{
ASSERT(m_StopRequested == true);
KsAcqureDevice();
DoShutdownHandling();
// ...
}
e)
NTSTATUS MyDeviceDispatchShutdown(PDEVICE_OBJECT DeviceObject, PIRP Irp)
{
PKSDEVICE KsDevice = KsGetDeviceForDeviceObject(DeviceObject);
if (KsDevice == NULL)
{ //...
}
else
{
KsAcquireDevice(KsDevice); // Prevent CancelStop/Remove
if (m_StopRequested == false)
DoShutdownHandling();
KsReleaseDevice(KsDevice);
}
}
What are you thinking about the above code?

WBR
Igor



Re: AVStream: DispatchShutdown handler by Maxim

Maxim
Mon Jul 04 19:02:25 CDT 2005

> with IRP_MN_SET_POWER (of course if I'm a power policy owner).

SET_POWER/Device is always sent, not only to power policy owners.

--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
maxim@storagecraft.com
http://www.storagecraft.com



Re: AVStream: DispatchShutdown handler by Igor

Igor
Tue Jul 05 03:46:26 CDT 2005

Hi!
Thanks for comment.
Maybe you know why sometimes I don't receive
IRP_MN_SET_POWER/Device during shutdown?

WBR
Igor


"Maxim S. Shatskih" <maxim@storagecraft.com> wrote in message
news:uNJN0SPgFHA.3428@TK2MSFTNGP09.phx.gbl...
>> with IRP_MN_SET_POWER (of course if I'm a power policy owner).
>
> SET_POWER/Device is always sent, not only to power policy owners.
>
> --
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> maxim@storagecraft.com
> http://www.storagecraft.com
>
>



Re: AVStream: DispatchShutdown handler by Maxim

Maxim
Tue Jul 05 06:37:03 CDT 2005

Maybe AVStream handles this itself and not delivers to your code. I do not
know AVStream.

--
Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
maxim@storagecraft.com
http://www.storagecraft.com

"Igor Slewsarev" <slewsarev_no_spam_@nospam.yahoo.com> wrote in message
news:%23L6aH4TgFHA.1412@TK2MSFTNGP09.phx.gbl...
> Hi!
> Thanks for comment.
> Maybe you know why sometimes I don't receive
> IRP_MN_SET_POWER/Device during shutdown?
>
> WBR
> Igor
>
>
> "Maxim S. Shatskih" <maxim@storagecraft.com> wrote in message
> news:uNJN0SPgFHA.3428@TK2MSFTNGP09.phx.gbl...
> >> with IRP_MN_SET_POWER (of course if I'm a power policy owner).
> >
> > SET_POWER/Device is always sent, not only to power policy owners.
> >
> > --
> > Maxim Shatskih, Windows DDK MVP
> > StorageCraft Corporation
> > maxim@storagecraft.com
> > http://www.storagecraft.com
> >
> >
>
>



Re: AVStream: DispatchShutdown handler by Max

Max
Tue Jul 05 13:23:53 CDT 2005

This looks fine to me (except for missing KsReleaseDevice() in
AVStrMiniDeviceStop, which is typo for sure).

-- Max.



"Igor Slewsarev" <slewsarev_no_spam_@nospam.yahoo.com> wrote in message
news:O7OYBwKgFHA.3540@TK2MSFTNGP14.phx.gbl...
> Hi, Max!
>
> I think, finally I've found a fault safe solution:
>
> a)
> NTSTATUS AVStrMiniDeviceStart(...)
> {
> m_StopRequested = false;
> IoRegisterShutdownNotification(KsDevice->FunctionalDeviceObject);
> //...
> }
> b)
> NTSTATUS AVStrMiniDeviceQueryStop(...) // also QueryRemove
> {
> // DeviceMutex is already held by ks.sys
> m_StopRequested = true;
> IoUnregisterShutdownNotification(KsDevice->FunctionalDeviceObject);
> // ...
> }
> c)
> NTSTATUS AVStrMiniDeviceCancelStop(...)
> {
> m_StopRequested = false;
> IoRegisterShutdownNotification(KsDevice->FunctionalDeviceObject);
> // ...
> }
> d)
> VOID AVStrMiniDeviceStop(...) // also spurious Remove (or surprise
> remove?)
> {
> ASSERT(m_StopRequested == true);
> KsAcqureDevice();
> DoShutdownHandling();
> // ...
> }
> e)
> NTSTATUS MyDeviceDispatchShutdown(PDEVICE_OBJECT DeviceObject, PIRP Irp)
> {
> PKSDEVICE KsDevice = KsGetDeviceForDeviceObject(DeviceObject);
> if (KsDevice == NULL)
> { //...
> }
> else
> {
> KsAcquireDevice(KsDevice); // Prevent CancelStop/Remove
> if (m_StopRequested == false)
> DoShutdownHandling();
> KsReleaseDevice(KsDevice);
> }
> }
> What are you thinking about the above code?
>
> WBR
> Igor
>
>



Re: AVStream: DispatchShutdown handler by Max

Max
Tue Jul 05 13:24:30 CDT 2005

It shouldn't.
All power events are transparently forwarded to the minidriver.

-- Max.



"Maxim S. Shatskih" <maxim@storagecraft.com> wrote in message
news:%23HWp$WVgFHA.3788@TK2MSFTNGP10.phx.gbl...
> Maybe AVStream handles this itself and not delivers to your code. I do
> not
> know AVStream.
>
> --
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> maxim@storagecraft.com
> http://www.storagecraft.com
>
> "Igor Slewsarev" <slewsarev_no_spam_@nospam.yahoo.com> wrote in message
> news:%23L6aH4TgFHA.1412@TK2MSFTNGP09.phx.gbl...
>> Hi!
>> Thanks for comment.
>> Maybe you know why sometimes I don't receive
>> IRP_MN_SET_POWER/Device during shutdown?
>>
>> WBR
>> Igor
>>
>>
>> "Maxim S. Shatskih" <maxim@storagecraft.com> wrote in message
>> news:uNJN0SPgFHA.3428@TK2MSFTNGP09.phx.gbl...
>> >> with IRP_MN_SET_POWER (of course if I'm a power policy owner).
>> >
>> > SET_POWER/Device is always sent, not only to power policy owners.
>> >
>> > --
>> > Maxim Shatskih, Windows DDK MVP
>> > StorageCraft Corporation
>> > maxim@storagecraft.com
>> > http://www.storagecraft.com
>> >
>> >
>>
>>
>
>