ReactOS 0.4.17-dev-1321-g5c122a9
lockctrl.c
Go to the documentation of this file.
1/*++
2
3Copyright (c) 1989-2000 Microsoft Corporation
4
5Module Name:
6
7 LockCtrl.c
8
9Abstract:
10
11 This module implements the Lock Control routines for Cdfs called
12 by the Fsd/Fsp dispatch driver.
13
14
15--*/
16
17#include "cdprocs.h"
18
19//
20// The Bug check file id for this module
21//
22
23#define BugCheckFileId (CDFS_BUG_CHECK_LOCKCTRL)
24
25#ifdef ALLOC_PRAGMA
26#pragma alloc_text(PAGE, CdCommonLockControl)
27#pragma alloc_text(PAGE, CdFastLock)
28#pragma alloc_text(PAGE, CdFastUnlockAll)
29#pragma alloc_text(PAGE, CdFastUnlockAllByKey)
30#pragma alloc_text(PAGE, CdFastUnlockSingle)
31#endif
32
33
36 _Inout_ PIRP_CONTEXT IrpContext,
38 )
39
40/*++
41
42Routine Description:
43
44 This is the common routine for Lock Control called by both the fsd and fsp
45 threads.
46
47Arguments:
48
49 Irp - Supplies the Irp to process
50
51Return Value:
52
53 NTSTATUS - The return status for the operation
54
55--*/
56
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}
138
139
141NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
147 _In_ ULONG Key,
152 )
153
154/*++
155
156Routine Description:
157
158 This is a call back routine for doing the fast lock call.
159
160Arguments:
161
162 FileObject - Supplies the file object used in this operation
163
164 FileOffset - Supplies the file offset used in this operation
165
166 Length - Supplies the length used in this operation
167
168 ProcessId - Supplies the process ID used in this operation
169
170 Key - Supplies the key used in this operation
171
172 FailImmediately - Indicates if the request should fail immediately
173 if the lock cannot be granted.
174
175 ExclusiveLock - Indicates if this is a request for an exclusive or
176 shared lock
177
178 IoStatus - Receives the Status if this operation is successful
179
180Return Value:
181
182 BOOLEAN - TRUE if this operation completed and FALSE if caller
183 needs to take the long route.
184
185--*/
186
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}
290
291
293NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
299 _In_ ULONG Key,
302 )
303
304/*++
305
306Routine Description:
307
308 This is a call back routine for doing the fast unlock single call.
309
310Arguments:
311
312 FileObject - Supplies the file object used in this operation
313
314 FileOffset - Supplies the file offset used in this operation
315
316 Length - Supplies the length used in this operation
317
318 ProcessId - Supplies the process ID used in this operation
319
320 Key - Supplies the key used in this operation
321
322 Status - Receives the Status if this operation is successful
323
324Return Value:
325
326 BOOLEAN - TRUE if this operation completed and FALSE if caller
327 needs to take the long route.
328
329--*/
330
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}
433
434
436NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
442 )
443
444/*++
445
446Routine Description:
447
448 This is a call back routine for doing the fast unlock all call.
449
450Arguments:
451
452 FileObject - Supplies the file object used in this operation
453
454 ProcessId - Supplies the process ID used in this operation
455
456 Status - Receives the Status if this operation is successful
457
458Return Value:
459
460 BOOLEAN - TRUE if this operation completed and FALSE if caller
461 needs to take the long route.
462
463--*/
464
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}
558
559
561NTAPI /* ReactOS Change: GCC Does not support STDCALL by default */
565 _In_ ULONG Key,
568 )
569
570/*++
571
572Routine Description:
573
574 This is a call back routine for doing the fast unlock all by key call.
575
576Arguments:
577
578 FileObject - Supplies the file object used in this operation
579
580 ProcessId - Supplies the process ID used in this operation
581
582 Key - Supplies the key used in this operation
583
584 Status - Receives the Status if this operation is successful
585
586Return Value:
587
588 BOOLEAN - TRUE if this operation completed and FALSE if caller
589 needs to take the long route.
590
591--*/
592
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}
687
688
689
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
#define PAGED_CODE()
unsigned char BOOLEAN
Definition: actypes.h:127
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 ASSERT_FILE_OBJECT(FO)
Definition: cddata.h:252
NTSTATUS CdCommonLockControl(_Inout_ PIRP_CONTEXT IrpContext, _Inout_ PIRP Irp)
Definition: lockctrl.c:35
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:160
#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
FAST_IO_UNLOCK_SINGLE CdFastUnlockSingle
Definition: cdprocs.h:1916
TYPE_OF_OPEN CdFastDecodeFileObject(_In_ PFILE_OBJECT FileObject, _Out_ PFCB *Fcb)
Definition: filobsup.c:206
#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
FAST_IO_UNLOCK_ALL CdFastUnlockAll
Definition: cdprocs.h:1926
enum _TYPE_OF_OPEN TYPE_OF_OPEN
#define try_return(S)
Definition: cdprocs.h:2179
FAST_IO_UNLOCK_ALL_BY_KEY CdFastUnlockAllByKey
Definition: cdprocs.h:1937
FAST_IO_LOCK CdFastLock
Definition: cdprocs.h:1903
#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
#define FALSE
Definition: types.h:117
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4138
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
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
NTSTATUS NTAPI FsRtlProcessFileLock(IN PFILE_LOCK FileLock, IN PIRP Irp, IN PVOID Context OPTIONAL)
Definition: filelock.c:1156
NTSTATUS NTAPI FsRtlFastUnlockAll(IN PFILE_LOCK FileLock, IN PFILE_OBJECT FileObject, IN PEPROCESS Process, IN PVOID Context OPTIONAL)
Definition: filelock.c:1027
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
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
#define FsRtlAreThereCurrentFileLocks(FL)
Definition: fsrtlfuncs.h:1584
#define FsRtlFastLock(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11)
Definition: fsrtlfuncs.h:1581
@ FastIoIsPossible
Definition: fsrtltypes.h:241
Status
Definition: gdiplustypes.h:24
#define NOTHING
Definition: input_list.c:10
_In_ PIRP Irp
Definition: kse.h:79
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 _Inout_
Definition: no_sal2.h:162
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:329
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define STATUS_RANGE_NOT_LOCKED
Definition: ntstatus.h:456
BOOLEAN NTAPI FsRtlOplockIsFastIoPossible(IN POPLOCK Oplock)
Definition: oplock.c:1564
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_FINALLY
Definition: pseh2_64.h:153
#define _SEH2_END
Definition: pseh2_64.h:194
#define _SEH2_TRY
Definition: pseh2_64.h:93
#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 NTAPI
Definition: typedefs.h:36
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2061
_In_ WDFREQUEST _In_ WDFFILEOBJECT FileObject
Definition: wdfdevice.h:550
* PFILE_OBJECT
Definition: iotypes.h:1998