Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

278 lines
7.5 KiB

  1. /*****************************************************************************
  2. ******************************************************************************
  3. *
  4. * ******************************************
  5. * * Copyright (c) 1996, Cirrus Logic, Inc. *
  6. * * All Rights Reserved *
  7. * ******************************************
  8. *
  9. * PROJECT: Laguna I (CL-GD546x) -
  10. *
  11. * FILE: logfile.c
  12. *
  13. * AUTHOR: Sue Schell
  14. *
  15. * DESCRIPTION:
  16. * This file contains routines that create and write to
  17. * the log file, used for debugging and testing purposes
  18. * only.
  19. *
  20. * MODULES:
  21. * CreateLogFile()
  22. * WriteLogFile()
  23. * CloseLogFile()
  24. *
  25. * REVISION HISTORY:
  26. *
  27. * $Log: X:/log/laguna/nt35/displays/cl546x/logfile.c $
  28. *
  29. * Rev 1.5 21 Mar 1997 11:43:58 noelv
  30. *
  31. * Combined LOG_WRITES LOG_CALLS and LOG_QFREE together into ENABLE_LOG_FILE
  32. *
  33. * Rev 1.4 17 Dec 1996 16:43:32 SueS
  34. * On a CloseLogFile call, dump the current buffer to the file.
  35. *
  36. * Rev 1.3 05 Dec 1996 08:49:24 SueS
  37. * Added function to help with formatting strings for DirectDraw logging.
  38. *
  39. * Rev 1.2 03 Dec 1996 11:37:36 SueS
  40. * Removed extraneous semicolon left over from testing.
  41. *
  42. * Rev 1.1 26 Nov 1996 10:50:42 SueS
  43. * Instead of sending a single string of text at a time, buffer up the
  44. * requests to the miniport. The buffer is currently 4K. Added a
  45. * CloseLogFile function.
  46. *
  47. * Rev 1.0 13 Nov 1996 17:03:36 SueS
  48. * Initial revision.
  49. *
  50. ****************************************************************************
  51. ****************************************************************************/
  52. /////////////////////
  53. // Include Files //
  54. /////////////////////
  55. #include "precomp.h"
  56. #include "clioctl.h"
  57. ///////////////
  58. // Defines //
  59. ///////////////
  60. #define BUFFER_SIZE 0x1000
  61. ///////////////////////////
  62. // Function Prototypes //
  63. ///////////////////////////
  64. #if ENABLE_LOG_FILE
  65. HANDLE CreateLogFile(
  66. HANDLE hDriver,
  67. PDWORD Index);
  68. BOOL WriteLogFile(
  69. HANDLE hDriver,
  70. LPVOID lpBuffer,
  71. DWORD BytesToWrite,
  72. PCHAR TextBuffer,
  73. PDWORD Index);
  74. BOOL CloseLogFile(
  75. HANDLE hDriver,
  76. PCHAR TextBuffer,
  77. PDWORD Index);
  78. void DDFormatLogFile(
  79. LPSTR szFormat, ...);
  80. //
  81. // Used by sprintf to build strings.
  82. //
  83. char lg_buf[256];
  84. long lg_i;
  85. ///////////////////////////////////////////////////////////////////////////////
  86. //
  87. // HANDLE CreateLogFile(HANDLE hDriver, PDWORD Index)
  88. //
  89. // Parameters:
  90. // hDriver - the handle to the miniport driver
  91. // Index - pointer to the index into the text buffer sent to the miniport
  92. //
  93. // Return:
  94. // the handle of the just-opened log file
  95. //
  96. // Notes:
  97. //
  98. // This function posts a message to the miniport driver to
  99. // tell it to open the log file.
  100. //
  101. ///////////////////////////////////////////////////////////////////////////////
  102. HANDLE CreateLogFile(
  103. HANDLE hDriver, // handle to miniport driver
  104. PDWORD Index // size of text buffer
  105. )
  106. {
  107. DWORD BytesReturned;
  108. // Initialize the buffer pointer
  109. *Index = 0;
  110. // Tell the miniport driver to open the log file
  111. if (DEVICE_IO_CTRL(hDriver,
  112. IOCTL_CL_CREATE_LOG_FILE,
  113. NULL,
  114. 0,
  115. NULL,
  116. 0,
  117. &BytesReturned,
  118. NULL))
  119. return((HANDLE)-1);
  120. else
  121. return((HANDLE)0);
  122. }
  123. ///////////////////////////////////////////////////////////////////////////////
  124. //
  125. // BOOL WriteLogFile(HANDLE hDriver, LPVOID lpBuffer, DWORD BytesToWrite,
  126. // PCHAR TextBuffer, PDWORD Index)
  127. //
  128. // Parameters:
  129. // hDriver - the handle to the miniport driver
  130. // lpBuffer - pointer to data to write to file
  131. // BytesToWrite - number of bytes to write
  132. // TextBuffer - the buffer eventually sent to the miniport
  133. // Index - size of TextBuffer
  134. //
  135. // Return:
  136. // TRUE - the DeviceIoControl call succeeded
  137. // FALSE - the DeviceIoControl call failed
  138. //
  139. // Notes:
  140. //
  141. // This function posts a message to the miniport driver to
  142. // tell it to write the input buffer to the log file. It waits
  143. // until it has a full text buffer before doing so.
  144. //
  145. ///////////////////////////////////////////////////////////////////////////////
  146. BOOL WriteLogFile(
  147. HANDLE hDriver, // handle to miniport driver
  148. LPVOID lpBuffer, // pointer to data to write to file
  149. DWORD BytesToWrite, // number of bytes to write
  150. PCHAR TextBuffer, // buffer sent to miniport
  151. PDWORD Index // size of buffer
  152. )
  153. {
  154. DWORD BytesReturned;
  155. BOOLEAN Status = TRUE;
  156. // Do we have room in the buffer?
  157. if (BytesToWrite + *Index >= BUFFER_SIZE - 1)
  158. {
  159. // No, we're full - it's time to send the message
  160. // Tell the miniport driver to write to the log file
  161. Status = DEVICE_IO_CTRL(hDriver,
  162. IOCTL_CL_WRITE_LOG_FILE,
  163. TextBuffer,
  164. *Index,
  165. NULL,
  166. 0,
  167. &BytesReturned,
  168. NULL);
  169. // Reset the buffer
  170. *TextBuffer = 0;
  171. *Index = 0;
  172. }
  173. // Add to the buffer and bump the count
  174. RtlMoveMemory(TextBuffer+*Index, lpBuffer, BytesToWrite);
  175. *Index += BytesToWrite;
  176. *(TextBuffer+*Index) = 0;
  177. return(Status);
  178. }
  179. ///////////////////////////////////////////////////////////////////////////////
  180. //
  181. // HANDLE CloseLogFile(HANDLE hDriver)
  182. //
  183. // Parameters:
  184. // hDriver - the handle to the miniport driver
  185. //
  186. // Return:
  187. // TRUE - the DeviceIoControl call succeeded
  188. // FALSE - the DeviceIoControl call failed
  189. //
  190. // Notes:
  191. //
  192. // This function sends the current buffer to the miniport driver
  193. // to tell it to write to the logfile immediately.
  194. //
  195. ///////////////////////////////////////////////////////////////////////////////
  196. BOOL CloseLogFile(
  197. HANDLE hDriver, // handle to miniport driver
  198. PCHAR TextBuffer, // buffer sent to miniport
  199. PDWORD Index // size of buffer
  200. )
  201. {
  202. DWORD BytesReturned;
  203. BOOLEAN Status;
  204. // Dump the buffer contents
  205. // Tell the miniport driver to write to the log file
  206. Status = DEVICE_IO_CTRL(hDriver,
  207. IOCTL_CL_WRITE_LOG_FILE,
  208. TextBuffer,
  209. *Index,
  210. NULL,
  211. 0,
  212. &BytesReturned,
  213. NULL);
  214. // Reset the buffer
  215. *TextBuffer = 0;
  216. *Index = 0;
  217. return(Status);
  218. }
  219. ///////////////////////////////////////////////////////////////////////////////
  220. //
  221. // void DDFormatLogFile(LPSTR szFormat, ...)
  222. //
  223. // Parameters:
  224. // szFormat - format and string to be printed to log file
  225. //
  226. // Return:
  227. // none
  228. //
  229. // Notes:
  230. //
  231. // This function formats a string according to the specified format
  232. // into the global string variable used to write to the log file.
  233. //
  234. ///////////////////////////////////////////////////////////////////////////////
  235. void DDFormatLogFile(
  236. LPSTR szFormat, ...)
  237. {
  238. lg_i = vsprintf(lg_buf, szFormat, (LPVOID)(&szFormat+1));
  239. return;
  240. }
  241. #endif // ENABLE_LOG_FILE