ReactOS 0.4.17-dev-1321-g5c122a9
lockctrl.c File Reference
#include "cdprocs.h"
Include dependency graph for lockctrl.c:

Go to the source code of this file.

Macros

#define BugCheckFileId   (CDFS_BUG_CHECK_LOCKCTRL)
 

Functions

NTSTATUS CdCommonLockControl (_Inout_ PIRP_CONTEXT IrpContext, _Inout_ PIRP Irp)
 
BOOLEAN NTAPI CdFastLock (_In_ PFILE_OBJECT FileObject, _In_ PLARGE_INTEGER FileOffset, _In_ PLARGE_INTEGER Length, _In_ PEPROCESS ProcessId, _In_ ULONG Key, _In_ BOOLEAN FailImmediately, _In_ BOOLEAN ExclusiveLock, _Out_ PIO_STATUS_BLOCK IoStatus, _In_ PDEVICE_OBJECT DeviceObject)
 
BOOLEAN NTAPI CdFastUnlockSingle (_In_ PFILE_OBJECT FileObject, _In_ PLARGE_INTEGER FileOffset, _In_ PLARGE_INTEGER Length, _In_ PEPROCESS ProcessId, _In_ ULONG Key, _Out_ PIO_STATUS_BLOCK IoStatus, _In_ PDEVICE_OBJECT DeviceObject)
 
BOOLEAN NTAPI CdFastUnlockAll (_In_ PFILE_OBJECT FileObject, _In_ PEPROCESS ProcessId, _Out_ PIO_STATUS_BLOCK IoStatus, _In_ PDEVICE_OBJECT DeviceObject)
 
BOOLEAN NTAPI CdFastUnlockAllByKey (_In_ PFILE_OBJECT FileObject, _In_ PVOID ProcessId, _In_ ULONG Key, _Out_ PIO_STATUS_BLOCK IoStatus, _In_ PDEVICE_OBJECT DeviceObject)
 

Macro Definition Documentation

◆ BugCheckFileId

#define BugCheckFileId   (CDFS_BUG_CHECK_LOCKCTRL)

Definition at line 23 of file lockctrl.c.

Function Documentation

◆ CdCommonLockControl()

NTSTATUS CdCommonLockControl ( _Inout_ PIRP_CONTEXT  IrpContext,
_Inout_ PIRP  Irp 
)

Definition at line 35 of file lockctrl.c.

57{
60
62 PFCB Fcb;
63 PCCB Ccb;
64
65 PAGED_CODE();
66
67 //
68 // Extract and decode the type of file object we're being asked to process
69 //
70
71 TypeOfOpen = CdDecodeFileObject( IrpContext, IrpSp->FileObject, &Fcb, &Ccb );
72
73 //
74 // If the file is not a user file open then we reject the request
75 // as an invalid parameter
76 //
77
78 if (TypeOfOpen != UserFileOpen) {
79
82 }
83
84 //
85 // We check whether we can proceed based on the state of the file oplocks.
86 // This call might post the irp for us.
87 //
88
90 Irp,
91 IrpContext,
92 (PVOID)CdOplockComplete,/* ReactOS Change: GCC "assignment from incompatible pointer type" */
93 NULL );
94
95 //
96 // If we don't get success then the oplock package completed the request.
97 //
98
99 if (Status != STATUS_SUCCESS) {
100
101 return Status;
102 }
103
104 //
105 // Verify the Fcb.
106 //
107
108 CdVerifyFcbOperation( IrpContext, Fcb );
109
110 //
111 // If we don't have a file lock, then get one now.
112 //
113
114 if (Fcb->FileLock == NULL) { CdCreateFileLock( IrpContext, Fcb, TRUE ); }
115
116 //
117 // Now call the FsRtl routine to do the actual processing of the
118 // Lock request
119 //
120
122
123 //
124 // Set the flag indicating if Fast I/O is possible
125 //
126
127 CdLockFcb( IrpContext, Fcb );
128 Fcb->IsFastIoPossible = CdIsFastIoPossible( Fcb );
129 CdUnlockFcb( IrpContext, Fcb );
130
131 //
132 // Complete the request.
133 //
134
135 CdCompleteRequest( IrpContext, NULL, Status );
136 return Status;
137}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
#define PAGED_CODE()
LONG NTSTATUS
Definition: precomp.h:26
VOID CdCompleteRequest(_Inout_opt_ PIRP_CONTEXT IrpContext, _Inout_opt_ PIRP Irp, _In_ NTSTATUS Status)
Definition: cddata.c:914
#define CdLockFcb(IC, F)
Definition: cdprocs.h:1044
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN TypeOfOpen
Definition: cdprocs.h:589
@ UserFileOpen
Definition: cdprocs.h:577
#define CdGetFcbOplock(F)
Definition: cdprocs.h:1081
_In_ PFCB Fcb
Definition: cdprocs.h:159
_Inout_ PFILE_OBJECT _In_ TYPE_OF_OPEN PFCB _In_opt_ PCCB Ccb
Definition: cdprocs.h:592
BOOLEAN CdVerifyFcbOperation(_In_opt_ PIRP_CONTEXT IrpContext, _In_ PFCB Fcb)
Definition: verfysup.c:615
enum _TYPE_OF_OPEN TYPE_OF_OPEN
#define CdIsFastIoPossible(F)
Definition: cdprocs.h:2015
#define CdUnlockFcb(IC, F)
Definition: cdprocs.h:1060
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4138
NTSTATUS NTAPI FsRtlProcessFileLock(IN PFILE_LOCK FileLock, IN PIRP Irp, IN PVOID Context OPTIONAL)
Definition: filelock.c:1156
Status
Definition: gdiplustypes.h:24
_In_ PIRP Irp
Definition: kse.h:79
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 STATUS_SUCCESS
Definition: shellext.h:65
Definition: cdstruc.h:1067
Definition: cdstruc.h:902
FILE_LOCK FileLock
Definition: fatstruc.h:1071
PFILE_OBJECT FileObject
Definition: iotypes.h:3184
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135

