Addref/Deref in shadow device

I wander how to solve this puzzle…
When shadow device handles create IRP it must set FileObject->DeviceObject
to
whatever is underlying volume (real) device. Otherwise NTFS will assert on
volume
being not its volume. So, FileObject->DeviceObject must be replaced with
underlying
volume device which means that on close IRP volume device’s refcount will be
decremented
by I/O Mgr. So, it must be incremented in shadow’s create. And shadow
device’s refcount
should be decremented (to maintain consistency). But decrementing shadow
device’s refcount
causes another assertion (in I/O Mgr after IoCallDriver is completed) that
expects this refcount
to be > 0. And even worst, because I/O Mgr assertion suggests that I/O Mgr
uses a “cached” device
object instead of reusing the one that is addressed by
FileObject->DeviceObject. So, if create
completes with a failure I/O Mgr will decrement “wrong” refcount (of shadow
device) and will not
decrement volume’s refcount. So, looks like in shadow’s create dispatch I
need to check create’s
status and rollback changes in case of failure. But (since create can be
asynchronous) it’s not
that simple anymore :slight_smile:
So, is it really that puzzling, or am I just paying too much attention to
these issues?

TIA,

Vladimir

As always, the devil is in the details. Conceptually, the shadow device technique is simple. However, the corner cases extract a pound of flesh. That is why maintaining ONE filter on this platform is practically a full time job.

-----Original Message-----
From: Vladimir Chtchetkine [mailto:xxxxx@starbase.com]
Sent: Tuesday, August 27, 2002 12:47 PM
To: File Systems Developers
Subject: [ntfsd] Addref/Deref in shadow device

I wander how to solve this puzzle…
When shadow device handles create IRP it must set FileObject->DeviceObject to
whatever is underlying volume (real) device. Otherwise NTFS will assert on volume
being not its volume. So, FileObject->DeviceObject must be replaced with underlying
volume device which means that on close IRP volume device’s refcount will be decremented
by I/O Mgr. So, it must be incremented in shadow’s create. And shadow device’s refcount
should be decremented (to maintain consistency). But decrementing shadow device’s refcount
causes another assertion (in I/O Mgr after IoCallDriver is completed) that expects this refcount
to be > 0. And even worst, because I/O Mgr assertion suggests that I/O Mgr uses a “cached” device
object instead of reusing the one that is addressed by FileObject->DeviceObject. So, if create
completes with a failure I/O Mgr will decrement “wrong” refcount (of shadow device) and will not
decrement volume’s refcount. So, looks like in shadow’s create dispatch I need to check create’s
status and rollback changes in case of failure. But (since create can be asynchronous) it’s not
that simple anymore :slight_smile:
So, is it really that puzzling, or am I just paying too much attention to these issues?

TIA,

Vladimir


You are currently subscribed to ntfsd as: xxxxx@inin.com
To unsubscribe send a blank email to %%email.unsub%%

Addref/Deref in shadow deviceWhy dont you just roll your own IRP_MJ_CREATE ?
----- Original Message -----
From: Fuller, Rob
To: File Systems Developers
Sent: Tuesday, August 27, 2002 10:26 PM
Subject: [ntfsd] RE: Addref/Deref in shadow device

As always, the devil is in the details. Conceptually, the shadow device technique is simple. However, the corner cases extract a pound of flesh. That is why maintaining ONE filter on this platform is practically a full time job.
-----Original Message-----
From: Vladimir Chtchetkine [mailto:xxxxx@starbase.com]
Sent: Tuesday, August 27, 2002 12:47 PM
To: File Systems Developers
Subject: [ntfsd] Addref/Deref in shadow device

I wander how to solve this puzzle…
When shadow device handles create IRP it must set FileObject->DeviceObject to
whatever is underlying volume (real) device. Otherwise NTFS will assert on volume
being not its volume. So, FileObject->DeviceObject must be replaced with underlying
volume device which means that on close IRP volume device’s refcount will be decremented
by I/O Mgr. So, it must be incremented in shadow’s create. And shadow device’s refcount
should be decremented (to maintain consistency). But decrementing shadow device’s refcount
causes another assertion (in I/O Mgr after IoCallDriver is completed) that expects this refcount
to be > 0. And even worst, because I/O Mgr assertion suggests that I/O Mgr uses a “cached” device
object instead of reusing the one that is addressed by FileObject->DeviceObject. So, if create
completes with a failure I/O Mgr will decrement “wrong” refcount (of shadow device) and will not
decrement volume’s refcount. So, looks like in shadow’s create dispatch I need to check create’s
status and rollback changes in case of failure. But (since create can be asynchronous) it’s not
that simple anymore :slight_smile:
So, is it really that puzzling, or am I just paying too much attention to these issues?

TIA,

Vladimir


You are currently subscribed to ntfsd as: xxxxx@inin.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
To unsubscribe send a blank email to %%email.unsub%%

'cause rolling your own create IRP is much more complex thing…

-----Original Message-----
From: Dan Partelly [mailto:xxxxx@rdsor.ro]
Sent: Tuesday, August 27, 2002 3:30 PM
To: File Systems Developers
Subject: [ntfsd] RE: Addref/Deref in shadow device

Why dont you just roll your own IRP_MJ_CREATE ?

----- Original Message -----
From: Fuller, mailto:xxxxx Rob
To: File Systems Developers mailto:xxxxx
Sent: Tuesday, August 27, 2002 10:26 PM
Subject: [ntfsd] RE: Addref/Deref in shadow device

As always, the devil is in the details. Conceptually, the shadow device
technique is simple. However, the corner cases extract a pound of flesh.
That is why maintaining ONE filter on this platform is practically a full
time job.

-----Original Message-----
From: Vladimir Chtchetkine [mailto:xxxxx@starbase.com]
Sent: Tuesday, August 27, 2002 12:47 PM
To: File Systems Developers
Subject: [ntfsd] Addref/Deref in shadow device

I wander how to solve this puzzle…
When shadow device handles create IRP it must set FileObject->DeviceObject
to
whatever is underlying volume (real) device. Otherwise NTFS will assert on
volume
being not its volume. So, FileObject->DeviceObject must be replaced with
underlying
volume device which means that on close IRP volume device’s refcount will be
decremented
by I/O Mgr. So, it must be incremented in shadow’s create. And shadow
device’s refcount
should be decremented (to maintain consistency). But decrementing shadow
device’s refcount
causes another assertion (in I/O Mgr after IoCallDriver is completed) that
expects this refcount
to be > 0. And even worst, because I/O Mgr assertion suggests that I/O Mgr
uses a “cached” device
object instead of reusing the one that is addressed by
FileObject->DeviceObject. So, if create
completes with a failure I/O Mgr will decrement “wrong” refcount (of shadow
device) and will not
decrement volume’s refcount. So, looks like in shadow’s create dispatch I
need to check create’s
status and rollback changes in case of failure. But (since create can be
asynchronous) it’s not
that simple anymore :slight_smile:
So, is it really that puzzling, or am I just paying too much attention to
these issues?

