Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

lockctrl.c File Reference

#include "UdfProcs.h"

Go to the source code of this file.

Defines

#define BugCheckFileId   (UDFS_BUG_CHECK_LOCKCTRL)
#define Dbg   (UDFS_DEBUG_LEVEL_LOCKCTRL)

Functions

NTSTATUS UdfCommonLockControl (IN PIRP_CONTEXT IrpContext, IN PIRP Irp)
BOOLEAN UdfFastLock (IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN PLARGE_INTEGER Length, PEPROCESS ProcessId, ULONG Key, BOOLEAN FailImmediately, BOOLEAN ExclusiveLock, OUT PIO_STATUS_BLOCK IoStatus, IN PDEVICE_OBJECT DeviceObject)
BOOLEAN UdfFastUnlockSingle (IN PFILE_OBJECT FileObject, IN PLARGE_INTEGER FileOffset, IN PLARGE_INTEGER Length, PEPROCESS ProcessId, ULONG Key, OUT PIO_STATUS_BLOCK IoStatus, IN PDEVICE_OBJECT DeviceObject)
BOOLEAN UdfFastUnlockAll (IN PFILE_OBJECT FileObject, PEPROCESS ProcessId, OUT PIO_STATUS_BLOCK IoStatus, IN PDEVICE_OBJECT DeviceObject)
BOOLEAN UdfFastUnlockAllByKey (IN PFILE_OBJECT FileObject, PVOID ProcessId, ULONG Key, OUT PIO_STATUS_BLOCK IoStatus, IN PDEVICE_OBJECT DeviceObject)


Define Documentation

#define BugCheckFileId   (UDFS_BUG_CHECK_LOCKCTRL)
 

Definition at line 28 of file lockctrl.c.

#define Dbg   (UDFS_DEBUG_LEVEL_LOCKCTRL)
 

Definition at line 34 of file lockctrl.c.


Function Documentation

NTSTATUS UdfCommonLockControl IN PIRP_CONTEXT  IrpContext,
IN PIRP  Irp
 

Definition at line 46 of file lockctrl.c.

References _IO_STACK_LOCATION::FileObject, FsRtlCheckOplock(), FsRtlProcessFileLock(), IoGetCurrentIrpStackLocation, Irp, NTSTATUS(), NULL, PAGED_CODE, Status, TRUE, TYPE_OF_OPEN, UdfCompleteRequest(), UdfCreateFileLock(), UdfDecodeFileObject(), UdfIsFastIoPossible, UdfLockFcb, UdfOplockComplete(), UdfUnlockFcb, UdfVerifyFcbOperation(), and UserFileOpen.

Referenced by UdfFsdDispatch(), and UdfFspDispatch().

