Question about IoRegisterFsRegistrationChange

Hello, Gurus.

Let me ask on IoRegisterFsRegistrationChange. Of course I searched this
article first to find solution, unfortunately still not get. I think that I
also need your help in this time.

Now I am implementing IoRegisterFsRegistrationChange to let our filesystem
filter driver attach to filesystem driver’s control device object.
Furtunately I success to attach to it, but I have problem in detaching.

When FsActive is FALSE, I am going to delete our device object and before
calling IoDeleteDevice, call IoDetachDevice to release our device object
from device stack chain. It works fine when noone attaching our device
object,. but when any device object attaches to our device object, it do not
delete device object.

Can I delete our device object with IoDeleteDevice even if any device object
attaches to ours? I am worry about what happen to attached device object if
I delete our device object.

Please give me your adivce and any pointer is also welcome.

Thank you,
Hideyuki Inamasu.

========== OUTLINE OF MY CODE ============
VOID
MyFileSystemNotification(
PDEVICE_OBJECT DeviceObject,
BOOLEAN FsActive
)
{
NTSTATUS status;
PDEVICE_OBJECT hookDevice, layeredDevice;
PFSRC_HOOK_EXTENSION deviceExtension;
PDEVICE_OBJECT saveDevice;
PDEVICE_OBJECT targetDevice;

if (DeviceObject->DeviceType != FILE_DEVICE_DISK_FILE_SYSTEM &&
DeviceObject->DeviceType != FILE_DEVICE_CD_ROM_FILE_SYSTEM &&
DeviceObject->DeviceType != FILE_DEVICE_TAPE_FILE_SYSTEM)
return;

if (FsActive) {
//
// Attaching to device object handler is here.
//
} else {

ASSERT(DeviceObject);

targetDevice=DeviceObject;

for (layeredDevice=DeviceObject->AttachedDevice;
layeredDevice!=NULL;
layeredDevice=layeredDevice->AttachedDevice) {

hookDevice=thisDriver->DeviceObject;
while (hookDevice!=NULL) {

if (hookDevice==layeredDevice) {

DebugPrint((“CWATNET: determined that the device going
a”
“way is attached to by CWATNET device
%x\n”,hookDevice));

IoDetachDevice(targetDevice);
deviceExtension=hookDevice->DeviceExtension;
deviceExtension->attachedDevice=NULL;

//
// We should delete our device, but if someone attached
to
// it, that could be unwise.
//
if (hookDevice->AttachedDevice==NULL) {
saveDevice=hookDevice->NextDevice;
IoDeleteDevice(hookDevice);
hookDevice=saveDevice;
return;
} else {
hookDevice=hookDevice->NextDevice;
}
} else {
hookDevice=hookDevice->NextDevice;
}
}

targetDevice=layeredDevice;
}
}
}

Sorry for not enough investigation for my problem.

Anyway, I leaned something from this newsgroup, information on internet and
IFSKIT.

To solve my problem:

  1. I need to detach/delete device object when de-registering filesystem.
  2. I need to support FastIoDetach device to pick up lower device deletion.

Is this enougth for my problem? Please give me your advice!

Thank you,
Hideyuki Inamasu.

“Hideyuki Inamasu” wrote in message
news:xxxxx@ntfsd…
> Hello, Gurus.
>
> Let me ask on IoRegisterFsRegistrationChange. Of course I searched this
> article first to find solution, unfortunately still not get. I think that
> I also need your help in this time.
>
> Now I am implementing IoRegisterFsRegistrationChange to let our filesystem
> filter driver attach to filesystem driver’s control device object.
> Furtunately I success to attach to it, but I have problem in detaching.
>
> When FsActive is FALSE, I am going to delete our device object and before
> calling IoDeleteDevice, call IoDetachDevice to release our device object
> from device stack chain. It works fine when noone attaching our device
> object,. but when any device object attaches to our device object, it do
> not delete device object.
>
> Can I delete our device object with IoDeleteDevice even if any device
> object attaches to ours? I am worry about what happen to attached device
> object if I delete our device object.
>
> Please give me your adivce and any pointer is also welcome.
>
> Thank you,
> Hideyuki Inamasu.
>
> ========== OUTLINE OF MY CODE ============
> VOID
> MyFileSystemNotification(
> PDEVICE_OBJECT DeviceObject,
> BOOLEAN FsActive
> )
> {
> NTSTATUS status;
> PDEVICE_OBJECT hookDevice, layeredDevice;
> PFSRC_HOOK_EXTENSION deviceExtension;
> PDEVICE_OBJECT saveDevice;
> PDEVICE_OBJECT targetDevice;
>
> if (DeviceObject->DeviceType != FILE_DEVICE_DISK_FILE_SYSTEM &&
> DeviceObject->DeviceType != FILE_DEVICE_CD_ROM_FILE_SYSTEM &&
> DeviceObject->DeviceType != FILE_DEVICE_TAPE_FILE_SYSTEM)
> return;
>
> if (FsActive) {
> //
> // Attaching to device object handler is here.
> //
> } else {
>
> ASSERT(DeviceObject);
>
> targetDevice=DeviceObject;
>
> for (layeredDevice=DeviceObject->AttachedDevice;
> layeredDevice!=NULL;
> layeredDevice=layeredDevice->AttachedDevice) {
>
> hookDevice=thisDriver->DeviceObject;
> while (hookDevice!=NULL) {
>
> if (hookDevice==layeredDevice) {
>
> DebugPrint((“CWATNET: determined that the device going
> a”
> “way is attached to by CWATNET device
> %x\n”,hookDevice));
>
> IoDetachDevice(targetDevice);
> deviceExtension=hookDevice->DeviceExtension;
> deviceExtension->attachedDevice=NULL;
>
> //
> // We should delete our device, but if someone attached
> to
> // it, that could be unwise.
> //
> if (hookDevice->AttachedDevice==NULL) {
> saveDevice=hookDevice->NextDevice;
> IoDeleteDevice(hookDevice);
> hookDevice=saveDevice;
> return;
> } else {
> hookDevice=hookDevice->NextDevice;
> }
> } else {
> hookDevice=hookDevice->NextDevice;
> }
> }
>
> targetDevice=layeredDevice;
> }
> }
> }
>
>
>

