:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / ntoskrnl / io / flush.c
1 /*
2  * COPYRIGHT:       See COPYING in the top level directory
3  * PROJECT:         ReactOS kernel
4  * FILE:            ntoskrnl/io/flush.c
5  * PURPOSE:         Flushing file buffer
6  * PROGRAMMER:      David Welch (welch@cwcom.net)
7  * UPDATE HISTORY:
8  *                  Created 22/05/98
9  */
10
11 /* INCLUDES *****************************************************************/
12
13 #include <ddk/ntddk.h>
14 #include <internal/ob.h>
15
16 #define NDEBUG
17 #include <internal/debug.h>
18
19 /* FUNCTIONS *****************************************************************/
20
21
22 NTSTATUS
23 STDCALL
24 NtFlushWriteBuffer(VOID)
25 {
26         KeFlushWriteBuffer();
27         return STATUS_SUCCESS;
28 }
29
30 NTSTATUS
31 STDCALL
32 NtFlushBuffersFile (
33         IN      HANDLE                  FileHandle,
34         OUT     PIO_STATUS_BLOCK        IoStatusBlock
35         )
36 /*
37  * FUNCTION: Flushes cached file data to disk
38  * ARGUMENTS:
39  *       FileHandle = Points to the file
40  *       IoStatusBlock = Caller must supply storage to receive the result of 
41  *                       the flush buffers operation. The information field is
42  *                       set to number of bytes flushed to disk.
43  * RETURNS: Status 
44  * REMARKS: This function maps to the win32 FlushFileBuffers
45  */
46 {
47    PFILE_OBJECT FileObject = NULL;
48    PIRP Irp;
49    PIO_STACK_LOCATION StackPtr;
50    NTSTATUS Status;
51    IO_STATUS_BLOCK IoSB;
52       
53    Status = ObReferenceObjectByHandle(FileHandle,
54                                       FILE_WRITE_DATA,
55                                       NULL,
56                                       UserMode,
57                                       (PVOID*)&FileObject,
58                                       NULL);
59    if (Status != STATUS_SUCCESS)
60      {
61         return(Status);
62      }
63    KeResetEvent( &FileObject->Event );
64    Irp = IoBuildSynchronousFsdRequest(IRP_MJ_FLUSH_BUFFERS,
65                                       FileObject->DeviceObject,
66                                       NULL,
67                                       0,
68                                       NULL,
69                                       &FileObject->Event,
70                                       &IoSB);
71
72    StackPtr = IoGetNextIrpStackLocation(Irp);
73    StackPtr->FileObject = FileObject;
74
75    Status = IoCallDriver(FileObject->DeviceObject,Irp);
76    if (Status==STATUS_PENDING)
77      {
78         KeWaitForSingleObject(&FileObject->Event,Executive,KernelMode,FALSE,NULL);
79         Status = IoSB.Status;
80      }
81    if (IoStatusBlock)
82      {
83        *IoStatusBlock = IoSB;
84      }
85    return(Status);
86 }