I anlyzed SFilter source code from Windows 2003 IFS Kit and noticed
SfAttachDeviceToDeviceStack routine. It suggests as workaround for Windows
versions where IoAttachDeviceToDeviceStackSafe routine isnot available to
set AttachedToDeviceObject to the device object that the SourceDevice is
most likely to attach to. In the code it looks like this:
*AttachedToDeviceObject = TargetDevice;
*AttachedToDeviceObject = IoAttachDeviceToDeviceStack(SourceDevice,
TargetDevice);
But TargetDevice may not point to the topmost device in device stack.
Perhaps even more reliable workaround is to find the topmost device in
device stack first. Something like this:
*AttachedToDeviceObject = TargetDevice;
while ((*AttachedToDeviceObject)->AttachedDevice)
{
*AttachedToDeviceObject = (*AttachedToDeviceObject)->AttachedDevice;
}
*AttachedToDeviceObject = IoAttachDeviceToDeviceStack(SourceDevice,
TargetDevice);
Any thought on the topic?
-htfv
Im not 100% sure whatever walking the AttachedDevice chain whithout holding
the IoDatabase lock is safe. Since all attach operations seems to get this
lock before proceeding, i assume walking the chain should be done with the
lock hold. Unfortunately, this lock aint exposed in NT 4, 2k. In XP it is a
queeued lock, easy to access.
Dan
----- Original Message -----
From: “Alexey Logachyov”
To: “File Systems Developers”
Sent: Saturday, August 09, 2003 5:00 PM
Subject: [ntfsd] SfAttachDeviceToDeviceStack
> I anlyzed SFilter source code from Windows 2003 IFS Kit and noticed
> SfAttachDeviceToDeviceStack routine. It suggests as workaround for Windows
> versions where IoAttachDeviceToDeviceStackSafe routine isnot available to
> set AttachedToDeviceObject to the device object that the SourceDevice is
> most likely to attach to. In the code it looks like this:
>
> *AttachedToDeviceObject = TargetDevice;
> *AttachedToDeviceObject = IoAttachDeviceToDeviceStack(SourceDevice,
> TargetDevice);
>
> But TargetDevice may not point to the topmost device in device stack.
> Perhaps even more reliable workaround is to find the topmost device in
> device stack first. Something like this:
>
> *AttachedToDeviceObject = TargetDevice;
> while ((*AttachedToDeviceObject)->AttachedDevice)
> {
> *AttachedToDeviceObject = (*AttachedToDeviceObject)->AttachedDevice;
> }
> *AttachedToDeviceObject = IoAttachDeviceToDeviceStack(SourceDevice,
> TargetDevice);
>
> Any thought on the topic?
>
> -htfv
>
>
>
>
>
> —
> You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
There is a note in SfIsAttachedToDevice routine that read the following:
In Windows 2000, the APIs to safely walk an arbitrary file system device
stack were not supported. If we can guarantee that a device stack won’t be
torn down during the walking of the device stack, we can walk from the base
file system’s device object up to the top of the device stack to see if we
are attached. We know the device stack will not go away if we are in the
process of processing a mount request OR we have a file object open on this
device.
-htfv
----- Original Message -----
From: “Dan Partelly”
To: “File Systems Developers”
Sent: Saturday, August 09, 2003 6:30 PM
Subject: [ntfsd] Re: SfAttachDeviceToDeviceStack
> Im not 100% sure whatever walking the AttachedDevice chain whithout
holding
> the IoDatabase lock is safe. Since all attach operations seems to get this
> lock before proceeding, i assume walking the chain should be done with the
> lock hold. Unfortunately, this lock aint exposed in NT 4, 2k. In XP it is
a
> queeued lock, easy to access.
>
>
> Dan
>
> ----- Original Message -----
> From: “Alexey Logachyov”
> To: “File Systems Developers”
> Sent: Saturday, August 09, 2003 5:00 PM
> Subject: [ntfsd] SfAttachDeviceToDeviceStack
>
>
> > I anlyzed SFilter source code from Windows 2003 IFS Kit and noticed
> > SfAttachDeviceToDeviceStack routine. It suggests as workaround for
Windows
> > versions where IoAttachDeviceToDeviceStackSafe routine isnot available
to
> > set AttachedToDeviceObject to the device object that the SourceDevice is
> > most likely to attach to. In the code it looks like this:
> >
> > *AttachedToDeviceObject = TargetDevice;
> > *AttachedToDeviceObject = IoAttachDeviceToDeviceStack(SourceDevice,
> > TargetDevice);
> >
> > But TargetDevice may not point to the topmost device in device stack.
> > Perhaps even more reliable workaround is to find the topmost device in
> > device stack first. Something like this:
> >
> > *AttachedToDeviceObject = TargetDevice;
> > while ((*AttachedToDeviceObject)->AttachedDevice)
> > {
> > *AttachedToDeviceObject = (*AttachedToDeviceObject)->AttachedDevice;
> > }
> > *AttachedToDeviceObject = IoAttachDeviceToDeviceStack(SourceDevice,
> > TargetDevice);
> >
> > Any thought on the topic?
> >
> > -htfv
> >
> >
> >
> >
> >
> > —
> > You are currently subscribed to ntfsd as: xxxxx@rdsor.ro
> > To unsubscribe send a blank email to xxxxx@lists.osr.com
> >
>
>
>
> —
> You are currently subscribed to ntfsd as: xxxxx@vba.com.by
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>