Referenced by _IRQL_requires_max_(), and CdFspDispatch().

◆ CdFastLock()

BOOLEAN NTAPI CdFastLock ( _In_ PFILE_OBJECT  FileObject,
_In_ PLARGE_INTEGER  FileOffset,
_In_ PLARGE_INTEGER  Length,
_In_ PEPROCESS  ProcessId,
_In_ ULONG  Key,
_In_ BOOLEAN  FailImmediately,
_In_ BOOLEAN  ExclusiveLock,
_Out_ PIO_STATUS_BLOCK  IoStatus,
_In_ PDEVICE_OBJECT  DeviceObject 
)

Definition at line 142 of file lockctrl.c.

187{
189
190 PFCB Fcb;
192
193 PAGED_CODE();
194
196
198
199 IoStatus->Information = 0;
200
201 //
202 // Decode the type of file object we're being asked to process and
203 // make sure that is is only a user file open.
204 //
205
207
208 if (TypeOfOpen != UserFileOpen) {
209
211 return TRUE;
212 }
213
214 //
215 // Only deal with 'good' Fcb's.
216 //
217
218 if (!CdVerifyFcbOperation( NULL, Fcb )) {
219
220 return FALSE;
221 }
222
224
225 //
226 // Use a try-finally to facilitate cleanup.
227 //
228
229 _SEH2_TRY {
230
231 //
232 // We check whether we can proceed based on the state of the file oplocks.
233 //
234
236
238 }
239
240 //
241 // If we don't have a file lock, then get one now.
242 //
243
244 if ((Fcb->FileLock == NULL) && !CdCreateFileLock( NULL, Fcb, FALSE )) {
245
247 }
248
249 //
250 // Now call the FsRtl routine to perform the lock request.
251 //
252
253#ifdef _MSC_VER
254#pragma prefast(suppress: 28159, "prefast thinks this is an obsolete routine, but it is ok for CDFS to use it")
255#endif
259 Length,
260 ProcessId,
261 Key,
264 IoStatus,
265 NULL,
266 FALSE )) != FALSE) {
267
268 //
269 // Set the flag indicating if Fast I/O is questionable. We
270 // only change this flag if the current state is possible.
271 // Retest again after synchronizing on the header.
272 //
273
274 if (Fcb->IsFastIoPossible == FastIoIsPossible) {
275
276 CdLockFcb( NULL, Fcb );
277 Fcb->IsFastIoPossible = CdIsFastIoPossible( Fcb );
278 CdUnlockFcb( NULL, Fcb );
279 }
280 }
281
282 try_exit: NOTHING;
283 } _SEH2_FINALLY {
284
286 } _SEH2_END;
287
288 return Results;
289}
unsigned char BOOLEAN
Definition: actypes.h:127
#define ASSERT_FILE_OBJECT(FO)
Definition: cddata.h:252
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:160
TYPE_OF_OPEN CdFastDecodeFileObject(_In_ PFILE_OBJECT FileObject, _Out_ PFCB *Fcb)
Definition: filobsup.c:206
#define try_return(S)
Definition: cdprocs.h:2179
#define FALSE
Definition: types.h:117
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ULONG BOOLEAN BOOLEAN ExclusiveLock
Definition: fatprocs.h:2715
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ULONG BOOLEAN FailImmediately
Definition: fatprocs.h:2714
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ProcessId
Definition: fatprocs.h:2712
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
#define FsRtlFastLock(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11)
Definition: fsrtlfuncs.h:1581
@ FastIoIsPossible
Definition: fsrtltypes.h:241
#define NOTHING
Definition: input_list.c:10
macro TEXTAREA section xr p2align endm macro DATAAREA section dw endm macro RODATAAREA section dr endm macro EXPORT Attribute global Name endm macro IMPORT Target ifc WEAK weak Name set Target endif endm set macro SET_COMDAT_ALIGNMENT Alignment set Alignment endm macro NESTED_ENTRY Name global Name p2align xr p2align __ComdatAlignment NESTED_ENTRY Name endm macro ALTERNATE_ENTRY Name global Name Results
Definition: kxarm64.h:154
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:159
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:329
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
BOOLEAN NTAPI FsRtlOplockIsFastIoPossible(IN POPLOCK Oplock)
Definition: oplock.c:1564
#define _SEH2_FINALLY
Definition: pseh2_64.h:153
#define _SEH2_END
Definition: pseh2_64.h:194
#define _SEH2_TRY
Definition: pseh2_64.h:93
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2061
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550

◆ CdFastUnlockAll()

BOOLEAN NTAPI CdFastUnlockAll ( _In_ PFILE_OBJECT  FileObject,
_In_ PEPROCESS  ProcessId,
_Out_ PIO_STATUS_BLOCK  IoStatus,
_In_ PDEVICE_OBJECT  DeviceObject 
)

Definition at line 437 of file lockctrl.c.

465{
468 PFCB Fcb;
469
470 PAGED_CODE();
471
473
474 IoStatus->Information = 0;
475
476 //
477 // Decode the type of file object we're being asked to process and
478 // make sure that is is only a user file open.
479 //
480
482
483 if (TypeOfOpen != UserFileOpen) {
484
486 return TRUE;
487 }
488
489 //
490 // Only deal with 'good' Fcb's.
491 //
492
493 if (!CdVerifyFcbOperation( NULL, Fcb )) {
494
495 return FALSE;
496 }
497
498 //
499 // If there is no lock then return immediately.
500 //
501
502 if (Fcb->FileLock == NULL) {
503
505 return TRUE;
506 }
507
509
510 _SEH2_TRY {
511
512 //
513 // We check whether we can proceed based on the state of the file oplocks.
514 //
515
517
519 }
520
521 //
522 // If we don't have a file lock, then get one now.
523 //
524
525 if ((Fcb->FileLock == NULL) && !CdCreateFileLock( NULL, Fcb, FALSE )) {
526
528 }
529
530 //
531 // Now call the FsRtl routine to do the actual processing of the
532 // Lock request. The call will always succeed.
533 //
534
535 Results = TRUE;
538 ProcessId,
539 NULL );
540
541
542 //
543 // Set the flag indicating if Fast I/O is possible
544 //
545
546 CdLockFcb( IrpContext, Fcb );
547 Fcb->IsFastIoPossible = CdIsFastIoPossible( Fcb );
548 CdUnlockFcb( IrpContext, Fcb );
549
550 try_exit: NOTHING;
551 } _SEH2_FINALLY {
552
554 } _SEH2_END;
555
556 return Results;
557}
NTSTATUS NTAPI FsRtlFastUnlockAll(IN PFILE_LOCK FileLock, IN PFILE_OBJECT FileObject, IN PEPROCESS Process, IN PVOID Context OPTIONAL)
Definition: filelock.c:1027
#define STATUS_RANGE_NOT_LOCKED
Definition: ntstatus.h:456

◆ CdFastUnlockAllByKey()

BOOLEAN NTAPI CdFastUnlockAllByKey ( _In_ PFILE_OBJECT  FileObject,
_In_ PVOID  ProcessId,
_In_ ULONG  Key,
_Out_ PIO_STATUS_BLOCK  IoStatus,
_In_ PDEVICE_OBJECT  DeviceObject 
)

Definition at line 562 of file lockctrl.c.

