ReactOS  0.4.14-dev-342-gdc047f9
create.c File Reference
#include "classp.h"
Include dependency graph for create.c:

Go to the source code of this file.

Functions

PFILE_OBJECT_EXTENSION NTAPI ClasspGetFsContext (IN PCOMMON_DEVICE_EXTENSION CommonExtension, IN PFILE_OBJECT FileObject)
 
VOID NTAPI ClasspCleanupDisableMcn (IN PFILE_OBJECT_EXTENSION FsContext)
 
NTSTATUS NTAPI ClassCreateClose (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
NTSTATUS NTAPI ClasspCreateClose (IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
 
VOID NTAPI ClasspCleanupProtectedLocks (IN PFILE_OBJECT_EXTENSION FsContext)
 
NTSTATUS NTAPI ClasspEjectionControl (IN PDEVICE_OBJECT Fdo, IN PIRP Irp, IN MEDIA_LOCK_TYPE LockType, IN BOOLEAN Lock)
 

Variables

ULONG BreakOnClose = 0
 
PCSTR LockTypeStrings []
 

Function Documentation

◆ ClassCreateClose()

NTSTATUS NTAPI ClassCreateClose ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 59 of file create.c.

83 {
85  ULONG removeState;
87 
88  PAGED_CODE();
89 
90  //
91  // If we're getting a close request then we know the device object hasn't
92  // been completely destroyed. Let the driver cleanup if necessary.
93  //
94 
95  removeState = ClassAcquireRemoveLock(DeviceObject, Irp);
96 
97  //
98  // Invoke the device-specific routine, if one exists. Otherwise complete
99  // with SUCCESS
100  //
101 
102  if((removeState == NO_REMOVE) ||
104 
106 
107  if((NT_SUCCESS(status)) &&
108  (commonExtension->DevInfo->ClassCreateClose)) {
109 
110  return commonExtension->DevInfo->ClassCreateClose(DeviceObject, Irp);
111  }
112 
113  } else {
115  }
116 
117  Irp->IoStatus.Status = status;
120  return status;
121 }
#define STATUS_DEVICE_DOES_NOT_EXIST
Definition: ntstatus.h:414
#define ClassAcquireRemoveLock(devobj, tag)
Definition: classpnp.h:97
_In_ PIRP Irp
Definition: csq.h:116
LONG NTSTATUS
Definition: precomp.h:26
PCLASS_CREATE_CLOSE ClassCreateClose
Definition: classpnp.h:509
PVOID DeviceExtension
Definition: env_spec_w32.h:418
PAGED_CODE()
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define NO_REMOVE
Definition: classpnp.h:93
NTSTATUS NTAPI ClasspCreateClose(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: create.c:125
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
VOID NTAPI ClassCompleteRequest(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN CCHAR PriorityBoost)
Definition: lock.c:376
PCLASS_DEV_INFO DevInfo
Definition: classpnp.h:596
#define IS_CLEANUP_REQUEST(majorFunction)
Definition: classpnp.h:30
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:566
static SERVICE_STATUS status
Definition: service.c:31
VOID NTAPI ClassReleaseRemoveLock(IN PDEVICE_OBJECT DeviceObject, IN OPTIONAL PIRP Tag)
Definition: lock.c:212
Definition: ps.c:97

◆ ClasspCleanupDisableMcn()

VOID NTAPI ClasspCleanupDisableMcn ( IN PFILE_OBJECT_EXTENSION  FsContext)

Definition at line 409 of file create.c.

412 {
413  PCOMMON_DEVICE_EXTENSION commonExtension =
414  FsContext->DeviceObject->DeviceExtension;
415 
416  PFUNCTIONAL_DEVICE_EXTENSION fdoExtension =
417  commonExtension->PartitionZeroExtension;
418 
419  PAGED_CODE();
420 
422  "ClasspCleanupDisableMcn called for %p\n",
423  FsContext->DeviceObject));
425  "ClasspCleanupDisableMcn - FsContext %p is disabled "
426  "%d times\n", FsContext, FsContext->McnDisableCount));
427 
428  //
429  // For each secure lock on this handle decrement the secured lock count
430  // for the FDO. Keep track of the new value.
431  //
432 
433  while(FsContext->McnDisableCount != 0) {
434  FsContext->McnDisableCount--;
435  ClassEnableMediaChangeDetection(fdoExtension);
436  }
437 
438  return;
439 }
_Inout_ PLIST_ENTRY _In_ PVOID FsContext
Definition: fltkernel.h:2239
struct _FUNCTIONAL_DEVICE_EXTENSION * PartitionZeroExtension
Definition: classpnp.h:575
PAGED_CODE()
VOID NTAPI ClassEnableMediaChangeDetection(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension)
Definition: autorun.c:2718
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23

