Git conversion: Make reactos the root directory, move rosapps, rostests, wallpapers...
[reactos.git] / drivers / filesystems / reiserfs / src / shutdown.c
1 /*
2 * COPYRIGHT: GNU GENERAL PUBLIC LICENSE VERSION 2
3 * PROJECT: ReiserFs file system driver for Windows NT/2000/XP/Vista.
4 * FILE: shutdown.c
5 * PURPOSE:
6 * PROGRAMMER: Mark Piper, Matt Wu, Bo Brantén.
7 * HOMEPAGE:
8 * UPDATE HISTORY:
9 */
10
11 /* INCLUDES *****************************************************************/
12
13 #include "rfsd.h"
14
15 /* GLOBALS ***************************************************************/
16
17 extern PRFSD_GLOBAL RfsdGlobal;
18
19 /* DEFINITIONS *************************************************************/
20
21 #ifdef ALLOC_PRAGMA
22 #pragma alloc_text(PAGE, RfsdShutDown)
23 #endif
24
25 __drv_mustHoldCriticalRegion
26 NTSTATUS
27 RfsdShutDown (IN PRFSD_IRP_CONTEXT IrpContext)
28 {
29 NTSTATUS Status;
30 PKEVENT Event;
31 PIRP Irp;
32 PIO_STACK_LOCATION IrpSp;
33 PRFSD_VCB Vcb;
34 PLIST_ENTRY ListEntry;
35 BOOLEAN GlobalResourceAcquired = FALSE;
36
37 PAGED_CODE();
38
39 _SEH2_TRY {
40
41 ASSERT(IrpContext);
42
43 ASSERT((IrpContext->Identifier.Type == RFSDICX) &&
44 (IrpContext->Identifier.Size == sizeof(RFSD_IRP_CONTEXT)));
45
46 Status = STATUS_SUCCESS;
47
48 Irp = IrpContext->Irp;
49
50 IrpSp = IoGetCurrentIrpStackLocation(Irp);
51
52 #ifdef _MSC_VER
53 #pragma prefast( suppress: 28137, "by design" )
54 #endif
55 if (!ExAcquireResourceExclusiveLite(
56 &RfsdGlobal->Resource,
57 IrpContext->IsSynchronous )) {
58 Status = STATUS_PENDING;
59 _SEH2_LEAVE;
60 }
61
62 GlobalResourceAcquired = TRUE;
63
64 Event = ExAllocatePoolWithTag(NonPagedPool, sizeof(KEVENT), RFSD_POOL_TAG);
65 KeInitializeEvent(Event, NotificationEvent, FALSE );
66
67 for (ListEntry = RfsdGlobal->VcbList.Flink;
68 ListEntry != &(RfsdGlobal->VcbList);
69 ListEntry = ListEntry->Flink ) {
70
71 Vcb = CONTAINING_RECORD(ListEntry, RFSD_VCB, Next);
72
73 if (ExAcquireResourceExclusiveLite(
74 &Vcb->MainResource,
75 TRUE )) {
76
77 Status = RfsdFlushFiles(Vcb, TRUE);
78 if(!NT_SUCCESS(Status)) {
79 DbgBreak();
80 }
81
82 Status = RfsdFlushVolume(Vcb, TRUE);
83
84 if(!NT_SUCCESS(Status)) {
85 DbgBreak();
86 }
87
88 RfsdDiskShutDown(Vcb);
89
90 ExReleaseResourceForThreadLite(
91 &Vcb->MainResource,
92 ExGetCurrentResourceThread());
93 }
94 }
95
96 /*
97 IoUnregisterFileSystem(RfsdGlobal->DeviceObject);
98 */
99 } _SEH2_FINALLY {
100
101 if (GlobalResourceAcquired) {
102 ExReleaseResourceForThreadLite(
103 &RfsdGlobal->Resource,
104 ExGetCurrentResourceThread() );
105 }
106
107 if (!IrpContext->ExceptionInProgress) {
108 if (Status == STATUS_PENDING) {
109 RfsdQueueRequest(IrpContext);
110 } else {
111 RfsdCompleteIrpContext(IrpContext, Status);
112 }
113 }
114 } _SEH2_END;
115
116 return Status;
117 }