Only delete the device objects from FastIoDetachDevice callback. This is
the way old style FS filters should behave.

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

----- Original Message -----
From: “Hideyuki Inamasu”
Newsgroups: ntfsd
To: “Windows File Systems Devs Interest List”
Sent: Friday, June 03, 2005 1:58 PM
Subject: Re:[ntfsd] Question about IoRegisterFsRegistrationChange

> Sorry for not enough investigation for my problem.
>
> Anyway, I leaned something from this newsgroup, information on internet and
> IFSKIT.
>
> To solve my problem:
>
> 1. I need to detach/delete device object when de-registering filesystem.
> 2. I need to support FastIoDetach device to pick up lower device deletion.
>
> Is this enougth for my problem? Please give me your advice!
>
> Thank you,
> Hideyuki Inamasu.
>
> “Hideyuki Inamasu” wrote in message
> news:xxxxx@ntfsd…
> > Hello, Gurus.
> >
> > Let me ask on IoRegisterFsRegistrationChange. Of course I searched this
> > article first to find solution, unfortunately still not get. I think that
> > I also need your help in this time.
> >
> > Now I am implementing IoRegisterFsRegistrationChange to let our filesystem
> > filter driver attach to filesystem driver’s control device object.
> > Furtunately I success to attach to it, but I have problem in detaching.
> >
> > When FsActive is FALSE, I am going to delete our device object and before
> > calling IoDeleteDevice, call IoDetachDevice to release our device object
> > from device stack chain. It works fine when noone attaching our device
> > object,. but when any device object attaches to our device object, it do
> > not delete device object.
> >
> > Can I delete our device object with IoDeleteDevice even if any device
> > object attaches to ours? I am worry about what happen to attached device
> > object if I delete our device object.
> >
> > Please give me your adivce and any pointer is also welcome.
> >
> > Thank you,
> > Hideyuki Inamasu.
> >
> > ========== OUTLINE OF MY CODE ============
> > VOID
> > MyFileSystemNotification(
> > PDEVICE_OBJECT DeviceObject,
> > BOOLEAN FsActive
> > )
> > {
> > NTSTATUS status;
> > PDEVICE_OBJECT hookDevice, layeredDevice;
> > PFSRC_HOOK_EXTENSION deviceExtension;
> > PDEVICE_OBJECT saveDevice;
> > PDEVICE_OBJECT targetDevice;
> >
> > if (DeviceObject->DeviceType != FILE_DEVICE_DISK_FILE_SYSTEM &&
> > DeviceObject->DeviceType != FILE_DEVICE_CD_ROM_FILE_SYSTEM &&
> > DeviceObject->DeviceType != FILE_DEVICE_TAPE_FILE_SYSTEM)
> > return;
> >
> > if (FsActive) {
> > //
> > // Attaching to device object handler is here.
> > //
> > } else {
> >
> > ASSERT(DeviceObject);
> >
> > targetDevice=DeviceObject;
> >
> > for (layeredDevice=DeviceObject->AttachedDevice;
> > layeredDevice!=NULL;
> > layeredDevice=layeredDevice->AttachedDevice) {
> >
> > hookDevice=thisDriver->DeviceObject;
> > while (hookDevice!=NULL) {
> >
> > if (hookDevice==layeredDevice) {
> >
> > DebugPrint((“CWATNET: determined that the device going
> > a”
> > “way is attached to by CWATNET device
> > %x\n”,hookDevice));
> >
> > IoDetachDevice(targetDevice);
> > deviceExtension=hookDevice->DeviceExtension;
> > deviceExtension->attachedDevice=NULL;
> >
> > //
> > // We should delete our device, but if someone attached
> > to
> > // it, that could be unwise.
> > //
> > if (hookDevice->AttachedDevice==NULL) {
> > saveDevice=hookDevice->NextDevice;
> > IoDeleteDevice(hookDevice);
> > hookDevice=saveDevice;
> > return;
> > } else {
> > hookDevice=hookDevice->NextDevice;
> > }
> > } else {
> > hookDevice=hookDevice->NextDevice;
> > }
> > }
> >
> > targetDevice=layeredDevice;
> > }
> > }
> > }
> >
> >
> >
>
>
> —
> Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com

