Author: ekohl
Date: Mon Sep 12 14:24:24 2011
New Revision: 53696
URL:
http://svn.reactos.org/svn/reactos?rev=53696&view=rev
Log:
[MSPORTS]
Implement ComDBResizeDatabase.
Modified:
trunk/reactos/dll/win32/msports/comdb.c
Modified: trunk/reactos/dll/win32/msports/comdb.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/msports/comdb.c?…
==============================================================================
--- trunk/reactos/dll/win32/msports/comdb.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/msports/comdb.c [iso-8859-1] Mon Sep 12 14:24:24 2011
@@ -11,6 +11,8 @@
WINE_DEFAULT_DEBUG_CHANNEL(msports);
#define BITS_PER_BYTE 8
+#define BITMAP_SIZE_INCREMENT 0x400
+#define BITMAP_SIZE_INVALID_BITS 0x3FF
typedef struct _COMDB
{
@@ -275,6 +277,9 @@
PBYTE pBitmap = NULL;
BYTE cMask;
LONG lError = ERROR_SUCCESS;
+
+ TRACE("ComDBGetCurrentPortUsage(%p %p %lu %lu %p)\n",
+ hComDB, Buffer, BufferSize, ReportType, MaxPortsReported);
if (hComDB == INVALID_HANDLE_VALUE ||
hComDB == NULL ||
@@ -581,8 +586,83 @@
ComDBResizeDatabase(IN HCOMDB hComDB,
IN DWORD NewSize)
{
- FIXME("ComDBResizeDatabase(%p %lu)\n", hComDB, NewSize);
- return ERROR_CALL_NOT_IMPLEMENTED;
+ PCOMDB pComDB;
+ PBYTE pBitmap = NULL;
+ DWORD dwSize;
+ DWORD dwNewSize;
+ DWORD dwType;
+ LONG lError;
+
+ TRACE("ComDBResizeDatabase(%p %lu)\n", hComDB, NewSize);
+
+ if (hComDB == INVALID_HANDLE_VALUE ||
+ hComDB == NULL ||
+ (NewSize & BITMAP_SIZE_INVALID_BITS))
+ return ERROR_INVALID_PARAMETER;
+
+ pComDB = (PCOMDB)hComDB;
+
+ /* Wait for the mutex */
+ WaitForSingleObject(pComDB->hMutex, INFINITE);
+
+ /* Get the required bitmap size */
+ lError = RegQueryValueExW(pComDB->hKey,
+ L"ComDB",
+ NULL,
+ &dwType,
+ NULL,
+ &dwSize);
+ if (lError != ERROR_SUCCESS)
+ goto done;
+
+ /* Check the size limits */
+ if (NewSize > COMDB_MAX_PORTS_ARBITRATED ||
+ NewSize <= dwSize * BITS_PER_BYTE)
+ {
+ lError = ERROR_BAD_LENGTH;
+ goto done;
+ }
+
+ /* Calculate the new bitmap size */
+ dwNewSize = NewSize / BITS_PER_BYTE;
+
+ /* Allocate the new bitmap */
+ pBitmap = HeapAlloc(GetProcessHeap(),
+ HEAP_ZERO_MEMORY,
+ dwSize);
+ if (pBitmap == NULL)
+ {
+ ERR("Failed to allocate the bitmap!\n");
+ lError = ERROR_ACCESS_DENIED;
+ goto done;
+ }
+
+ /* Read the current bitmap */
+ lError = RegQueryValueExW(pComDB->hKey,
+ L"ComDB",
+ NULL,
+ &dwType,
+ pBitmap,
+ &dwSize);
+ if (lError != ERROR_SUCCESS)
+ goto done;
+
+ /* Write the new bitmap */
+ lError = RegSetValueExW(pComDB->hKey,
+ L"ComDB",
+ 0,
+ REG_BINARY,
+ pBitmap,
+ dwNewSize);
+
+done:;
+ /* Release the mutex */
+ ReleaseMutex(pComDB->hMutex);
+
+ if (pBitmap != NULL)
+ HeapFree(GetProcessHeap(), 0, pBitmap);
+
+ return lError;
}
/* EOF */