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

libcommon/util.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 
00046 VOID
00047 LogError(IN PDEVICE_OBJECT Fdo,
00048          IN NTSTATUS ErrorCode,
00049          const WCHAR *String1,
00050          const WCHAR *String2)
00051 {
00052     USHORT stringSize;
00053     USHORT stringOffset;
00054     USHORT stringSize1;
00055     USHORT stringSize2;
00056     USHORT size;
00057     USHORT numberOfStrings;
00058 
00059     FUNC_ENTER();
00060 
00061     // IoAllocateErrorLogEntry() and IoWriteErrorLogEntry() require this
00062 
00063     DBG_IRQL( <= DISPATCH_LEVEL);
00064 
00065     // calculate the size of the strings
00066 
00067     numberOfStrings = 0;
00068 
00069     // Check if there is a string 1, and calculate its size
00070     // (including the trailing zero)
00071 
00072     stringSize1 = String1 ? (++numberOfStrings, sizeof(WCHAR) * (wcslen(String1) + 1)) : 0;
00073 
00074     // Check if there is a string 2, and calculate its size
00075     // (including the trailing zero)
00076 
00077     stringSize2 = String2 ? (++numberOfStrings, sizeof(WCHAR) * (wcslen(String2) + 1)) : 0;
00078 
00079     // Add the sizes of both strings
00080     // This is the size of what has to be added to the error log entry
00081 
00082     stringSize = stringSize1 + stringSize2;
00083 
00084     // Offset where the string(s) will be written into the error log entry
00085 
00086     stringOffset = sizeof(IO_ERROR_LOG_PACKET);
00087 
00088     // The complete size of the event log entry
00089 
00090     size = stringOffset + stringSize;
00091 
00092     // Make sure we don't need more space than needed.
00093     // For debugging purposes, have an DBG_ASSERT(). Anyway,
00094     // in the wild, don't do anything if the size is too big.
00095     // Remember: Not being able to write a log is not an error!
00096 
00101     DBG_ASSERT(size <= ERROR_LOG_MAXIMUM_SIZE);
00102 
00103     if (size <= ERROR_LOG_MAXIMUM_SIZE) 
00104     {
00105         PIO_ERROR_LOG_PACKET pentry;
00106 
00107         // allocate the entry for the error log
00108 
00109         DBG_IRQL( <= DISPATCH_LEVEL);
00110         pentry = IoAllocateErrorLogEntry(Fdo, (UCHAR) size);
00111 
00112         DBG_ASSERT(pentry);
00113         if (pentry) {
00114 
00115             // clear the complete entry (to be sure)
00116 
00117             RtlZeroMemory(pentry, sizeof(*pentry));
00118 
00119             // Write the relevant entries
00120 
00121             pentry->NumberOfStrings = numberOfStrings;
00122             pentry->StringOffset = stringOffset;
00123             pentry->ErrorCode = ErrorCode;
00124 
00125             // If there was a string1, write that into the entry
00126 
00127             if (String1)
00128             {
00129                 wcscpy((wchar_t*)&((UCHAR*)pentry)[stringOffset], String1);
00130             }
00131 
00132             // If there was a string2, write that into the entry
00133 
00134             if (String2)
00135             {
00136                 wcscpy((wchar_t*)&((UCHAR*)pentry)[stringOffset + stringSize1], String2);
00137             }
00138 
00139             // Now, give that entry to the system
00140 
00141             DBG_IRQL( <= DISPATCH_LEVEL);
00142             IoWriteErrorLogEntry(pentry);
00143         }
00144     }
00145 
00146         FUNC_LEAVE();
00147 }

Generated on Sun Apr 30 18:46:00 2006 for opencbm by  doxygen 1.4.2