Mr Maxim,

Thank you very much for your advice.

And let me ask one question.

I well understand I only need to support FastIoDetachDevice for my case
(problem), anyway if lower device object is not deleted and will re-use it
to attach other device object, I guess that lower device will adjust its
StackSize when attaching to another device object, but our device object
(actually our device object was not deleted, because lower device is not
deleted) is still attached to that device object and keep same StackSize.
This can cause StackSize problem?

Sorry for not enough aknowlege for device driver and filesystem and give me
your help.

Thank you,
Hideyuki Inamasu.

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntfsd…
> Only delete the device objects from FastIoDetachDevice callback. This
> is
> the way old style FS filters should behave.
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
> ----- Original Message -----
> From: “Hideyuki Inamasu”
> Newsgroups: ntfsd
> To: “Windows File Systems Devs Interest List”
> Sent: Friday, June 03, 2005 1:58 PM
> Subject: Re:[ntfsd] Question about IoRegisterFsRegistrationChange
>
>
>> Sorry for not enough investigation for my problem.
>>
>> Anyway, I leaned something from this newsgroup, information on internet
>> and
>> IFSKIT.
>>
>> To solve my problem:
>>
>> 1. I need to detach/delete device object when de-registering filesystem.
>> 2. I need to support FastIoDetach device to pick up lower device
>> deletion.
>>
>> Is this enougth for my problem? Please give me your advice!
>>
>> Thank you,
>> Hideyuki Inamasu.
>>
>> “Hideyuki Inamasu” wrote in message
>> news:xxxxx@ntfsd…
>> > Hello, Gurus.
>> >
>> > Let me ask on IoRegisterFsRegistrationChange. Of course I searched this
>> > article first to find solution, unfortunately still not get. I think
>> > that
>> > I also need your help in this time.
>> >
>> > Now I am implementing IoRegisterFsRegistrationChange to let our
>> > filesystem
>> > filter driver attach to filesystem driver’s control device object.
>> > Furtunately I success to attach to it, but I have problem in detaching.
>> >
>> > When FsActive is FALSE, I am going to delete our device object and
>> > before
>> > calling IoDeleteDevice, call IoDetachDevice to release our device
>> > object
>> > from device stack chain. It works fine when noone attaching our device
>> > object,. but when any device object attaches to our device object, it
>> > do
>> > not delete device object.
>> >
>> > Can I delete our device object with IoDeleteDevice even if any device
>> > object attaches to ours? I am worry about what happen to attached
>> > device
>> > object if I delete our device object.
>> >
>> > Please give me your adivce and any pointer is also welcome.
>> >
>> > Thank you,
>> > Hideyuki Inamasu.
>> >
>> > ========== OUTLINE OF MY CODE ============
>> > VOID
>> > MyFileSystemNotification(
>> > PDEVICE_OBJECT DeviceObject,
>> > BOOLEAN FsActive
>> > )
>> > {
>> > NTSTATUS status;
>> > PDEVICE_OBJECT hookDevice, layeredDevice;
>> > PFSRC_HOOK_EXTENSION deviceExtension;
>> > PDEVICE_OBJECT saveDevice;
>> > PDEVICE_OBJECT targetDevice;
>> >
>> > if (DeviceObject->DeviceType != FILE_DEVICE_DISK_FILE_SYSTEM &&
>> > DeviceObject->DeviceType != FILE_DEVICE_CD_ROM_FILE_SYSTEM &&
>> > DeviceObject->DeviceType != FILE_DEVICE_TAPE_FILE_SYSTEM)
>> > return;
>> >
>> > if (FsActive) {
>> > //
>> > // Attaching to device object handler is here.
>> > //
>> > } else {
>> >
>> > ASSERT(DeviceObject);
>> >
>> > targetDevice=DeviceObject;
>> >
>> > for (layeredDevice=DeviceObject->AttachedDevice;
>> > layeredDevice!=NULL;
>> > layeredDevice=layeredDevice->AttachedDevice) {
>> >
>> > hookDevice=thisDriver->DeviceObject;
>> > while (hookDevice!=NULL) {
>> >
>> > if (hookDevice==layeredDevice) {
>> >
>> > DebugPrint((“CWATNET: determined that the device
>> > going
>> > a”
>> > “way is attached to by CWATNET device
>> > %x\n”,hookDevice));
>> >
>> > IoDetachDevice(targetDevice);
>> > deviceExtension=hookDevice->DeviceExtension;
>> > deviceExtension->attachedDevice=NULL;
>> >
>> > //
>> > // We should delete our device, but if someone
>> > attached
>> > to
>> > // it, that could be unwise.
>> > //
>> > if (hookDevice->AttachedDevice==NULL) {
>> > saveDevice=hookDevice->NextDevice;
>> > IoDeleteDevice(hookDevice);
>> > hookDevice=saveDevice;
>> > return;
>> > } else {
>> > hookDevice=hookDevice->NextDevice;
>> > }
>> > } else {
>> > hookDevice=hookDevice->NextDevice;
>> > }
>> > }
>> >
>> > targetDevice=layeredDevice;
>> > }
>> > }
>> > }
>> >
>> >
>> >
>>
>>
>> —
>> Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17
>>
>> You are currently subscribed to ntfsd as: xxxxx@storagecraft.com
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>

