2003-03-16 Casper S. Hornstrup <chorns@users.sourceforge.net>
[reactos.git] / reactos / ntoskrnl / fs / util.c
1 /* $Id: util.c,v 1.13 2003/03/16 13:18:49 chorns Exp $
2 *
3 * reactos/ntoskrnl/fs/util.c
4 *
5 */
6 #include <ddk/ntddk.h>
7 #include <ddk/ntifs.h>
8
9
10 /**********************************************************************
11 * NAME EXPORTED
12 * FsRtlIsTotalDeviceFailure@4
13 *
14 * DESCRIPTION
15 * Check if an NTSTATUS error code represents a
16 * disk hardware failure.
17 *
18 * ARGUMENTS
19 * NtStatus
20 * NTSTATUS to test.
21 *
22 * RETURN VALUE
23 * FALSE if either (NtStatus >= STATUS_SUCCESS),
24 * STATUS_CRC_ERROR, STATUS_DEVICE_DATA_ERROR;
25 * TRUE otherwise.
26 *
27 */
28 BOOLEAN
29 STDCALL
30 FsRtlIsTotalDeviceFailure (
31 IN NTSTATUS NtStatus
32 )
33 {
34 return (
35 (NT_SUCCESS(NtStatus))
36 || (STATUS_CRC_ERROR == NtStatus)
37 || (STATUS_DEVICE_DATA_ERROR == NtStatus)
38 ? FALSE
39 : TRUE
40 );
41 }
42
43
44 /**********************************************************************
45 * NAME EXPORTED
46 * FsRtlIsNtstatusExpected/1
47 * stack32 = 4
48 *
49 * DESCRIPTION
50 * Check an NTSTATUS value is expected by the FS kernel
51 * subsystem.
52 *
53 * ARGUMENTS
54 * NtStatus
55 * NTSTATUS to test.
56 *
57 * RETURN VALUE
58 * TRUE if NtStatus is NOT one out of:
59 * - STATUS_ACCESS_VIOLATION
60 * - STATUS_ILLEGAL_INSTRUCTION
61 * - STATUS_DATATYPE_MISALIGNMENT
62 * - STATUS_INSTRUCTION_MISALIGNMENT
63 * which are the forbidden return stati in the FsRtl
64 * subsystem; FALSE otherwise.
65 *
66 * REVISIONS
67 * 2002-01-17 Fixed a bad bug reported by Bo Brantén.
68 * Up to version 1.8, this function's semantics was
69 * exactly the opposite! Thank you Bo.
70 */
71 BOOLEAN
72 STDCALL
73 FsRtlIsNtstatusExpected (
74 IN NTSTATUS NtStatus
75 )
76 {
77 return (
78 (STATUS_DATATYPE_MISALIGNMENT == NtStatus)
79 || (STATUS_ACCESS_VIOLATION == NtStatus)
80 || (STATUS_ILLEGAL_INSTRUCTION == NtStatus)
81 || (STATUS_INSTRUCTION_MISALIGNMENT == NtStatus)
82 )
83 ? FALSE
84 : TRUE;
85 }
86
87
88 /**********************************************************************
89 * NAME EXPORTED
90 * FsRtlNormalizeNtstatus@8
91 *
92 * DESCRIPTION
93 * Normalize an NTSTATUS value for using in the FS subsystem.
94 *
95 * ARGUMENTS
96 * NtStatusToNormalize
97 * NTSTATUS to normalize.
98 * NormalizedNtStatus
99 * NTSTATUS to return if the NtStatusToNormalize
100 * value is unexpected by the FS kernel subsystem.
101 *
102 * RETURN VALUE
103 * NtStatusToNormalize if it is an expected value,
104 * otherwise NormalizedNtStatus.
105 */
106 NTSTATUS
107 STDCALL
108 FsRtlNormalizeNtstatus (
109 IN NTSTATUS NtStatusToNormalize,
110 IN NTSTATUS NormalizedNtStatus
111 )
112 {
113 return
114 (TRUE == FsRtlIsNtstatusExpected(NtStatusToNormalize))
115 ? NtStatusToNormalize
116 : NormalizedNtStatus;
117 }
118
119
120 /**********************************************************************
121 * Miscellanea (they may fit somewhere else)
122 *********************************************************************/
123
124
125 /**********************************************************************
126 * NAME EXPORTED
127 * FsRtlAllocateResource@0
128 *
129 * DESCRIPTION
130 *
131 * ARGUMENTS
132 *
133 * RETURN VALUE
134 *
135 */
136 DWORD
137 STDCALL
138 FsRtlAllocateResource (VOID)
139 {
140 return 0;
141 }
142
143
144 /**********************************************************************
145 * NAME EXPORTED
146 * FsRtlBalanceReads@4
147 *
148 * DESCRIPTION
149 *
150 * ARGUMENTS
151 *
152 * RETURN VALUE
153 *
154 */
155 DWORD
156 STDCALL
157 FsRtlBalanceReads (
158 DWORD Unknown0
159 )
160 {
161 return 0;
162 }
163
164
165 /**********************************************************************
166 * NAME EXPORTED
167 * FsRtlCopyRead@32
168 *
169 * DESCRIPTION
170 *
171 * ARGUMENTS
172 *
173 * RETURN VALUE
174 *
175 * NOTE
176 * From Bo Branten's ntifs.h v12.
177 *
178 */
179 BOOLEAN
180 STDCALL
181 FsRtlCopyRead (
182 IN PFILE_OBJECT FileObject,
183 IN PLARGE_INTEGER FileOffset,
184 IN ULONG Length,
185 IN BOOLEAN Wait,
186 IN ULONG LockKey,
187 OUT PVOID Buffer,
188 OUT PIO_STATUS_BLOCK IoStatus,
189 IN PDEVICE_OBJECT DeviceObject
190 )
191 {
192 return FALSE;
193 }
194
195
196 /**********************************************************************
197 * NAME EXPORTED
198 * FsRtlCopyWrite@32
199 *
200 * DESCRIPTION
201 *
202 * ARGUMENTS
203 *
204 * RETURN VALUE
205 *
206 * NOTE
207 * From Bo Branten's ntifs.h v12.
208 */
209 BOOLEAN
210 STDCALL
211 FsRtlCopyWrite (
212 IN PFILE_OBJECT FileObject,
213 IN PLARGE_INTEGER FileOffset,
214 IN ULONG Length,
215 IN BOOLEAN Wait,
216 IN ULONG LockKey,
217 IN PVOID Buffer,
218 OUT PIO_STATUS_BLOCK IoStatus,
219 IN PDEVICE_OBJECT DeviceObject
220 )
221 {
222 return FALSE;
223 }
224
225
226 /**********************************************************************
227 * NAME EXPORTED
228 * FsRtlGetFileSize@8
229 *
230 * DESCRIPTION
231 *
232 * ARGUMENTS
233 *
234 * RETURN VALUE
235 *
236 */
237 NTSTATUS
238 STDCALL
239 FsRtlGetFileSize (
240 IN PFILE_OBJECT FileObject,
241 IN OUT PLARGE_INTEGER FileSize
242 )
243 {
244 FILE_STANDARD_INFORMATION Info;
245 NTSTATUS Status;
246 ULONG Length;
247
248 Status = IoQueryFileInformation(FileObject,
249 FileStandardInformation,
250 sizeof(Info),
251 &Info,
252 &Length);
253 if (NT_SUCCESS(Status))
254 {
255 FileSize->QuadPart = Info.EndOfFile.QuadPart;
256 }
257
258 return Status;
259 }
260
261
262 /**********************************************************************
263 * NAME EXPORTED
264 * FsRtlPostPagingFileStackOverflow@12
265 *
266 * DESCRIPTION
267 *
268 * ARGUMENTS
269 *
270 * RETURN VALUE
271 *
272 */
273 VOID
274 STDCALL
275 FsRtlPostPagingFileStackOverflow (
276 DWORD Unknown0,
277 DWORD Unknown1,
278 DWORD Unknown2
279 )
280 {
281 }
282
283
284 /**********************************************************************
285 * NAME EXPORTED
286 * FsRtlPostStackOverflow@12
287 *
288 * DESCRIPTION
289 *
290 * ARGUMENTS
291 *
292 * RETURN VALUE
293 *
294 */
295 VOID
296 STDCALL
297 FsRtlPostStackOverflow (
298 DWORD Unknown0,
299 DWORD Unknown1,
300 DWORD Unknown2
301 )
302 {
303 }
304
305
306 /**********************************************************************
307 * NAME EXPORTED
308 * FsRtlSyncVolumes@12
309 *
310 * DESCRIPTION
311 * Obsolete function.
312 *
313 * ARGUMENTS
314 *
315 * RETURN VALUE
316 * It always returns STATUS_SUCCESS.
317 */
318 NTSTATUS
319 STDCALL
320 FsRtlSyncVolumes (
321 DWORD Unknown0,
322 DWORD Unknown1,
323 DWORD Unknown2
324 )
325 {
326 return STATUS_SUCCESS;
327 }
328
329
330 /* EOF */
331