* Sync up to trunk head (r65353).
[reactos.git] / drivers / storage / classpnp / create.c
index 12fc002..00cfe2d 100644 (file)
@@ -21,13 +21,11 @@ Revision History:
 
 --*/
 
-#define CLASS_INIT_GUID 0
 #include "classp.h"
-#include "debug.h"
 
 ULONG BreakOnClose = 0;
 
-PUCHAR LockTypeStrings[] = {
+PCSTR LockTypeStrings[] = {
     "Simple",
     "Secure",
     "Internal"
@@ -35,16 +33,18 @@ PUCHAR LockTypeStrings[] = {
 
 
 PFILE_OBJECT_EXTENSION
+NTAPI
 ClasspGetFsContext(
     IN PCOMMON_DEVICE_EXTENSION CommonExtension,
     IN PFILE_OBJECT FileObject
     );
 
 VOID
+NTAPI
 ClasspCleanupDisableMcn(
     IN PFILE_OBJECT_EXTENSION FsContext
     );
-\f
+
 #ifdef ALLOC_PRAGMA
 #pragma alloc_text(PAGE, ClassCreateClose)
 #pragma alloc_text(PAGE, ClasspCreateClose)
@@ -55,6 +55,7 @@ ClasspCleanupDisableMcn(
 #endif
 
 NTSTATUS
+NTAPI
 ClassCreateClose(
     IN PDEVICE_OBJECT DeviceObject,
     IN PIRP Irp
@@ -119,8 +120,8 @@ Return Value:
     return status;
 }
 
-\f
 NTSTATUS
+NTAPI
 ClasspCreateClose(
     IN PDEVICE_OBJECT DeviceObject,
     IN PIRP Irp
@@ -191,10 +192,10 @@ Return Value:
 
             status = AllocateDictionaryEntry(
                         &commonExtension->FileObjectDictionary,
-                        (ULONGLONG) irpStack->FileObject,
+                        (ULONG_PTR)irpStack->FileObject,
                         sizeof(FILE_OBJECT_EXTENSION),
                         CLASS_TAG_FILE_OBJECT_EXTENSION,
-                        &fsContext);
+                        (PVOID *)&fsContext);
 
             if(NT_SUCCESS(status)) {
 
@@ -292,8 +293,8 @@ Return Value:
     return status;
 }
 
-\f
 VOID
+NTAPI
 ClasspCleanupProtectedLocks(
     IN PFILE_OBJECT_EXTENSION FsContext
     )
@@ -337,7 +338,7 @@ ClasspCleanupProtectedLocks(
 
         do {
 
-            InterlockedDecrement(&FsContext->LockCount);
+            InterlockedDecrement((PLONG)&FsContext->LockCount);
 
             newDeviceLockCount =
                 InterlockedDecrement(&fdoExtension->ProtectedLockCount);
@@ -403,8 +404,8 @@ ClasspCleanupProtectedLocks(
     return;
 }
 
-\f
 VOID
+NTAPI
 ClasspCleanupDisableMcn(
     IN PFILE_OBJECT_EXTENSION FsContext
     )
@@ -415,8 +416,6 @@ ClasspCleanupDisableMcn(
     PFUNCTIONAL_DEVICE_EXTENSION fdoExtension =
         commonExtension->PartitionZeroExtension;
 
-    ULONG newCount = 1;
-
     PAGED_CODE();
 
     DebugPrint((ClassDebugTrace,
@@ -439,14 +438,14 @@ ClasspCleanupDisableMcn(
     return;
 }
 
-
 #if 1
 /*
- *  BUGBUG REMOVE this old function implementation as soon as the 
- *                  boottime pagefile problems with the new one (below) 
+ *  BUGBUG REMOVE this old function implementation as soon as the
+ *                  boottime pagefile problems with the new one (below)
  *                  are resolved.
  */
 NTSTATUS
+NTAPI
 ClasspEjectionControl(
     IN PDEVICE_OBJECT Fdo,
     IN PIRP Irp,
@@ -457,10 +456,10 @@ ClasspEjectionControl(
     PFUNCTIONAL_DEVICE_EXTENSION FdoExtension = Fdo->DeviceExtension;
     PCOMMON_DEVICE_EXTENSION commonExtension =
         (PCOMMON_DEVICE_EXTENSION) FdoExtension;
-    
+
     PFILE_OBJECT_EXTENSION fsContext = NULL;
     NTSTATUS status;
-    PSCSI_REQUEST_BLOCK srb = NULL;
+    volatile PSCSI_REQUEST_BLOCK srb = NULL;
     BOOLEAN countChanged = FALSE;
 
     PAGED_CODE();
@@ -505,7 +504,7 @@ ClasspEjectionControl(
         //
 
         if(LockType == SecureMediaLock) {
-             
+
             PIO_STACK_LOCATION irpStack = IoGetCurrentIrpStackLocation(Irp);
             PFILE_OBJECT fileObject = irpStack->FileObject;
 
@@ -560,7 +559,7 @@ ClasspEjectionControl(
                     break;
                 }
             }
-        
+
         } else {
 
             //
@@ -618,25 +617,25 @@ ClasspEjectionControl(
 
             srb->CdbLength = 6;
             cdb->MEDIA_REMOVAL.OperationCode = SCSIOP_MEDIUM_REMOVAL;
-    
+
             //
             // TRUE - prevent media removal.
             // FALSE - allow media removal.
             //
-    
+
             cdb->MEDIA_REMOVAL.Prevent = Lock;
-    
+
             //
             // Set timeout value.
             //
-    
+
             srb->TimeOutValue = FdoExtension->TimeOutValue;
-    
+
             //
             // The actual lock operation on the device isn't so important
             // as the internal lock counts.  Ignore failures.
             //
-    
+
             status = ClassSendSrbSynchronous(FdoExtension->DeviceObject,
                                              srb,
                                              NULL,
@@ -650,7 +649,7 @@ ClasspEjectionControl(
             DebugPrint((2,
                         "ClasspEjectionControl: FAILED status %x -- "
                         "reverting lock counts\n", status));
-            
+
             if (countChanged) {
 
                 //
@@ -659,7 +658,7 @@ ClasspEjectionControl(
                 //
 
                 if(Lock) {
-                    
+
                     switch(LockType) {
 
                         case SimpleMediaLock: {
@@ -738,7 +737,8 @@ ClasspEjectionControl(
  *      HOWEVER, it seems to cause pagefile initialization to fail during boot
  *      for some reason.  Need to resolve this before switching to this function.
  */
-NTSTATUS  
+NTSTATUS
+NTAPI
 ClasspEjectionControl(
     IN PDEVICE_OBJECT Fdo,
     IN PIRP Irp,
@@ -751,9 +751,9 @@ ClasspEjectionControl(
     BOOLEAN fileHandleOk = TRUE;
     BOOLEAN countChanged = FALSE;
     NTSTATUS status;
-    
+
     PAGED_CODE();
-    
+
     status = KeWaitForSingleObject(
                 &fdoExt->EjectSynchronizationEvent,
                 UserRequest,
@@ -799,7 +799,7 @@ ClasspEjectionControl(
                     fdoExt->LockCount++;
                     countChanged = TRUE;
                     break;
-                case SecureMediaLock: 
+                case SecureMediaLock:
                     fsContext->LockCount++;
                     fdoExt->ProtectedLockCount++;
                     countChanged = TRUE;
@@ -809,14 +809,14 @@ ClasspEjectionControl(
                     countChanged = TRUE;
                     break;
             }
-        } 
+        }
         else {
             /*
              *  This is an unlock command.  If it's a secured one then make sure
              *  the caller has a lock outstanding or return an error.
              */
             switch (LockType){
-                case SimpleMediaLock: 
+                case SimpleMediaLock:
                     if (fdoExt->LockCount > 0){
                         fdoExt->LockCount--;
                         countChanged = TRUE;
@@ -855,7 +855,7 @@ ClasspEjectionControl(
                (fdoExt->ProtectedLockCount ||
                 fdoExt->InternalLockCount ||
                 fdoExt->LockCount)){
-                
+
                 /*
                  *  The lock count is still positive, so don't unlock yet.
                  */
@@ -869,14 +869,14 @@ ClasspEjectionControl(
             }
             else {
                 TRANSFER_PACKET *pkt;
-                
+
                 pkt = DequeueFreeTransferPacket(Fdo, TRUE);
                 if (pkt){
                     KEVENT event;
-                    
+
                     /*
                      *  Store the number of packets servicing the irp (one)
-                     *  inside the original IRP.  It will be used to counted down 
+                     *  inside the original IRP.  It will be used to counted down
                      *  to zero when the packet completes.
                      *  Initialize the original IRP's status to success.
                      *  If the packet fails, we will set it to the error status.
@@ -889,10 +889,10 @@ ClasspEjectionControl(
                      *  and wait for the packet to complete.  The result
                      *  status will be written to the original irp.
                      */
-                    KeInitializeEvent(&event, SynchronizationEvent, FALSE);                
+                    KeInitializeEvent(&event, SynchronizationEvent, FALSE);
                     SetupEjectionTransferPacket(pkt, Lock, &event, Irp);
                     SubmitTransferPacket(pkt);
-                    KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);        
+                    KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, NULL);
                     status = Irp->IoStatus.Status;
                 }
                 else {
@@ -957,7 +957,7 @@ ClasspEjectionControl(
     }
 
 
-    
+
     KeSetEvent(&fdoExt->EjectSynchronizationEvent, IO_NO_INCREMENT, FALSE);
 
     return status;
@@ -965,6 +965,7 @@ ClasspEjectionControl(
 #endif
 
 PFILE_OBJECT_EXTENSION
+NTAPI
 ClasspGetFsContext(
     IN PCOMMON_DEVICE_EXTENSION CommonExtension,
     IN PFILE_OBJECT FileObject
@@ -972,6 +973,5 @@ ClasspGetFsContext(
 {
     PAGED_CODE();
     return GetDictionaryEntry(&(CommonExtension->FileObjectDictionary),
-                              (ULONGLONG) FileObject);
+                              (ULONG_PTR)FileObject);
 }
-