Usually, the device objects are never re-attached to another stack. They
are deleted, and the new one is created instead.

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

----- Original Message -----
From: “Hideyuki Inamasu”
Newsgroups: ntfsd
To: “Windows File Systems Devs Interest List”
Sent: Sunday, June 05, 2005 8:58 AM
Subject: Re:[ntfsd] Re:Question about IoRegisterFsRegistrationChange

> Mr Maxim,
>
> Thank you very much for your advice.
>
> And let me ask one question.
>
> I well understand I only need to support FastIoDetachDevice for my case
> (problem), anyway if lower device object is not deleted and will re-use it
> to attach other device object, I guess that lower device will adjust its
> StackSize when attaching to another device object, but our device object
> (actually our device object was not deleted, because lower device is not
> deleted) is still attached to that device object and keep same StackSize.
> This can cause StackSize problem?
>
> Sorry for not enough aknowlege for device driver and filesystem and give me
> your help.
>
> Thank you,
> Hideyuki Inamasu.
>
> “Maxim S. Shatskih” wrote in message
> news:xxxxx@ntfsd…
> > Only delete the device objects from FastIoDetachDevice callback. This
> > is
> > the way old style FS filters should behave.
> >
> > Maxim Shatskih, Windows DDK MVP
> > StorageCraft Corporation
> > xxxxx@storagecraft.com
> > http://www.storagecraft.com
> >
> > ----- Original Message -----
> > From: “Hideyuki Inamasu”
> > Newsgroups: ntfsd
> > To: “Windows File Systems Devs Interest List”
> > Sent: Friday, June 03, 2005 1:58 PM
> > Subject: Re:[ntfsd] Question about IoRegisterFsRegistrationChange
> >
> >
> >> Sorry for not enough investigation for my problem.
> >>
> >> Anyway, I leaned something from this newsgroup, information on internet
> >> and
> >> IFSKIT.
> >>
> >> To solve my problem:
> >>
> >> 1. I need to detach/delete device object when de-registering filesystem.
> >> 2. I need to support FastIoDetach device to pick up lower device
> >> deletion.
> >>
> >> Is this enougth for my problem? Please give me your advice!
> >>
> >> Thank you,
> >> Hideyuki Inamasu.
> >>
> >> “Hideyuki Inamasu” wrote in message
> >> news:xxxxx@ntfsd…
> >> > Hello, Gurus.
> >> >
> >> > Let me ask on IoRegisterFsRegistrationChange. Of course I searched this
> >> > article first to find solution, unfortunately still not get. I think
> >> > that
> >> > I also need your help in this time.
> >> >
> >> > Now I am implementing IoRegisterFsRegistrationChange to let our
> >> > filesystem
> >> > filter driver attach to filesystem driver’s control device object.
> >> > Furtunately I success to attach to it, but I have problem in detaching.
> >> >
> >> > When FsActive is FALSE, I am going to delete our device object and
> >> > before
> >> > calling IoDeleteDevice, call IoDetachDevice to release our device
> >> > object
> >> > from device stack chain. It works fine when noone attaching our device
> >> > object,. but when any device object attaches to our device object, it
> >> > do
> >> > not delete device object.
> >> >
> >> > Can I delete our device object with IoDeleteDevice even if any device
> >> > object attaches to ours? I am worry about what happen to attached
> >> > device
> >> > object if I delete our device object.
> >> >
> >> > Please give me your adivce and any pointer is also welcome.
> >> >
> >> > Thank you,
> >> > Hideyuki Inamasu.
> >> >
> >> > ========== OUTLINE OF MY CODE ============
> >> > VOID
> >> > MyFileSystemNotification(
> >> > PDEVICE_OBJECT DeviceObject,
> >> > BOOLEAN FsActive
> >> > )
> >> > {
> >> > NTSTATUS status;
> >> > PDEVICE_OBJECT hookDevice, layeredDevice;
> >> > PFSRC_HOOK_EXTENSION deviceExtension;
> >> > PDEVICE_OBJECT saveDevice;
> >> > PDEVICE_OBJECT targetDevice;
> >> >
> >> > if (DeviceObject->DeviceType != FILE_DEVICE_DISK_FILE_SYSTEM &&
> >> > DeviceObject->DeviceType != FILE_DEVICE_CD_ROM_FILE_SYSTEM &&
> >> > DeviceObject->DeviceType != FILE_DEVICE_TAPE_FILE_SYSTEM)
> >> > return;
> >> >
> >> > if (FsActive) {
> >> > //
> >> > // Attaching to device object handler is here.
> >> > //
> >> > } else {
> >> >
> >> > ASSERT(DeviceObject);
> >> >
> >> > targetDevice=DeviceObject;
> >> >
> >> > for (layeredDevice=DeviceObject->AttachedDevice;
> >> > layeredDevice!=NULL;
> >> > layeredDevice=layeredDevice->AttachedDevice) {
> >> >
> >> > hookDevice=thisDriver->DeviceObject;
> >> > while (hookDevice!=NULL) {
> >> >
> >> > if (hookDevice==layeredDevice) {
> >> >
> >> > DebugPrint((“CWATNET: determined that the device
> >> > going
> >> > a”
> >> > “way is attached to by CWATNET device
> >> > %x\n”,hookDevice));
> >> >
> >> > IoDetachDevice(targetDevice);
> >> > deviceExtension=hookDevice->DeviceExtension;
> >> > deviceExtension->attachedDevice=NULL;
> >> >
> >> > //
> >> > // We should delete our device, but if someone
> >> > attached
> >> > to
> >> > // it, that could be unwise.
> >> > //
> >> > if (hookDevice->AttachedDevice==NULL) {
> >> > saveDevice=hookDevice->NextDevice;
> >> > IoDeleteDevice(hookDevice);
> >> > hookDevice=saveDevice;
> >> > return;
> >> > } else {
> >> > hookDevice=hookDevice->NextDevice;
> >> > }
> >> > } else {
> >> > hookDevice=hookDevice->NextDevice;
> >> > }
> >> > }
> >> >
> >> > targetDevice=layeredDevice;
> >> > }
> >> > }
> >> > }
> >> >
> >> >
> >> >
> >>
> >>
> >> —
> >> Questions? First check the IFS FAQ at
> > https://www.osronline.com/article.cfm?id=17
> >>
> >> You are currently subscribed to ntfsd as: xxxxx@storagecraft.com
> >> To unsubscribe send a blank email to xxxxx@lists.osr.com
> >
> >
>
>
> —
> Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com