TIA,

Vladimir


You are currently subscribed to ntfsd as: xxxxx@inin.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntfsd as: xxxxx@Starbase.com
To unsubscribe send a blank email to %%email.unsub%%</mailto:xxxxx></mailto:xxxxx>

Addref/Deref in shadow deviceOnly in theory.
----- Original Message -----
From: Vladimir Chtchetkine
To: File Systems Developers
Sent: Wednesday, August 28, 2002 2:10 AM
Subject: [ntfsd] RE: Addref/Deref in shadow device

'cause rolling your own create IRP is much more complex thing…
-----Original Message-----
From: Dan Partelly [mailto:xxxxx@rdsor.ro]
Sent: Tuesday, August 27, 2002 3:30 PM
To: File Systems Developers
Subject: [ntfsd] RE: Addref/Deref in shadow device

Why dont you just roll your own IRP_MJ_CREATE ?
----- Original Message -----
From: Fuller, Rob
To: File Systems Developers
Sent: Tuesday, August 27, 2002 10:26 PM
Subject: [ntfsd] RE: Addref/Deref in shadow device

As always, the devil is in the details. Conceptually, the shadow device technique is simple. However, the corner cases extract a pound of flesh. That is why maintaining ONE filter on this platform is practically a full time job.
-----Original Message-----
From: Vladimir Chtchetkine [mailto:xxxxx@starbase.com]
Sent: Tuesday, August 27, 2002 12:47 PM
To: File Systems Developers
Subject: [ntfsd] Addref/Deref in shadow device

I wander how to solve this puzzle…
When shadow device handles create IRP it must set FileObject->DeviceObject to
whatever is underlying volume (real) device. Otherwise NTFS will assert on volume
being not its volume. So, FileObject->DeviceObject must be replaced with underlying
volume device which means that on close IRP volume device’s refcount will be decremented
by I/O Mgr. So, it must be incremented in shadow’s create. And shadow device’s refcount
should be decremented (to maintain consistency). But decrementing shadow device’s refcount
causes another assertion (in I/O Mgr after IoCallDriver is completed) that expects this refcount
to be > 0. And even worst, because I/O Mgr assertion suggests that I/O Mgr uses a “cached” device
object instead of reusing the one that is addressed by FileObject->DeviceObject. So, if create
completes with a failure I/O Mgr will decrement “wrong” refcount (of shadow device) and will not
decrement volume’s refcount. So, looks like in shadow’s create dispatch I need to check create’s
status and rollback changes in case of failure. But (since create can be asynchronous) it’s not
that simple anymore :slight_smile:
So, is it really that puzzling, or am I just paying too much attention to these issues?

TIA,

Vladimir


You are currently subscribed to ntfsd as: xxxxx@inin.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntfsd as: xxxxx@Starbase.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
To unsubscribe send a blank email to %%email.unsub%%

Do you have a code sample I can take a look at?

-----Original Message-----
From: Dan Partelly [mailto:xxxxx@rdsor.ro]
Sent: Tuesday, August 27, 2002 4:16 PM
To: File Systems Developers
Subject: [ntfsd] RE: Addref/Deref in shadow device

Only in theory.

----- Original Message -----
From: Vladimir Chtchetkine mailto:xxxxx
To: File Systems Developers mailto:xxxxx
Sent: Wednesday, August 28, 2002 2:10 AM
Subject: [ntfsd] RE: Addref/Deref in shadow device

'cause rolling your own create IRP is much more complex thing…

-----Original Message-----
From: Dan Partelly [mailto:xxxxx@rdsor.ro]
Sent: Tuesday, August 27, 2002 3:30 PM
To: File Systems Developers
Subject: [ntfsd] RE: Addref/Deref in shadow device

Why dont you just roll your own IRP_MJ_CREATE ?

----- Original Message -----
From: Fuller, mailto:xxxxx Rob
To: File Systems Developers mailto:xxxxx
Sent: Tuesday, August 27, 2002 10:26 PM
Subject: [ntfsd] RE: Addref/Deref in shadow device

As always, the devil is in the details. Conceptually, the shadow device
technique is simple. However, the corner cases extract a pound of flesh.
That is why maintaining ONE filter on this platform is practically a full
time job.

-----Original Message-----
From: Vladimir Chtchetkine [mailto:xxxxx@starbase.com]
Sent: Tuesday, August 27, 2002 12:47 PM
To: File Systems Developers
Subject: [ntfsd] Addref/Deref in shadow device

I wander how to solve this puzzle…
When shadow device handles create IRP it must set FileObject->DeviceObject
to
whatever is underlying volume (real) device. Otherwise NTFS will assert on
volume
being not its volume. So, FileObject->DeviceObject must be replaced with
underlying
volume device which means that on close IRP volume device’s refcount will be
decremented
by I/O Mgr. So, it must be incremented in shadow’s create. And shadow
device’s refcount
should be decremented (to maintain consistency). But decrementing shadow
device’s refcount
causes another assertion (in I/O Mgr after IoCallDriver is completed) that
expects this refcount
to be > 0. And even worst, because I/O Mgr assertion suggests that I/O Mgr
uses a “cached” device
object instead of reusing the one that is addressed by
FileObject->DeviceObject. So, if create
completes with a failure I/O Mgr will decrement “wrong” refcount (of shadow
device) and will not
decrement volume’s refcount. So, looks like in shadow’s create dispatch I
need to check create’s
status and rollback changes in case of failure. But (since create can be
asynchronous) it’s not
that simple anymore :slight_smile:
So, is it really that puzzling, or am I just paying too much attention to
these issues?

TIA,

Vladimir


You are currently subscribed to ntfsd as: xxxxx@inin.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntfsd as: xxxxx@Starbase.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntfsd as: xxxxx@Starbase.com
To unsubscribe send a blank email to %%email.unsub%%</mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx>

Addref/Deref in shadow deviceMr. Pavel Hrdina posted such a code smaple here, then later someone else moded it a bit. Search the archives, by poster name is a good ideea, or for “create reenterancy” “filter own transactions” that sample is a very good start. If you aint unable to find it anymore Ill search my files to see what I can find for you.

