How can I read a file before writing the file?

How can I read a file before writing the file?
I want to redirect file A to file B(i.e. an write request for file A will
be redirected

to write file B other than file A).
I deal with them by intercepting IRP_MJ_WRITE .
now I define :
BOOLEAN Flag = (Irp->Flags & (IRP_NOCACHE | IRP_PAGING_IO |
IRP_SYNCHRONOUS_PAGING_IO));
Flag==FALSE means IRP DOES NOT write data to disk.
(1)NORMALLY, when writing file A , there are two different IRP containing
IRP_MJ_WRITE:
one’s Flag is FALSE , the other’s Flag is TRUE.
in this case, i can copy the file A to file B by constructing an synchronous
IRP for

reading file A and write data to file B when Flag is FALSE.

(2)ABNORMALLY, when writing file A , there are only one IRP containing
IRP_MJ_WRITE:
and its Flag is TRUE. this can happen when FILE_NO_INTERMEDIATE_BUFFERING
and

FILE_WRITE_THROUGH is set.
in this case, i cannot construct an synchronous IRP for reading the file A
when Flag is

TRUE, it seems like file A is locked and os is down.
how can i read file A in this case?

Your basic design has problems, what are you going to do about memory mapped
I/O? You are getting TRUE since FILE_NO_INTERMEDIATE_BUFFERING translates
into IRP_NOCACHE. Bottom line your design is flawed, go over the the NTFSD
group, look at the archives, and then explain your overall goal.


Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Remove StopSpam from the email to reply

“ccoy” wrote in message news:xxxxx@ntdev…
> How can I read a file before writing the file?
> I want to redirect file A to file B(i.e. an write request for file A will
> be redirected
>
> to write file B other than file A).
> I deal with them by intercepting IRP_MJ_WRITE .
> now I define :
> BOOLEAN Flag = (Irp->Flags & (IRP_NOCACHE | IRP_PAGING_IO |
> IRP_SYNCHRONOUS_PAGING_IO));
> Flag==FALSE means IRP DOES NOT write data to disk.
> (1)NORMALLY, when writing file A , there are two different IRP containing
> IRP_MJ_WRITE:
> one’s Flag is FALSE , the other’s Flag is TRUE.
> in this case, i can copy the file A to file B by constructing an
> synchronous IRP for
>
> reading file A and write data to file B when Flag is FALSE.
>
> (2)ABNORMALLY, when writing file A , there are only one IRP containing
> IRP_MJ_WRITE:
> and its Flag is TRUE. this can happen when FILE_NO_INTERMEDIATE_BUFFERING
> and
>
> FILE_WRITE_THROUGH is set.
> in this case, i cannot construct an synchronous IRP for reading the file A
> when Flag is
>
> TRUE, it seems like file A is locked and os is down.
> how can i read file A in this case?
>
>

ccoy , you should ask this question in ntfsd board
“ccoy” wrote in message news:xxxxx@ntdev…
> How can I read a file before writing the file?
> I want to redirect file A to file B(i.e. an write request for file A will
> be redirected
>
> to write file B other than file A).
> I deal with them by intercepting IRP_MJ_WRITE .
> now I define :
> BOOLEAN Flag = (Irp->Flags & (IRP_NOCACHE | IRP_PAGING_IO |
> IRP_SYNCHRONOUS_PAGING_IO));
> Flag==FALSE means IRP DOES NOT write data to disk.
> (1)NORMALLY, when writing file A , there are two different IRP containing
> IRP_MJ_WRITE:
> one’s Flag is FALSE , the other’s Flag is TRUE.
> in this case, i can copy the file A to file B by constructing an
> synchronous IRP for
>
> reading file A and write data to file B when Flag is FALSE.
>
> (2)ABNORMALLY, when writing file A , there are only one IRP containing
> IRP_MJ_WRITE:
> and its Flag is TRUE. this can happen when FILE_NO_INTERMEDIATE_BUFFERING
> and
>
> FILE_WRITE_THROUGH is set.
> in this case, i cannot construct an synchronous IRP for reading the file A
> when Flag is
>
> TRUE, it seems like file A is locked and os is down.
> how can i read file A in this case?
>
>