00053 : 00054 00055 This is the common routine for Lock Control called by both the fsd and fsp 00056 threads. 00057 00058 Arguments: 00059 00060 Irp - Supplies the Irp to process 00061 00062 Return Value: 00063 00064 NTSTATUS - The return status for the operation 00065 00066 --*/ 00067 00068 { 00069 NTSTATUS Status; 00070 PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation( Irp ); 00071 00072 TYPE_OF_OPEN TypeOfOpen; 00073 PFCB Fcb; 00074 PCCB Ccb; 00075 00076 PAGED_CODE(); 00077 00078 // 00079 // Extract and decode the type of file object we're being asked to process 00080 // 00081 00082 TypeOfOpen = UdfDecodeFileObject( IrpSp->FileObject, &Fcb, &Ccb ); 00083 00084 // 00085 // If the file is not a user file open then we reject the request 00086 // as an invalid parameter 00087 // 00088 00089 if (TypeOfOpen != UserFileOpen) { 00090 00091 UdfCompleteRequest( IrpContext, Irp, STATUS_INVALID_PARAMETER ); 00092 return STATUS_INVALID_PARAMETER; 00093 } 00094 00095 // 00096 // We check whether we can proceed based on the state of the file oplocks. 00097 // This call might post the irp for us. 00098 // 00099 00100 Status = FsRtlCheckOplock( &Fcb->Oplock, 00101 Irp, 00102 IrpContext, 00103 UdfOplockComplete, 00104 NULL ); 00105 00106 // 00107 // If we don't get success then the oplock package completed the request. 00108 // 00109 00110 if (Status != STATUS_SUCCESS) { 00111 00112 return Status; 00113 } 00114 00115 // 00116 // Verify the Fcb. 00117 // 00118 00119 UdfVerifyFcbOperation( IrpContext, Fcb ); 00120 00121 // 00122 // If we don't have a file lock, then get one now. 00123 // 00124 00125 if (Fcb->FileLock == NULL) { UdfCreateFileLock( IrpContext, Fcb, TRUE ); } 00126 00127 // 00128 // Now call the FsRtl routine to do the actual processing of the 00129 // Lock request 00130 // 00131 00132 Status = FsRtlProcessFileLock( Fcb->FileLock, Irp, NULL ); 00133 00134 // 00135 // Set the flag indicating if Fast I/O is possible 00136 // 00137 00138 UdfLockFcb( IrpContext, Fcb ); 00139 Fcb->IsFastIoPossible = UdfIsFastIoPossible( Fcb ); 00140 UdfUnlockFcb( IrpContext, Fcb ); 00141 00142 // 00143 // Complete the request. 00144 // 00145 00146 UdfCompleteRequest( IrpContext, NULL, Status ); 00147 return Status; 00148 }

BOOLEAN UdfFastLock IN PFILE_OBJECT  FileObject,
IN PLARGE_INTEGER  FileOffset,
IN PLARGE_INTEGER  Length,
PEPROCESS  ProcessId,
ULONG  Key,
BOOLEAN  FailImmediately,
BOOLEAN  ExclusiveLock,
OUT PIO_STATUS_BLOCK  IoStatus,
IN PDEVICE_OBJECT  DeviceObject
 

Definition at line 152 of file lockctrl.c.

References ASSERT_FILE_OBJECT, FALSE, FastIoIsPossible, FsRtlEnterFileSystem, FsRtlExitFileSystem, FsRtlFastLock, FsRtlOplockIsFastIoPossible(), Key, NULL, PAGED_CODE, TRUE, try_leave, TYPE_OF_OPEN, UdfCreateFileLock(), UdfFastDecodeFileObject(), UdfIsFastIoPossible, UdfLockFcb, UdfUnlockFcb, UdfVerifyFcbOperation(), and UserFileOpen.

00166 : 00167 00168 This is a call back routine for doing the fast lock call. 00169 00170 Arguments: 00171 00172 FileObject - Supplies the file object used in this operation 00173 00174 FileOffset - Supplies the file offset used in this operation 00175 00176 Length - Supplies the length used in this operation 00177 00178 ProcessId - Supplies the process ID used in this operation 00179 00180 Key - Supplies the key used in this operation 00181 00182 FailImmediately - Indicates if the request should fail immediately 00183 if the lock cannot be granted. 00184 00185 ExclusiveLock - Indicates if this is a request for an exclusive or 00186 shared lock 00187 00188 IoStatus - Receives the Status if this operation is successful 00189 00190 Return Value: 00191 00192 BOOLEAN - TRUE if this operation completed and FALSE if caller 00193 needs to take the long route. 00194 00195 --*/ 00196 00197 { 00198 BOOLEAN Results = FALSE; 00199 00200 PFCB Fcb; 00201 TYPE_OF_OPEN TypeOfOpen; 00202 00203 PAGED_CODE(); 00204 00205 ASSERT_FILE_OBJECT( FileObject ); 00206 00207 IoStatus->Information = 0; 00208 00209 // 00210 // Decode the type of file object we're being asked to process and 00211 // make sure that is is only a user file open. 00212 // 00213 00214 TypeOfOpen = UdfFastDecodeFileObject( FileObject, &Fcb ); 00215 00216 if (TypeOfOpen != UserFileOpen) { 00217 00218 IoStatus->Status = STATUS_INVALID_PARAMETER; 00219 return TRUE; 00220 } 00221 00222 // 00223 // Only deal with 'good' Fcb's. 00224 // 00225 00226 if (!UdfVerifyFcbOperation( NULL, Fcb )) { 00227 00228 return FALSE; 00229 } 00230 00231 FsRtlEnterFileSystem(); 00232 00233 // 00234 // Use a try-finally to facilitate cleanup. 00235 // 00236 00237 try { 00238 00239 // 00240 // We check whether we can proceed based on the state of the file oplocks. 00241 // 00242 00243 if ((Fcb->Oplock != NULL) && !FsRtlOplockIsFastIoPossible( &Fcb->Oplock )) { 00244 00245 try_leave( NOTHING ); 00246 } 00247 00248 // 00249 // If we don't have a file lock, then get one now. 00250 // 00251 00252 if ((Fcb->FileLock == NULL) && !UdfCreateFileLock( NULL, Fcb, FALSE )) { 00253 00254 try_leave( NOTHING ); 00255 } 00256 00257 // 00258 // Now call the FsRtl routine to perform the lock request. 00259 // 00260 00261 if (Results = FsRtlFastLock( Fcb->FileLock, 00262 FileObject, 00263 FileOffset, 00264 Length, 00265 ProcessId, 00266 Key, 00267 FailImmediately, 00268 ExclusiveLock, 00269 IoStatus, 00270 NULL, 00271 FALSE )) { 00272 00273 // 00274 // Set the flag indicating if Fast I/O is questionable. We 00275 // only change this flag if the current state is possible. 00276 // Retest again after synchronizing on the header. 00277 // 00278 00279 if (Fcb->IsFastIoPossible == FastIoIsPossible) { 00280 00281 UdfLockFcb( NULL, Fcb ); 00282 Fcb->IsFastIoPossible = UdfIsFastIoPossible( Fcb ); 00283 UdfUnlockFcb( NULL, Fcb ); 00284 } 00285 } 00286 00287 } finally { 00288 00289 FsRtlExitFileSystem(); 00290 } 00291 00292 return Results; 00293 }

BOOLEAN UdfFastUnlockAll IN PFILE_OBJECT  FileObject,
PEPROCESS  ProcessId,
OUT PIO_STATUS_BLOCK  IoStatus,
IN PDEVICE_OBJECT  DeviceObject
 

Definition at line 436 of file lockctrl.c.

References FALSE, FsRtlEnterFileSystem, FsRtlExitFileSystem, FsRtlFastUnlockAll(), FsRtlOplockIsFastIoPossible(), NULL, PAGED_CODE, TRUE, try_leave, TYPE_OF_OPEN, UdfCreateFileLock(), UdfFastDecodeFileObject(), UdfIsFastIoPossible, UdfLockFcb, UdfUnlockFcb, UdfVerifyFcbOperation(), and UserFileOpen.

00445 : 00446 00447 This is a call back routine for doing the fast unlock all call. 00448 00449 Arguments: 00450 00451 FileObject - Supplies the file object used in this operation 00452 00453 ProcessId - Supplies the process ID used in this operation 00454 00455 Status - Receives the Status if this operation is successful 00456 00457 Return Value: 00458 00459 BOOLEAN - TRUE if this operation completed and FALSE if caller 00460 needs to take the long route. 00461 00462 --*/ 00463 00464 { 00465 BOOLEAN Results = FALSE; 00466 TYPE_OF_OPEN TypeOfOpen; 00467 PFCB Fcb; 00468 00469 PAGED_CODE(); 00470 00471 IoStatus->Information = 0; 00472 00473 // 00474 // Decode the type of file object we're being asked to process and 00475 // make sure that is is only a user file open. 00476 // 00477 00478 TypeOfOpen = UdfFastDecodeFileObject( FileObject, &Fcb ); 00479 00480 if (TypeOfOpen != UserFileOpen) { 00481 00482 IoStatus->Status = STATUS_INVALID_PARAMETER; 00483 return TRUE; 00484 } 00485 00486 // 00487 // Only deal with 'good' Fcb's. 00488 // 00489 00490 if (!UdfVerifyFcbOperation( NULL, Fcb )) { 00491 00492 return FALSE; 00493 } 00494 00495 // 00496 // If there is no lock then return immediately. 00497 // 00498 00499 if (Fcb->FileLock == NULL) { 00500 00501 IoStatus->Status = STATUS_RANGE_NOT_LOCKED; 00502 return TRUE; 00503 } 00504 00505 FsRtlEnterFileSystem(); 00506 00507 try { 00508 00509 // 00510 // We check whether we can proceed based on the state of the file oplocks. 00511 // 00512 00513 if ((Fcb->Oplock != NULL) && !FsRtlOplockIsFastIoPossible( &Fcb->Oplock )) { 00514 00515 try_leave( NOTHING ); 00516 } 00517 00518 // 00519 // If we don't have a file lock, then get one now. 00520 // 00521 00522 if ((Fcb->FileLock == NULL) && !UdfCreateFileLock( NULL, Fcb, FALSE )) { 00523 00524 try_leave( NOTHING ); 00525 } 00526 00527 // 00528 // Now call the FsRtl routine to do the actual processing of the 00529 // Lock request. The call will always succeed. 00530 // 00531 00532 Results = TRUE; 00533 IoStatus->Status = FsRtlFastUnlockAll( Fcb->FileLock, 00534 FileObject, 00535 ProcessId, 00536 NULL ); 00537 00538 00539 // 00540 // Set the flag indicating if Fast I/O is possible 00541 // 00542 00543 UdfLockFcb( IrpContext, Fcb ); 00544 Fcb->IsFastIoPossible = UdfIsFastIoPossible( Fcb ); 00545 UdfUnlockFcb( IrpContext, Fcb ); 00546 00547 } finally { 00548 00549 FsRtlExitFileSystem(); 00550 } 00551 00552 return Results; 00553 }

BOOLEAN UdfFastUnlockAllByKey IN PFILE_OBJECT  FileObject,
PVOID  ProcessId,
ULONG  Key,
OUT PIO_STATUS_BLOCK  IoStatus,
IN PDEVICE_OBJECT  DeviceObject
 

Definition at line 557 of file lockctrl.c.

References FALSE, FsRtlEnterFileSystem, FsRtlExitFileSystem, FsRtlFastUnlockAllByKey(), FsRtlOplockIsFastIoPossible(), Key, NULL, PAGED_CODE, TRUE, try_leave, TYPE_OF_OPEN, UdfCreateFileLock(), UdfFastDecodeFileObject(), UdfIsFastIoPossible, UdfLockFcb, UdfUnlockFcb, UdfVerifyFcbOperation(), and UserFileOpen.

00567 : 00568 00569 This is a call back routine for doing the fast unlock all by key call. 00570 00571 Arguments: 00572 00573 FileObject - Supplies the file object used in this operation 00574 00575 ProcessId - Supplies the process ID used in this operation 00576 00577 Key - Supplies the key used in this operation 00578 00579 Status - Receives the Status if this operation is successful 00580 00581 Return Value: 00582 00583 BOOLEAN - TRUE if this operation completed and FALSE if caller 00584 needs to take the long route. 00585 00586 --*/ 00587 00588 { 00589 BOOLEAN Results = FALSE; 00590 TYPE_OF_OPEN TypeOfOpen; 00591 PFCB Fcb; 00592 00593 PAGED_CODE(); 00594 00595 IoStatus->Information = 0; 00596 00597 // 00598 // Decode the type of file object we're being asked to process and 00599 // make sure that is is only a user file open. 00600 // 00601 00602 TypeOfOpen = UdfFastDecodeFileObject( FileObject, &Fcb ); 00603 00604 if (TypeOfOpen != UserFileOpen) { 00605 00606 IoStatus->Status = STATUS_INVALID_PARAMETER; 00607 return TRUE; 00608 } 00609 00610 // 00611 // Only deal with 'good' Fcb's. 00612 // 00613 00614 if (!UdfVerifyFcbOperation( NULL, Fcb )) { 00615 00616 return FALSE; 00617 } 00618 00619 // 00620 // If there is no lock then return immediately. 00621 // 00622 00623 if (Fcb->FileLock == NULL) { 00624 00625 IoStatus->Status = STATUS_RANGE_NOT_LOCKED; 00626 return TRUE; 00627 } 00628 00629 FsRtlEnterFileSystem(); 00630 00631 try { 00632 00633 // 00634 // We check whether we can proceed based on the state of the file oplocks. 00635 // 00636 00637 if ((Fcb->Oplock != NULL) && !FsRtlOplockIsFastIoPossible( &Fcb->Oplock )) { 00638 00639 try_leave( NOTHING ); 00640 } 00641 00642 // 00643 // If we don't have a file lock, then get one now. 00644 // 00645 00646 if ((Fcb->FileLock == NULL) && !UdfCreateFileLock( NULL, Fcb, FALSE )) { 00647 00648 try_leave( NOTHING ); 00649 } 00650 00651 // 00652 // Now call the FsRtl routine to do the actual processing of the 00653 // Lock request. The call will always succeed. 00654 // 00655 00656 Results = TRUE; 00657 IoStatus->Status = FsRtlFastUnlockAllByKey( Fcb->FileLock, 00658 FileObject, 00659 ProcessId, 00660 Key, 00661 NULL ); 00662 00663 00664 // 00665 // Set the flag indicating if Fast I/O is possible 00666 // 00667 00668 UdfLockFcb( IrpContext, Fcb ); 00669 Fcb->IsFastIoPossible = UdfIsFastIoPossible( Fcb ); 00670 UdfUnlockFcb( IrpContext, Fcb ); 00671 00672 } finally { 00673 00674 FsRtlExitFileSystem(); 00675 } 00676 00677 return Results; 00678 }

BOOLEAN UdfFastUnlockSingle IN PFILE_OBJECT  FileObject,
IN PLARGE_INTEGER  FileOffset,
IN PLARGE_INTEGER  Length,
PEPROCESS  ProcessId,
ULONG  Key,
OUT PIO_STATUS_BLOCK  IoStatus,
IN PDEVICE_OBJECT  DeviceObject
 

Definition at line 297 of file lockctrl.c.

References FALSE, FastIoIsPossible, FsRtlAreThereCurrentFileLocks, FsRtlEnterFileSystem, FsRtlExitFileSystem, FsRtlFastUnlockSingle(), FsRtlOplockIsFastIoPossible(), Key, NULL, PAGED_CODE, TRUE, try_leave, TYPE_OF_OPEN, UdfCreateFileLock(), UdfFastDecodeFileObject(), UdfIsFastIoPossible, UdfLockFcb, UdfUnlockFcb, UdfVerifyFcbOperation(), and UserFileOpen.

00309 : 00310 00311 This is a call back routine for doing the fast unlock single call. 00312 00313 Arguments: 00314 00315 FileObject - Supplies the file object used in this operation 00316 00317 FileOffset - Supplies the file offset used in this operation 00318 00319 Length - Supplies the length used in this operation 00320 00321 ProcessId - Supplies the process ID used in this operation 00322 00323 Key - Supplies the key used in this operation 00324 00325 Status - Receives the Status if this operation is successful 00326 00327 Return Value: 00328 00329 BOOLEAN - TRUE if this operation completed and FALSE if caller 00330 needs to take the long route. 00331 00332 --*/ 00333 00334 { 00335 BOOLEAN Results = FALSE; 00336 TYPE_OF_OPEN TypeOfOpen; 00337 PFCB Fcb; 00338 00339 PAGED_CODE(); 00340 00341 IoStatus->Information = 0; 00342 00343 // 00344 // Decode the type of file object we're being asked to process and 00345 // make sure that is is only a user file open. 00346 // 00347 00348 TypeOfOpen = UdfFastDecodeFileObject( FileObject, &Fcb ); 00349 00350 if (TypeOfOpen != UserFileOpen) { 00351 00352 IoStatus->Status = STATUS_INVALID_PARAMETER; 00353 return TRUE; 00354 } 00355 00356 // 00357 // Only deal with 'good' Fcb's. 00358 // 00359 00360 if (!UdfVerifyFcbOperation( NULL, Fcb )) { 00361 00362 return FALSE; 00363 } 00364 00365 // 00366 // If there is no lock then return immediately. 00367 // 00368 00369 if (Fcb->FileLock == NULL) { 00370 00371 IoStatus->Status = STATUS_RANGE_NOT_LOCKED; 00372 return TRUE; 00373 } 00374 00375 FsRtlEnterFileSystem(); 00376 00377 try { 00378 00379 // 00380 // We check whether we can proceed based on the state of the file oplocks. 00381 // 00382 00383 if ((Fcb->Oplock != NULL) && !FsRtlOplockIsFastIoPossible( &Fcb->Oplock )) { 00384 00385 try_leave( NOTHING ); 00386 } 00387 00388 // 00389 // If we don't have a file lock, then get one now. 00390 // 00391 00392 if ((Fcb->FileLock == NULL) && !UdfCreateFileLock( NULL, Fcb, FALSE )) { 00393 00394 try_leave( NOTHING ); 00395 } 00396 00397 // 00398 // Now call the FsRtl routine to do the actual processing of the 00399 // Lock request. The call will always succeed. 00400 // 00401 00402 Results = TRUE; 00403 IoStatus->Status = FsRtlFastUnlockSingle( Fcb->FileLock, 00404 FileObject, 00405 FileOffset, 00406 Length, 00407 ProcessId, 00408 Key, 00409 NULL, 00410 FALSE ); 00411 00412 // 00413 // Set the flag indicating if Fast I/O is possible. We are 00414 // only concerned if there are no longer any filelocks on this 00415 // file. 00416 // 00417 00418 if (!FsRtlAreThereCurrentFileLocks( Fcb->FileLock ) && 00419 (Fcb->IsFastIoPossible != FastIoIsPossible)) { 00420 00421 UdfLockFcb( IrpContext, Fcb ); 00422 Fcb->IsFastIoPossible = UdfIsFastIoPossible( Fcb ); 00423 UdfUnlockFcb( IrpContext, Fcb ); 00424 } 00425 00426 } finally { 00427 00428 FsRtlExitFileSystem(); 00429 } 00430 00431 return Results; 00432 }


Generated on Sat May 15 19:44:33 2004 for test by doxygen 1.3.7