When is FileObject->CurrentByteOffset used?

All,

Looking at the DDK docs, I see that the current file offset is used in
read/writes when:

The FO_SYNCHRONOUS_IO flag is set in the file object and either of the
following are true:

  1. IrpSp->Parameters.Write.ByteOffset == NULL
  2. IrpSp->Parameters.Write.ByteOffset.LowPart ==
    FILE_USE_FILE_POINTER_POSITION and
    IrpSp->Parameters.Write.ByteOffset.HighPart == -1

Is this true for all IO, including non cached, paging and synchronous paging
IO? I don’t have enough experience or knowledge to back this up, but it
feels like this shouldn’t be true for paging IO.

I had a look through FastFat and so far I have only managed to find
CurrentByteOffset being assigned to; not read from. And the
CurrentByteOffset is only updated for Synchronous IO that is not Paging IO.

Are there any hard and fast rules I can follow?

Many thanks,

Carl

> Is this true for all IO, including non cached, paging and synchronous paging

IO? I don’t have enough experience or knowledge to back this up, but it
feels like this shouldn’t be true for paging IO.

You cannot send paging IO via NtRead/WriteFile, and the byte offset logic you
mentioned in in this routine.

With paging IO, you must fill irpSp yourself.


Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

Thank you Maxim,

I am maintaining a legacy filter driver and we are researching adding file
encryption to it. We are encrypting/decrypting non-cached, paging and
synchronous paging io (encrypting a copy of the buffer so as not pollute the
cache). The Initialization Vector for the crypto algorithm needs to know the
offset the data was read from or written to.

So, am I right in thinking that Paging IO never uses the current file offset
i.e. always uses offset specified in ByteOffset in the IrpSp? Whereas, non
cached IO can use the current byte offset if the file object was opened for
synchronous IO and ByteOffset is 0?

Carl

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntfsd…
>> Is this true for all IO, including non cached, paging and synchronous
>> paging
>> IO? I don’t have enough experience or knowledge to back this up, but it
>> feels like this shouldn’t be true for paging IO.
>
> You cannot send paging IO via NtRead/WriteFile, and the byte offset logic
> you
> mentioned in in this routine.
>
> With paging IO, you must fill irpSp yourself.
>
> –
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>

> So, am I right in thinking that Paging IO never uses the current file offset

i.e. always uses offset specified in ByteOffset in the IrpSp?

I would always use this offset for crypto.


Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

Thanks again Maxim,

Sorry to be a pain, but I just want to make sure. Do you mean always use
ByteOffset from irpSp or CurrentByteOffset from the file object for crypto?
I am assuming that you are saying I should use ByteOffset.

Carl

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntfsd…
>> So, am I right in thinking that Paging IO never uses the current file
>> offset
>> i.e. always uses offset specified in ByteOffset in the IrpSp?
>
> I would always use this offset for crypto.
>
> –
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>

> Sorry to be a pain, but I just want to make sure. Do you mean always use

ByteOffset from irpSp

Yes.


Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

Thank you very much!

Carl

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntfsd…
>> Sorry to be a pain, but I just want to make sure. Do you mean always use
>> ByteOffset from irpSp
>
> Yes.
>
> –
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>

Remember that the CurrentByteOffset could be any value up to the
filesize, but the
irpSp in a paging io is going to by a multiple of the pagesize. So it
doesn’t make
sense to use the CurrentByteOffset, since you would be writing/reading
pages in paging io,
and your write/read position could have started out in the middle of a
page.

-Jeff

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Carl
Sent: Tuesday, February 12, 2008 12:08 PM
To: Windows File Systems Devs Interest List
Subject: Re:[ntfsd] When is FileObject->CurrentByteOffset used?

Thank you very much!

Carl

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntfsd…
>> Sorry to be a pain, but I just want to make sure. Do you mean always
use
>> ByteOffset from irpSp
>
> Yes.
>
> –
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>


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: xxxxx@emc.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Jeff,

Thank you for your answer. After a lot of playing and obscure searches, it
seems that CurrentByteOffset is of little or no consequence for non-cached
and paging io. Thanks to you and Maxim I think I have got my head around
this now.

There was an old list thread that came in useful too:
http://www.osronline.com/showThread.cfm?link=36933. I spent about a day
searching for information before I eventually posted, I am amazed I didn’t
find it.

Thanks again.

Carl

wrote in message news:xxxxx@ntfsd…
> Remember that the CurrentByteOffset could be any value up to the
> filesize, but the
> irpSp in a paging io is going to by a multiple of the pagesize. So it
> doesn’t make
> sense to use the CurrentByteOffset, since you would be writing/reading
> pages in paging io,
> and your write/read position could have started out in the middle of a
> page.
>
> -Jeff
>
> -----Original Message-----
> From: xxxxx@lists.osr.com
> [mailto:xxxxx@lists.osr.com] On Behalf Of Carl
> Sent: Tuesday, February 12, 2008 12:08 PM
> To: Windows File Systems Devs Interest List
> Subject: Re:[ntfsd] When is FileObject->CurrentByteOffset used?
>
> Thank you very much!
>
> Carl
>
> “Maxim S. Shatskih” wrote in message
> news:xxxxx@ntfsd…
>>> Sorry to be a pain, but I just want to make sure. Do you mean always
> use
>>> ByteOffset from irpSp
>>
>> Yes.
>>
>> –
>> Maxim Shatskih, Windows DDK MVP
>> StorageCraft Corporation
>> xxxxx@storagecraft.com
>> http://www.storagecraft.com
>>
>>
>
> —
> 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: xxxxx@emc.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>