----- Original Message -----
From: Vladimir Chtchetkine
To: File Systems Developers
Sent: Wednesday, August 28, 2002 2:48 AM
Subject: [ntfsd] RE: Addref/Deref in shadow device

Do you have a code sample I can take a look at?
-----Original Message-----
From: Dan Partelly [mailto:xxxxx@rdsor.ro]
Sent: Tuesday, August 27, 2002 4:16 PM
To: File Systems Developers
Subject: [ntfsd] RE: Addref/Deref in shadow device

Only in theory.
----- Original Message -----
From: Vladimir Chtchetkine
To: File Systems Developers
Sent: Wednesday, August 28, 2002 2:10 AM
Subject: [ntfsd] RE: Addref/Deref in shadow device

'cause rolling your own create IRP is much more complex thing…
-----Original Message-----
From: Dan Partelly [mailto:xxxxx@rdsor.ro]
Sent: Tuesday, August 27, 2002 3:30 PM
To: File Systems Developers
Subject: [ntfsd] RE: Addref/Deref in shadow device

Why dont you just roll your own IRP_MJ_CREATE ?
----- Original Message -----
From: Fuller, Rob
To: File Systems Developers
Sent: Tuesday, August 27, 2002 10:26 PM
Subject: [ntfsd] RE: Addref/Deref in shadow device

As always, the devil is in the details. Conceptually, the shadow device technique is simple. However, the corner cases extract a pound of flesh. That is why maintaining ONE filter on this platform is practically a full time job.
-----Original Message-----
From: Vladimir Chtchetkine [mailto:xxxxx@starbase.com]
Sent: Tuesday, August 27, 2002 12:47 PM
To: File Systems Developers
Subject: [ntfsd] Addref/Deref in shadow device

I wander how to solve this puzzle…
When shadow device handles create IRP it must set FileObject->DeviceObject to
whatever is underlying volume (real) device. Otherwise NTFS will assert on volume
being not its volume. So, FileObject->DeviceObject must be replaced with underlying
volume device which means that on close IRP volume device’s refcount will be decremented
by I/O Mgr. So, it must be incremented in shadow’s create. And shadow device’s refcount
should be decremented (to maintain consistency). But decrementing shadow device’s refcount
causes another assertion (in I/O Mgr after IoCallDriver is completed) that expects this refcount
to be > 0. And even worst, because I/O Mgr assertion suggests that I/O Mgr uses a “cached” device
object instead of reusing the one that is addressed by FileObject->DeviceObject. So, if create
completes with a failure I/O Mgr will decrement “wrong” refcount (of shadow device) and will not
decrement volume’s refcount. So, looks like in shadow’s create dispatch I need to check create’s
status and rollback changes in case of failure. But (since create can be asynchronous) it’s not
that simple anymore :slight_smile:
So, is it really that puzzling, or am I just paying too much attention to these issues?

TIA,

Vladimir


You are currently subscribed to ntfsd as: xxxxx@inin.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntfsd as: xxxxx@Starbase.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntfsd as: xxxxx@Starbase.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
To unsubscribe send a blank email to %%email.unsub%%

The only relevant thing that I found is below. So, if you can find something
for me I would
appreciate that.



Fri, 24 Nov 2000 11:13:31 +0100
<mailto:hrdina pavel> ">Hrdina Pavel
RE: Rolling IRP_MJ_CREATE

Content-Type: text/plain

Yes, I used this technique, successfuly.
If you want to know some details or want some
source codes please contact me separately.

Paul

-----Original Message-----
From: xxxxx@lists.osr.com
mailto:xxxxx
[mailto: xxxxx@lists.osr.com
mailto:xxxxx]On Behalf Of
xxxxx@yahoo.com mailto:xxxxx
Sent: Monday, November 20, 2000 7:00 PM
To: File Systems Developers
Subject: [ntfsd] Rolling IRP_MJ_CREATE

Hi everybody!

Has anybody ever created a IRP_MJ_CREATE Irp from scratch? (I’m trying
to
avoid certain re-enter issues for my filter driver)

Unfortunately I don’t know how to initialize the AccessState struct in
‘SecurityContext’. Internally the OS uses SeCreateAccessState() but I’m

not sure about the second parameter (the one which ends up under
ACCESS_STATE.AuxData.)

Any hints?

Thanks,
-Stephan
------------------------------------------------------------------

-----Original Message-----
From: Dan Partelly [mailto:xxxxx@rdsor.ro]
Sent: Tuesday, August 27, 2002 5:02 PM
To: File Systems Developers
Subject: [ntfsd] RE: Addref/Deref in shadow device

Mr. Pavel Hrdina posted such a code smaple here, then later someone else
moded it a bit. Search the archives, by poster name is a good ideea, or for
“create reenterancy” “filter own transactions” that sample is a very good
start. If you aint unable to find it anymore Ill search my files to see what
I can find for you.

----- Original Message -----

From: Vladimir Chtchetkine mailto:xxxxx
To: File Systems Developers mailto:xxxxx
Sent: Wednesday, August 28, 2002 2:48 AM
Subject: [ntfsd] RE: Addref/Deref in shadow device

Do you have a code sample I can take a look at?

-----Original Message-----
From: Dan Partelly [mailto:xxxxx@rdsor.ro]
Sent: Tuesday, August 27, 2002 4:16 PM
To: File Systems Developers
Subject: [ntfsd] RE: Addref/Deref in shadow device

Only in theory.

----- Original Message -----
From: Vladimir Chtchetkine mailto:xxxxx
To: File Systems Developers mailto:xxxxx
Sent: Wednesday, August 28, 2002 2:10 AM
Subject: [ntfsd] RE: Addref/Deref in shadow device

'cause rolling your own create IRP is much more complex thing…

-----Original Message-----
From: Dan Partelly [mailto:xxxxx@rdsor.ro]
Sent: Tuesday, August 27, 2002 3:30 PM
To: File Systems Developers
Subject: [ntfsd] RE: Addref/Deref in shadow device

Why dont you just roll your own IRP_MJ_CREATE ?

----- Original Message -----
From: Fuller, Rob mailto:xxxxx
To: File mailto:xxxxx Systems Developers
Sent: Tuesday, August 27, 2002 10:26 PM
Subject: [ntfsd] RE: Addref/Deref in shadow device

As always, the devil is in the details. Conceptually, the shadow device
technique is simple. However, the corner cases extract a pound of flesh.
That is why maintaining ONE filter on this platform is practically a full
time job.

-----Original Message-----
From: Vladimir Chtchetkine [mailto:xxxxx@starbase.com]
Sent: Tuesday, August 27, 2002 12:47 PM
To: File Systems Developers
Subject: [ntfsd] Addref/Deref in shadow device