593{
596 PFCB Fcb;
597
598 PAGED_CODE();
599
601
602 IoStatus->Information = 0;
603
604 //
605 // Decode the type of file object we're being asked to process and
606 // make sure that is is only a user file open.
607 //
608
610
611 if (TypeOfOpen != UserFileOpen) {
612
614 return TRUE;
615 }
616
617 //
618 // Only deal with 'good' Fcb's.
619 //
620
621 if (!CdVerifyFcbOperation( NULL, Fcb )) {
622
623 return FALSE;
624 }
625
626 //
627 // If there is no lock then return immediately.
628 //
629
630 if (Fcb->FileLock == NULL) {
631
633 return TRUE;
634 }
635
637
638 _SEH2_TRY {
639
640 //
641 // We check whether we can proceed based on the state of the file oplocks.
642 //
643
645
647 }
648
649 //
650 // If we don't have a file lock, then get one now.
651 //
652
653 if ((Fcb->FileLock == NULL) && !CdCreateFileLock( NULL, Fcb, FALSE )) {
654
656 }
657
658 //
659 // Now call the FsRtl routine to do the actual processing of the
660 // Lock request. The call will always succeed.
661 //
662
663 Results = TRUE;
666 ProcessId,
667 Key,
668 NULL );
669
670
671 //
672 // Set the flag indicating if Fast I/O is possible
673 //
674
675 CdLockFcb( IrpContext, Fcb );
676 Fcb->IsFastIoPossible = CdIsFastIoPossible( Fcb );
677 CdUnlockFcb( IrpContext, Fcb );
678
679 try_exit: NOTHING;
680 } _SEH2_FINALLY {
681
683 } _SEH2_END;
684
685 return Results;
686}
NTSTATUS NTAPI FsRtlFastUnlockAllByKey(IN PFILE_LOCK FileLock, IN PFILE_OBJECT FileObject, IN PEPROCESS Process, IN ULONG Key, IN PVOID Context OPTIONAL)
Definition: filelock.c:1090

◆ CdFastUnlockSingle()

BOOLEAN NTAPI CdFastUnlockSingle ( _In_ PFILE_OBJECT  FileObject,
_In_ PLARGE_INTEGER  FileOffset,
_In_ PLARGE_INTEGER  Length,
_In_ PEPROCESS  ProcessId,
_In_ ULONG  Key,
_Out_ PIO_STATUS_BLOCK  IoStatus,
_In_ PDEVICE_OBJECT  DeviceObject 
)

Definition at line 294 of file lockctrl.c.

331{
334 PFCB Fcb;
335
336 PAGED_CODE();
337
339
340 IoStatus->Information = 0;
341
342 //
343 // Decode the type of file object we're being asked to process and
344 // make sure that is is only a user file open.
345 //
346
348
349 if (TypeOfOpen != UserFileOpen) {
350
352 return TRUE;
353 }
354
355 //
356 // Only deal with 'good' Fcb's.
357 //
358
359 if (!CdVerifyFcbOperation( NULL, Fcb )) {
360
361 return FALSE;
362 }
363
364 //
365 // If there is no lock then return immediately.
366 //
367
368 if (Fcb->FileLock == NULL) {
369
371 return TRUE;
372 }
373
375
376 _SEH2_TRY {
377
378 //
379 // We check whether we can proceed based on the state of the file oplocks.
380 //
381
383
385 }
386
387 //
388 // If we don't have a file lock, then get one now.
389 //
390
391 if ((Fcb->FileLock == NULL) && !CdCreateFileLock( NULL, Fcb, FALSE )) {
392
394 }
395
396 //
397 // Now call the FsRtl routine to do the actual processing of the
398 // Lock request. The call will always succeed.
399 //
400
401 Results = TRUE;
405 Length,
406 ProcessId,
407 Key,
408 NULL,
409 FALSE );
410
411 //
412 // Set the flag indicating if Fast I/O is possible. We are
413 // only concerned if there are no longer any filelocks on this
414 // file.
415 //
416
418 (Fcb->IsFastIoPossible != FastIoIsPossible)) {
419
420 CdLockFcb( IrpContext, Fcb );
421 Fcb->IsFastIoPossible = CdIsFastIoPossible( Fcb );
422 CdUnlockFcb( IrpContext, Fcb );
423 }
424
425 try_exit: NOTHING;
426 } _SEH2_FINALLY {
427
429 } _SEH2_END;
430
431 return Results;
432}
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:827
#define FsRtlAreThereCurrentFileLocks(FL)
Definition: fsrtlfuncs.h:1584