Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

Flush file cache

OSR_Community_UserOSR_Community_User Member Posts: 110,217
Hi, All
I use these code to write file in my program.
Status = ZwCreateFile(&hFileHandle,
DesiredAccess,
&strObjectAttributes,
&strIoStatusBlock,
NULL,
FILE_ATTRIBUTE_HIDDEN,
ulShareAccess,
FILE_OPEN,
FILE_NON_DIRECTORY_FILE,
NULL,
0);

Status = ZwWriteFile(hFileHandle,
NULL,
NULL,
NULL,
&strIoStatusBlock,
pBuffer,
ulLength,
&unOffset,
NULL);
And I want the data written to the disk immediately. What should I do? For the buffer is not alined with 512 bytes I can not use FILE_NO_INTERMEDIATE_BUFFERING in ZwCreateFile.

Thanks & Regards.

Comments

  • Ken_JohnsonKen_Johnson Member - All Emails Posts: 1,559
    What are you trying to do that requires this?

    - S

    -----Original Message-----
    From: xxxxx@huaweisymantec.com <xxxxx@huaweisymantec.com>
    Sent: Sunday, May 03, 2009 20:26
    To: Windows System Software Devs Interest List <xxxxx@lists.osr.com>
    Subject: [ntdev] Flush file cache


    Hi, All
    I use these code to write file in my program.
    Status = ZwCreateFile(&hFileHandle,
    DesiredAccess,
    &strObjectAttributes,
    &strIoStatusBlock,
    NULL,
    FILE_ATTRIBUTE_HIDDEN,
    ulShareAccess,
    FILE_OPEN,
    FILE_NON_DIRECTORY_FILE,
    NULL,
    0);

    Status = ZwWriteFile(hFileHandle,
    NULL,
    NULL,
    NULL,
    &strIoStatusBlock,
    pBuffer,
    ulLength,
    &unOffset,
    NULL);
    And I want the data written to the disk immediately. What should I do? For the buffer is not alined with 512 bytes I can not use FILE_NO_INTERMEDIATE_BUFFERING in ZwCreateFile.

    Thanks & Regards.

    ---
    NTDEV is sponsored by OSR

    For our schedule of WDF, WDM, debugging and other seminars visit:
    http://www.osr.com/seminars

    To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    If power off, the data will not be written to the disk. So I want to "synchronously" write data before my follow-up operations.
  • Ken_JohnsonKen_Johnson Member - All Emails Posts: 1,559
    If you are trying to achieve transactional robustness manually, then there's much more involved here than just turning flushing buffers in order to ensure that you're truly robust. For instance, what if only a portion of a write gets through before a power failure?

    - S

    -----Original Message-----
    From: xxxxx@huaweisymantec.com <xxxxx@huaweisymantec.com>
    Sent: Sunday, May 03, 2009 22:55
    To: Windows System Software Devs Interest List <xxxxx@lists.osr.com>
    Subject: RE:[ntdev] Flush file cache


    If power off, the data will not be written to the disk. So I want to "synchronously" write data before my follow-up operations.



    ---
    NTDEV is sponsored by OSR

    For our schedule of WDF, WDM, debugging and other seminars visit:
    http://www.osr.com/seminars

    To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
  • Maxim_S._ShatskihMaxim_S._Shatskih Member Posts: 10,396
    > And I want the data written to the disk immediately. What should I do?

    Send IRP_MJ_FLUSH_BUFFERS to the file.

    --
    Maxim S. Shatskih
    Windows DDK MVP
    xxxxx@storagecraft.com
    http://www.storagecraft.com
  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    Thanks

    I'll get a try.
  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    But how can I get the file object by file name or handle?
  • Maxim_S._ShatskihMaxim_S._Shatskih Member Posts: 10,396
    ObReferenceObjectByHandle

    --
    Maxim S. Shatskih
    Windows DDK MVP
    xxxxx@storagecraft.com
    http://www.storagecraft.com

    <xxxxx@huaweisymantec.com> wrote in message news:xxxxx@ntdev...
    > But how can I get the file object by file name or handle?
    >
  • sudhakarsudhakar Member - All Emails Posts: 15

    @OSR_Community_User said:
    But how can I get the file object by file name or handle?

    Can use ZwFlushBuffersFile with handle ?

  • anton_bassovanton_bassov Member Posts: 5,023

    It looks like this hosting platform, despite all its "scary functionality", does not have the concept of thread expiry. This is already not the first time that people "revive" the threads that had been dead for at least a decade. It was impossible to do it on the older platform...

    Anton Bassov

  • Peter_Viscarola_(OSR)Peter_Viscarola_(OSR) Administrator Posts: 7,345
    edited December 2018

    It looks like this hosting platform, despite all its "scary functionality", does not have the concept of thread expiry

    Sad but true.

    Another thread, back from the dead.

    Discussion closed.

    Peter

    Peter Viscarola
    OSR
    @OSRDrivers

This discussion has been closed.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upcoming OSR Seminars
Developing Minifilters 29 July 2019 OSR Seminar Space
Writing WDF Drivers 23 Sept 2019 OSR Seminar Space
Kernel Debugging 21 Oct 2019 OSR Seminar Space
Internals & Software Drivers 18 Nov 2019 Dulles, VA