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.

What are you trying to do that requires this?

  • S

-----Original Message-----
From: xxxxx@huaweisymantec.com
Sent: Sunday, May 03, 2009 20:26
To: Windows System Software Devs Interest List
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

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

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
Sent: Sunday, May 03, 2009 22:55
To: Windows System Software Devs Interest List
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

> 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

Thanks

I’ll get a try.

But how can I get the file object by file name or handle?

ObReferenceObjectByHandle


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

wrote in message news:xxxxx@ntdev…
> But how can I get the file object by file name or handle?
>

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

Can use ZwFlushBuffersFile with handle ?

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

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