I have seen exactly this situation in the past; it is due to products
that used the older SFILTER example that does exactly what you
described.

There are a few possible solutions to this situation:

(1) In your IRP_MJ_CREATE handler, you can check to see if the number of
I/O stack locations in your device object is correct, given the number
in the underlying device object. If it is not, you may return
STATUS_REPARSE with IO_REMOUNT to have the I/O Manager rebuild the
create IRP and reissue the create operation.

(2) Prior to forwarding an IRP, you can verify that you have a
sufficient number of I/O Stack Locations. If you do not, you can build
a new IRP, with sufficient stack space, and send it to the underlying
device for further processing.

(3) In your fs registration change notification function, you can run
through all of your existing attachments and verify that their StackSize
field is correct for the device over which they are attached.

Any of these should work, although I’ve only ever used option (2).
Option (1) relies upon the very behavior of the OS during remount
operations (you can see that FastFat returns this error combination when
it detects media change, for example) and exploits that. Option (3)
presumes that the other filter will attach differently as a result of a
change notification, although my concern here is the ordering of the
calls between the two filters, but presumably if you are layered on top
of the other filter’s device object it is because you were called after
the other filter.

No matter, the other filter is based upon a broken example and is itself
broken. The last time I saw this was with the “Ghost” product, which
appears to use a file system filter driver, but I suspect there are
other products in the field with the same bug.

I hope that this helps.

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Hideyuki Inamasu
Sent: Sunday, June 05, 2005 12:59 AM
To: ntfsd redirect
Subject: Re:[ntfsd] Re:Question about IoRegisterFsRegistrationChange

Mr Maxim,

Thank you very much for your advice.

And let me ask one question.

I well understand I only need to support FastIoDetachDevice for my case
(problem), anyway if lower device object is not deleted and will re-use
it
to attach other device object, I guess that lower device will adjust its

StackSize when attaching to another device object, but our device object

(actually our device object was not deleted, because lower device is not

deleted) is still attached to that device object and keep same
StackSize.
This can cause StackSize problem?

Sorry for not enough aknowlege for device driver and filesystem and give
me
your help.

Thank you,
Hideyuki Inamasu.

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntfsd…
> Only delete the device objects from FastIoDetachDevice callback.
This
> is
> the way old style FS filters should behave.
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
> ----- Original Message -----
> From: “Hideyuki Inamasu”
> Newsgroups: ntfsd
> To: “Windows File Systems Devs Interest List”
> Sent: Friday, June 03, 2005 1:58 PM
> Subject: Re:[ntfsd] Question about IoRegisterFsRegistrationChange
>
>
>> Sorry for not enough investigation for my problem.
>>
>> Anyway, I leaned something from this newsgroup, information on
internet
>> and
>> IFSKIT.
>>
>> To solve my problem:
>>
>> 1. I need to detach/delete device object when de-registering
filesystem.
>> 2. I need to support FastIoDetach device to pick up lower device
>> deletion.
>>
>> Is this enougth for my problem? Please give me your advice!
>>
>> Thank you,
>> Hideyuki Inamasu.
>>
>> “Hideyuki Inamasu” wrote in message
>> news:xxxxx@ntfsd…
>> > Hello, Gurus.
>> >
>> > Let me ask on IoRegisterFsRegistrationChange. Of course I searched
this
>> > article first to find solution, unfortunately still not get. I
think
>> > that
>> > I also need your help in this time.
>> >
>> > Now I am implementing IoRegisterFsRegistrationChange to let our
>> > filesystem
>> > filter driver attach to filesystem driver’s control device object.
>> > Furtunately I success to attach to it, but I have problem in
detaching.
>> >
>> > When FsActive is FALSE, I am going to delete our device object and
>> > before
>> > calling IoDeleteDevice, call IoDetachDevice to release our device
>> > object
>> > from device stack chain. It works fine when noone attaching our
device
>> > object,. but when any device object attaches to our device object,
it
>> > do
>> > not delete device object.
>> >
>> > Can I delete our device object with IoDeleteDevice even if any
device
>> > object attaches to ours? I am worry about what happen to attached
>> > device
>> > object if I delete our device object.
>> >
>> > Please give me your adivce and any pointer is also welcome.
>> >
>> > Thank you,
>> > Hideyuki Inamasu.
>> >
>> > ========== OUTLINE OF MY CODE ============
>> > VOID
>> > MyFileSystemNotification(
>> > PDEVICE_OBJECT DeviceObject,
>> > BOOLEAN FsActive
>> > )
>> > {
>> > NTSTATUS status;
>> > PDEVICE_OBJECT hookDevice, layeredDevice;
>> > PFSRC_HOOK_EXTENSION deviceExtension;
>> > PDEVICE_OBJECT saveDevice;
>> > PDEVICE_OBJECT targetDevice;
>> >
>> > if (DeviceObject->DeviceType != FILE_DEVICE_DISK_FILE_SYSTEM &&
>> > DeviceObject->DeviceType != FILE_DEVICE_CD_ROM_FILE_SYSTEM &&
>> > DeviceObject->DeviceType != FILE_DEVICE_TAPE_FILE_SYSTEM)
>> > return;
>> >
>> > if (FsActive) {
>> > //
>> > // Attaching to device object handler is here.
>> > //
>> > } else {
>> >
>> > ASSERT(DeviceObject);
>> >
>> > targetDevice=DeviceObject;
>> >
>> > for (layeredDevice=DeviceObject->AttachedDevice;
>> > layeredDevice!=NULL;
>> > layeredDevice=layeredDevice->AttachedDevice) {
>> >
>> > hookDevice=thisDriver->DeviceObject;
>> > while (hookDevice!=NULL) {
>> >
>> > if (hookDevice==layeredDevice) {
>> >
>> > DebugPrint((“CWATNET: determined that the device

>> > going
>> > a”
>> > “way is attached to by CWATNET device
>> > %x\n”,hookDevice));
>> >
>> > IoDetachDevice(targetDevice);
>> > deviceExtension=hookDevice->DeviceExtension;
>> > deviceExtension->attachedDevice=NULL;
>> >
>> > //
>> > // We should delete our device, but if someone
>> > attached
>> > to
>> > // it, that could be unwise.
>> > //
>> > if (hookDevice->AttachedDevice==NULL) {
>> > saveDevice=hookDevice->NextDevice;
>> > IoDeleteDevice(hookDevice);
>> > hookDevice=saveDevice;
>> > return;
>> > } else {
>> > hookDevice=hookDevice->NextDevice;
>> > }
>> > } else {
>> > hookDevice=hookDevice->NextDevice;
>> > }
>> > }
>> >
>> > targetDevice=layeredDevice;
>> > }
>> > }
>> > }
>> >
>> >
>> >
>>
>>
>> —
>> Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17
>>
>> You are currently subscribed to ntfsd as: xxxxx@storagecraft.com
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@osr.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

