1*c2c66affSColin Finck /*
2*c2c66affSColin Finck * PROJECT: ReactOS Named Pipe FileSystem
3*c2c66affSColin Finck * LICENSE: BSD - See COPYING.ARM in the top level directory
4*c2c66affSColin Finck * FILE: drivers/filesystems/npfs/flushbuf.c
5*c2c66affSColin Finck * PURPOSE: Buffers Flushing Support
6*c2c66affSColin Finck * PROGRAMMERS: ReactOS Portable Systems Group
7*c2c66affSColin Finck */
8*c2c66affSColin Finck
9*c2c66affSColin Finck /* INCLUDES *******************************************************************/
10*c2c66affSColin Finck
11*c2c66affSColin Finck #include "npfs.h"
12*c2c66affSColin Finck
13*c2c66affSColin Finck // File ID number for NPFS bugchecking support
14*c2c66affSColin Finck #define NPFS_BUGCHECK_FILE_ID (NPFS_BUGCHECK_FLUSHBUF)
15*c2c66affSColin Finck
16*c2c66affSColin Finck /* FUNCTIONS ******************************************************************/
17*c2c66affSColin Finck
18*c2c66affSColin Finck NTSTATUS
19*c2c66affSColin Finck NTAPI
NpCommonFlushBuffers(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)20*c2c66affSColin Finck NpCommonFlushBuffers(IN PDEVICE_OBJECT DeviceObject,
21*c2c66affSColin Finck IN PIRP Irp)
22*c2c66affSColin Finck {
23*c2c66affSColin Finck NODE_TYPE_CODE NodeTypeCode;
24*c2c66affSColin Finck PNP_CCB Ccb;
25*c2c66affSColin Finck ULONG NamedPipeEnd;
26*c2c66affSColin Finck NTSTATUS Status;
27*c2c66affSColin Finck PNP_DATA_QUEUE FlushQueue;
28*c2c66affSColin Finck PAGED_CODE();
29*c2c66affSColin Finck
30*c2c66affSColin Finck NodeTypeCode = NpDecodeFileObject(IoGetCurrentIrpStackLocation(Irp)->FileObject,
31*c2c66affSColin Finck NULL,
32*c2c66affSColin Finck &Ccb,
33*c2c66affSColin Finck &NamedPipeEnd);
34*c2c66affSColin Finck if (NodeTypeCode != NPFS_NTC_CCB) return STATUS_PIPE_DISCONNECTED;
35*c2c66affSColin Finck
36*c2c66affSColin Finck ExAcquireResourceExclusiveLite(&Ccb->NonPagedCcb->Lock, TRUE);
37*c2c66affSColin Finck
38*c2c66affSColin Finck if (NamedPipeEnd == FILE_PIPE_SERVER_END)
39*c2c66affSColin Finck {
40*c2c66affSColin Finck FlushQueue = &Ccb->DataQueue[FILE_PIPE_OUTBOUND];
41*c2c66affSColin Finck }
42*c2c66affSColin Finck else
43*c2c66affSColin Finck {
44*c2c66affSColin Finck FlushQueue = &Ccb->DataQueue[FILE_PIPE_INBOUND];
45*c2c66affSColin Finck }
46*c2c66affSColin Finck
47*c2c66affSColin Finck if (FlushQueue->QueueState == WriteEntries)
48*c2c66affSColin Finck {
49*c2c66affSColin Finck Status = NpAddDataQueueEntry(NamedPipeEnd,
50*c2c66affSColin Finck Ccb,
51*c2c66affSColin Finck FlushQueue,
52*c2c66affSColin Finck WriteEntries,
53*c2c66affSColin Finck 2,
54*c2c66affSColin Finck 0,
55*c2c66affSColin Finck Irp,
56*c2c66affSColin Finck NULL,
57*c2c66affSColin Finck 0);
58*c2c66affSColin Finck }
59*c2c66affSColin Finck else
60*c2c66affSColin Finck {
61*c2c66affSColin Finck Status = STATUS_SUCCESS;
62*c2c66affSColin Finck }
63*c2c66affSColin Finck
64*c2c66affSColin Finck ExReleaseResourceLite(&Ccb->NonPagedCcb->Lock);
65*c2c66affSColin Finck return Status;
66*c2c66affSColin Finck }
67*c2c66affSColin Finck
68*c2c66affSColin Finck NTSTATUS
69*c2c66affSColin Finck NTAPI
NpFsdFlushBuffers(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)70*c2c66affSColin Finck NpFsdFlushBuffers(IN PDEVICE_OBJECT DeviceObject,
71*c2c66affSColin Finck IN PIRP Irp)
72*c2c66affSColin Finck {
73*c2c66affSColin Finck NTSTATUS Status;
74*c2c66affSColin Finck PAGED_CODE();
75*c2c66affSColin Finck
76*c2c66affSColin Finck FsRtlEnterFileSystem();
77*c2c66affSColin Finck NpAcquireSharedVcb();
78*c2c66affSColin Finck
79*c2c66affSColin Finck Status = NpCommonFlushBuffers(DeviceObject, Irp);
80*c2c66affSColin Finck
81*c2c66affSColin Finck NpReleaseVcb();
82*c2c66affSColin Finck FsRtlExitFileSystem();
83*c2c66affSColin Finck
84*c2c66affSColin Finck if (Status != STATUS_PENDING)
85*c2c66affSColin Finck {
86*c2c66affSColin Finck Irp->IoStatus.Status = Status;
87*c2c66affSColin Finck IoCompleteRequest(Irp, IO_NAMED_PIPE_INCREMENT);
88*c2c66affSColin Finck }
89*c2c66affSColin Finck
90*c2c66affSColin Finck return Status;
91*c2c66affSColin Finck }
92*c2c66affSColin Finck
93*c2c66affSColin Finck /* EOF */
94