Git conversion: Make reactos the root directory, move rosapps, rostests, wallpapers...
[reactos.git] / drivers / filesystems / reiserfs / src / except.c
1 /*
2 * COPYRIGHT: GNU GENERAL PUBLIC LICENSE VERSION 2
3 * PROJECT: ReiserFs file system driver for Windows NT/2000/XP/Vista.
4 * FILE: except.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, RfsdExceptionFilter)
23 //#pragma alloc_text(PAGE, RfsdExceptionHandler)
24 #endif
25
26 NTSTATUS
27 RfsdExceptionFilter (
28 IN PRFSD_IRP_CONTEXT IrpContext,
29 IN PEXCEPTION_POINTERS ExceptionPointer)
30 {
31 NTSTATUS Status, ExceptionCode;
32 PEXCEPTION_RECORD ExceptRecord;
33
34 ExceptRecord = ExceptionPointer->ExceptionRecord;
35
36 ExceptionCode = ExceptRecord->ExceptionCode;
37
38 DbgBreak();
39
40 //
41 // Check IrpContext is valid or not
42 //
43
44 if (IrpContext) {
45 if ((IrpContext->Identifier.Type != RFSDICX) ||
46 (IrpContext->Identifier.Size != sizeof(RFSD_IRP_CONTEXT))) {
47 IrpContext = NULL;
48 }
49 } else {
50 if (FsRtlIsNtstatusExpected(ExceptionCode)) {
51 return EXCEPTION_EXECUTE_HANDLER;
52 } else {
53 RfsdBugCheck( RFSD_BUGCHK_EXCEPT, (ULONG_PTR)ExceptRecord,
54 (ULONG_PTR)ExceptionPointer->ContextRecord,
55 (ULONG_PTR)ExceptRecord->ExceptionAddress );
56 }
57 }
58
59 //
60 // For the purposes of processing this exception, let's mark this
61 // request as being able to wait, and neither write through nor on
62 // removable media if we aren't posting it.
63 //
64
65 if (IrpContext)
66 { SetFlag(IrpContext->Flags, IRP_CONTEXT_FLAG_WAIT); }
67
68 if (FsRtlIsNtstatusExpected(ExceptionCode)) {
69 //
70 // If the exception is expected execute our handler
71 //
72
73 RfsdPrint((DBG_ERROR, "RfsdExceptionFilter: Catching exception %xh\n",
74 ExceptionCode));
75
76 Status = EXCEPTION_EXECUTE_HANDLER;
77
78 if (IrpContext) {
79 IrpContext->ExceptionInProgress = TRUE;
80 IrpContext->ExceptionCode = ExceptionCode;
81 }
82
83 } else {
84
85 //
86 // Continue search for an higher level exception handler
87 //
88
89 RfsdPrint((DBG_ERROR, "RfsdExceptionFilter: Passing on exception %#x\n",
90 ExceptionCode));
91
92 Status = EXCEPTION_CONTINUE_SEARCH;
93
94 if (IrpContext) {
95 RfsdFreeIrpContext(IrpContext);
96 }
97 }
98
99 return Status;
100 }
101
102 NTSTATUS
103 RfsdExceptionHandler (IN PRFSD_IRP_CONTEXT IrpContext)
104 {
105 NTSTATUS Status;
106
107 if (IrpContext) {
108 if ( (IrpContext->Identifier.Type != RFSDICX) ||
109 (IrpContext->Identifier.Size != sizeof(RFSD_IRP_CONTEXT))) {
110 DbgBreak();
111 return STATUS_UNSUCCESSFUL;
112 }
113
114 Status = IrpContext->ExceptionCode;
115
116 if (IrpContext->Irp) {
117
118 //
119 // Check if this error is a result of user actions
120 //
121
122 PIRP Irp = IrpContext->Irp;
123
124
125 if (IoIsErrorUserInduced(Status)) {
126
127 //
128 // Now we will generate a pop-up to user
129 //
130
131 PDEVICE_OBJECT RealDevice;
132 PVPB Vpb = NULL;
133 PETHREAD Thread;
134
135 if (IoGetCurrentIrpStackLocation(Irp)->FileObject != NULL) {
136 Vpb = IoGetCurrentIrpStackLocation(Irp)->FileObject->Vpb;
137 }
138
139 //
140 // Get the initial thread
141 //
142
143 Thread = Irp->Tail.Overlay.Thread;
144 RealDevice = IoGetDeviceToVerify( Thread );
145
146 if (RealDevice == NULL) {
147 //
148 // Get current thread
149 //
150
151 Thread = PsGetCurrentThread();
152 RealDevice = IoGetDeviceToVerify( Thread );
153
154 ASSERT( RealDevice != NULL );
155 }
156
157 if (RealDevice != NULL) {
158
159 //
160 // Now we pop-up the error dialog ...
161 //
162
163 IoMarkIrpPending( Irp );
164 IoRaiseHardError( Irp, Vpb, RealDevice );
165
166 IoSetDeviceToVerify( Thread, NULL );
167
168 Status = STATUS_PENDING;
169 goto errorout;
170 }
171 }
172
173 IrpContext->Irp->IoStatus.Status = Status;
174
175 RfsdCompleteRequest(IrpContext->Irp, FALSE, IO_NO_INCREMENT);
176 }
177
178 errorout:
179
180 RfsdFreeIrpContext(IrpContext);
181
182 } else {
183
184 Status = STATUS_INSUFFICIENT_RESOURCES;
185 }
186
187 return Status;
188 }