>No matter, the other filter is based upon a broken example and is itself

broken.

Am I right that this “brokenness” is due to reuse list of the device objects
guarded by the global fast mutex in old SFILTER?

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

I believe that is the case, yes. They detach and then re-attach to a
different device stack; this adjusts the StackSize field in their
device, but not in any subsequent device objects still attached.

The other option would have been for them (Microsoft) to change
IoAttachDeviceToDeviceStackSafe (and friends) to walk the entire list
and adjust the StackSize for all associated device objects, but they did
not do that. Instead, they’ve changed the SFILTER example to not reuse
device objects like this.

Regards,

Tony

Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
http://www.osr.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Maxim S. Shatskih
Sent: Sunday, June 05, 2005 11:52 AM
To: ntfsd redirect
Subject: Re: [ntfsd] Re:Question about IoRegisterFsRegistrationChange

No matter, the other filter is based upon a broken example and is
itself
broken.

Am I right that this “brokenness” is due to reuse list of the device
objects
guarded by the global fast mutex in old SFILTER?

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


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@osr.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Mr. Maxim.

Again, thank you very much for your advice.

Anyway, I found article on OSROnline

http://www.osronline.com/article.cfm?article=337

and it tells me that such (do is not deleted and re-attached) case causes
BSOD and I worry about that. Could you please give me your advice on this?