Referenced by ClasspCreateClose().

◆ ClasspCleanupProtectedLocks()

VOID NTAPI ClasspCleanupProtectedLocks ( IN PFILE_OBJECT_EXTENSION  FsContext)

Definition at line 298 of file create.c.

301 {
302  PCOMMON_DEVICE_EXTENSION commonExtension =
303  FsContext->DeviceObject->DeviceExtension;
304 
305  PFUNCTIONAL_DEVICE_EXTENSION fdoExtension =
306  commonExtension->PartitionZeroExtension;
307 
308  ULONG newDeviceLockCount = 1;
309 
310  PAGED_CODE();
311 
312  DebugPrint((2,
313  "ClasspCleanupProtectedLocks called for %p\n",
314  FsContext->DeviceObject));
315  DebugPrint((2,
316  "ClasspCleanupProtectedLocks - FsContext %p is locked "
317  "%d times\n", FsContext, FsContext->LockCount));
318 
320 
321  //
322  // Synchronize with ejection and ejection control requests.
323  //
324 
327  UserRequest,
328  UserMode,
329  FALSE,
330  NULL);
331 
332  //
333  // For each secure lock on this handle decrement the secured lock count
334  // for the FDO. Keep track of the new value.
335  //
336 
337  if(FsContext->LockCount != 0) {
338 
339  do {
340 
341  InterlockedDecrement((PLONG)&FsContext->LockCount);
342 
343  newDeviceLockCount =
345 
346  } while(FsContext->LockCount != 0);
347 
348  //
349  // If the new lock count has been dropped to zero then issue a lock
350  // command to the device.
351  //
352 
353  DebugPrint((2,
354  "ClasspCleanupProtectedLocks: FDO secured lock count = %d "
355  "lock count = %d\n",
356  fdoExtension->ProtectedLockCount,
357  fdoExtension->LockCount));
358 
359  if((newDeviceLockCount == 0) && (fdoExtension->LockCount == 0)) {
360 
361  SCSI_REQUEST_BLOCK srb;
362  PCDB cdb;
364 
365  DebugPrint((2,
366  "ClasspCleanupProtectedLocks: FDO lock count dropped "
367  "to zero\n"));
368 
369  RtlZeroMemory(&srb, sizeof(SCSI_REQUEST_BLOCK));
370  cdb = (PCDB) &(srb.Cdb);
371 
372  srb.CdbLength = 6;
373 
374  cdb->MEDIA_REMOVAL.OperationCode = SCSIOP_MEDIUM_REMOVAL;
375 
376  //
377  // TRUE - prevent media removal.
378  // FALSE - allow media removal.
379  //
380 
381  cdb->MEDIA_REMOVAL.Prevent = FALSE;
382 
383  //
384  // Set timeout value.
385  //
386 
387  srb.TimeOutValue = fdoExtension->TimeOutValue;
389  &srb,
390  NULL,
391  0,
392  FALSE);
393 
394  DebugPrint((2,
395  "ClasspCleanupProtectedLocks: unlock request to drive "
396  "returned status %lx\n", status));
397  }
398  }
399 
400  KeSetEvent(&fdoExtension->EjectSynchronizationEvent,
402  FALSE);
404  return;
405 }
_Inout_ PLIST_ENTRY _In_ PVOID FsContext
Definition: fltkernel.h:2239
UCHAR Cdb[16]
Definition: srb.h:271
struct _CDB::_MEDIA_REMOVAL MEDIA_REMOVAL
struct _FUNCTIONAL_DEVICE_EXTENSION * PartitionZeroExtension
Definition: classpnp.h:575
Definition: cdrw_hw.h:28
LONG NTSTATUS
Definition: precomp.h:26
UCHAR CdbLength
Definition: srb.h:250
ULONG TimeOutValue
Definition: srb.h:254
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
NTSTATUS NTAPI ClassSendSrbSynchronous(PDEVICE_OBJECT Fdo, PSCSI_REQUEST_BLOCK Srb, PVOID BufferAddress, ULONG BufferLength, BOOLEAN WriteToDevice)
Definition: class.c:2648
ULONG BreakOnClose
Definition: create.c:26
smooth NULL
Definition: ftsmooth.c:416
union _CDB * PCDB
PAGED_CODE()
PDEVICE_OBJECT DeviceObject
Definition: classpnp.h:693
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define InterlockedDecrement
Definition: armddk.h:52
#define SCSIOP_MEDIUM_REMOVAL
Definition: cdrw_hw.h:902
#define KeEnterCriticalRegion()
Definition: ke_x.h:83
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
#define KeLeaveCriticalRegion()
Definition: ke_x.h:114
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:566
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
signed int * PLONG
Definition: retypes.h:5
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

