Hi,
Sorry for repeating my earlier question. Nagar’s book states certain
resource acquision constraints before calling these functions. If I
understand it right, it would mean invoking the corresponding fastio calls
on the base file system object. But if I disassemble these calls, they
already seem to be doing the right thing. Am I missing something? Do I need
to acquire certain resources in a specified order before calling these two
functions?
Thanks
This is not theoretically tested, but has been practically tested:
(someone posted it a while back when I asked for cache purging code,
I am skeptical about acquiring the resources, but it has so far done
correctly - not to mention that without this code, an encryption driver
would not correctly work for already accessed files)
void PurgeCache(PFILE_OBJECT lpFileObject)
{
IO_STATUS_BLOCK IoStatus;
PFSRTL_COMMON_FCB_HEADER lpFcb;
lpFcb = (PFSRTL_COMMON_FCB_HEADER)lpFileObject->FsContext;
KeEnterCriticalRegion();
if(lpFcb->Resource)
{
ExAcquireResourceExclusiveLite(lpFcb->Resource, TRUE);
}
if(lpFcb->PagingIoResource)
{
ExAcquireResourceExclusiveLite(lpFcb->PagingIoResource, TRUE);
}
if(lpFileObject->SectionObjectPointer)
{
try
{
CcFlushCache(lpFileObject->SectionObjectPointer,
NULL,
0,
&IoStatus);
if(lpFileObject->SectionObjectPointer->ImageSectionObject)
{
MmFlushImageSection(lpFileObject->SectionObjectPointer,
MmFlushForWrite);
}
if(lpFileObject->SectionObjectPointer->DataSectionObject)
{
CcPurgeCacheSection(lpFileObject->SectionObjectPointer,
NULL,
0,
FALSE);
}
}
except(EXCEPTION_EXECUTE_HANDLER)
{
// Do nothing
}
}
if(lpFcb->PagingIoResource)
{
ExReleaseResourceLite(lpFcb->PagingIoResource);
}
if(lpFcb->Resource)
{
ExReleaseResourceLite(lpFcb->Resource);
}
KeLeaveCriticalRegion();
}
faras namus wrote:
Hi,
Sorry for repeating my earlier question. Nagar’s book states certain
resource acquision constraints before calling these functions. If I
understand it right, it would mean invoking the corresponding fastio
calls
on the base file system object. But if I disassemble these calls, theyalready seem to be doing the right thing. Am I missing something? Do I
need
to acquire certain resources in a specified order before calling these
two
functions?
Thanks
–
Kind regards, Dejan M.
http://www.alfasp.com E-mail: xxxxx@alfasp.com
Alfa Transparent File Encryptor - Transparent file encryption services.
Alfa File Protector - File protection and hiding library for Win32
developers.
Alfa File Monitor - File monitoring library for Win32 developers.
Well, bad news for you, Dejan
This code will deadlock.
Unfortunately NTFS and FAT use different orders acquiring FCB’s
resources. I don’t remember by now which order for which FS but they
are different. So, code below will deadlock on one or the other FS.
For W2K+ use FsRtlAquireFileExclusive / FsRtlReleaseFile. For NT…
Well, for NT you have to figure out acquisition orders for NTFS and FAT,
detect what FS handles your FO and apply appropriate acquisition order.
Vladimir Chtchetkine
Principal Engineer
Borland Software is the global leader in platform independent solutions
for Software Delivery Optimization, helping customers address the
constraints of modern day software development to maximize the business
value of their software.
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Dejan Maksimovic
Sent: Friday, September 09, 2005 4:32 AM
To: Windows File Systems Devs Interest List
Subject: Re: [ntfsd] CcFlushCache and MmFlushImageSection
This is not theoretically tested, but has been practically tested:
(someone posted it a while back when I asked for cache purging code,
I am skeptical about acquiring the resources, but it has so far done
correctly - not to mention that without this code, an encryption driver
would not correctly work for already accessed files)
void PurgeCache(PFILE_OBJECT lpFileObject)
{
IO_STATUS_BLOCK IoStatus;
PFSRTL_COMMON_FCB_HEADER lpFcb;
lpFcb = (PFSRTL_COMMON_FCB_HEADER)lpFileObject->FsContext;
KeEnterCriticalRegion();
if(lpFcb->Resource)
{
ExAcquireResourceExclusiveLite(lpFcb->Resource, TRUE);
}
if(lpFcb->PagingIoResource)
{
ExAcquireResourceExclusiveLite(lpFcb->PagingIoResource, TRUE);
}
if(lpFileObject->SectionObjectPointer)
{
try
{
CcFlushCache(lpFileObject->SectionObjectPointer,
NULL,
0,
&IoStatus);
if(lpFileObject->SectionObjectPointer->ImageSectionObject)
{
MmFlushImageSection(lpFileObject->SectionObjectPointer,
MmFlushForWrite);
}
if(lpFileObject->SectionObjectPointer->DataSectionObject)
{
CcPurgeCacheSection(lpFileObject->SectionObjectPointer,
NULL,
0,
FALSE);
}
}
except(EXCEPTION_EXECUTE_HANDLER)
{
// Do nothing
}
}
if(lpFcb->PagingIoResource)
{
ExReleaseResourceLite(lpFcb->PagingIoResource);
}
if(lpFcb->Resource)
{
ExReleaseResourceLite(lpFcb->Resource);
}
KeLeaveCriticalRegion();
}
faras namus wrote:
Hi,
Sorry for repeating my earlier question. Nagar’s book states certain
resource acquision constraints before calling these functions. If I
understand it right, it would mean invoking the corresponding fastio
calls on the base file system object. But if I disassemble these
calls, theyalready seem to be doing the right thing. Am I missing something? Do I
need to acquire certain resources in a specified order before calling
these two functions?
Thanks
–
Kind regards, Dejan M.
http://www.alfasp.com E-mail: xxxxx@alfasp.com Alfa Transparent File
Encryptor - Transparent file encryption services.
Alfa File Protector - File protection and hiding library for Win32
developers.
Alfa File Monitor - File monitoring library for Win32 developers.
Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17
You are currently subscribed to ntfsd as:
xxxxx@borland.com To unsubscribe send a blank email to
xxxxx@lists.osr.com
That is excellent… thank you.
Vladimir Chtchetkine wrote:
Well, bad news for you, Dejan
This code will deadlock.
Unfortunately NTFS and FAT use different orders acquiring FCB’s
resources. I don’t remember by now which order for which FS but they
are different. So, code below will deadlock on one or the other FS.
For W2K+ use FsRtlAquireFileExclusive / FsRtlReleaseFile. For NT…
Well, for NT you have to figure out acquisition orders for NTFS and FAT,
detect what FS handles your FO and apply appropriate acquisition order.
–
Kind regards, Dejan M.
http://www.alfasp.com E-mail: xxxxx@alfasp.com
Alfa Transparent File Encryptor - Transparent file encryption services.
Alfa File Protector - File protection and hiding library for Win32 developers.
Alfa File Monitor - File monitoring library for Win32 developers.
Looks like I have to do the ERESOURCE dance described by Nick Ryan in one
old post.
I still wondering if I should be invoking the fastio calls or going for the
locks in the FCB directly.
On 9/10/05, Dejan Maksimovic wrote:
>
>
> That is excellent… thank you.
>
> Vladimir Chtchetkine wrote:
>
> > Well, bad news for you, Dejan
This code will deadlock.
> > Unfortunately NTFS and FAT use different orders acquiring FCB’s
> > resources. I don’t remember by now which order for which FS but they
> > are different. So, code below will deadlock on one or the other FS.
> > For W2K+ use FsRtlAquireFileExclusive / FsRtlReleaseFile. For NT…
> > Well, for NT you have to figure out acquisition orders for NTFS and FAT,
> > detect what FS handles your FO and apply appropriate acquisition order.
>
> –
> Kind regards, Dejan M.
> http://www.alfasp.com E-mail: xxxxx@alfasp.com
> Alfa Transparent File Encryptor - Transparent file encryption services.
> Alfa File Protector - File protection and hiding library for Win32
> developers.
> Alfa File Monitor - File monitoring library for Win32 developers.
>
>
>
> —
> Questions? First check the IFS FAQ at
> https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@gmail.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
Going for the locks directly is a dangerous path - it presumes you
understand the locking model of the underlying file system. In our own
file systems we’ve continued to move to a “richer” and more flexible
locking model than the basic model shown in the FAT file system; I
believe that this is also the case for NTFS and likely UDFS. Using the
FsRtl functions is the safest approach because they will use the
callbacks (if registered) or the fast I/O functions (if present) or fall
back to the standard locking paradigm. It is certainly the most “future
proof” as well since it means that if the underlying file system’s
implementation model changes you are more likely to continue to work
correctly.
Alternatively, you’d be best served to ensure your driver only runs on
platforms where you’ve tested it.
Regards,
Tony
Tony Mason
Consulting Partner
OSR Open Systems Resources, Inc.
Looking forward to seeing you at the next OSR File Systems class in Los
Angeles, CA October 24-27, 2005.
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of faras namus
Sent: Saturday, September 10, 2005 3:01 AM
To: ntfsd redirect
Subject: Re: [ntfsd] CcFlushCache and MmFlushImageSection
Looks like I have to do the ERESOURCE dance described by Nick Ryan in
one old post.
I still wondering if I should be invoking the fastio calls or going for
the locks in the FCB directly.
On 9/10/05, Dejan Maksimovic wrote:
That is excellent… thank you.
Vladimir Chtchetkine wrote:
> Well, bad news for you, Dejan
This code will deadlock.
> Unfortunately NTFS and FAT use different orders acquiring FCB’s
> resources. I don’t remember by now which order for which FS but they
> are different. So, code below will deadlock on one or the other FS.
> For W2K+ use FsRtlAquireFileExclusive / FsRtlReleaseFile. For NT…
> Well, for NT you have to figure out acquisition orders for NTFS and
FAT,
> detect what FS handles your FO and apply appropriate acquisition
order.
–
Kind regards, Dejan M.
http://www.alfasp.com E-mail: xxxxx@alfasp.com
Alfa Transparent File Encryptor - Transparent file encryption services.
Alfa File Protector - File protection and hiding library for Win32
developers.
Alfa File Monitor - File monitoring library for Win32 developers.
—
Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17
You are currently subscribed to ntfsd as: xxxxx@gmail.com
To unsubscribe send a blank email to xxxxx@lists.osr.com
mailto:xxxxx
— Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17 You are currently subscribed
to ntfsd as: unknown lmsubst tag argument: ‘’ To unsubscribe send a
blank email to xxxxx@lists.osr.com</mailto:xxxxx>