Thank you,
Hideyuki Inamasu.
“Maxim S. Shatskih” wrote in message
news:xxxxx@ntfsd…
> Usually, the device objects are never re-attached to another stack.
> They
> are deleted, and the new one is created instead.
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
> ----- Original Message -----
> From: “Hideyuki Inamasu”
> Newsgroups: ntfsd
> To: “Windows File Systems Devs Interest List”
> Sent: Sunday, June 05, 2005 8:58 AM
> Subject: Re:[ntfsd] Re:Question about IoRegisterFsRegistrationChange
>
>
>> Mr Maxim,
>>
>> Thank you very much for your advice.
>>
>> And let me ask one question.
>>
>> I well understand I only need to support FastIoDetachDevice for my case
>> (problem), anyway if lower device object is not deleted and will re-use
>> it
>> to attach other device object, I guess that lower device will adjust its
>> StackSize when attaching to another device object, but our device object
>> (actually our device object was not deleted, because lower device is not
>> deleted) is still attached to that device object and keep same StackSize.
>> This can cause StackSize problem?
>>
>> Sorry for not enough aknowlege for device driver and filesystem and give
>> me
>> your help.
>>
>> Thank you,
>> Hideyuki Inamasu.
>>
>> “Maxim S. Shatskih” wrote in message
>> news:xxxxx@ntfsd…
>> > Only delete the device objects from FastIoDetachDevice callback.
>> > This
>> > is
>> > the way old style FS filters should behave.
>> >
>> > Maxim Shatskih, Windows DDK MVP
>> > StorageCraft Corporation
>> > xxxxx@storagecraft.com
>> > http://www.storagecraft.com
>> >
>> > ----- Original Message -----
>> > From: “Hideyuki Inamasu”
>> > Newsgroups: ntfsd
>> > To: “Windows File Systems Devs Interest List”
>> > Sent: Friday, June 03, 2005 1:58 PM
>> > Subject: Re:[ntfsd] Question about IoRegisterFsRegistrationChange
>> >
>> >
>> >> Sorry for not enough investigation for my problem.
>> >>
>> >> Anyway, I leaned something from this newsgroup, information on
>> >> internet
>> >> and
>> >> IFSKIT.
>> >>
>> >> To solve my problem:
>> >>
>> >> 1. I need to detach/delete device object when de-registering
>> >> filesystem.
>> >> 2. I need to support FastIoDetach device to pick up lower device
>> >> deletion.
>> >>
>> >> Is this enougth for my problem? Please give me your advice!
>> >>
>> >> Thank you,
>> >> Hideyuki Inamasu.
>> >>
>> >> “Hideyuki Inamasu” wrote in message
>> >> news:xxxxx@ntfsd…
>> >> > Hello, Gurus.
>> >> >
>> >> > Let me ask on IoRegisterFsRegistrationChange. Of course I searched
>> >> > this
>> >> > article first to find solution, unfortunately still not get. I think
>> >> > that
>> >> > I also need your help in this time.
>> >> >
>> >> > Now I am implementing IoRegisterFsRegistrationChange to let our
>> >> > filesystem
>> >> > filter driver attach to filesystem driver’s control device object.
>> >> > Furtunately I success to attach to it, but I have problem in
>> >> > detaching.
>> >> >
>> >> > When FsActive is FALSE, I am going to delete our device object and
>> >> > before
>> >> > calling IoDeleteDevice, call IoDetachDevice to release our device
>> >> > object
>> >> > from device stack chain. It works fine when noone attaching our
>> >> > device
>> >> > object,. but when any device object attaches to our device object,
>> >> > it
>> >> > do
>> >> > not delete device object.
>> >> >
>> >> > Can I delete our device object with IoDeleteDevice even if any
>> >> > device
>> >> > object attaches to ours? I am worry about what happen to attached
>> >> > device
>> >> > object if I delete our device object.
>> >> >
>> >> > Please give me your adivce and any pointer is also welcome.
>> >> >
>> >> > Thank you,
>> >> > Hideyuki Inamasu.
>> >> >
>> >> > ========== OUTLINE OF MY CODE ============
>> >> > VOID
>> >> > MyFileSystemNotification(
>> >> > PDEVICE_OBJECT DeviceObject,
>> >> > BOOLEAN FsActive
>> >> > )
>> >> > {
>> >> > NTSTATUS status;
>> >> > PDEVICE_OBJECT hookDevice, layeredDevice;
>> >> > PFSRC_HOOK_EXTENSION deviceExtension;
>> >> > PDEVICE_OBJECT saveDevice;
>> >> > PDEVICE_OBJECT targetDevice;
>> >> >
>> >> > if (DeviceObject->DeviceType != FILE_DEVICE_DISK_FILE_SYSTEM &&
>> >> > DeviceObject->DeviceType != FILE_DEVICE_CD_ROM_FILE_SYSTEM &&
>> >> > DeviceObject->DeviceType != FILE_DEVICE_TAPE_FILE_SYSTEM)
>> >> > return;
>> >> >
>> >> > if (FsActive) {
>> >> > //
>> >> > // Attaching to device object handler is here.
>> >> > //
>> >> > } else {
>> >> >
>> >> > ASSERT(DeviceObject);
>> >> >
>> >> > targetDevice=DeviceObject;
>> >> >
>> >> > for (layeredDevice=DeviceObject->AttachedDevice;
>> >> > layeredDevice!=NULL;
>> >> > layeredDevice=layeredDevice->AttachedDevice) {
>> >> >
>> >> > hookDevice=thisDriver->DeviceObject;
>> >> > while (hookDevice!=NULL) {
>> >> >
>> >> > if (hookDevice==layeredDevice) {
>> >> >
>> >> > DebugPrint((“CWATNET: determined that the device
>> >> > going
>> >> > a”
>> >> > “way is attached to by CWATNET device
>> >> > %x\n”,hookDevice));
>> >> >
>> >> > IoDetachDevice(targetDevice);
>> >> > deviceExtension=hookDevice->DeviceExtension;
>> >> > deviceExtension->attachedDevice=NULL;
>> >> >
>> >> > //
>> >> > // We should delete our device, but if someone
>> >> > attached
>> >> > to
>> >> > // it, that could be unwise.
>> >> > //
>> >> > if (hookDevice->AttachedDevice==NULL) {
>> >> > saveDevice=hookDevice->NextDevice;
>> >> > IoDeleteDevice(hookDevice);
>> >> > hookDevice=saveDevice;
>> >> > return;
>> >> > } else {
>> >> > hookDevice=hookDevice->NextDevice;
>> >> > }
>> >> > } else {
>> >> > hookDevice=hookDevice->NextDevice;
>> >> > }
>> >> > }
>> >> >
>> >> > targetDevice=layeredDevice;
>> >> > }
>> >> > }
>> >> > }
>> >> >
>> >> >
>> >> >
>> >>
>> >>
>> >> —
>> >> Questions? First check the IFS FAQ at
>> > https://www.osronline.com/article.cfm?id=17
>> >>
>> >> You are currently subscribed to ntfsd as: xxxxx@storagecraft.com
>> >> To unsubscribe send a blank email to xxxxx@lists.osr.com
>> >
>> >
>>
>>
>> —
>> Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17
>>
>> You are currently subscribed to ntfsd as: xxxxx@storagecraft.com
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>