Referenced by ClasspCreateClose().

◆ ClasspCreateClose()

NTSTATUS NTAPI ClasspCreateClose ( IN PDEVICE_OBJECT  DeviceObject,
IN PIRP  Irp 
)

Definition at line 125 of file create.c.

150 {
153 
154  PFILE_OBJECT fileObject = irpStack->FileObject;
155 
157 
158  PAGED_CODE();
159 
160 
161  //
162  // ISSUE-2000/3/28-henrygab - if lower stack fails create/close, we end up
163  // in an inconsistent state. re-write to verify all args and allocate all
164  // required resources, then pass the irp down, then complete the
165  // transaction. this is because we also cannot forward the irp, then fail
166  // it after it has succeeded a lower-level driver.
167  //
168 
169  if(irpStack->MajorFunction == IRP_MJ_CREATE) {
170 
171  PIO_SECURITY_CONTEXT securityContext =
172  irpStack->Parameters.Create.SecurityContext;
173  DebugPrint((2,
174  "ClasspCREATEClose: create received for device %p\n",
175  DeviceObject));
176  DebugPrint((2,
177  "ClasspCREATEClose: desired access %lx\n",
178  securityContext->DesiredAccess));
179  DebugPrint((2,
180  "ClasspCREATEClose: file object %lx\n",
181  irpStack->FileObject));
182 
184 
185  if(irpStack->FileObject != NULL) {
186 
187  PFILE_OBJECT_EXTENSION fsContext;
188 
189  //
190  // Allocate our own file object extension for this device object.
191  //
192 
194  &commonExtension->FileObjectDictionary,
195  (ULONG_PTR)irpStack->FileObject,
196  sizeof(FILE_OBJECT_EXTENSION),
198  (PVOID *)&fsContext);
199 
200  if(NT_SUCCESS(status)) {
201 
202  RtlZeroMemory(fsContext,
203  sizeof(FILE_OBJECT_EXTENSION));
204 
205  fsContext->FileObject = irpStack->FileObject;
206  fsContext->DeviceObject = DeviceObject;
207  } else if (status == STATUS_OBJECT_NAME_COLLISION) {
209  }
210  }
211 
212  } else {
213 
214  DebugPrint((2,
215  "ClasspCreateCLOSE: close received for device %p\n",
216  DeviceObject));
217  DebugPrint((2,
218  "ClasspCreateCLOSE: file object %p\n",
219  fileObject));
220 
221  if(irpStack->FileObject != NULL) {
222 
223  PFILE_OBJECT_EXTENSION fsContext =
224  ClasspGetFsContext(commonExtension, irpStack->FileObject);
225 
226  DebugPrint((2,
227  "ClasspCreateCLOSE: file extension %p\n",
228  fsContext));
229 
230  if(fsContext != NULL) {
231 
232  DebugPrint((2,
233  "ClasspCreateCLOSE: extension is ours - "
234  "freeing\n"));
236 
237  ClasspCleanupProtectedLocks(fsContext);
238 
239  ClasspCleanupDisableMcn(fsContext);
240 
241  FreeDictionaryEntry(&(commonExtension->FileObjectDictionary),
242  fsContext);
243  }
244  }
245  }
246 
247  //
248  // Notify the lower levels about the create or close operation - give them
249  // a chance to cleanup too.
250  //
251 
252  DebugPrint((2,
253  "ClasspCreateClose: %s for devobj %p\n",
254  (NT_SUCCESS(status) ? "Success" : "FAILED"),
255  DeviceObject));
256 
257 
258  if(NT_SUCCESS(status)) {
259 
260  KEVENT event;
261 
262  //
263  // Set up the event to wait on
264  //
265 
267 
270  TRUE, TRUE, TRUE);
271 
272  status = IoCallDriver(commonExtension->LowerDeviceObject, Irp);
273 
274  if(status == STATUS_PENDING) {
276  Executive,
277  KernelMode,
278  FALSE,
279  NULL);
280  status = Irp->IoStatus.Status;
281  }
282 
283  if (!NT_SUCCESS(status)) {
285  "ClasspCreateClose: Lower driver failed, but we "
286  "succeeded. This is a problem, lock counts will be "
287  "out of sync between levels.\n"));
288  }
289 
290  }
291 
292 
293  return status;
294 }
VOID NTAPI ClasspCleanupDisableMcn(IN PFILE_OBJECT_EXTENSION FsContext)
Definition: create.c:409
#define STATUS_OBJECT_NAME_COLLISION
Definition: udferr_usr.h:150
#define TRUE
Definition: types.h:120
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
VOID NTAPI ClasspCleanupProtectedLocks(IN PFILE_OBJECT_EXTENSION FsContext)
Definition: create.c:298
_In_ PIRP Irp
Definition: csq.h:116
ACCESS_MASK DesiredAccess
Definition: iotypes.h:2513
IO_COMPLETION_ROUTINE ClassSignalCompletion
Definition: classpnp.h:1137
LONG NTSTATUS
Definition: precomp.h:26
PDEVICE_OBJECT DeviceObject
Definition: classpnp.h:533
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
NTSTATUS NTAPI AllocateDictionaryEntry(IN PDICTIONARY Dictionary, IN ULONGLONG Key, IN ULONG Size, IN ULONG Tag, OUT PVOID *Entry)
Definition: dictlib.c:60
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:515
uint32_t ULONG_PTR
Definition: typedefs.h:63
FORCEINLINE VOID IoCopyCurrentIrpStackLocationToNext(_Inout_ PIRP Irp)
Definition: iofuncs.h:2820
ULONG BreakOnClose
Definition: create.c:26
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
PAGED_CODE()
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
* PFILE_OBJECT
Definition: iotypes.h:1955
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define CLASS_TAG_FILE_OBJECT_EXTENSION
Definition: classpnp.h:78
struct _cl_event * event
Definition: glext.h:7739
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
PFILE_OBJECT_EXTENSION NTAPI ClasspGetFsContext(IN PCOMMON_DEVICE_EXTENSION CommonExtension, IN PFILE_OBJECT FileObject)
Definition: create.c:969
PDEVICE_OBJECT LowerDeviceObject
Definition: classpnp.h:574
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
DICTIONARY FileObjectDictionary
Definition: classpnp.h:607
VOID NTAPI FreeDictionaryEntry(IN PDICTIONARY Dictionary, IN PVOID Entry)
Definition: dictlib.c:171
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2938
PFILE_OBJECT FileObject
Definition: classpnp.h:532
static SERVICE_STATUS status
Definition: service.c:31
HRESULT Create([out]ITransactionReceiver **ppReceiver)
Definition: ps.c:97

