Update of /cvsroot/com0com/com0com/sys
In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv9382
Modified Files:
com0com.h io.c openclos.c pnp.c startirp.c timeout.c timeout.h
Log Message:
Fixed open reject just after close in exclusiveMode
Index: openclos.c
===================================================================
RCS file: /cvsroot/com0com/com0com/sys/openclos.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** openclos.c 1 Jun 2007 16:22:40 -0000 1.17
--- openclos.c 4 Jun 2007 15:24:32 -0000 1.18
***************
*** 20,23 ****
--- 20,26 ----
*
* $Log$
+ * Revision 1.18 2007/06/04 15:24:32 vfrolov
+ * Fixed open reject just after close in exclusiveMode
+ *
* Revision 1.17 2007/06/01 16:22:40 vfrolov
* Implemented plug-in and exclusive modes
***************
*** 83,86 ****
--- 86,90 ----
#include "bufutils.h"
#include "strutils.h"
+ #include "timeout.h"
NTSTATUS FdoPortOpen(IN PC0C_FDOPORT_EXTENSION pDevExt)
***************
*** 174,179 ****
}
! NTSTATUS FdoPortClose(IN PC0C_FDOPORT_EXTENSION pDevExt)
{
LIST_ENTRY queueToComplete;
KIRQL oldIrql;
--- 178,205 ----
}
! NTSTATUS StartIrpClose(
! IN PC0C_IO_PORT pIoPort,
! IN PLIST_ENTRY pQueueToComplete)
{
+ UNREFERENCED_PARAMETER(pQueueToComplete);
+
+ if (!pIoPort->exclusiveMode) {
+ PIRP pIrp;
+
+ InterlockedDecrement(&pIoPort->pDevExt->openCount);
+ pIrp = pIoPort->irpQueues[C0C_QUEUE_CLOSE].pCurrent;
+ pIrp->IoStatus.Information = 0;
+ return STATUS_SUCCESS;
+ }
+
+ IoInvalidateDeviceRelations(pIoPort->pPhDevObj, BusRelations);
+ SetCloseTimeout(pIoPort);
+
+ return STATUS_PENDING;
+ }
+
+ NTSTATUS FdoPortClose(IN PC0C_FDOPORT_EXTENSION pDevExt, IN PIRP pIrp)
+ {
+ NTSTATUS status;
LIST_ENTRY queueToComplete;
KIRQL oldIrql;
***************
*** 199,210 ****
KeReleaseSpinLock(pIoPort->pIoLock, oldIrql);
- if (pIoPort->exclusiveMode)
- IoInvalidateDeviceRelations(pIoPort->pPhDevObj, BusRelations);
-
FdoPortCompleteQueue(&queueToComplete);
! InterlockedDecrement(&pDevExt->openCount);
! return STATUS_SUCCESS;
}
--- 225,238 ----
KeReleaseSpinLock(pIoPort->pIoLock, oldIrql);
FdoPortCompleteQueue(&queueToComplete);
! status = FdoPortStartIrp(pIoPort, pIrp, C0C_QUEUE_CLOSE, StartIrpClose);
! if (status != STATUS_PENDING) {
! pIrp->IoStatus.Status = status;
! IoCompleteRequest(pIrp, IO_NO_INCREMENT);
! }
!
! return status;
}
***************
*** 226,231 ****
--- 254,261 ----
pIrp->IoStatus.Information = 0;
+ #if DBG
if (!NT_SUCCESS(status))
TraceIrp("c0cOpen", pIrp, &status, TRACE_FLAG_RESULTS);
+ #endif /* DBG */
pIrp->IoStatus.Status = status;
***************
*** 240,260 ****
PC0C_COMMON_EXTENSION pDevExt = pDevObj->DeviceExtension;
TraceIrp("--- Close ---", pIrp, NULL, TRACE_FLAG_PARAMS);
switch (pDevExt->doType) {
case C0C_DOTYPE_FP:
! status = FdoPortClose((PC0C_FDOPORT_EXTENSION)pDevExt);
break;
default:
status = STATUS_INVALID_DEVICE_REQUEST;
}
! pIrp->IoStatus.Information = 0;
!
! if (!NT_SUCCESS(status))
! TraceIrp("c0cClose", pIrp, &status, TRACE_FLAG_RESULTS);
!
! pIrp->IoStatus.Status = status;
! IoCompleteRequest(pIrp, IO_NO_INCREMENT);
return status;
--- 270,294 ----
PC0C_COMMON_EXTENSION pDevExt = pDevObj->DeviceExtension;
+ #if DBG
+ ULONG code = IoGetCurrentIrpStackLocation(pIrp)->MajorFunction;
+ #endif /* DBG */
+
TraceIrp("--- Close ---", pIrp, NULL, TRACE_FLAG_PARAMS);
switch (pDevExt->doType) {
case C0C_DOTYPE_FP:
! status = FdoPortClose((PC0C_FDOPORT_EXTENSION)pDevExt, pIrp);
break;
default:
status = STATUS_INVALID_DEVICE_REQUEST;
+ pIrp->IoStatus.Information = 0;
+ pIrp->IoStatus.Status = status;
+ IoCompleteRequest(pIrp, IO_NO_INCREMENT);
}
! #if DBG
! if (status != STATUS_SUCCESS)
! TraceCode(pDevExt, "IRP_MJ_", codeNameTableIrpMj, code, &status);
! #endif /* DBG */
return status;
Index: timeout.h
===================================================================
RCS file: /cvsroot/com0com/com0com/sys/timeout.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** timeout.h 20 Feb 2007 12:05:11 -0000 1.5
--- timeout.h 4 Jun 2007 15:24:33 -0000 1.6
***************
*** 20,23 ****
--- 20,26 ----
*
* $Log$
+ * Revision 1.6 2007/06/04 15:24:33 vfrolov
+ * Fixed open reject just after close in exclusiveMode
+ *
* Revision 1.5 2007/02/20 12:05:11 vfrolov
* Implemented IOCTL_SERIAL_XOFF_COUNTER
***************
*** 47,50 ****
--- 50,55 ----
VOID SetIntervalTimeout(PC0C_IO_PORT pIoPort);
+ VOID SetCloseTimeout(PC0C_IO_PORT pIoPort);
+
VOID SetXoffCounterTimeout(
PC0C_IO_PORT pIoPort,
Index: com0com.h
===================================================================
RCS file: /cvsroot/com0com/com0com/sys/com0com.h,v
retrieving revision 1.34
retrieving revision 1.35
diff -C2 -d -r1.34 -r1.35
*** com0com.h 1 Jun 2007 16:22:40 -0000 1.34
--- com0com.h 4 Jun 2007 15:24:32 -0000 1.35
***************
*** 20,23 ****
--- 20,26 ----
*
* $Log$
+ * Revision 1.35 2007/06/04 15:24:32 vfrolov
+ * Fixed open reject just after close in exclusiveMode
+ *
* Revision 1.34 2007/06/01 16:22:40 vfrolov
* Implemented plug-in and exclusive modes
***************
*** 214,219 ****
#define C0C_QUEUE_WRITE 1
#define C0C_QUEUE_WAIT 2
! #define C0C_QUEUE_SIZE 3
C0C_IRP_QUEUE irpQueues[C0C_QUEUE_SIZE];
--- 217,223 ----
#define C0C_QUEUE_WRITE 1
#define C0C_QUEUE_WAIT 2
+ #define C0C_QUEUE_CLOSE 3
! #define C0C_QUEUE_SIZE 4
C0C_IRP_QUEUE irpQueues[C0C_QUEUE_SIZE];
***************
*** 229,232 ****
--- 233,239 ----
KDPC timerWriteTotalDpc;
+ KTIMER timerClose;
+ KDPC timerCloseDpc;
+
struct _C0C_ADAPTIVE_DELAY *pWriteDelay;
***************
*** 399,402 ****
--- 406,410 ----
ULONG GetWriteLength(IN PIRP pIrp);
+ #define C0C_IO_TYPE_CLOSE_COMPLETE 2
#define C0C_IO_TYPE_WAIT_COMPLETE 3
#define C0C_IO_TYPE_INSERT 4
Index: startirp.c
===================================================================
RCS file: /cvsroot/com0com/com0com/sys/startirp.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** startirp.c 20 Feb 2007 12:05:11 -0000 1.16
--- startirp.c 4 Jun 2007 15:24:33 -0000 1.17
***************
*** 20,23 ****
--- 20,26 ----
*
* $Log$
+ * Revision 1.17 2007/06/04 15:24:33 vfrolov
+ * Fixed open reject just after close in exclusiveMode
+ *
* Revision 1.16 2007/02/20 12:05:11 vfrolov
* Implemented IOCTL_SERIAL_XOFF_COUNTER
***************
*** 100,103 ****
--- 103,107 ----
break;
case IRP_MJ_FLUSH_BUFFERS:
+ case IRP_MJ_CLOSE:
return (PC0C_IRP_STATE)&pIrpStack->Parameters.Others.Argument1;
}
Index: io.c
===================================================================
RCS file: /cvsroot/com0com/com0com/sys/io.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -d -r1.30 -r1.31
*** io.c 20 Feb 2007 12:05:11 -0000 1.30
--- io.c 4 Jun 2007 15:24:32 -0000 1.31
***************
*** 20,23 ****
--- 20,26 ----
*
* $Log$
+ * Revision 1.31 2007/06/04 15:24:32 vfrolov
+ * Fixed open reject just after close in exclusiveMode
+ *
* Revision 1.30 2007/02/20 12:05:11 vfrolov
* Implemented IOCTL_SERIAL_XOFF_COUNTER
***************
*** 675,682 ****
PIRP pIrpCurrent;
PDRIVER_CANCEL pCancelRoutineCurrent;
- SIZE_T done;
first = TRUE;
- done = 0;
status = STATUS_PENDING;
--- 678,683 ----
***************
*** 701,704 ****
--- 702,710 ----
InsertDirect((PC0C_RAW_DATA)pParam, pIrpCurrent, &status, &statusCurrent, &doneCurrent);
break;
+ case C0C_IO_TYPE_CLOSE_COMPLETE:
+ InterlockedDecrement(&pIoPort->pDevExt->openCount);
+ pIrpCurrent->IoStatus.Information = 0;
+ statusCurrent = STATUS_SUCCESS;
+ break;
}
Index: pnp.c
===================================================================
RCS file: /cvsroot/com0com/com0com/sys/pnp.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** pnp.c 1 Jun 2007 16:22:40 -0000 1.7
--- pnp.c 4 Jun 2007 15:24:33 -0000 1.8
***************
*** 20,23 ****
--- 20,26 ----
*
* $Log$
+ * Revision 1.8 2007/06/04 15:24:33 vfrolov
+ * Fixed open reject just after close in exclusiveMode
+ *
* Revision 1.7 2007/06/01 16:22:40 vfrolov
* Implemented plug-in and exclusive modes
***************
*** 319,322 ****
--- 322,327 ----
switch (minorFunction) {
case IRP_MN_QUERY_DEVICE_RELATIONS: {
+ LIST_ENTRY queueToComplete;
+ KIRQL oldIrql;
PC0C_IO_PORT pIoPort = pDevExt->pIoPortLocal;
***************
*** 328,331 ****
--- 333,350 ----
ShowPort(pDevExt);
}
+
+ /* complete pending CLOSE IRPs */
+
+ InitializeListHead(&queueToComplete);
+
+ KeAcquireSpinLock(pIoPort->pIoLock, &oldIrql);
+ FdoPortIo(C0C_IO_TYPE_CLOSE_COMPLETE,
+ NULL,
+ pIoPort,
+ &pIoPort->irpQueues[C0C_QUEUE_CLOSE],
+ &queueToComplete);
+ KeReleaseSpinLock(pIoPort->pIoLock, oldIrql);
+
+ FdoPortCompleteQueue(&queueToComplete);
break;
}
Index: timeout.c
===================================================================
RCS file: /cvsroot/com0com/com0com/sys/timeout.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** timeout.c 20 Feb 2007 12:05:11 -0000 1.8
--- timeout.c 4 Jun 2007 15:24:33 -0000 1.9
***************
*** 20,23 ****
--- 20,26 ----
*
* $Log$
+ * Revision 1.9 2007/06/04 15:24:33 vfrolov
+ * Fixed open reject just after close in exclusiveMode
+ *
* Revision 1.8 2007/02/20 12:05:11 vfrolov
* Implemented IOCTL_SERIAL_XOFF_COUNTER
***************
*** 75,82 ****
pState->flags |= C0C_IRP_FLAG_EXPIRED;
! if (pState->iQueue == C0C_QUEUE_WRITE)
! ReadWrite(pIoPort->pIoPortRemote, FALSE, pIoPort, FALSE, &queueToComplete);
! else
! ReadWrite(pIoPort, FALSE, pIoPort->pIoPortRemote, FALSE, &queueToComplete);
}
--- 78,96 ----
pState->flags |= C0C_IRP_FLAG_EXPIRED;
! switch (pState->iQueue) {
! case C0C_QUEUE_WRITE:
! ReadWrite(pIoPort->pIoPortRemote, FALSE, pIoPort, FALSE, &queueToComplete);
! break;
! case C0C_QUEUE_READ:
! ReadWrite(pIoPort, FALSE, pIoPort->pIoPortRemote, FALSE, &queueToComplete);
! break;
! case C0C_QUEUE_CLOSE:
! FdoPortIo(C0C_IO_TYPE_CLOSE_COMPLETE,
! NULL,
! pIoPort,
! &pIoPort->irpQueues[C0C_QUEUE_CLOSE],
! &queueToComplete);
! break;
! }
}
***************
*** 277,280 ****
--- 291,309 ----
}
+ VOID TimeoutClose(
+ IN PKDPC pDpc,
+ IN PVOID deferredContext,
+ IN PVOID systemArgument1,
+ IN PVOID systemArgument2)
+ {
+ PC0C_IO_PORT pIoPort = (PC0C_IO_PORT)deferredContext;
+
+ UNREFERENCED_PARAMETER(pDpc);
+ UNREFERENCED_PARAMETER(systemArgument1);
+ UNREFERENCED_PARAMETER(systemArgument2);
+
+ TimeoutRoutine(pIoPort, &pIoPort->irpQueues[C0C_QUEUE_CLOSE]);
+ }
+
VOID AllocTimeouts(PC0C_IO_PORT pIoPort)
{
***************
*** 282,289 ****
--- 311,320 ----
KeInitializeTimer(&pIoPort->timerReadInterval);
KeInitializeTimer(&pIoPort->timerWriteTotal);
+ KeInitializeTimer(&pIoPort->timerClose);
KeInitializeDpc(&pIoPort->timerReadTotalDpc, TimeoutReadTotal, pIoPort);
KeInitializeDpc(&pIoPort->timerReadIntervalDpc, TimeoutReadInterval, pIoPort);
KeInitializeDpc(&pIoPort->timerWriteTotalDpc, TimeoutWriteTotal, pIoPort);
+ KeInitializeDpc(&pIoPort->timerCloseDpc, TimeoutClose, pIoPort);
}
***************
*** 293,300 ****
--- 324,333 ----
KeCancelTimer(&pIoPort->timerReadInterval);
KeCancelTimer(&pIoPort->timerWriteTotal);
+ KeCancelTimer(&pIoPort->timerClose);
KeRemoveQueueDpc(&pIoPort->timerReadTotalDpc);
KeRemoveQueueDpc(&pIoPort->timerReadIntervalDpc);
KeRemoveQueueDpc(&pIoPort->timerWriteTotalDpc);
+ KeRemoveQueueDpc(&pIoPort->timerCloseDpc);
}
***************
*** 304,307 ****
--- 337,349 ----
}
+ VOID SetCloseTimeout(PC0C_IO_PORT pIoPort)
+ {
+ LARGE_INTEGER total;
+
+ total.QuadPart = ((LONGLONG)1000) * -10000;
+
+ KeSetTimer(&pIoPort->timerClose, total, &pIoPort->timerCloseDpc);
+ }
+
NTSTATUS SetIrpTimeout(
PC0C_IO_PORT pIoPort,
|