I wander how to solve this puzzle…
When shadow device handles create IRP it must set FileObject->DeviceObject
to
whatever is underlying volume (real) device. Otherwise NTFS will assert on
volume
being not its volume. So, FileObject->DeviceObject must be replaced with
underlying
volume device which means that on close IRP volume device’s refcount will be
decremented
by I/O Mgr. So, it must be incremented in shadow’s create. And shadow
device’s refcount
should be decremented (to maintain consistency). But decrementing shadow
device’s refcount
causes another assertion (in I/O Mgr after IoCallDriver is completed) that
expects this refcount
to be > 0. And even worst, because I/O Mgr assertion suggests that I/O Mgr
uses a “cached” device
object instead of reusing the one that is addressed by
FileObject->DeviceObject. So, if create
completes with a failure I/O Mgr will decrement “wrong” refcount (of shadow
device) and will not
decrement volume’s refcount. So, looks like in shadow’s create dispatch I
need to check create’s
status and rollback changes in case of failure. But (since create can be
asynchronous) it’s not
that simple anymore :slight_smile:
So, is it really that puzzling, or am I just paying too much attention to
these issues?

TIA,

Vladimir


You are currently subscribed to ntfsd as: xxxxx@inin.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntfsd as: xxxxx@Starbase.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntfsd as: xxxxx@Starbase.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntfsd as: xxxxx@Starbase.com
To unsubscribe send a blank email to %%email.unsub%%</mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:hrdina>

Addref/Deref in shadow deviceVladimir ,

Last adaptation is here, in this message:

Message posted by: Smith Joel, at Wed 14 Feb 2001, subject is

“Question on preventing my driver from filtering it;s own transactions.”

It is in OSR archives completly. I think now itll be easy to locate it. If you have troubles with the code, and anything aint working as supposed, or have any questions feel free to contact me personally.

Ciao, Dan

----- Original Message -----
From: Vladimir Chtchetkine
To: File Systems Developers
Sent: Wednesday, August 28, 2002 3:52 AM
Subject: [ntfsd] RE: Addref/Deref in shadow device

The only relevant thing that I found is below. So, if you can find something for me I would
appreciate that.


Fri, 24 Nov 2000 11:13:31 +0100
Hrdina Pavel
RE: Rolling IRP_MJ_CREATE

Content-Type: text/plain

Yes, I used this technique, successfuly.
If you want to know some details or want some
source codes please contact me separately.

Paul

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of
xxxxx@yahoo.com
Sent: Monday, November 20, 2000 7:00 PM
To: File Systems Developers
Subject: [ntfsd] Rolling IRP_MJ_CREATE

Hi everybody!

Has anybody ever created a IRP_MJ_CREATE Irp from scratch? (I’m trying
to
avoid certain re-enter issues for my filter driver)

Unfortunately I don’t know how to initialize the AccessState struct in
‘SecurityContext’. Internally the OS uses SeCreateAccessState() but I’m

not sure about the second parameter (the one which ends up under
ACCESS_STATE.AuxData.)

Any hints?

Thanks,
-Stephan
------------------------------------------------------------------

-----Original Message-----
From: Dan Partelly [mailto:xxxxx@rdsor.ro]
Sent: Tuesday, August 27, 2002 5:02 PM
To: File Systems Developers
Subject: [ntfsd] RE: Addref/Deref in shadow device

Mr. Pavel Hrdina posted such a code smaple here, then later someone else moded it a bit. Search the archives, by poster name is a good ideea, or for “create reenterancy” “filter own transactions” that sample is a very good start. If you aint unable to find it anymore Ill search my files to see what I can find for you.

----- Original Message -----
From: Vladimir Chtchetkine
To: File Systems Developers
Sent: Wednesday, August 28, 2002 2:48 AM
Subject: [ntfsd] RE: Addref/Deref in shadow device

Do you have a code sample I can take a look at?
-----Original Message-----
From: Dan Partelly [mailto:xxxxx@rdsor.ro]
Sent: Tuesday, August 27, 2002 4:16 PM
To: File Systems Developers
Subject: [ntfsd] RE: Addref/Deref in shadow device

Only in theory.
----- Original Message -----
From: Vladimir Chtchetkine
To: File Systems Developers
Sent: Wednesday, August 28, 2002 2:10 AM
Subject: [ntfsd] RE: Addref/Deref in shadow device

'cause rolling your own create IRP is much more complex thing…
-----Original Message-----
From: Dan Partelly [mailto:xxxxx@rdsor.ro]
Sent: Tuesday, August 27, 2002 3:30 PM
To: File Systems Developers
Subject: [ntfsd] RE: Addref/Deref in shadow device

Why dont you just roll your own IRP_MJ_CREATE ?
----- Original Message -----
From: Fuller, Rob
To: File Systems Developers
Sent: Tuesday, August 27, 2002 10:26 PM
Subject: [ntfsd] RE: Addref/Deref in shadow device

As always, the devil is in the details. Conceptually, the shadow device technique is simple. However, the corner cases extract a pound of flesh. That is why maintaining ONE filter on this platform is practically a full time job.
-----Original Message-----
From: Vladimir Chtchetkine [mailto:xxxxx@starbase.com]
Sent: Tuesday, August 27, 2002 12:47 PM
To: File Systems Developers
Subject: [ntfsd] Addref/Deref in shadow device

I wander how to solve this puzzle…
When shadow device handles create IRP it must set FileObject->DeviceObject to
whatever is underlying volume (real) device. Otherwise NTFS will assert on volume
being not its volume. So, FileObject->DeviceObject must be replaced with underlying
volume device which means that on close IRP volume device’s refcount will be decremented
by I/O Mgr. So, it must be incremented in shadow’s create. And shadow device’s refcount
should be decremented (to maintain consistency). But decrementing shadow device’s refcount
causes another assertion (in I/O Mgr after IoCallDriver is completed) that expects this refcount
to be > 0. And even worst, because I/O Mgr assertion suggests that I/O Mgr uses a “cached” device
object instead of reusing the one that is addressed by FileObject->DeviceObject. So, if create
completes with a failure I/O Mgr will decrement “wrong” refcount (of shadow device) and will not
decrement volume’s refcount. So, looks like in shadow’s create dispatch I need to check create’s
status and rollback changes in case of failure. But (since create can be asynchronous) it’s not
that simple anymore :slight_smile:
So, is it really that puzzling, or am I just paying too much attention to these issues?

TIA,

Vladimir


You are currently subscribed to ntfsd as: xxxxx@inin.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntfsd as: xxxxx@Starbase.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntfsd as: xxxxx@Starbase.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntfsd as: xxxxx@Starbase.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
To unsubscribe send a blank email to %%email.unsub%%

