Extend file length.

Hi,
I am writing the encryption minifilter driver.
I extend file length in CACHED WRITE, like:

if (Data->Iopb->Parameters.Write.Length + Data->Iopb->Parameters.Write.ByteOffset.QuadPart) > (fcb->ValidDataLength.QuadPart-sizeof(ENCRYPT_HEADER))
Data->Iopb->Parameters.Write.Length += sizeof(ENCRYPT_HEADER);
FltSetCallbackDataDirty(Data);

I append 10 bytes to the file, it works well.But when i append 512 bytes or more, the file was only extended 511 bytes, the rest was not.
I try to use CcSetFileSizes(…) instead of “Data->Iopb->Parameters.Write.Length += sizeof(ENCRYPT_HEADER);”, but the file length was not extended.

Thanks,
Box

Can anyone figure out the problem here?
Any help will be appreciate.

Probably not in the six minutes you waited before posting this.

xxxxx@gmail.com wrote:

Can anyone figure out the problem here?
Any help will be appreciate.

xxxxx@gmail.com wrote:

I can’t tell you how much I loved Martin’s response.

Just taking a shot in the dark here, but at glance it appears your not
extending the length of the file,
instead your just extending the length of the data.

Then again, this isn’t my thing, nor are drivers really. Just my two cents.

Matt

Hi,
I am writing the encryption minifilter driver.
I extend file length in CACHED WRITE, like:

if (Data->Iopb->Parameters.Write.Length + Data->Iopb->Parameters.Write.ByteOffset.QuadPart) > (fcb->ValidDataLength.QuadPart-sizeof(ENCRYPT_HEADER))
Data->Iopb->Parameters.Write.Length += sizeof(ENCRYPT_HEADER);
FltSetCallbackDataDirty(Data);

I append 10 bytes to the file, it works well.But when i append 512 bytes or more, the file was only extended 511 bytes, the rest was not.
I try to use CcSetFileSizes(…) instead of “Data->Iopb->Parameters.Write.Length += sizeof(ENCRYPT_HEADER);”, but the file length was not extended.

Thanks,
Box


NTFSD is sponsored by OSR

For our schedule debugging and file system seminars
(including our new fs mini-filter seminar) visit:
http://www.osr.com/seminars

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

> I am writing the encryption minifilter driver

Ok, but this is impossible without deep intrusion into Memory and Cache
Manager unless you mange FOs in your filter.

I extend file length in CACHED WRITE, like:
if (Data->Iopb->Parameters.Write.Length +
Data->Iopb->Parameters.Write.ByteOffset.QuadPart) >
(fcb->ValidDataLength.QuadPart-sizeof(ENCRYPT_HEADER))
… the file was only extended 511 bytes, the rest was not.

What is the logic behind this operation?
You compare the valid data length to be set by FSD with
fcb->ValidDataLength.QuadPart minus your header, but fcb->ValidDataLength is
not a file size and should not be interpreted by filters.

I try to use CcSetFileSizes(…) instead

This function should be used only after physical space has been allocated by
FSD.


Slava Imameyev, xxxxx@hotmail.com

wrote in message news:xxxxx@ntfsd…
> Hi,
> I am writing the encryption minifilter driver.
> I extend file length in CACHED WRITE, like:
>
> if (Data->Iopb->Parameters.Write.Length +
> Data->Iopb->Parameters.Write.ByteOffset.QuadPart) >
> (fcb->ValidDataLength.QuadPart-sizeof(ENCRYPT_HEADER))
> Data->Iopb->Parameters.Write.Length += sizeof(ENCRYPT_HEADER);
> FltSetCallbackDataDirty(Data);
>
> I append 10 bytes to the file, it works well.But when i append 512 bytes
> or more, the file was only extended 511 bytes, the rest was not.
> I try to use CcSetFileSizes(…) instead of
> “Data->Iopb->Parameters.Write.Length += sizeof(ENCRYPT_HEADER);”, but the
> file length was not extended.
>
> Thanks,
> Box
>

Thank you very much, Slava Imameyev.

Alexei Jelvis said:
“The write scenario usually works this way 1) A cached write
comes to the FSD. The FileSize and ValidDataLength will be updated, if
the write goes past the end of the file. 2) File system will issue some
cache-writing function (e.g. CcCopyWrite) 3) Later, when the cache
manager lazily flushes the file, it will send a paging write request.
The File system will write the data up to FileSize, adjusted in the step
1)”

When write data to CC, “fcb->ValidDataLength.QuadPart” is the file length with my header, and “(Data->Iopb->Parameters.Write.Length + Data->Iopb->Parameters.Write.ByteOffset.QuadPart)” is the the file length without my header. I want " the write goes past the end of the file", so, I write more sizeof(ENCRYPT_HEADER).I think the FileSize and ValidDataLength will be updated. Did i do right?

> ValidDataLength.QuadPart" is the file length with my header

ValidDataLength is the “valid data length” which might be smaller than the
file size.

I want " the write goes past the end of the file"

If so, why do you use ValidDataLength? The ValidDataLength is changed by FSD
itself and by requests from the Cache Manager and Memory Manager( the exact
behavior depends on particular FSD ). Fcb->ValidDataLength might be smaller
than the offset of the last dirty page in the cache. Also, I doubt that you
properly lock the FCB before using ValidDataLength as only FSD can do this
in a safe maner.


Slava Imameyev, xxxxx@hotmail.com

wrote in message news:xxxxx@ntfsd…
> Thank you very much, Slava Imameyev.
>
> Alexei Jelvis said:
> “The write scenario usually works this way 1) A cached write
> comes to the FSD. The FileSize and ValidDataLength will be updated, if
> the write goes past the end of the file. 2) File system will issue some
> cache-writing function (e.g. CcCopyWrite) 3) Later, when the cache
> manager lazily flushes the file, it will send a paging write request.
> The File system will write the data up to FileSize, adjusted in the step
> 1)”
>
>
> When write data to CC, “fcb->ValidDataLength.QuadPart” is the file length
> with my header, and “(Data->Iopb->Parameters.Write.Length +
> Data->Iopb->Parameters.Write.ByteOffset.QuadPart)” is the the file length
> without my header. I want " the write goes past the end of the file", so,
> I write more sizeof(ENCRYPT_HEADER).I think the FileSize and
> ValidDataLength will be updated. Did i do right?
>
>

Thank you very much, Slava Imameyev.
I almost fixed my work :slight_smile:
I call FltSetInformationFile() in noncached,paging write instead, to extend ValidDataLength, FileSize, AllocationSize.But the system hanged some time. I will try to find it out :slight_smile: