ReactOS 0.4.15-dev-8348-gc1b9bb5
lockctrl.c File Reference
#include "fatprocs.h"
Include dependency graph for lockctrl.c:

Go to the source code of this file.

Macros

#define Dbg   (DEBUG_TRACE_LOCKCTRL)
 

Functions

 _Function_class_ (IRP_MJ_LOCK_CONTROL)
 
 _Function_class_ (FAST_IO_LOCK)
 
 _Function_class_ (FAST_IO_UNLOCK_SINGLE)
 
 _Function_class_ (FAST_IO_UNLOCK_ALL)
 
 _Function_class_ (FAST_IO_UNLOCK_ALL_BY_KEY)
 
 _Requires_lock_held_ (_Global_critical_region_)
 

Macro Definition Documentation

◆ Dbg

#define Dbg   (DEBUG_TRACE_LOCKCTRL)

Definition at line 23 of file lockctrl.c.

Function Documentation

◆ _Function_class_() [1/5]

_Function_class_ ( FAST_IO_LOCK  )

Definition at line 116 of file lockctrl.c.

164{
165 BOOLEAN Results = FALSE;
166 PVCB Vcb;
167 PFCB Fcb;
168 PCCB Ccb;
169
170 PAGED_CODE();
172
173 DebugTrace(+1, Dbg, "FatFastLock\n", 0);
174
175 //
176 // Decode the type of file object we're being asked to process and make
177 // sure it is only a user file open.
178 //
179
181
183 IoStatus->Information = 0;
184
185 DebugTrace(-1, Dbg, "FatFastLock -> TRUE (STATUS_INVALID_PARAMETER)\n", 0);
186 return TRUE;
187 }
188
189 //
190 // Acquire shared access to the Fcb
191 //
192
195
196 _SEH2_TRY {
197
198 //
199 // We check whether we can proceed
200 // based on the state of the file oplocks.
201 //
202
204
205 try_return( Results = FALSE );
206 }
207
208 //
209 // Now call the FsRtl routine to do the actual processing of the
210 // Lock request
211 //
212
213#ifdef _MSC_VER
214#pragma prefast( suppress:28159, "prefast indicates this API is obsolete but it is ok for fastfat to continue using it" )
215#endif
216 Results = FsRtlFastLock( &Fcb->Specific.Fcb.FileLock,
219 Length,
220 ProcessId,
221 Key,
224 IoStatus,
225 NULL,
226 FALSE );
227
228 if (Results) {
229
230 //
231 // Set the flag indicating if Fast I/O is possible
232 //
233
234 Fcb->Header.IsFastIoPossible = FatIsFastIoPossible( Fcb );
235 }
236
237 try_exit: NOTHING;
238 } _SEH2_FINALLY {
239
240 DebugUnwind( FatFastLock );
241
242 //
243 // Release the Fcb, and return to our caller
244 //
245
246 ExReleaseResourceLite( Fcb->Header.Resource );
248
249 DebugTrace(-1, Dbg, "FatFastLock -> %08lx\n", Results);
250 } _SEH2_END;
251
252 return Results;
253}
#define PAGED_CODE()
unsigned char BOOLEAN
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:160
@ UserFileOpen
Definition: cdprocs.h:577
_In_ PFCB Fcb
Definition: cdprocs.h:159
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:592
#define try_return(S)
Definition: cdprocs.h:2179
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ExAcquireResourceSharedLite(res, wait)
Definition: env_spec_w32.h:621
#define Dbg
Definition: lockctrl.c:23
#define DebugTrace(INDENT, LEVEL, X, Y)
Definition: fatdata.h:313
#define DebugUnwind(X)
Definition: fatdata.h:315
TYPE_OF_OPEN FatDecodeFileObject(_In_ PFILE_OBJECT FileObject, _Outptr_ PVCB *Vcb, _Outptr_ PFCB *FcbOrDcb, _Outptr_ PCCB *Ccb)
Definition: filobsup.c:176
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ULONG BOOLEAN BOOLEAN ExclusiveLock
Definition: fatprocs.h:2714
#define FatIsFastIoPossible(FCB)
Definition: fatprocs.h:2813
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ULONG BOOLEAN FailImmediately
Definition: fatprocs.h:2713
#define FatGetFcbOplock(F)
Definition: fatprocs.h:1656
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ProcessId
Definition: fatprocs.h:2711
#define _SEH2_FINALLY
Definition: filesup.c:21
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
#define FsRtlFastLock(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11)
Definition: fsrtlfuncs.h:1581
#define NOTHING
Definition: input_list.c:10
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:159
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1822
BOOLEAN NTAPI FsRtlOplockIsFastIoPossible(IN POPLOCK Oplock)
Definition: oplock.c:1564
#define Vcb
Definition: cdprocs.h:1415
Definition: cdstruc.h:1067
Definition: cdstruc.h:902
union _FCB::@719 Specific
struct _FCB::@719::@722 Fcb
FSRTL_ADVANCED_FCB_HEADER Header
Definition: cdstruc.h:925
Definition: cdstruc.h:498
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550

◆ _Function_class_() [2/5]

_Function_class_ ( FAST_IO_UNLOCK_ALL  )

Definition at line 378 of file lockctrl.c.

409{
410 BOOLEAN Results = FALSE;
411 PVCB Vcb;
412 PFCB Fcb;
413 PCCB Ccb;
414
415 PAGED_CODE();
417
418 DebugTrace(+1, Dbg, "FatFastUnlockAll\n", 0);
419
420 IoStatus->Information = 0;
421
422 //
423 // Decode the type of file object we're being asked to process and make sure
424 // it is only a user file open.
425 //
426
428
430
431 DebugTrace(-1, Dbg, "FatFastUnlockAll -> TRUE (STATUS_INVALID_PARAMETER)\n", 0);
432 return TRUE;
433 }
434
435 //
436 // Acquire exclusive access to the Fcb this operation can always wait
437 //
438
440
442
443 _SEH2_TRY {
444
445 //
446 // We check whether we can proceed based on the state of the file oplocks.
447 //
448
450
451 try_return( Results = FALSE );
452 }
453
454 //
455 // Now call the FsRtl routine to do the actual processing of the
456 // Lock request. The call will always succeed.
457 //
458
459 Results = TRUE;
460 IoStatus->Status = FsRtlFastUnlockAll( &Fcb->Specific.Fcb.FileLock,
462 ProcessId,
463 NULL );
464
465 //
466 // Set the flag indicating if Fast I/O is possible
467 //
468
469 Fcb->Header.IsFastIoPossible = FatIsFastIoPossible( Fcb );
470
471 try_exit: NOTHING;
472 } _SEH2_FINALLY {
473
474 DebugUnwind( FatFastUnlockAll );
475
476 //
477 // Release the Fcb, and return to our caller
478 //
479
480 ExReleaseResourceLite( (Fcb)->Header.Resource );
481
483
484 DebugTrace(-1, Dbg, "FatFastUnlockAll -> %08lx\n", Results);
485 } _SEH2_END;
486
487 return Results;
488}
#define VOID
Definition: acefi.h:82
Definition: Header.h:9
NTSTATUS NTAPI FsRtlFastUnlockAll(IN PFILE_LOCK FileLock, IN PFILE_OBJECT FileObject, IN PEPROCESS Process, IN PVOID Context OPTIONAL)
Definition: filelock.c:1025

◆ _Function_class_() [3/5]

_Function_class_ ( FAST_IO_UNLOCK_ALL_BY_KEY  )

Definition at line 491 of file lockctrl.c.

525{
526 BOOLEAN Results = FALSE;
527 PVCB Vcb;
528 PFCB Fcb;
529 PCCB Ccb;
530
531 PAGED_CODE();
533
534 DebugTrace(+1, Dbg, "FatFastUnlockAllByKey\n", 0);
535
536 IoStatus->Information = 0;
537
538 //
539 // Decode the type of file object we're being asked to process and make sure
540 // it is only a user file open.
541 //
542
544
546
547 DebugTrace(-1, Dbg, "FatFastUnlockAll -> TRUE (STATUS_INVALID_PARAMETER)\n", 0);
548 return TRUE;
549 }
550
551 //
552 // Acquire exclusive access to the Fcb this operation can always wait
553 //
554
556
558
559 _SEH2_TRY {
560
561 //
562 // We check whether we can proceed based on the state of the file oplocks.
563 //
564
566
567 try_return( Results = FALSE );
568 }
569
570 //
571 // Now call the FsRtl routine to do the actual processing of the
572 // Lock request. The call will always succeed.
573 //
574
575 Results = TRUE;
576 IoStatus->Status = FsRtlFastUnlockAllByKey( &Fcb->Specific.Fcb.FileLock,
578 ProcessId,
579 Key,
580 NULL );
581
582 //
583 // Set the flag indicating if Fast I/O is possible
584 //
585
586 Fcb->Header.IsFastIoPossible = FatIsFastIoPossible( Fcb );
587
588 try_exit: NOTHING;
589 } _SEH2_FINALLY {
590
591 DebugUnwind( FatFastUnlockAllByKey );
592
593 //
594 // Release the Fcb, and return to our caller
595 //
596
597 ExReleaseResourceLite( (Fcb)->Header.Resource );
598
600
601 DebugTrace(-1, Dbg, "FatFastUnlockAllByKey -> %08lx\n", Results);
602 } _SEH2_END;
603
604 return Results;
605}
NTSTATUS NTAPI FsRtlFastUnlockAllByKey(IN PFILE_LOCK FileLock, IN PFILE_OBJECT FileObject, IN PEPROCESS Process, IN ULONG Key, IN PVOID Context OPTIONAL)
Definition: filelock.c:1086

◆ _Function_class_() [4/5]

_Function_class_ ( FAST_IO_UNLOCK_SINGLE  )

Definition at line 256 of file lockctrl.c.

296{
297 BOOLEAN Results = FALSE;
298 PVCB Vcb;
299 PFCB Fcb;
300 PCCB Ccb;
301
302 PAGED_CODE();
304
305 DebugTrace(+1, Dbg, "FatFastUnlockSingle\n", 0);
306
307 IoStatus->Information = 0;
308
309 //
310 // Decode the type of file object we're being asked to process and make sure
311 // it is only a user file open
312 //
313
315
317
318 DebugTrace(-1, Dbg, "FatFastUnlockSingle -> TRUE (STATUS_INVALID_PARAMETER)\n", 0);
319 return TRUE;
320 }
321
322 //
323 // Acquire exclusive access to the Fcb this operation can always wait
324 //
325
327
328 _SEH2_TRY {
329
330 //
331 // We check whether we can proceed based on the state of the file oplocks.
332 //
333
335
336 try_return( Results = FALSE );
337 }
338
339 //
340 // Now call the FsRtl routine to do the actual processing of the
341 // Lock request. The call will always succeed.
342 //
343
344 Results = TRUE;
345 IoStatus->Status = FsRtlFastUnlockSingle( &Fcb->Specific.Fcb.FileLock,
348 Length,
349 ProcessId,
350 Key,
351 NULL,
352 FALSE );
353
354 //
355 // Set the flag indicating if Fast I/O is possible
356 //
357
358 Fcb->Header.IsFastIoPossible = FatIsFastIoPossible( Fcb );
359
360 try_exit: NOTHING;
361 } _SEH2_FINALLY {
362
363 DebugUnwind( FatFastUnlockSingle );
364
365 //
366 // Release the Fcb, and return to our caller
367 //
368
370
371 DebugTrace(-1, Dbg, "FatFastUnlockSingle -> %08lx\n", Results);
372 } _SEH2_END;
373
374 return Results;
375}
NTSTATUS NTAPI FsRtlFastUnlockSingle(IN PFILE_LOCK FileLock, IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN PLARGE_INTEGER Length, IN PEPROCESS Process, IN ULONG Key, IN PVOID Context OPTIONAL, IN BOOLEAN AlreadySynchronized)
Definition: filelock.c:825

◆ _Function_class_() [5/5]

_Function_class_ ( IRP_MJ_LOCK_CONTROL  )

Definition at line 35 of file lockctrl.c.

63{
65 PIRP_CONTEXT IrpContext = NULL;
66
68
69 PAGED_CODE();
70
71 DebugTrace(+1, Dbg, "FatFsdLockControl\n", 0);
72
73 //
74 // Call the common Lock Control routine, with blocking allowed if
75 // synchronous
76 //
77
79
81
82 _SEH2_TRY {
83
84 IrpContext = FatCreateIrpContext( Irp, CanFsdWait( Irp ) );
85
86 Status = FatCommonLockControl( IrpContext, Irp );
87
89
90 //
91 // We had some trouble trying to perform the requested
92 // operation, so we'll abort the I/O request with
93 // the error status that we get back from the
94 // execption code
95 //
96
97 Status = FatProcessException( IrpContext, Irp, _SEH2_GetExceptionCode() );
98 } _SEH2_END;
99
100 if (TopLevel) { IoSetTopLevelIrp( NULL ); }
101
103
104 //
105 // And return to our caller
106 //
107
108 DebugTrace(-1, Dbg, "FatFsdLockControl -> %08lx\n", Status);
109
110 UNREFERENCED_PARAMETER( VolumeDeviceObject );
111
112 return Status;
113}
LONG NTSTATUS
Definition: precomp.h:26
#define CanFsdWait(I)
Definition: cdprocs.h:2001
_In_ PIRP Irp
Definition: csq.h:116
ULONG FatExceptionFilter(IN PIRP_CONTEXT IrpContext, IN PEXCEPTION_POINTERS ExceptionPointer)
Definition: fatdata.c:204
BOOLEAN FatIsIrpTopLevel(IN PIRP Irp)
Definition: fatdata.c:817
IN PFCB IN PCCB IN TYPE_OF_OPEN IN BOOLEAN IN BOOLEAN TopLevel
Definition: fatprocs.h:2417
PIRP_CONTEXT FatCreateIrpContext(IN PIRP Irp, IN BOOLEAN Wait)
Definition: strucsup.c:2301
Status
Definition: gdiplustypes.h:25
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:165
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
#define _SEH2_GetExceptionInformation()
Definition: pseh2_64.h:164

◆ _Requires_lock_held_()

_Requires_lock_held_ ( _Global_critical_region_  )

Definition at line 608 of file lockctrl.c.

632{
635
637
638 PVCB Vcb;
639 PFCB Fcb;
640 PCCB Ccb;
641
642 BOOLEAN OplockPostIrp = FALSE;
643
644 PAGED_CODE();
645
646 //
647 // Get a pointer to the current Irp stack location
648 //
649
651
652 DebugTrace(+1, Dbg, "FatCommonLockControl\n", 0);
653 DebugTrace( 0, Dbg, "Irp = %p\n", Irp);
654 DebugTrace( 0, Dbg, "MinorFunction = %08lx\n", IrpSp->MinorFunction);
655
656 //
657 // Decode the type of file object we're being asked to process
658 //
659
661
662 //
663 // If the file is not a user file open then we reject the request
664 // as an invalid parameter
665 //
666
667 if (TypeOfOpen != UserFileOpen) {
668
670
671 DebugTrace(-1, Dbg, "FatCommonLockControl -> STATUS_INVALID_PARAMETER\n", 0);
673 }
674
675 //
676 // Acquire exclusive access to the Fcb and enqueue the Irp if we didn't
677 // get access
678 //
679
680 if (!FatAcquireSharedFcb( IrpContext, Fcb )) {
681
682 Status = FatFsdPostRequest( IrpContext, Irp );
683
684 DebugTrace(-1, Dbg, "FatCommonLockControl -> %08lx\n", Status);
685 return Status;
686 }
687
688 _SEH2_TRY {
689
690 //
691 // We check whether we can proceed
692 // based on the state of the file oplocks.
693 //
694
695#if (NTDDI_VERSION >= NTDDI_WIN8)
696
697 if (((IRP_MN_LOCK == IrpSp->MinorFunction) &&
698 ((ULONGLONG)IrpSp->Parameters.LockControl.ByteOffset.QuadPart <
699 (ULONGLONG)Fcb->Header.AllocationSize.QuadPart)) ||
701 FsRtlAreThereWaitingFileLocks( &Fcb->Specific.Fcb.FileLock ))) {
702
703 //
704 // Check whether we can proceed based on the state of file oplocks if doing
705 // an operation that interferes with oplocks. Those operations are:
706 //
707 // 1. Lock a range within the file's AllocationSize.
708 // 2. Unlock a range when there are waiting locks on the file. This one
709 // is not guaranteed to interfere with oplocks, but it could, as
710 // unlocking this range might cause a waiting lock to be granted
711 // within AllocationSize!
712 //
713
714#endif
716 Irp,
717 IrpContext,
719 NULL );
720
721#if (NTDDI_VERSION >= NTDDI_WIN8)
722 }
723#endif
724
725 if (Status != STATUS_SUCCESS) {
726
727 OplockPostIrp = TRUE;
729 }
730
731 //
732 // Now call the FsRtl routine to do the actual processing of the
733 // Lock request
734 //
735
737
738 //
739 // Set the flag indicating if Fast I/O is possible
740 //
741
742 Fcb->Header.IsFastIoPossible = FatIsFastIoPossible( Fcb );
743
744 try_exit: NOTHING;
745 } _SEH2_FINALLY {
746
747 DebugUnwind( FatCommonLockControl );
748
749 //
750 // Only if this is not an abnormal termination do we delete the
751 // irp context
752 //
753
754 if (!_SEH2_AbnormalTermination() && !OplockPostIrp) {
755
756 FatCompleteRequest( IrpContext, FatNull, 0 );
757 }
758
759 //
760 // Release the Fcb, and return to our caller
761 //
762
763 FatReleaseFcb( IrpContext, Fcb );
764
765 DebugTrace(-1, Dbg, "FatCommonLockControl -> %08lx\n", Status);
766 } _SEH2_END;
767
768 return Status;
769}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN TypeOfOpen
Definition: cdprocs.h:589
enum _TYPE_OF_OPEN TYPE_OF_OPEN
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4137
#define FatNull
Definition: fatdata.h:321
NTSTATUS FatFsdPostRequest(IN PIRP_CONTEXT IrpContext, IN PIRP Irp)
Definition: workque.c:229
#define FatCompleteRequest(IRPCONTEXT, IRP, STATUS)
Definition: fatprocs.h:2633
#define FatReleaseFcb(IRPCONTEXT, Fcb)
Definition: fatprocs.h:1644
VOID NTAPI FatOplockComplete(IN PVOID Context, IN PIRP Irp)
Definition: workque.c:35
NTSTATUS NTAPI FsRtlProcessFileLock(IN PFILE_LOCK FileLock, IN PIRP Irp, IN PVOID Context OPTIONAL)
Definition: filelock.c:1152
NTSTATUS NTAPI FsRtlCheckOplock(IN POPLOCK Oplock, IN PIRP Irp, IN PVOID Context, IN POPLOCK_WAIT_COMPLETE_ROUTINE CompletionRoutine OPTIONAL, IN POPLOCK_FS_PREPOST_IRP PostIrpRoutine OPTIONAL)
Definition: oplock.c:1170
#define _SEH2_AbnormalTermination()
Definition: pseh2_64.h:166
#define STATUS_SUCCESS
Definition: shellext.h:65
union _IO_STACK_LOCATION::@1565 Parameters
PFILE_OBJECT FileObject
Definition: iotypes.h:3169
struct _IO_STACK_LOCATION::@3974::@3990 LockControl
uint64_t ULONGLONG
Definition: typedefs.h:67
#define IRP_MN_LOCK
Definition: iotypes.h:4410