Referenced by ClassCreateClose().

◆ ClasspEjectionControl()

NTSTATUS NTAPI ClasspEjectionControl ( IN PDEVICE_OBJECT  Fdo,
IN PIRP  Irp,
IN MEDIA_LOCK_TYPE  LockType,
IN BOOLEAN  Lock 
)

Definition at line 449 of file create.c.

455 {
456  PFUNCTIONAL_DEVICE_EXTENSION FdoExtension = Fdo->DeviceExtension;
457  PCOMMON_DEVICE_EXTENSION commonExtension =
459 
460  PFILE_OBJECT_EXTENSION fsContext = NULL;
462  volatile PSCSI_REQUEST_BLOCK srb = NULL;
463  BOOLEAN countChanged = FALSE;
464 
465  PAGED_CODE();
466 
467  //
468  // Interlock with ejection and secure lock cleanup code. This is a
469  // user request so we can allow the stack to get swapped out while we
470  // wait for synchronization.
471  //
472 
474  &(FdoExtension->EjectSynchronizationEvent),
475  UserRequest,
476  UserMode,
477  FALSE,
478  NULL);
479 
481 
482  DebugPrint((2,
483  "ClasspEjectionControl: "
484  "Received request for %s lock type\n",
485  LockTypeStrings[LockType]
486  ));
487 
488  _SEH2_TRY {
489  PCDB cdb;
490 
492 
493  if(srb == NULL) {
495  _SEH2_LEAVE;
496  }
497 
498  RtlZeroMemory(srb, sizeof(SCSI_REQUEST_BLOCK));
499 
500  cdb = (PCDB) srb->Cdb;
501 
502  //
503  // Determine if this is a "secured" request.
504  //
505 
506  if(LockType == SecureMediaLock) {
507 
509  PFILE_OBJECT fileObject = irpStack->FileObject;
510 
511  //
512  // Make sure that the file object we are supplied has a
513  // proper FsContext before we try doing a secured lock.
514  //
515 
516  if(fileObject != NULL) {
517  fsContext = ClasspGetFsContext(commonExtension, fileObject);
518  }
519 
520  if (fsContext == NULL) {
521 
522  //
523  // This handle isn't setup correctly. We can't let the
524  // operation go.
525  //
526 
528  _SEH2_LEAVE;
529  }
530  }
531 
532  if(Lock) {
533 
534  //
535  // This is a lock command. Reissue the command in case bus or
536  // device was reset and the lock was cleared.
537  // note: may need to decrement count if actual lock operation
538  // failed....
539  //
540 
541  switch(LockType) {
542 
543  case SimpleMediaLock: {
544  FdoExtension->LockCount++;
545  countChanged = TRUE;
546  break;
547  }
548 
549  case SecureMediaLock: {
550  fsContext->LockCount++;
551  FdoExtension->ProtectedLockCount++;
552  countChanged = TRUE;
553  break;
554  }
555 
556  case InternalMediaLock: {
557  FdoExtension->InternalLockCount++;
558  countChanged = TRUE;
559  break;
560  }
561  }
562 
563  } else {
564 
565  //
566  // This is an unlock command. If it's a secured one then make sure
567  // the caller has a lock outstanding or return an error.
568  // note: may need to re-increment the count if actual unlock
569  // operation fails....
570  //
571 
572  switch(LockType) {
573 
574  case SimpleMediaLock: {
575  if(FdoExtension->LockCount != 0) {
576  FdoExtension->LockCount--;
577  countChanged = TRUE;
578  }
579  break;
580  }
581 
582  case SecureMediaLock: {
583  if(fsContext->LockCount == 0) {
585  _SEH2_LEAVE;
586  }
587  fsContext->LockCount--;
588  FdoExtension->ProtectedLockCount--;
589  countChanged = TRUE;
590  break;
591  }
592 
593  case InternalMediaLock: {
594  ASSERT(FdoExtension->InternalLockCount != 0);
595  FdoExtension->InternalLockCount--;
596  countChanged = TRUE;
597  break;
598  }
599  }
600 
601  //
602  // We only send an unlock command to the drive if both the
603  // secured and unsecured lock counts have dropped to zero.
604  //
605 
606  if((FdoExtension->ProtectedLockCount != 0) ||
607  (FdoExtension->InternalLockCount != 0) ||
608  (FdoExtension->LockCount != 0)) {
609 
611  _SEH2_LEAVE;
612  }
613  }
614 
616  if (TEST_FLAG(Fdo->Characteristics, FILE_REMOVABLE_MEDIA)) {
617 
618  srb->CdbLength = 6;
619  cdb->MEDIA_REMOVAL.OperationCode = SCSIOP_MEDIUM_REMOVAL;
620 
621  //
622  // TRUE - prevent media removal.
623  // FALSE - allow media removal.
624  //
625 
626  cdb->MEDIA_REMOVAL.Prevent = Lock;
627 
628  //
629  // Set timeout value.
630  //
631 
632  srb->TimeOutValue = FdoExtension->TimeOutValue;
633 
634  //
635  // The actual lock operation on the device isn't so important
636  // as the internal lock counts. Ignore failures.
637  //
638 
640  srb,
641  NULL,
642  0,
643  FALSE);
644  }
645 
646  } _SEH2_FINALLY {
647 
648  if (!NT_SUCCESS(status)) {
649  DebugPrint((2,
650  "ClasspEjectionControl: FAILED status %x -- "
651  "reverting lock counts\n", status));
652 
653  if (countChanged) {
654 
655  //
656  // have to revert to previous counts if the
657  // lock/unlock operation actually failed.
658  //
659 
660  if(Lock) {
661 
662  switch(LockType) {
663 
664  case SimpleMediaLock: {
665  FdoExtension->LockCount--;
666  break;
667  }
668 
669  case SecureMediaLock: {
670  fsContext->LockCount--;
671  FdoExtension->ProtectedLockCount--;
672  break;
673  }
674 
675  case InternalMediaLock: {
676  FdoExtension->InternalLockCount--;
677  break;
678  }
679  }
680 
681  } else {
682 
683  switch(LockType) {
684 
685  case SimpleMediaLock: {
686  FdoExtension->LockCount++;
687  break;
688  }
689 
690  case SecureMediaLock: {
691  fsContext->LockCount++;
692  FdoExtension->ProtectedLockCount++;
693  break;
694  }
695 
696  case InternalMediaLock: {
697  FdoExtension->InternalLockCount++;
698  break;
699  }
700  }
701  }
702 
703  }
704 
705  } else {
706 
707  DebugPrint((2,
708  "ClasspEjectionControl: Succeeded\n"));
709 
710  }
711 
712  DebugPrint((2,
713  "ClasspEjectionControl: "
714  "Current Counts: Internal: %x Secure: %x Simple: %x\n",
715  FdoExtension->InternalLockCount,
716  FdoExtension->ProtectedLockCount,
717  FdoExtension->LockCount
718  ));
719 
720  KeSetEvent(&(FdoExtension->EjectSynchronizationEvent),
722  FALSE);
723  if (srb) {
725  }
726 
727  } _SEH2_END;
728  return status;
729 }
#define TRUE
Definition: types.h:120
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
UCHAR Cdb[16]
Definition: srb.h:271
struct _CDB::_MEDIA_REMOVAL MEDIA_REMOVAL
#define TEST_FLAG(Flags, Bit)
Definition: classpnp.h:156
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
Definition: cdrw_hw.h:28
LONG NTSTATUS
Definition: precomp.h:26
UCHAR CdbLength
Definition: srb.h:250
ULONG TimeOutValue
Definition: srb.h:254
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
_SEH2_TRY
Definition: create.c:4250
#define STATUS_INVALID_DEVICE_STATE
Definition: udferr_usr.h:178
NTSTATUS NTAPI ClassSendSrbSynchronous(PDEVICE_OBJECT Fdo, PSCSI_REQUEST_BLOCK Srb, PVOID BufferAddress, ULONG BufferLength, BOOLEAN WriteToDevice)
Definition: class.c:2648
#define FILE_REMOVABLE_MEDIA
Definition: nt_native.h:807
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
union _CDB * PCDB
PAGED_CODE()
#define ClasspAllocateSrb(ext)
Definition: classpnp.h:143
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _COMMON_DEVICE_EXTENSION * PCOMMON_DEVICE_EXTENSION
* PFILE_OBJECT
Definition: iotypes.h:1955
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define SCSIOP_MEDIUM_REMOVAL
Definition: cdrw_hw.h:902
IN OUT PLONG IN OUT PLONG Addend IN OUT PLONG IN LONG IN OUT PLONG IN LONG Increment IN PNDIS_RW_LOCK Lock
Definition: CrNtStubs.h:75
VOID NTAPI ClassFreeOrReuseSrb(IN PFUNCTIONAL_DEVICE_EXTENSION FdoExtension, IN PSCSI_REQUEST_BLOCK Srb)
Definition: obsolete.c:824
ULONG NTAPI DebugPrint(IN PSTRING DebugString, IN ULONG ComponentId, IN ULONG Level)
Definition: debug.c:23
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2813
_SEH2_END
Definition: create.c:4424
PFILE_OBJECT_EXTENSION NTAPI ClasspGetFsContext(IN PCOMMON_DEVICE_EXTENSION CommonExtension, IN PFILE_OBJECT FileObject)
Definition: create.c:969
_SEH2_FINALLY
Definition: create.c:4395
#define IO_NO_INCREMENT
Definition: iotypes.h:566
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define _SEH2_LEAVE
Definition: filesup.c:20
return STATUS_SUCCESS
Definition: btrfs.c:2938
static SERVICE_STATUS status
Definition: service.c:31
PCSTR LockTypeStrings[]
Definition: create.c:28
Definition: ps.c:97