OK, I’ve found on the OSR’s web site that in Pavel’s message
as of July 19, 2000 9:51 AM there was an attachment APISUP.C
Unfortunately, attachemts are not available from OSR and I don’t
have this message in my archives. Can anyone “resend” me this
file?

TIA,

Vladimir

-----Original Message-----
From: Vladimir Chtchetkine [mailto:xxxxx@starbase.com]
Sent: Tuesday, August 27, 2002 5:53 PM
To: File Systems Developers
Subject: [ntfsd] RE: Addref/Deref in shadow device

The only relevant thing that I found is below. So, if you can find something
for me I would
appreciate that.



Fri, 24 Nov 2000 11:13:31 +0100
<mailto:hrdina pavel> ">Hrdina Pavel
RE: Rolling IRP_MJ_CREATE

Content-Type: text/plain

Yes, I used this technique, successfuly.
If you want to know some details or want some
source codes please contact me separately.

Paul

-----Original Message-----
From: xxxxx@lists.osr.com
mailto:xxxxx
[mailto: xxxxx@lists.osr.com
mailto:xxxxx]On Behalf Of
xxxxx@yahoo.com mailto:xxxxx
Sent: Monday, November 20, 2000 7:00 PM
To: File Systems Developers
Subject: [ntfsd] Rolling IRP_MJ_CREATE

Hi everybody!

Has anybody ever created a IRP_MJ_CREATE Irp from scratch? (I’m trying
to
avoid certain re-enter issues for my filter driver)

Unfortunately I don’t know how to initialize the AccessState struct in
‘SecurityContext’. Internally the OS uses SeCreateAccessState() but I’m

not sure about the second parameter (the one which ends up under
ACCESS_STATE.AuxData.)

Any hints?

Thanks,
-Stephan
------------------------------------------------------------------

-----Original Message-----
From: Dan Partelly [mailto:xxxxx@rdsor.ro]
Sent: Tuesday, August 27, 2002 5:02 PM
To: File Systems Developers
Subject: [ntfsd] RE: Addref/Deref in shadow device

Mr. Pavel Hrdina posted such a code smaple here, then later someone else
moded it a bit. Search the archives, by poster name is a good ideea, or for
“create reenterancy” “filter own transactions” that sample is a very good
start. If you aint unable to find it anymore Ill search my files to see what
I can find for you.

----- Original Message -----

From: Vladimir Chtchetkine mailto:xxxxx
To: File Systems Developers mailto:xxxxx
Sent: Wednesday, August 28, 2002 2:48 AM
Subject: [ntfsd] RE: Addref/Deref in shadow device

Do you have a code sample I can take a look at?

-----Original Message-----
From: Dan Partelly [mailto:xxxxx@rdsor.ro]
Sent: Tuesday, August 27, 2002 4:16 PM
To: File Systems Developers
Subject: [ntfsd] RE: Addref/Deref in shadow device

Only in theory.

----- Original Message -----
From: Vladimir mailto:xxxxx Chtchetkine
To: File Systems Developers mailto:xxxxx
Sent: Wednesday, August 28, 2002 2:10 AM
Subject: [ntfsd] RE: Addref/Deref in shadow device

'cause rolling your own create IRP is much more complex thing…

-----Original Message-----
From: Dan Partelly [mailto:xxxxx@rdsor.ro]
Sent: Tuesday, August 27, 2002 3:30 PM
To: File Systems Developers
Subject: [ntfsd] RE: Addref/Deref in shadow device

Why dont you just roll your own IRP_MJ_CREATE ?

----- Original Message -----
From: Fuller, Rob mailto:xxxxx
To: File mailto:xxxxx Systems Developers
Sent: Tuesday, August 27, 2002 10:26 PM
Subject: [ntfsd] RE: Addref/Deref in shadow device

As always, the devil is in the details. Conceptually, the shadow device
technique is simple. However, the corner cases extract a pound of flesh.
That is why maintaining ONE filter on this platform is practically a full
time job.

-----Original Message-----
From: Vladimir Chtchetkine [mailto:xxxxx@starbase.com]
Sent: Tuesday, August 27, 2002 12:47 PM
To: File Systems Developers
Subject: [ntfsd] Addref/Deref in shadow device

I wander how to solve this puzzle…
When shadow device handles create IRP it must set FileObject->DeviceObject
to
whatever is underlying volume (real) device. Otherwise NTFS will assert on
volume
being not its volume. So, FileObject->DeviceObject must be replaced with
underlying
volume device which means that on close IRP volume device’s refcount will be
decremented
by I/O Mgr. So, it must be incremented in shadow’s create. And shadow
device’s refcount
should be decremented (to maintain consistency). But decrementing shadow
device’s refcount
causes another assertion (in I/O Mgr after IoCallDriver is completed) that
expects this refcount
to be > 0. And even worst, because I/O Mgr assertion suggests that I/O Mgr
uses a “cached” device
object instead of reusing the one that is addressed by
FileObject->DeviceObject. So, if create
completes with a failure I/O Mgr will decrement “wrong” refcount (of shadow
device) and will not
decrement volume’s refcount. So, looks like in shadow’s create dispatch I
need to check create’s
status and rollback changes in case of failure. But (since create can be
asynchronous) it’s not
that simple anymore :slight_smile:
So, is it really that puzzling, or am I just paying too much attention to
these issues?

TIA,

Vladimir


You are currently subscribed to ntfsd as: xxxxx@inin.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntfsd as: xxxxx@Starbase.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntfsd as: xxxxx@Starbase.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntfsd as: xxxxx@Starbase.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntfsd as: xxxxx@Starbase.com
To unsubscribe send a blank email to %%email.unsub%%</mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:hrdina>

Addref/Deref in shadow device
Well, seems the following code in
the shadow dispatch and complete works well…

ShadowDispatch ------------------------

IoCopyCurrentIrpStackLocationToNext(Irp);
IrpSp = IoGetNextIrpStackLocation(Irp);

IrpSp->DeviceObject = DeviceExtension->TargetDevice;

if (IrpSp->FileObject) {
IrpSp->FileObject->DeviceObject = DeviceExtension->RealDevice;
InterlockedIncrement(&DeviceExtension->RealDevice->ReferenceCount);
DerefOnFailure = TRUE;
}

IoSetCompletionRoutine(
Irp,
ShadowComplete,
(PVOID) DerefOnFailure,
TRUE, TRUE, TRUE
);

return(IoCallDriver(DeviceExtension->TargetDevice, Irp));

ShadowComplete:------------------------------

