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.

223 lines
7.7 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/miniport/cl546x/logfile.c $
  28. *
  29. * Rev 1.2 03 Dec 1996 15:34:34 SueS
  30. * When CreateLogFile is called, do not overwrite the existing file. In the
  31. * DirectDraw tests, DrvEnablePDEV is called numerous times, which wiped
  32. * out the log file. Also, open and append to the log file each time, instead
  33. * of attaching to the creating process.
  34. *
  35. * Rev 1.1 26 Nov 1996 08:52:06 SueS
  36. * When the log file is opened, get the system process that owns the handle.
  37. * Switch to this process when writing to the file. Otherwise, only the
  38. * process that owns the handle can write to the file.
  39. *
  40. * Rev 1.0 13 Nov 1996 15:32:42 SueS
  41. * Initial revision.
  42. *
  43. ****************************************************************************
  44. ****************************************************************************/
  45. /////////////////////
  46. // Include Files //
  47. /////////////////////
  48. #include <ntddk.h> // various NT definitions
  49. #include "type.h"
  50. #include "logfile.h"
  51. ////////////////////////
  52. // Global Variables //
  53. ////////////////////////
  54. #if LOG_FILE
  55. HANDLE LogFileHandle; // Handle for log file
  56. UNICODE_STRING FileName; // Unicode string name of log file
  57. OBJECT_ATTRIBUTES ObjectAttributes; // File object attributes
  58. IO_STATUS_BLOCK IoStatus; // Returned status information
  59. LARGE_INTEGER MaxFileSize; // File size
  60. NTSTATUS Status; // Returned status
  61. //////////////////////////
  62. // External Functions //
  63. //////////////////////////
  64. ///////////////////////////////////////////////////////////////////////////////
  65. //
  66. // HANDLE CreateLogFile(void)
  67. //
  68. // Parameters:
  69. // none
  70. //
  71. // Return:
  72. // the handle of the just-opened log file
  73. //
  74. // Notes:
  75. //
  76. // This function uses kernel mode support routines to open the
  77. // log file, used to log activity in the display driver.
  78. //
  79. ///////////////////////////////////////////////////////////////////////////////
  80. HANDLE CreateLogFile(void)
  81. {
  82. HANDLE FileHandle; // Handle to opened file
  83. // Initialize a Unicode String containing the name of
  84. // the file to be opened and read.
  85. RtlInitUnicodeString(&FileName, L"\\DosDevices\\C:\\temp\\CL546x.LOG");
  86. // Initialize file attributes
  87. InitializeObjectAttributes(&ObjectAttributes, // initialized attrib
  88. &FileName, // full file path name
  89. OBJ_CASE_INSENSITIVE, // attributes
  90. NULL, // root directory
  91. NULL); // security descriptor
  92. // Open the file, creating it if necessary
  93. MaxFileSize.QuadPart = 20000000;
  94. Status = ZwCreateFile(&FileHandle, // file handle
  95. SYNCHRONIZE | FILE_APPEND_DATA,// desired access
  96. &ObjectAttributes, // object attributes
  97. &IoStatus, // returned status
  98. &MaxFileSize, // alloc size
  99. FILE_ATTRIBUTE_NORMAL, // file attributes
  100. FILE_SHARE_READ, // share access
  101. FILE_OPEN_IF, // create disposition
  102. FILE_SYNCHRONOUS_IO_NONALERT, // create options
  103. NULL, // eabuffer
  104. 0); // ealength
  105. ZwClose(FileHandle);
  106. if (NT_SUCCESS(Status))
  107. return(FileHandle);
  108. else
  109. return((HANDLE)-1);
  110. }
  111. ///////////////////////////////////////////////////////////////////////////////
  112. //
  113. // BOOLEAN WriteLogFile(HANDLE FileHandle, PVOID InputBuffer,
  114. // ULONG InputBufferLength)
  115. //
  116. // Parameters:
  117. // FileHandle - the handle of the log file, already opened
  118. // InputBuffer - the data to be written to the log file
  119. // InputBufferLength - the length of the data
  120. //
  121. // Return:
  122. // TRUE - the write operation was successful
  123. // FALSE - the write operation failed
  124. //
  125. // Notes:
  126. //
  127. // This function writes the supplied buffer to the open log file
  128. //
  129. ///////////////////////////////////////////////////////////////////////////////
  130. BOOLEAN WriteLogFile(
  131. HANDLE FileHandle,
  132. PVOID InputBuffer,
  133. ULONG InputBufferLength
  134. )
  135. {
  136. // Open the file for writing
  137. Status = ZwCreateFile(&FileHandle, // file handle
  138. SYNCHRONIZE | FILE_APPEND_DATA,// desired access
  139. &ObjectAttributes, // object attributes
  140. &IoStatus, // returned status
  141. &MaxFileSize, // alloc size
  142. FILE_ATTRIBUTE_NORMAL, // file attributes
  143. FILE_SHARE_READ, // share access
  144. FILE_OPEN_IF, // create disposition
  145. FILE_SYNCHRONOUS_IO_NONALERT, // create options
  146. NULL, // eabuffer
  147. 0); // ealength
  148. // Write to the file
  149. Status = ZwWriteFile(FileHandle, // handle from ZwCreateFile
  150. NULL, // NULL for device drivers
  151. NULL, // NULL for device drivers
  152. NULL, // NULL for device drivers
  153. &IoStatus, // returned status
  154. InputBuffer, // buffer with data to be written
  155. InputBufferLength, // size in bytes of buffer
  156. NULL, // write at current file position
  157. NULL); // NULL for device drivers
  158. ZwClose(FileHandle);
  159. if (NT_SUCCESS(Status))
  160. return(TRUE);
  161. else
  162. return(FALSE);
  163. }
  164. ///////////////////////////////////////////////////////////////////////////////
  165. //
  166. // void CloseLogFile(HANDLE FileHandle)
  167. //
  168. // Parameters:
  169. // FileHandle - the handle of the open log file
  170. //
  171. // Return:
  172. //
  173. // Notes:
  174. // TRUE - the close operation was successful
  175. // FALSE - the close operation failed
  176. //
  177. // This function closes the already open log file
  178. //
  179. ///////////////////////////////////////////////////////////////////////////////
  180. BOOLEAN CloseLogFile(HANDLE FileHandle)
  181. {
  182. NTSTATUS Status;
  183. // Close the log file
  184. Status = ZwClose(FileHandle);
  185. if (NT_SUCCESS(Status))
  186. return(TRUE);
  187. else
  188. return(FALSE);
  189. }
  190. #endif // LOG_FILE