CcCopyWrite non-aligned writes

Hi,

I am having difficulties with non-aligned writes and CcCopyWrite(). For
instance, I open a file, use SetFilePointer() to point to byte offset 10 and
then call WriteFile() for a 16KB buffer.
This operating causes a IRP_MJ_WRITE with the correct offset of 10 and
length of 16KB. My driver then calls CcCopyWrite() and the write completes.
Eventually, an other IRP_MJ_WRITE is called with IRP_PAGING_IO and my driver
writes this to disk. The problem is that the first 10 bytes of the file are
overwritten by zeros.

According to Rajeev Nagar’s book in his discussion of CcCopyWrite() and
partial writes, “If, however,an enitre page is not being modified, the VMM
must ensure that the original contents of the page have been brought into
memory before the modification of a subset of the appropriate byte range is
allowed to proceed.”

Should CcCopyWrite() invoke a IRP_MJ_READ? If so, what is my driver doing
to prevent this? If not, do I need to handle the read during the
IRP_MJ_WRITE, IRP_PAGING_IO operation? All page-aligned I/O works great;
I’m only having problems with non-aligned writes. Any and all help is
welcome.

Thanks in advance,

Steve

I answered my own question. My driver wasn’t setting directly
ValidDataLength in the FSRTL_COMMON_FCB_HEADER of FsContext. For some
reason, I was under the impression that CcSetFileSizes() actually
manipulated these values. After setting VDL appropriately, CcCopyWrite()
invoked an IRP_MJ_READ call correctly.

Cheers,

Steve

“Steve Soltis” wrote in message news:xxxxx@ntfsd…
> I am having difficulties with non-aligned writes and CcCopyWrite(). For
> instance, I open a file, use SetFilePointer() to point to byte offset 10
and
> then call WriteFile() for a 16KB buffer.
> This operating causes a IRP_MJ_WRITE with the correct offset of 10 and
> length of 16KB. My driver then calls CcCopyWrite() and the write
completes.
> Eventually, an other IRP_MJ_WRITE is called with IRP_PAGING_IO and my
driver
> writes this to disk. The problem is that the first 10 bytes of the file
are
> overwritten by zeros.
>
> According to Rajeev Nagar’s book in his discussion of CcCopyWrite() and
> partial writes, “If, however,an enitre page is not being modified, the VMM
> must ensure that the original contents of the page have been brought into
> memory before the modification of a subset of the appropriate byte range
is
> allowed to proceed.”