if (Irp->PendingReturned) {
IoMarkIrpPending(Irp);
}

if (NT_SUCCESS(Irp->IoStatus.Status)) {
//
// In the case of successfull open, we need to
// dereference our shadow device object, cause
// no one will do it on close.
//
InterlockedDecrement(&DeviceObject->ReferenceCount);
}
else {
//
// In the case of unsuccessfull open, we need
// to dereference real device object, if we
// have referenced it before.
//
if (DerefOnFailure) {
InterlockedDecrement(&DeviceExtension->RealDevice->ReferenceCount);
}
}

return(STATUS_SUCCESS);

Leonid.

P.S. I would also like to to have an example of rolling out
own create IRP. Could you send me it also. Thanks in advance.

“Vladimir Chtchetkine” wrote in message news:xxxxx@ntfsd…
I wander how to solve this puzzle…
When shadow device handles create IRP it must set FileObject->DeviceObject to
whatever is underlying volume (real) device. Otherwise NTFS will assert on volume
being not its volume. So, FileObject->DeviceObject must be replaced with underlying
volume device which means that on close IRP volume device’s refcount will be decremented
by I/O Mgr. So, it must be incremented in shadow’s create. And shadow device’s refcount
should be decremented (to maintain consistency). But decrementing shadow device’s refcount
causes another assertion (in I/O Mgr after IoCallDriver is completed) that expects this refcount
to be > 0. And even worst, because I/O Mgr assertion suggests that I/O Mgr uses a “cached” device
object instead of reusing the one that is addressed by FileObject->DeviceObject. So, if create
completes with a failure I/O Mgr will decrement “wrong” refcount (of shadow device) and will not
decrement volume’s refcount. So, looks like in shadow’s create dispatch I need to check create’s
status and rollback changes in case of failure. But (since create can be asynchronous) it’s not
that simple anymore :slight_smile:
So, is it really that puzzling, or am I just paying too much attention to these issues?

TIA,

Vladimir

