67062dab9b68dfae2aaa64e7e9b409ae0cf9f49a
[reactos.git] / drivers / filesystems / ffs / src / shutdown.c
1 /*
2 * FFS File System Driver for Windows
3 *
4 * read.c
5 *
6 * 2004.5.6 ~
7 *
8 * Lee Jae-Hong, http://www.pyrasis.com
9 *
10 * See License.txt
11 *
12 */
13
14 #include "ntifs.h"
15 #include "ffsdrv.h"
16
17 /* Globals */
18
19 extern PFFS_GLOBAL FFSGlobal;
20
21
22 /* Definitions */
23
24 #ifdef ALLOC_PRAGMA
25 #pragma alloc_text(PAGE, FFSShutDown)
26 #endif
27
28
29 __drv_mustHoldCriticalRegion
30 NTSTATUS
31 FFSShutDown(
32 IN PFFS_IRP_CONTEXT IrpContext)
33 {
34 NTSTATUS Status;
35
36 PKEVENT Event;
37
38 PIRP Irp;
39 PIO_STACK_LOCATION IrpSp;
40
41 PFFS_VCB Vcb;
42 PLIST_ENTRY ListEntry;
43
44 BOOLEAN GlobalResourceAcquired = FALSE;
45
46 PAGED_CODE();
47
48 _SEH2_TRY
49 {
50 ASSERT(IrpContext);
51
52 ASSERT((IrpContext->Identifier.Type == FFSICX) &&
53 (IrpContext->Identifier.Size == sizeof(FFS_IRP_CONTEXT)));
54
55 Status = STATUS_SUCCESS;
56
57 Irp = IrpContext->Irp;
58
59 IrpSp = IoGetCurrentIrpStackLocation(Irp);
60 #ifdef _MSC_VER
61 #pragma prefast( suppress: 28137, "by design" )
62 #endif
63 if (!ExAcquireResourceExclusiveLite(
64 &FFSGlobal->Resource,
65 IrpContext->IsSynchronous))
66 {
67 Status = STATUS_PENDING;
68 _SEH2_LEAVE;
69 }
70
71 GlobalResourceAcquired = TRUE;
72
73 Event = ExAllocatePoolWithTag(NonPagedPool, sizeof(KEVENT), FFS_POOL_TAG);
74 KeInitializeEvent(Event, NotificationEvent, FALSE);
75
76 for (ListEntry = FFSGlobal->VcbList.Flink;
77 ListEntry != &(FFSGlobal->VcbList);
78 ListEntry = ListEntry->Flink)
79 {
80 Vcb = CONTAINING_RECORD(ListEntry, FFS_VCB, Next);
81
82 if (ExAcquireResourceExclusiveLite(
83 &Vcb->MainResource,
84 TRUE))
85 {
86
87 Status = FFSFlushFiles(Vcb, TRUE);
88 if(!NT_SUCCESS(Status))
89 {
90 FFSBreakPoint();
91 }
92
93 Status = FFSFlushVolume(Vcb, TRUE);
94
95 if(!NT_SUCCESS(Status))
96 {
97 FFSBreakPoint();
98 }
99
100 FFSDiskShutDown(Vcb);
101
102 ExReleaseResourceForThreadLite(
103 &Vcb->MainResource,
104 ExGetCurrentResourceThread());
105 }
106 }
107
108 /*
109 IoUnregisterFileSystem(FFSGlobal->DeviceObject);
110 */
111 }
112
113 _SEH2_FINALLY
114 {
115 if (GlobalResourceAcquired)
116 {
117 ExReleaseResourceForThreadLite(
118 &FFSGlobal->Resource,
119 ExGetCurrentResourceThread());
120 }
121
122 if (!IrpContext->ExceptionInProgress)
123 {
124 if (Status == STATUS_PENDING)
125 {
126 FFSQueueRequest(IrpContext);
127 }
128 else
129 {
130 FFSCompleteIrpContext(IrpContext, Status);
131 }
132 }
133 } _SEH2_END;
134
135 return Status;
136 }