Read a file currently beeing used by a driver

  • Thread starter Thread starter Thomas Johansen
  • Start date Start date
T

Thomas Johansen

Hi

In my driver, I do log some data in af file on the harddrive. It would be
nice to read the file with notepad, will the driver still is running and
using the file.
I do have some problems doing this.

This is what I would like to do:
Read the file in eg. Notepad, while the driver stilling using the file
If the file allready exits, the driver opens the file, and append anything
new to it.

This is how I open the file in the driver

// Create the file
status = ZwCreateFile( &hLogFile,
SYNCHRONIZE,
&objectAttributes,
&IoStatus,
0,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_WRITE | FILE_SHARE_WRITE,
FILE_OPEN_IF,
FILE_SYNCHRONOUS_IO_NONALERT,
NULL,
0 );

I guess the problem is in the way I create the file, but what ?

Thomas
 
Thomas said:
Hi

In my driver, I do log some data in af file on the harddrive. It would be
nice to read the file with notepad, will the driver still is running and
using the file.
I do have some problems doing this.

This is what I would like to do:
Read the file in eg. Notepad, while the driver stilling using the file
If the file allready exits, the driver opens the file, and append anything
new to it.

This is how I open the file in the driver

// Create the file
status = ZwCreateFile( &hLogFile,
SYNCHRONIZE,
&objectAttributes,
&IoStatus,
0,
FILE_ATTRIBUTE_NORMAL,
FILE_SHARE_WRITE | FILE_SHARE_WRITE,
FILE_OPEN_IF,
FILE_SYNCHRONOUS_IO_NONALERT,
NULL,
0 );

I guess the problem is in the way I create the file, but what ?

Thomas

Hi,

Just a guess, but shouldn't that be:

FILE_SHARE_WRITE | FILE_SHARE_READ

:)

Max Bolingbroke
 
I have a vague memory that the last time I looked into this I ultimately
discovered that Notepad wasn't opening the file for SHARE access, so it
was failing because it couldn't get exclusive access... but this was a
long time ago, so my memory could be faulty.

I do remember writing my own app that opens the file "the right way" and
getting it to work...
 
Ray,

You are right... Most of the Microsoft Apps don't open for share... I just
ran into this (again) with log files from an app that are CSV and if you
open them in Excel they are write locked... <sigh> and yeah my workaround
was to add yet another dialog to this app to read the logs....

The sad thing here for the OP (and me) is that if I don't change the file
extent and someone DOES open the files in Notepad (or Excel) we're
screwed.. <sigh>

Dave (who's out in App land this month not DDK)
 
OLE-based Office apps surely open files exclusively, and require byte range
locking (they fail on FSDs with no such locking. MSI Installer also fails).
 
Back
Top