Well, with all my respect to Paul I must admit that his code heavily depends
on
using undocumented stuff. I’m not saying that it doesn’t work (sure it
does!). I’m
just saying that there are a lot of undoced calls and structures. Some
people
find this acceptable (and they are right). I don’t (and I’m also right :slight_smile:
So, personally,
I would stick to the shadow device. After all, the implementation of
addref/deref unpuzzling
is (was, actually) pretty much straight forward.

Regards,

Vladimir

-----Original Message-----
From: Vladimir Chtchetkine [mailto:xxxxx@starbase.com]
Sent: Tuesday, August 27, 2002 6:42 PM
To: File Systems Developers
Subject: [ntfsd] RE: Addref/Deref in shadow device

OK, I’ve found on the OSR’s web site that in Pavel’s message
as of July 19, 2000 9:51 AM there was an attachment APISUP.C
Unfortunately, attachemts are not available from OSR and I don’t
have this message in my archives. Can anyone “resend” me this
file?

TIA,

Vladimir

-----Original Message-----
From: Vladimir Chtchetkine [mailto:xxxxx@starbase.com]
Sent: Tuesday, August 27, 2002 5:53 PM
To: File Systems Developers
Subject: [ntfsd] RE: Addref/Deref in shadow device

The only relevant thing that I found is below. So, if you can find something
for me I would
appreciate that.



Fri, 24 Nov 2000 11:13:31 +0100
<mailto:hrdina pavel> ">Hrdina Pavel
RE: Rolling IRP_MJ_CREATE

Content-Type: text/plain

Yes, I used this technique, successfuly.
If you want to know some details or want some
source codes please contact me separately.

Paul

-----Original Message-----
From: xxxxx@lists.osr.com
mailto:xxxxx
[mailto: xxxxx@lists.osr.com
mailto:xxxxx]On Behalf Of
xxxxx@yahoo.com mailto:xxxxx
Sent: Monday, November 20, 2000 7:00 PM
To: File Systems Developers
Subject: [ntfsd] Rolling IRP_MJ_CREATE

Hi everybody!

Has anybody ever created a IRP_MJ_CREATE Irp from scratch? (I’m trying
to
avoid certain re-enter issues for my filter driver)

Unfortunately I don’t know how to initialize the AccessState struct in
‘SecurityContext’. Internally the OS uses SeCreateAccessState() but I’m

not sure about the second parameter (the one which ends up under
ACCESS_STATE.AuxData.)

Any hints?

Thanks,
-Stephan
------------------------------------------------------------------

-----Original Message-----
From: Dan Partelly [mailto:xxxxx@rdsor.ro]
Sent: Tuesday, August 27, 2002 5:02 PM
To: File Systems Developers
Subject: [ntfsd] RE: Addref/Deref in shadow device

Mr. Pavel Hrdina posted such a code smaple here, then later someone else
moded it a bit. Search the archives, by poster name is a good ideea, or for
“create reenterancy” “filter own transactions” that sample is a very good
start. If you aint unable to find it anymore Ill search my files to see what
I can find for you.

----- Original Message -----

From: Vladimir Chtchetkine mailto:xxxxx
To: File Systems Developers mailto:xxxxx
Sent: Wednesday, August 28, 2002 2:48 AM
Subject: [ntfsd] RE: Addref/Deref in shadow device

Do you have a code sample I can take a look at?

-----Original Message-----
From: Dan Partelly [mailto:xxxxx@rdsor.ro]
Sent: Tuesday, August 27, 2002 4:16 PM
To: File Systems Developers
Subject: [ntfsd] RE: Addref/Deref in shadow device

Only in theory.

----- Original Message -----
From: Vladimir mailto:xxxxx Chtchetkine
To: File mailto:xxxxx Systems Developers
Sent: Wednesday, August 28, 2002 2:10 AM
Subject: [ntfsd] RE: Addref/Deref in shadow device

'cause rolling your own create IRP is much more complex thing…

-----Original Message-----
From: Dan Partelly [mailto:xxxxx@rdsor.ro]
Sent: Tuesday, August 27, 2002 3:30 PM
To: File Systems Developers
Subject: [ntfsd] RE: Addref/Deref in shadow device

Why dont you just roll your own IRP_MJ_CREATE ?

----- Original Message -----
From: Fuller, Rob mailto:xxxxx
To: File mailto:xxxxx Systems Developers
Sent: Tuesday, August 27, 2002 10:26 PM
Subject: [ntfsd] RE: Addref/Deref in shadow device

As always, the devil is in the details. Conceptually, the shadow device
technique is simple. However, the corner cases extract a pound of flesh.
That is why maintaining ONE filter on this platform is practically a full
time job.

-----Original Message-----
From: Vladimir Chtchetkine [mailto:xxxxx@starbase.com]
Sent: Tuesday, August 27, 2002 12:47 PM
To: File Systems Developers
Subject: [ntfsd] Addref/Deref in shadow device

I wander how to solve this puzzle…
When shadow device handles create IRP it must set FileObject->DeviceObject
to
whatever is underlying volume (real) device. Otherwise NTFS will assert on
volume
being not its volume. So, FileObject->DeviceObject must be replaced with
underlying
volume device which means that on close IRP volume device’s refcount will be
decremented
by I/O Mgr. So, it must be incremented in shadow’s create. And shadow
device’s refcount
should be decremented (to maintain consistency). But decrementing shadow
device’s refcount
causes another assertion (in I/O Mgr after IoCallDriver is completed) that
expects this refcount
to be > 0. And even worst, because I/O Mgr assertion suggests that I/O Mgr
uses a “cached” device
object instead of reusing the one that is addressed by
FileObject->DeviceObject. So, if create
completes with a failure I/O Mgr will decrement “wrong” refcount (of shadow
device) and will not
decrement volume’s refcount. So, looks like in shadow’s create dispatch I
need to check create’s
status and rollback changes in case of failure. But (since create can be
asynchronous) it’s not
that simple anymore :slight_smile:
So, is it really that puzzling, or am I just paying too much attention to
these issues?

TIA,

Vladimir


You are currently subscribed to ntfsd as: xxxxx@inin.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntfsd as: xxxxx@Starbase.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntfsd as: xxxxx@Starbase.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntfsd as: xxxxx@Starbase.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntfsd as: xxxxx@Starbase.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntfsd as: xxxxx@Starbase.com
To unsubscribe send a blank email to %%email.unsub%%</mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:xxxxx></mailto:hrdina>

IIRC, the “IO Manager” grabs the VPB spinlock while decrementing the ReferenceCount as well as using InterlockedDecrement (Although this seems like overkill, there is a reason you might want to do something like this in multi-threaded programming, but I digress.) The VPB spinlock is exported by the functions IoAcquireVpbSpinLock and IoReleaseVpbSpinLock.

-----Original Message-----
From: Leonid Zhigunov [mailto:xxxxx@progate.spb.ru]
Sent: Wednesday, August 28, 2002 7:20 AM
To: File Systems Developers
Subject: [ntfsd] Re: Addref/Deref in shadow device

Well, seems the following code in
the shadow dispatch and complete works well…

ShadowDispatch ------------------------

IoCopyCurrentIrpStackLocationToNext(Irp);
IrpSp = IoGetNextIrpStackLocation(Irp);

IrpSp->DeviceObject = DeviceExtension->TargetDevice;

if (IrpSp->FileObject) {
IrpSp->FileObject->DeviceObject = DeviceExtension->RealDevice;
InterlockedIncrement(&DeviceExtension->RealDevice->ReferenceCount);
DerefOnFailure = TRUE;
}

IoSetCompletionRoutine(
Irp,
ShadowComplete,
(PVOID) DerefOnFailure,
TRUE, TRUE, TRUE
);

return(IoCallDriver(DeviceExtension->TargetDevice, Irp));

ShadowComplete:------------------------------

if (Irp->PendingReturned) {
IoMarkIrpPending(Irp);
}

if (NT_SUCCESS(Irp->IoStatus.Status)) {
//
// In the case of successfull open, we need to
// dereference our shadow device object, cause
// no one will do it on close.
//
InterlockedDecrement(&DeviceObject->ReferenceCount);
}
else {
//
// In the case of unsuccessfull open, we need
// to dereference real device object, if we
// have referenced it before.
//
if (DerefOnFailure) {
InterlockedDecrement(&DeviceExtension->RealDevice->ReferenceCount);
}
}

return(STATUS_SUCCESS);

Leonid.

P.S. I would also like to to have an example of rolling out
own create IRP. Could you send me it also. Thanks in advance.

“Vladimir Chtchetkine” < xxxxx@starbase.com> wrote in message news:xxxxx@ntfsd…

I wander how to solve this puzzle…
When shadow device handles create IRP it must set FileObject->DeviceObject to
whatever is underlying volume (real) device. Otherwise NTFS will assert on volume
being not its volume. So, FileObject->DeviceObject must be replaced with underlying
volume device which means that on close IRP volume device’s refcount will be decremented
by I/O Mgr. So, it must be incremented in shadow’s create. And shadow device’s refcount
should be decremented (to maintain consistency). But decrementing shadow device’s refcount
causes another assertion (in I/O Mgr after IoCallDriver is completed) that expects this refcount
to be > 0. And even worst, because I/O Mgr assertion suggests that I/O Mgr uses a “cached” device
object instead of reusing the one that is addressed by FileObject->DeviceObject. So, if create
completes with a failure I/O Mgr will decrement “wrong” refcount (of shadow device) and will not
decrement volume’s refcount. So, looks like in shadow’s create dispatch I need to check create’s
status and rollback changes in case of failure. But (since create can be asynchronous) it’s not
that simple anymore :slight_smile:
So, is it really that puzzling, or am I just paying too much attention to these issues?

TIA,

Vladimir


You are currently subscribed to ntfsd as: xxxxx@inin.com
To unsubscribe send a blank email to %%email.unsub%%

Thanks, Rob!

-----Original Message-----
From: Fuller, Rob [mailto:xxxxx@inin.com]
Sent: Wednesday, August 28, 2002 10:22 AM
To: File Systems Developers
Subject: [ntfsd] Re: Addref/Deref in shadow device

IIRC, the “IO Manager” grabs the VPB spinlock while decrementing the
ReferenceCount as well as using InterlockedDecrement (Although this seems
like overkill, there is a reason you might want to do something like this in
multi-threaded programming, but I digress.) The VPB spinlock is exported by
the functions IoAcquireVpbSpinLock and IoReleaseVpbSpinLock.

-----Original Message-----
From: Leonid Zhigunov [mailto:xxxxx@progate.spb.ru]
Sent: Wednesday, August 28, 2002 7:20 AM
To: File Systems Developers
Subject: [ntfsd] Re: Addref/Deref in shadow device

Well, seems the following code in
the shadow dispatch and complete works well…

ShadowDispatch ------------------------

IoCopyCurrentIrpStackLocationToNext(Irp);
IrpSp = IoGetNextIrpStackLocation(Irp);

IrpSp->DeviceObject = DeviceExtension->TargetDevice;

if (IrpSp->FileObject) {
IrpSp->FileObject->DeviceObject = DeviceExtension->RealDevice;
InterlockedIncrement(&DeviceExtension->RealDevice->ReferenceCount);
DerefOnFailure = TRUE;
}

IoSetCompletionRoutine(
Irp,
ShadowComplete,
(PVOID) DerefOnFailure,
TRUE, TRUE, TRUE
);

return(IoCallDriver(DeviceExtension->TargetDevice, Irp));

ShadowComplete:------------------------------

if (Irp->PendingReturned) {
IoMarkIrpPending(Irp);
}

if (NT_SUCCESS(Irp->IoStatus.Status)) {
//
// In the case of successfull open, we need to
// dereference our shadow device object, cause
// no one will do it on close.
//
InterlockedDecrement(&DeviceObject->ReferenceCount);
}
else {
//
// In the case of unsuccessfull open, we need
// to dereference real device object, if we
// have referenced it before.
//
if (DerefOnFailure) {
InterlockedDecrement(&DeviceExtension->RealDevice->ReferenceCount);
}
}

return(STATUS_SUCCESS);

Leonid.

P.S. I would also like to to have an example of rolling out
own create IRP. Could you send me it also. Thanks in advance.

“Vladimir Chtchetkine” < xxxxx@starbase.com
mailto:xxxxx > wrote in message
news:xxxxx@ntfsd news:xxxxx

I wander how to solve this puzzle…
When shadow device handles create IRP it must set FileObject->DeviceObject
to
whatever is underlying volume (real) device. Otherwise NTFS will assert on
volume
being not its volume. So, FileObject->DeviceObject must be replaced with
underlying
volume device which means that on close IRP volume device’s refcount will be
decremented
by I/O Mgr. So, it must be incremented in shadow’s create. And shadow
device’s refcount
should be decremented (to maintain consistency). But decrementing shadow
device’s refcount
causes another assertion (in I/O Mgr after IoCallDriver is completed) that
expects this refcount
to be > 0. And even worst, because I/O Mgr assertion suggests that I/O Mgr
uses a “cached” device
object instead of reusing the one that is addressed by
FileObject->DeviceObject. So, if create
completes with a failure I/O Mgr will decrement “wrong” refcount (of shadow
device) and will not
decrement volume’s refcount. So, looks like in shadow’s create dispatch I
need to check create’s
status and rollback changes in case of failure. But (since create can be
asynchronous) it’s not
that simple anymore :slight_smile:
So, is it really that puzzling, or am I just paying too much attention to
these issues?

TIA,

Vladimir


You are currently subscribed to ntfsd as: xxxxx@inin.com
To unsubscribe send a blank email to %%email.unsub%%


You are currently subscribed to ntfsd as: xxxxx@Starbase.com
To unsubscribe send a blank email to %%email.unsub%%</news:xxxxx></mailto:xxxxx>

Addref/Deref in shadow deviceIf I recall right, the Vpb spinlock is hold only for manipulation and checks on VPB. In Win 2k , Incrementeing the device reference count requires holding the IopDatabaseLock and not the Vpb lock. Doesnt make any sense
to hold the Vpb lock while working on a device object.

Dan

----- Original Message -----
From: Fuller, Rob
To: File Systems Developers
Sent: Wednesday, August 28, 2002 8:22 PM
Subject: [ntfsd] Re: Addref/Deref in shadow device

IIRC, the “IO Manager” grabs the VPB spinlock while decrementing the ReferenceCount as well as using InterlockedDecrement (Although this seems like overkill, there is a reason you might want to do something like this in multi-threaded programming, but I digress.) The VPB spinlock is exported by the functions IoAcquireVpbSpinLock and IoReleaseVpbSpinLock.
-----Original Message-----
From: Leonid Zhigunov [mailto:xxxxx@progate.spb.ru]
Sent: Wednesday, August 28, 2002 7:20 AM
To: File Systems Developers
Subject: [ntfsd] Re: Addref/Deref in shadow device

Well, seems the following code in
the shadow dispatch and complete works well…

ShadowDispatch ------------------------

IoCopyCurrentIrpStackLocationToNext(Irp);
IrpSp = IoGetNextIrpStackLocation(Irp);

IrpSp->DeviceObject = DeviceExtension->TargetDevice;

if (IrpSp->FileObject) {
IrpSp->FileObject->DeviceObject = DeviceExtension->RealDevice;
InterlockedIncrement(&DeviceExtension->RealDevice->ReferenceCount);
DerefOnFailure = TRUE;
}

IoSetCompletionRoutine(
Irp,
ShadowComplete,
(PVOID) DerefOnFailure,
TRUE, TRUE, TRUE
);

return(IoCallDriver(DeviceExtension->TargetDevice, Irp));

ShadowComplete:------------------------------

if (Irp->PendingReturned) {
IoMarkIrpPending(Irp);
}

if (NT_SUCCESS(Irp->IoStatus.Status)) {
//
// In the case of successfull open, we need to
// dereference our shadow device object, cause
// no one will do it on close.
//
InterlockedDecrement(&DeviceObject->ReferenceCount);
}
else {
//
// In the case of unsuccessfull open, we need
// to dereference real device object, if we
// have referenced it before.
//
if (DerefOnFailure) {
InterlockedDecrement(&DeviceExtension->RealDevice->ReferenceCount);
}
}

return(STATUS_SUCCESS);

Leonid.

P.S. I would also like to to have an example of rolling out
own create IRP. Could you send me it also. Thanks in advance.

“Vladimir Chtchetkine” wrote in message news:xxxxx@ntfsd…
I wander how to solve this puzzle…
When shadow device handles create IRP it must set FileObject->DeviceObject to
whatever is underlying volume (real) device. Otherwise NTFS will assert on volume
being not its volume. So, FileObject->DeviceObject must be replaced with underlying
volume device which means that on close IRP volume device’s refcount will be decremented
by I/O Mgr. So, it must be incremented in shadow’s create. And shadow device’s refcount
should be decremented (to maintain consistency). But decrementing shadow device’s refcount
causes another assertion (in I/O Mgr after IoCallDriver is completed) that expects this refcount
to be > 0. And even worst, because I/O Mgr assertion suggests that I/O Mgr uses a “cached” device
object instead of reusing the one that is addressed by FileObject->DeviceObject. So, if create
completes with a failure I/O Mgr will decrement “wrong” refcount (of shadow device) and will not
decrement volume’s refcount. So, looks like in shadow’s create dispatch I need to check create’s
status and rollback changes in case of failure. But (since create can be asynchronous) it’s not
that simple anymore :slight_smile:
So, is it really that puzzling, or am I just paying too much attention to these issues?

TIA,

Vladimir


You are currently subscribed to ntfsd as: xxxxx@inin.com
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
To unsubscribe send a blank email to %%email.unsub%%