Referenced by ClassDeviceControl(), and ClassDispatchPnp().

◆ ClasspGetFsContext()

PFILE_OBJECT_EXTENSION NTAPI ClasspGetFsContext ( IN PCOMMON_DEVICE_EXTENSION  CommonExtension,
IN PFILE_OBJECT  FileObject 
)

Definition at line 969 of file create.c.

973 {
974  PAGED_CODE();
975  return GetDictionaryEntry(&(CommonExtension->FileObjectDictionary),
977 }
uint32_t ULONG_PTR
Definition: typedefs.h:63
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT FileObject
Definition: create.c:4157
PAGED_CODE()
PVOID NTAPI GetDictionaryEntry(IN PDICTIONARY Dictionary, IN ULONGLONG Key)
Definition: dictlib.c:139

Referenced by ClasspCreateClose(), ClasspEjectionControl(), and ClasspMcnControl().

Variable Documentation

◆ BreakOnClose

ULONG BreakOnClose = 0

Definition at line 26 of file create.c.

Referenced by ClasspCleanupProtectedLocks(), and ClasspCreateClose().

◆ LockTypeStrings

PCSTR LockTypeStrings[]
Initial value:
= {
"Simple",
"Secure",
"Internal"
}

Definition at line 28 of file create.c.

Referenced by ClasspEjectionControl().