Main Page | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

libcommon/openclose.c

Go to the documentation of this file.
00001 /*
00002  *  This program is free software; you can redistribute it and/or
00003  *  modify it under the terms of the GNU General Public License
00004  *  as published by the Free Software Foundation; either version
00005  *  2 of the License, or (at your option) any later version.
00006  *
00007  *  Copyright 2004 Spiro Trikaliotis
00008  *
00009  */
00010 
00020 #include <wdm.h>
00021 #include "cbm_driver.h"
00022 #include "iec.h"
00023 
00047 NTSTATUS
00048 cbm_createopenclose(IN PDEVICE_OBJECT Fdo, IN PIRP Irp)
00049 {
00050     PIO_STACK_LOCATION irpSp;
00051     PDEVICE_EXTENSION pdx;
00052     NTSTATUS ntStatus;
00053 
00054     FUNC_ENTER();
00055 
00056     // get the device extension
00057 
00058     pdx = Fdo->DeviceExtension;
00059 
00060     DBG_IRPPATH_PROCESS("create/open");
00061 
00062     // get the current IRP stack location
00063 
00064     irpSp = IoGetCurrentIrpStackLocation(Irp);
00065 
00066 
00067     if (irpSp->MajorFunction == IRP_MJ_CREATE
00068         && irpSp->Parameters.Create.Options & FILE_DIRECTORY_FILE) 
00069     {
00070         // The caller wants to open a directory.
00071         // As we do not support directories, fail that request!
00072 
00073         ntStatus = STATUS_NOT_A_DIRECTORY;
00074         DBG_IRPPATH_COMPLETE("create/open");
00075         QueueCompleteIrp(NULL, Irp, ntStatus, 0);
00076     }
00077     else
00078     {
00079         switch (irpSp->MajorFunction)
00080         {
00081         case IRP_MJ_CREATE:
00082             PERF_EVENT_OPEN_QUEUE();
00083             break;
00084 
00085         case IRP_MJ_CLOSE:
00086             PERF_EVENT_CLOSE_QUEUE();
00087             break;
00088 
00089         default:
00090             DBG_ERROR((DBG_PREFIX "UNKNOWN IRP->MAJORFUNCTION: %08x",
00091                 irpSp->MajorFunction));
00092             break;
00093         }
00094 
00095         // queue the IRP to be processed
00096 
00097         ntStatus = QueueStartPacket(&pdx->IrpQueue, Irp, FALSE, Fdo);
00098     }
00099     
00100     FUNC_LEAVE_NTSTATUS(ntStatus);
00101 }
00102 
00117 NTSTATUS
00118 cbm_execute_createopen(IN PDEVICE_EXTENSION Pdx, IN PIRP Irp)
00119 {
00120     NTSTATUS ntStatus;
00121 
00122     FUNC_ENTER();
00123 
00124     DBG_ASSERT(Pdx != NULL);
00125 
00126     PERF_EVENT_OPEN_EXECUTE();
00127 
00128     DBG_IRPPATH_EXECUTE("create/open");
00129 
00130     if (Pdx->ParallelPortLock)
00131     {
00132         // as we keep the parallel port locked all the time,
00133         // do not lock it now.
00134         ntStatus = STATUS_SUCCESS;
00135     }
00136     else
00137     {
00138         // Try to allocate the parallel port
00139 
00140         ntStatus = cbm_lock_parport(Pdx);
00141     }
00142 
00143     // We're done, complete the IRP
00144 
00145     DBG_IRPPATH_COMPLETE("create/open");
00146 
00147     QueueCompleteIrp(&Pdx->IrpQueue, Irp, ntStatus, 0);
00148 
00149     FUNC_LEAVE_NTSTATUS(ntStatus);
00150 }
00151 
00166 NTSTATUS
00167 cbm_execute_close(IN PDEVICE_EXTENSION Pdx, IN PIRP Irp)
00168 {
00169     NTSTATUS ntStatus;
00170 
00171     FUNC_ENTER();
00172 
00173     DBG_ASSERT(Pdx != NULL);
00174 
00175     PERF_EVENT_CLOSE_EXECUTE();
00176 
00177     DBG_IRPPATH_PROCESS("close");
00178 
00179     if (Pdx->ParallelPortLock)
00180     {
00181         // as we keep the parallel port locked all the time,
00182         // do not unlock it now.
00183         ntStatus = STATUS_SUCCESS;
00184     }
00185     else
00186     {
00187         // Unlock the parallel port
00188 
00189         ntStatus = cbm_unlock_parport(Pdx);
00190     }
00191 
00192 
00193     // Now, complete the IRP
00194 
00195     DBG_IRPPATH_COMPLETE("close");
00196     QueueCompleteIrp(&Pdx->IrpQueue, Irp, ntStatus, 0);
00197 
00198     FUNC_LEAVE_NTSTATUS(ntStatus);
00199 }

Generated on Sun Apr 30 18:45:55 2006 for opencbm by  doxygen 1.4.2