Git conversion: Make reactos the root directory, move rosapps, rostests, wallpapers...
[reactos.git] / drivers / filesystems / reiserfs / src / fastio.c
1 /*
2 * COPYRIGHT: GNU GENERAL PUBLIC LICENSE VERSION 2
3 * PROJECT: ReiserFs file system driver for Windows NT/2000/XP/Vista.
4 * FILE: fastio.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 #if DBG
23 #pragma alloc_text(PAGE, RfsdFastIoRead)
24 #if !RFSD_READ_ONLY
25 #pragma alloc_text(PAGE, RfsdFastIoWrite)
26 #endif // !RFSD_READ_ONLY
27 #endif // DBG
28 #pragma alloc_text(PAGE, RfsdFastIoCheckIfPossible)
29 #pragma alloc_text(PAGE, RfsdFastIoQueryBasicInfo)
30 #pragma alloc_text(PAGE, RfsdFastIoQueryStandardInfo)
31 #pragma alloc_text(PAGE, RfsdFastIoQueryNetworkOpenInfo)
32 #pragma alloc_text(PAGE, RfsdFastIoLock)
33 #pragma alloc_text(PAGE, RfsdFastIoUnlockSingle)
34 #pragma alloc_text(PAGE, RfsdFastIoUnlockAll)
35 #pragma alloc_text(PAGE, RfsdFastIoUnlockAllByKey)
36 #endif
37
38 BOOLEAN NTAPI
39 RfsdFastIoCheckIfPossible (
40 IN PFILE_OBJECT FileObject,
41 IN PLARGE_INTEGER FileOffset,
42 IN ULONG Length,
43 IN BOOLEAN Wait,
44 IN ULONG LockKey,
45 IN BOOLEAN CheckForReadOperation,
46 OUT PIO_STATUS_BLOCK IoStatus,
47 IN PDEVICE_OBJECT DeviceObject
48 )
49 {
50 BOOLEAN bPossible = FastIoIsNotPossible;
51 PRFSD_FCB Fcb;
52 LARGE_INTEGER lLength;
53
54 PAGED_CODE();
55
56 lLength.QuadPart = Length;
57
58 _SEH2_TRY {
59
60 _SEH2_TRY {
61
62 FsRtlEnterFileSystem();
63
64 if (DeviceObject == RfsdGlobal->DeviceObject) {
65 _SEH2_LEAVE;
66 }
67
68 Fcb = (PRFSD_FCB) FileObject->FsContext;
69
70 ASSERT(Fcb != NULL);
71
72 if (Fcb->Identifier.Type == RFSDVCB) {
73 _SEH2_LEAVE;
74 }
75
76 ASSERT((Fcb->Identifier.Type == RFSDFCB) &&
77 (Fcb->Identifier.Size == sizeof(RFSD_FCB)));
78
79 if (IsDirectory(Fcb)) {
80 _SEH2_LEAVE;
81 }
82
83 if (CheckForReadOperation) {
84
85 bPossible = FsRtlFastCheckLockForRead(
86 &Fcb->FileLockAnchor,
87 FileOffset,
88 &lLength,
89 LockKey,
90 FileObject,
91 PsGetCurrentProcess());
92
93 } else {
94
95 if (IsFlagOn(Fcb->Vcb->Flags, VCB_READ_ONLY) ||
96 IsFlagOn(Fcb->Vcb->Flags, VCB_WRITE_PROTECTED)) {
97 bPossible = FastIoIsNotPossible;
98 } else {
99 bPossible = FsRtlFastCheckLockForWrite(
100 &Fcb->FileLockAnchor,
101 FileOffset,
102 &lLength,
103 LockKey,
104 FileObject,
105 PsGetCurrentProcess());
106 }
107 }
108
109 RfsdPrint((DBG_INFO, "RfsdFastIoCheckIfPossible: %s %s %s\n",
110 RfsdGetCurrentProcessName(),
111 "FASTIO_CHECK_IF_POSSIBLE",
112 Fcb->AnsiFileName.Buffer
113 ));
114
115 RfsdPrint((DBG_INFO,
116 "RfsdFastIoCheckIfPossible: Offset: %I64xg Length: %xh Key: %u %s %s\n",
117 FileOffset->QuadPart,
118 Length,
119 LockKey,
120 (CheckForReadOperation ? "CheckForReadOperation:" :
121 "CheckForWriteOperation:"),
122 (bPossible ? "Succeeded" : "Failed")));
123 } _SEH2_EXCEPT (EXCEPTION_EXECUTE_HANDLER) {
124 bPossible = FastIoIsNotPossible;
125 } _SEH2_END;
126
127 } _SEH2_FINALLY {
128
129 FsRtlExitFileSystem();
130 } _SEH2_END;
131
132 return bPossible;
133 }
134
135 #if DBG
136
137 BOOLEAN NTAPI
138 RfsdFastIoRead (IN PFILE_OBJECT FileObject,
139 IN PLARGE_INTEGER FileOffset,
140 IN ULONG Length,
141 IN BOOLEAN Wait,
142 IN ULONG LockKey,
143 OUT PVOID Buffer,
144 OUT PIO_STATUS_BLOCK IoStatus,
145 IN PDEVICE_OBJECT DeviceObject)
146 {
147 BOOLEAN Status;
148 PRFSD_FCB Fcb;
149
150 PAGED_CODE();
151
152 Fcb = (PRFSD_FCB) FileObject->FsContext;
153
154 ASSERT(Fcb != NULL);
155
156 ASSERT((Fcb->Identifier.Type == RFSDFCB) &&
157 (Fcb->Identifier.Size == sizeof(RFSD_FCB)));
158
159 RfsdPrint((DBG_INFO, "RfsdFastIoRead: %s %s %s\n",
160 RfsdGetCurrentProcessName(),
161 "FASTIO_READ",
162 Fcb->AnsiFileName.Buffer ));
163
164 RfsdPrint((DBG_INFO, "RfsdFastIoRead: Offset: %I64xh Length: %xh Key: %u\n",
165 FileOffset->QuadPart,
166 Length,
167 LockKey ));
168
169 Status = FsRtlCopyRead (
170 FileObject, FileOffset, Length, Wait,
171 LockKey, Buffer, IoStatus, DeviceObject);
172
173 return Status;
174 }
175
176 #if !RFSD_READ_ONLY
177
178 NTAPI BOOLEAN
179 RfsdFastIoWrite (
180 IN PFILE_OBJECT FileObject,
181 IN PLARGE_INTEGER FileOffset,
182 IN ULONG Length,
183 IN BOOLEAN Wait,
184 IN ULONG LockKey,
185 OUT PVOID Buffer,
186 OUT PIO_STATUS_BLOCK IoStatus,
187 IN PDEVICE_OBJECT DeviceObject)
188 {
189 BOOLEAN bRet;
190 PRFSD_FCB Fcb;
191
192 PAGED_CODE();
193
194 Fcb = (PRFSD_FCB) FileObject->FsContext;
195
196 ASSERT(Fcb != NULL);
197
198 ASSERT((Fcb->Identifier.Type == RFSDFCB) &&
199 (Fcb->Identifier.Size == sizeof(RFSD_FCB)));
200
201 RfsdPrint((DBG_INFO,
202 "RfsdFastIoWrite: %s %s %s\n",
203 RfsdGetCurrentProcessName(),
204 "FASTIO_WRITE",
205 Fcb->AnsiFileName.Buffer ));
206
207 RfsdPrint((DBG_INFO,
208 "RfsdFastIoWrite: Offset: %I64xh Length: %xh Key: %xh\n",
209 FileOffset->QuadPart,
210 Length,
211 LockKey ));
212
213 if (IsFlagOn(Fcb->Vcb->Flags, VCB_READ_ONLY)) {
214 DbgBreak();
215 return FALSE;
216 }
217
218 bRet = FsRtlCopyWrite (
219 FileObject, FileOffset, Length, Wait,
220 LockKey, Buffer, IoStatus, DeviceObject);
221
222 return bRet;
223 }
224
225 #endif // !RFSD_READ_ONLY
226
227 #endif /* DBG */
228
229 BOOLEAN NTAPI
230 RfsdFastIoQueryBasicInfo (IN PFILE_OBJECT FileObject,
231 IN BOOLEAN Wait,
232 OUT PFILE_BASIC_INFORMATION Buffer,
233 OUT PIO_STATUS_BLOCK IoStatus,
234 IN PDEVICE_OBJECT DeviceObject)
235 {
236 BOOLEAN Status = FALSE;
237 PRFSD_FCB Fcb = 0;
238 BOOLEAN FcbMainResourceAcquired = FALSE;
239
240 PAGED_CODE();
241
242 _SEH2_TRY {
243
244 _SEH2_TRY {
245
246 FsRtlEnterFileSystem();
247
248 if (DeviceObject == RfsdGlobal->DeviceObject) {
249 IoStatus->Status = STATUS_INVALID_DEVICE_REQUEST;
250 Status = TRUE;
251 _SEH2_LEAVE;
252 }
253
254 Fcb = (PRFSD_FCB) FileObject->FsContext;
255
256 ASSERT(Fcb != NULL);
257
258 if (Fcb->Identifier.Type == RFSDVCB) {
259 IoStatus->Status = STATUS_INVALID_PARAMETER;
260 Status = TRUE;
261 _SEH2_LEAVE;
262 }
263
264 ASSERT((Fcb->Identifier.Type == RFSDFCB) &&
265 (Fcb->Identifier.Size == sizeof(RFSD_FCB)));
266
267 RfsdPrint((DBG_INFO,
268 "RfsdFastIoQueryBasicInfo: %s %s %s\n",
269 RfsdGetCurrentProcessName(),
270 "FASTIO_QUERY_BASIC_INFO",
271 Fcb->AnsiFileName.Buffer
272 ));
273
274 if (!ExAcquireResourceSharedLite(
275 &Fcb->MainResource,
276 Wait)) {
277 Status = FALSE;
278 _SEH2_LEAVE;
279 }
280
281 FcbMainResourceAcquired = TRUE;
282
283 RtlZeroMemory(Buffer, sizeof(FILE_BASIC_INFORMATION));
284
285 /*
286 typedef struct _FILE_BASIC_INFORMATION {
287 LARGE_INTEGER CreationTime;
288 LARGE_INTEGER LastAccessTime;
289 LARGE_INTEGER LastWriteTime;
290 LARGE_INTEGER ChangeTime;
291 ULONG FileAttributes;
292 } FILE_BASIC_INFORMATION, *PFILE_BASIC_INFORMATION;
293 */
294
295 Buffer->CreationTime = RfsdSysTime(Fcb->Inode->i_ctime);
296 Buffer->LastAccessTime = RfsdSysTime(Fcb->Inode->i_atime);
297 Buffer->LastWriteTime = RfsdSysTime(Fcb->Inode->i_mtime);
298 Buffer->ChangeTime = RfsdSysTime(Fcb->Inode->i_mtime);
299
300
301 Buffer->FileAttributes = Fcb->RfsdMcb->FileAttr;
302
303 IoStatus->Information = sizeof(FILE_BASIC_INFORMATION);
304
305 IoStatus->Status = STATUS_SUCCESS;
306
307 Status = TRUE;
308 } _SEH2_EXCEPT (EXCEPTION_EXECUTE_HANDLER) {
309
310 IoStatus->Status = _SEH2_GetExceptionCode();
311 Status = TRUE;
312 } _SEH2_END;
313
314 } _SEH2_FINALLY {
315
316 if (FcbMainResourceAcquired)
317 {
318 ExReleaseResourceForThreadLite(
319 &Fcb->MainResource,
320 ExGetCurrentResourceThread()
321 );
322 }
323
324 FsRtlExitFileSystem();
325 } _SEH2_END;
326
327
328 if (Status == FALSE) {
329
330 RfsdPrint((DBG_ERROR,
331 "RfsdFastIoQueryBasicInfo: %s %s *** Status: FALSE ***\n",
332 RfsdGetCurrentProcessName(),
333 "FASTIO_QUERY_BASIC_INFO"
334 ));
335 } else if (IoStatus->Status != STATUS_SUCCESS) {
336
337 RfsdPrint((DBG_ERROR,
338 "RfsdFastIoQueryBasicInfo: %s %s *** Status: %s (%#x) ***\n",
339 RfsdGetCurrentProcessName(),
340 "FASTIO_QUERY_BASIC_INFO",
341 RfsdNtStatusToString(IoStatus->Status),
342 IoStatus->Status
343 ));
344 }
345
346 return Status;
347 }
348
349 BOOLEAN NTAPI
350 RfsdFastIoQueryStandardInfo (
351 IN PFILE_OBJECT FileObject,
352 IN BOOLEAN Wait,
353 OUT PFILE_STANDARD_INFORMATION Buffer,
354 OUT PIO_STATUS_BLOCK IoStatus,
355 IN PDEVICE_OBJECT DeviceObject
356 )
357 {
358 BOOLEAN Status = FALSE;
359 PRFSD_VCB Vcb;
360 PRFSD_FCB Fcb = 0;
361 BOOLEAN FcbMainResourceAcquired = FALSE;
362 LONGLONG FileSize;
363 LONGLONG AllocationSize;
364
365 PAGED_CODE();
366
367 _SEH2_TRY {
368
369 _SEH2_TRY {
370
371 FsRtlEnterFileSystem();
372
373 if (DeviceObject == RfsdGlobal->DeviceObject) {
374
375 IoStatus->Status = STATUS_INVALID_DEVICE_REQUEST;
376 Status = TRUE;
377 _SEH2_LEAVE;
378 }
379
380 Fcb = (PRFSD_FCB) FileObject->FsContext;
381
382 ASSERT(Fcb != NULL);
383
384 if (Fcb->Identifier.Type == RFSDVCB) {
385 IoStatus->Status = STATUS_INVALID_PARAMETER;
386 Status = TRUE;
387 _SEH2_LEAVE;
388 }
389
390 ASSERT((Fcb->Identifier.Type == RFSDFCB) &&
391 (Fcb->Identifier.Size == sizeof(RFSD_FCB)));
392
393 RfsdPrint((DBG_INFO,
394 "RfsdFastIoQueryStandardInfo: %s %s %s\n",
395 RfsdGetCurrentProcessName(),
396 "FASTIO_QUERY_STANDARD_INFO",
397 Fcb->AnsiFileName.Buffer ));
398
399 Vcb = Fcb->Vcb;
400
401 if (!ExAcquireResourceSharedLite(
402 &Fcb->MainResource,
403 Wait )) {
404 Status = FALSE;
405 _SEH2_LEAVE;
406 }
407
408 FcbMainResourceAcquired = TRUE;
409
410 RtlZeroMemory(Buffer, sizeof(FILE_STANDARD_INFORMATION));
411
412 /*
413 typedef struct _FILE_STANDARD_INFORMATION {
414 LARGE_INTEGER AllocationSize;
415 LARGE_INTEGER EndOfFile;
416 ULONG NumberOfLinks;
417 BOOLEAN DeletePending;
418 BOOLEAN Directory;
419 } FILE_STANDARD_INFORMATION, *PFILE_STANDARD_INFORMATION;
420 */
421
422 FileSize = (LONGLONG) Fcb->Inode->i_size;
423
424 #if DISABLED
425 if (S_ISREG(Fcb->Inode->i_mode))
426 FileSize |= ((LONGLONG)(Fcb->Inode->i_size_high) << 32);
427 #endif
428
429 AllocationSize = CEILING_ALIGNED(FileSize, (ULONGLONG)Vcb->BlockSize); // TODO: This is incorrect for file tails...
430
431 Buffer->AllocationSize.QuadPart = AllocationSize;
432 Buffer->EndOfFile.QuadPart = FileSize;
433 Buffer->NumberOfLinks = Fcb->Inode->i_links_count;
434
435 if (IsFlagOn(Fcb->Vcb->Flags, VCB_READ_ONLY)) {
436 Buffer->DeletePending = FALSE;
437 } else {
438 Buffer->DeletePending = IsFlagOn(Fcb->Flags, FCB_DELETE_PENDING);
439 }
440
441 if (FlagOn(Fcb->RfsdMcb->FileAttr, FILE_ATTRIBUTE_DIRECTORY)) {
442 Buffer->Directory = TRUE;
443 } else {
444 Buffer->Directory = FALSE;
445 }
446
447 IoStatus->Information = sizeof(FILE_STANDARD_INFORMATION);
448
449 IoStatus->Status = STATUS_SUCCESS;
450
451 Status = TRUE;
452
453 } _SEH2_EXCEPT (EXCEPTION_EXECUTE_HANDLER) {
454
455 IoStatus->Status = _SEH2_GetExceptionCode();
456 Status = TRUE;
457 } _SEH2_END;
458
459 } _SEH2_FINALLY {
460 if (FcbMainResourceAcquired) {
461 ExReleaseResourceForThreadLite(
462 &Fcb->MainResource,
463 ExGetCurrentResourceThread()
464 );
465 }
466
467 FsRtlExitFileSystem();
468 } _SEH2_END;
469
470 #if DBG
471 if (Status == FALSE) {
472 RfsdPrint((DBG_INFO,
473 "RfsdFastIoQueryStandardInfo: %s %s *** Status: FALSE ***\n",
474 RfsdGetCurrentProcessName(),
475 "FASTIO_QUERY_STANDARD_INFO" ));
476 } else if (IoStatus->Status != STATUS_SUCCESS) {
477 RfsdPrint((DBG_INFO,
478 "RfsdFastIoQueryStandardInfo: %s %s *** Status: %s (%#x) ***\n",
479 RfsdGetCurrentProcessName(),
480 "FASTIO_QUERY_STANDARD_INFO",
481 RfsdNtStatusToString(IoStatus->Status),
482 IoStatus->Status ));
483 }
484 #endif
485
486 return Status;
487 }
488
489 BOOLEAN NTAPI
490 RfsdFastIoLock (
491 IN PFILE_OBJECT FileObject,
492 IN PLARGE_INTEGER FileOffset,
493 IN PLARGE_INTEGER Length,
494 IN PEPROCESS Process,
495 IN ULONG Key,
496 IN BOOLEAN FailImmediately,
497 IN BOOLEAN ExclusiveLock,
498 OUT PIO_STATUS_BLOCK IoStatus,
499 IN PDEVICE_OBJECT DeviceObject
500 )
501 {
502 BOOLEAN Status = FALSE;
503 PRFSD_FCB Fcb;
504
505 PAGED_CODE();
506
507 _SEH2_TRY {
508
509 _SEH2_TRY {
510
511 FsRtlEnterFileSystem();
512
513 if (DeviceObject == RfsdGlobal->DeviceObject) {
514 IoStatus->Status = STATUS_INVALID_DEVICE_REQUEST;
515 Status = TRUE;
516 _SEH2_LEAVE;
517 }
518
519 Fcb = (PRFSD_FCB) FileObject->FsContext;
520
521 ASSERT(Fcb != NULL);
522
523 if (Fcb->Identifier.Type == RFSDVCB) {
524
525 IoStatus->Status = STATUS_INVALID_PARAMETER;
526 Status = TRUE;
527 _SEH2_LEAVE;
528 }
529
530 ASSERT((Fcb->Identifier.Type == RFSDFCB) &&
531 (Fcb->Identifier.Size == sizeof(RFSD_FCB)));
532
533 if (IsDirectory(Fcb)) {
534 DbgBreak();
535 IoStatus->Status = STATUS_INVALID_PARAMETER;
536 Status = TRUE;
537 _SEH2_LEAVE;
538 }
539
540 RfsdPrint((DBG_INFO,
541 "RfsdFastIoLock: %s %s %s\n",
542 RfsdGetCurrentProcessName(),
543 "FASTIO_LOCK",
544 Fcb->AnsiFileName.Buffer ));
545
546 RfsdPrint((DBG_INFO,
547 "RfsdFastIoLock: Offset: %I64xh Length: %I64xh Key: %u %s%s\n",
548 FileOffset->QuadPart,
549 Length->QuadPart,
550 Key,
551 (FailImmediately ? "FailImmediately " : ""),
552 (ExclusiveLock ? "ExclusiveLock " : "") ));
553
554 if (Fcb->Header.IsFastIoPossible != FastIoIsQuestionable) {
555 RfsdPrint((DBG_INFO,
556 "RfsdFastIoLock: %s %s %s\n",
557 RfsdGetCurrentProcessName(),
558 "FastIoIsQuestionable",
559 Fcb->AnsiFileName.Buffer ));
560
561 Fcb->Header.IsFastIoPossible = FastIoIsQuestionable;
562 }
563
564 #ifdef _MSC_VER
565 #pragma prefast( suppress: 28159, "bug in prefast" )
566 #endif
567 Status = FsRtlFastLock(
568 &Fcb->FileLockAnchor,
569 FileObject,
570 FileOffset,
571 Length,
572 Process,
573 Key,
574 FailImmediately,
575 ExclusiveLock,
576 IoStatus,
577 NULL,
578 FALSE);
579 } _SEH2_EXCEPT (EXCEPTION_EXECUTE_HANDLER) {
580 IoStatus->Status = _SEH2_GetExceptionCode();
581 Status = TRUE;
582 } _SEH2_END;
583
584 } _SEH2_FINALLY {
585 FsRtlExitFileSystem();
586 } _SEH2_END;
587
588 #if DBG
589 if (Status == FALSE) {
590 RfsdPrint((DBG_ERROR,
591 "RfsdFastIoLock: %s %s *** Status: FALSE ***\n",
592 RfsdGetCurrentProcessName(),
593 "FASTIO_LOCK"
594 ));
595 } else if (IoStatus->Status != STATUS_SUCCESS) {
596 RfsdPrint((DBG_ERROR,
597 "RfsdFastIoLock: %s %s *** Status: %s (%#x) ***\n",
598 RfsdGetCurrentProcessName(),
599 "FASTIO_LOCK",
600 RfsdNtStatusToString(IoStatus->Status),
601 IoStatus->Status
602 ));
603 }
604 #endif
605
606 return Status;
607 }
608
609 BOOLEAN NTAPI
610 RfsdFastIoUnlockSingle (
611 IN PFILE_OBJECT FileObject,
612 IN PLARGE_INTEGER FileOffset,
613 IN PLARGE_INTEGER Length,
614 IN PEPROCESS Process,
615 IN ULONG Key,
616 OUT PIO_STATUS_BLOCK IoStatus,
617 IN PDEVICE_OBJECT DeviceObject
618 )
619 {
620 BOOLEAN Status = FALSE;
621 PRFSD_FCB Fcb;
622
623 PAGED_CODE();
624
625 _SEH2_TRY {
626
627 _SEH2_TRY {
628
629 FsRtlEnterFileSystem();
630
631 if (DeviceObject == RfsdGlobal->DeviceObject) {
632 IoStatus->Status = STATUS_INVALID_DEVICE_REQUEST;
633 Status = TRUE;
634 _SEH2_LEAVE;
635 }
636
637 Fcb = (PRFSD_FCB) FileObject->FsContext;
638
639 ASSERT(Fcb != NULL);
640
641 if (Fcb->Identifier.Type == RFSDVCB) {
642 DbgBreak();
643 IoStatus->Status = STATUS_INVALID_PARAMETER;
644 Status = TRUE;
645 _SEH2_LEAVE;
646 }
647
648 ASSERT((Fcb->Identifier.Type == RFSDFCB) &&
649 (Fcb->Identifier.Size == sizeof(RFSD_FCB)));
650
651 if (IsDirectory(Fcb)) {
652
653 DbgBreak();
654 IoStatus->Status = STATUS_INVALID_PARAMETER;
655 Status = TRUE;
656 _SEH2_LEAVE;
657 }
658
659 RfsdPrint((DBG_INFO,
660 "RfsdFastIoUnlockSingle: %s %s %s\n",
661 RfsdGetCurrentProcessName(),
662 "FASTIO_UNLOCK_SINGLE",
663 Fcb->AnsiFileName.Buffer ));
664
665 RfsdPrint((DBG_INFO,
666 "RfsdFastIoUnlockSingle: Offset: %I64xh Length: %I64xh Key: %u\n",
667 FileOffset->QuadPart,
668 Length->QuadPart,
669 Key ));
670
671 IoStatus->Status = FsRtlFastUnlockSingle(
672 &Fcb->FileLockAnchor,
673 FileObject,
674 FileOffset,
675 Length,
676 Process,
677 Key,
678 NULL,
679 FALSE);
680
681 IoStatus->Information = 0;
682
683 Status = TRUE;
684 } _SEH2_EXCEPT (EXCEPTION_EXECUTE_HANDLER) {
685 IoStatus->Status = _SEH2_GetExceptionCode();
686 Status = TRUE;
687 } _SEH2_END;
688
689 } _SEH2_FINALLY {
690
691 FsRtlExitFileSystem();
692 } _SEH2_END;
693
694 #if DBG
695 if (Status == FALSE) {
696
697 RfsdPrint((DBG_ERROR,
698 "RfsdFastIoUnlockSingle: %s %s *** Status: FALSE ***\n",
699 RfsdGetCurrentProcessName(),
700 "FASTIO_UNLOCK_SINGLE" ));
701 } else if (IoStatus->Status != STATUS_SUCCESS) {
702 RfsdPrint((DBG_ERROR,
703 "RfsdFastIoUnlockSingle: %s %s *** Status: %s (%#x) ***\n",
704 RfsdGetCurrentProcessName(),
705 "FASTIO_UNLOCK_SINGLE",
706 RfsdNtStatusToString(IoStatus->Status),
707 IoStatus->Status ));
708 }
709 #endif
710
711 return Status;
712 }
713
714 BOOLEAN NTAPI
715 RfsdFastIoUnlockAll (
716 IN PFILE_OBJECT FileObject,
717 IN PEPROCESS Process,
718 OUT PIO_STATUS_BLOCK IoStatus,
719 IN PDEVICE_OBJECT DeviceObject)
720 {
721 BOOLEAN Status = FALSE;
722 PRFSD_FCB Fcb;
723
724 PAGED_CODE();
725
726 _SEH2_TRY {
727
728 _SEH2_TRY {
729
730 FsRtlEnterFileSystem();
731
732 if (DeviceObject == RfsdGlobal->DeviceObject) {
733 IoStatus->Status = STATUS_INVALID_DEVICE_REQUEST;
734 Status = TRUE;
735 _SEH2_LEAVE;
736 }
737
738 Fcb = (PRFSD_FCB) FileObject->FsContext;
739
740 ASSERT(Fcb != NULL);
741
742 if (Fcb->Identifier.Type == RFSDVCB) {
743 DbgBreak();
744 IoStatus->Status = STATUS_INVALID_PARAMETER;
745 Status = TRUE;
746 _SEH2_LEAVE;
747 }
748
749 ASSERT((Fcb->Identifier.Type == RFSDFCB) &&
750 (Fcb->Identifier.Size == sizeof(RFSD_FCB)));
751
752 if (IsDirectory(Fcb)) {
753 DbgBreak();
754 IoStatus->Status = STATUS_INVALID_PARAMETER;
755 Status = TRUE;
756 _SEH2_LEAVE;
757 }
758
759 RfsdPrint((DBG_INFO,
760 "RfsdFastIoUnlockAll: %s %s %s\n",
761 RfsdGetCurrentProcessName(),
762 "FASTIO_UNLOCK_ALL",
763 Fcb->AnsiFileName.Buffer
764 ));
765
766 IoStatus->Status = FsRtlFastUnlockAll(
767 &Fcb->FileLockAnchor,
768 FileObject,
769 Process,
770 NULL );
771
772 IoStatus->Information = 0;
773
774 Status = TRUE;
775 } _SEH2_EXCEPT (EXCEPTION_EXECUTE_HANDLER) {
776 IoStatus->Status = _SEH2_GetExceptionCode();
777 Status = TRUE;
778 } _SEH2_END;
779
780 } _SEH2_FINALLY {
781
782 FsRtlExitFileSystem();
783 } _SEH2_END;
784
785 #if DBG
786 if (Status == FALSE) {
787
788 RfsdPrint((DBG_ERROR,
789 "RfsdFastIoUnlockAll: %s %s *** Status: FALSE ***\n",
790 RfsdGetCurrentProcessName(),
791 "FASTIO_UNLOCK_ALL"
792 ));
793 } else if (IoStatus->Status != STATUS_SUCCESS) {
794 RfsdPrint((DBG_ERROR,
795 "RfsdFastIoUnlockAll: %s %s *** Status: %s (%#x) ***\n",
796 RfsdGetCurrentProcessName(),
797 "FASTIO_UNLOCK_ALL",
798 RfsdNtStatusToString(IoStatus->Status),
799 IoStatus->Status
800 ));
801 }
802 #endif
803
804 return Status;
805 }
806
807 BOOLEAN NTAPI
808 RfsdFastIoUnlockAllByKey (
809 IN PFILE_OBJECT FileObject,
810 #ifdef __REACTOS__
811 IN PVOID Process,
812 #else
813 IN PEPROCESS Process,
814 #endif
815 IN ULONG Key,
816 OUT PIO_STATUS_BLOCK IoStatus,
817 IN PDEVICE_OBJECT DeviceObject
818 )
819 {
820 BOOLEAN Status = FALSE;
821 PRFSD_FCB Fcb;
822
823 PAGED_CODE();
824
825 _SEH2_TRY {
826
827 _SEH2_TRY {
828
829 FsRtlEnterFileSystem();
830
831 if (DeviceObject == RfsdGlobal->DeviceObject) {
832 IoStatus->Status = STATUS_INVALID_DEVICE_REQUEST;
833 Status = TRUE;
834 _SEH2_LEAVE;
835 }
836
837 Fcb = (PRFSD_FCB) FileObject->FsContext;
838
839 ASSERT(Fcb != NULL);
840
841 if (Fcb->Identifier.Type == RFSDVCB) {
842 DbgBreak();
843 IoStatus->Status = STATUS_INVALID_PARAMETER;
844 Status = TRUE;
845 _SEH2_LEAVE;
846 }
847
848 ASSERT((Fcb->Identifier.Type == RFSDFCB) &&
849 (Fcb->Identifier.Size == sizeof(RFSD_FCB)));
850
851 if (IsDirectory(Fcb)) {
852
853 DbgBreak();
854 IoStatus->Status = STATUS_INVALID_PARAMETER;
855 Status = TRUE;
856 _SEH2_LEAVE;
857 }
858
859 RfsdPrint((DBG_INFO,
860 "RfsdFastIoUnlockAllByKey: %s %s %s\n",
861 RfsdGetCurrentProcessName(),
862 "FASTIO_UNLOCK_ALL_BY_KEY",
863 Fcb->AnsiFileName.Buffer
864 ));
865
866 RfsdPrint((DBG_INFO,
867 "RfsdFastIoUnlockAllByKey: Key: %u\n",
868 Key
869 ));
870
871 IoStatus->Status = FsRtlFastUnlockAllByKey(
872 &Fcb->FileLockAnchor,
873 FileObject,
874 Process,
875 Key,
876 NULL
877 );
878
879 IoStatus->Information = 0;
880
881 Status = TRUE;
882
883 } _SEH2_EXCEPT (EXCEPTION_EXECUTE_HANDLER) {
884
885 IoStatus->Status = _SEH2_GetExceptionCode();
886 Status = TRUE;
887 } _SEH2_END;
888
889 } _SEH2_FINALLY {
890 FsRtlExitFileSystem();
891 } _SEH2_END;
892
893 #if DBG
894 if (Status == FALSE) {
895
896 RfsdPrint((DBG_ERROR,
897 "RfsdFastIoUnlockAllByKey: %s %s *** Status: FALSE ***\n",
898 RfsdGetCurrentProcessName(),
899 "FASTIO_UNLOCK_ALL_BY_KEY"
900 ));
901 } else if (IoStatus->Status != STATUS_SUCCESS) {
902
903 RfsdPrint((DBG_ERROR,
904 "RfsdFastIoUnlockAllByKey: %s %s *** Status: %s (%#x) ***\n",
905 RfsdGetCurrentProcessName(),
906 "FASTIO_UNLOCK_ALL_BY_KEY",
907 RfsdNtStatusToString(IoStatus->Status),
908 IoStatus->Status
909 ));
910 }
911 #endif
912
913 return Status;
914 }
915
916 BOOLEAN NTAPI
917 RfsdFastIoQueryNetworkOpenInfo (
918 IN PFILE_OBJECT FileObject,
919 IN BOOLEAN Wait,
920 IN OUT PFILE_NETWORK_OPEN_INFORMATION PFNOI,
921 OUT PIO_STATUS_BLOCK IoStatus,
922 IN PDEVICE_OBJECT DeviceObject
923 )
924 {
925 BOOLEAN bResult = FALSE;
926 PRFSD_FCB Fcb = NULL;
927 BOOLEAN FcbResourceAcquired = FALSE;
928
929 PAGED_CODE();
930
931 _SEH2_TRY {
932
933 FsRtlEnterFileSystem();
934
935 if (DeviceObject == RfsdGlobal->DeviceObject) {
936 IoStatus->Status = STATUS_INVALID_DEVICE_REQUEST;
937 _SEH2_LEAVE;
938 }
939
940 Fcb = (PRFSD_FCB) FileObject->FsContext;
941
942 ASSERT(Fcb != NULL);
943
944 if (Fcb->Identifier.Type == RFSDVCB) {
945 DbgBreak();
946 IoStatus->Status = STATUS_INVALID_PARAMETER;
947 _SEH2_LEAVE;
948 }
949
950 ASSERT((Fcb->Identifier.Type == RFSDFCB) &&
951 (Fcb->Identifier.Size == sizeof(RFSD_FCB)));
952
953 RfsdPrint((DBG_INFO,
954 "%-16.16s %-31s %s\n",
955 RfsdGetCurrentProcessName(),
956 "FASTIO_QUERY_NETWORK_OPEN_INFO",
957 Fcb->AnsiFileName.Buffer
958 ));
959
960 if (FileObject->FsContext2) {
961 _SEH2_LEAVE;
962 }
963
964 if (!FlagOn(Fcb->Flags, FCB_PAGE_FILE)) {
965
966 if (!ExAcquireResourceSharedLite(
967 &Fcb->MainResource,
968 Wait
969 )) {
970 _SEH2_LEAVE;
971 }
972
973 FcbResourceAcquired = TRUE;
974 }
975
976 if (IsDirectory(Fcb)) {
977 PFNOI->AllocationSize.QuadPart = 0;
978 PFNOI->EndOfFile.QuadPart = 0;
979 } else {
980 PFNOI->AllocationSize = Fcb->Header.AllocationSize;
981 PFNOI->EndOfFile = Fcb->Header.FileSize;
982 }
983
984 PFNOI->FileAttributes = Fcb->RfsdMcb->FileAttr;
985 if (PFNOI->FileAttributes == 0) {
986 PFNOI->FileAttributes = FILE_ATTRIBUTE_NORMAL;
987 }
988
989 PFNOI->CreationTime = RfsdSysTime(Fcb->Inode->i_ctime);
990 PFNOI->LastAccessTime = RfsdSysTime(Fcb->Inode->i_atime);
991 PFNOI->LastWriteTime = RfsdSysTime(Fcb->Inode->i_mtime);
992 PFNOI->ChangeTime = RfsdSysTime(Fcb->Inode->i_mtime);
993
994 bResult = TRUE;
995
996 IoStatus->Status = STATUS_SUCCESS;
997 IoStatus->Information = sizeof(FILE_NETWORK_OPEN_INFORMATION);
998
999 } _SEH2_FINALLY {
1000
1001 if (FcbResourceAcquired) {
1002 ExReleaseResourceLite(&Fcb->MainResource);
1003 }
1004
1005 FsRtlExitFileSystem();
1006 } _SEH2_END;
1007
1008 return bResult;
1009 }