Read a file currently beeing used by a driver

Archived from groups: microsoft.public.development.device.drivers,microsoft.public.win32.programmer.kernel,microsoft.public.windowsxp.device_driver.dev (More info?)

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
4 answers Last reply
More about read file beeing driver
  1. Archived from groups: microsoft.public.development.device.drivers,microsoft.public.win32.programmer.kernel,microsoft.public.windowsxp.device_driver.dev (More info?)

    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...

    Thomas Johansen wrote:
    > 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
    >
    >

    --
    .../ray\..

    Please remove ".spamblock" from my email address if you need to contact
    me outside the newsgroup.
  2. Archived from groups: microsoft.public.development.device.drivers,microsoft.public.win32.programmer.kernel,microsoft.public.windowsxp.device_driver.dev (More info?)

    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)


    "Ray Trent" <rat@synaptics.spamblock.com> wrote in message
    news:%23BlH1VDnEHA.3868@TK2MSFTNGP11.phx.gbl...
    >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...
    >
    > Thomas Johansen wrote:
    >> 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
    >>
    >>
    >
    > --
    > ../ray\..
    >
    > Please remove ".spamblock" from my email address if you need to contact me
    > outside the newsgroup.
  3. Archived from groups: microsoft.public.development.device.drivers,microsoft.public.win32.programmer.kernel,microsoft.public.windowsxp.device_driver.dev (More info?)

    Thomas Johansen wrote:
    > 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
  4. Archived from groups: microsoft.public.development.device.drivers,microsoft.public.win32.programmer.kernel,microsoft.public.windowsxp.device_driver.dev (More info?)

    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).

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

    "Dave August" <august@NOSPAMacmesi.com> wrote in message
    news:eF90WsEnEHA.3564@tk2msftngp13.phx.gbl...
    > 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)
    >
    >
    > "Ray Trent" <rat@synaptics.spamblock.com> wrote in message
    > news:%23BlH1VDnEHA.3868@TK2MSFTNGP11.phx.gbl...
    > >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...
    > >
    > > Thomas Johansen wrote:
    > >> 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
    > >>
    > >>
    > >
    > > --
    > > ../ray\..
    > >
    > > Please remove ".spamblock" from my email address if you need to contact me
    > > outside the newsgroup.
    >
    >
Ask a new question

Read More

Drivers Microsoft Windows XP