ReactOS  0.4.13-dev-99-g7e18b6d
bootlog.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS kernel
4  * FILE: ntoskrnl/io/iomgr/bootlog.c
5  * PURPOSE: Boot log file support
6  *
7  * PROGRAMMERS: Eric Kohl
8  */
9 
10 /* INCLUDES *****************************************************************/
11 
12 #include <ntoskrnl.h>
13 #define NDEBUG
14 #include <debug.h>
15 
16 #if defined (ALLOC_PRAGMA)
17 #pragma alloc_text(INIT, IopInitBootLog)
18 #pragma alloc_text(INIT, IopStartBootLog)
19 #endif
20 
21 /* GLOBALS ******************************************************************/
22 
28 
29 
30 /* FUNCTIONS ****************************************************************/
31 
32 VOID
33 INIT_FUNCTION
34 IopInitBootLog(BOOLEAN StartBootLog)
35 {
37  if (StartBootLog) IopStartBootLog();
38 }
39 
40 
41 VOID
42 INIT_FUNCTION
44 {
47 }
48 
49 
50 VOID
52 {
54 }
55 
56 
57 VOID
60 {
62  WCHAR Buffer[256];
63  WCHAR ValueNameBuffer[8];
66  HANDLE ControlSetKey;
67  HANDLE BootLogKey;
69 
70  if (IopBootLogEnabled == FALSE)
71  return;
72 
74 
75  DPRINT("Boot log: %wS %wZ\n",
76  Success ? L"Loaded driver" : L"Did not load driver",
77  DriverName);
78 
80  L"%ws %wZ",
81  Success ? L"Loaded driver" : L"Did not load driver",
82  DriverName);
83 
84  swprintf(ValueNameBuffer,
85  L"%lu",
87 
89  L"\\Registry\\Machine\\System\\CurrentControlSet");
91  &KeyName,
93  NULL,
94  NULL);
95  Status = ZwOpenKey(&ControlSetKey,
98  if (!NT_SUCCESS(Status))
99  {
100  DPRINT1("ZwOpenKey() failed (Status %lx)\n", Status);
102  return;
103  }
104 
105  RtlInitUnicodeString(&KeyName, L"BootLog");
107  &KeyName,
109  ControlSetKey,
110  NULL);
111  Status = ZwCreateKey(&BootLogKey,
114  0,
115  NULL,
117  NULL);
118  if (!NT_SUCCESS(Status))
119  {
120  DPRINT1("ZwCreateKey() failed (Status %lx)\n", Status);
121  ZwClose(ControlSetKey);
123  return;
124  }
125 
126  RtlInitUnicodeString(&ValueName, ValueNameBuffer);
127  Status = ZwSetValueKey(BootLogKey,
128  &ValueName,
129  0,
130  REG_SZ,
131  (PVOID)Buffer,
132  (ULONG)(wcslen(Buffer) + 1) * sizeof(WCHAR));
133  ZwClose(BootLogKey);
134  ZwClose(ControlSetKey);
135 
136  if (!NT_SUCCESS(Status))
137  {
138  DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status);
139  }
140  else
141  {
143  }
144 
146 }
147 
148 
149 static
150 NTSTATUS
152 {
157  PWSTR CrLf = L"\r\n";
159 
160  DPRINT("IopWriteLogFile() called\n");
161 
163  L"\\SystemRoot\\rosboot.log");
165  &FileName,
167  NULL,
168  NULL);
169 
170  Status = ZwCreateFile(&FileHandle,
173  &IoStatusBlock,
174  NULL,
175  0,
176  0,
177  FILE_OPEN,
179  NULL,
180  0);
181  if (!NT_SUCCESS(Status))
182  {
183  DPRINT1("ZwCreateFile() failed (Status %lx)\n", Status);
184  return Status;
185  }
186 
187  if (LogText != NULL)
188  {
189  Status = ZwWriteFile(FileHandle,
190  NULL,
191  NULL,
192  NULL,
193  &IoStatusBlock,
194  LogText,
195  (ULONG)wcslen(LogText) * sizeof(WCHAR),
196  NULL,
197  NULL);
198  if (!NT_SUCCESS(Status))
199  {
200  DPRINT1("ZwWriteFile() failed (Status %lx)\n", Status);
202  return Status;
203  }
204  }
205 
206  /* L"\r\n" */
207  Status = ZwWriteFile(FileHandle,
208  NULL,
209  NULL,
210  NULL,
211  &IoStatusBlock,
212  (PVOID)CrLf,
213  2 * sizeof(WCHAR),
214  NULL,
215  NULL);
216 
218 
219  if (!NT_SUCCESS(Status))
220  {
221  DPRINT1("ZwWriteFile() failed (Status %lx)\n", Status);
222  }
223 
224  return Status;
225 }
226 
227 
228 static
229 NTSTATUS
231 {
239 
240  DPRINT("IopSaveBootLogToFile() called\n");
241 
243 
245  L"\\SystemRoot\\rosboot.log");
247  &FileName,
249  NULL,
250  NULL);
251 
252  Status = ZwCreateFile(&FileHandle,
255  &IoStatusBlock,
256  NULL,
257  0,
258  0,
261  NULL,
262  0);
263  if (!NT_SUCCESS(Status))
264  {
265  DPRINT1("ZwCreateFile() failed (Status %lx)\n", Status);
266  return Status;
267  }
268 
269  ByteOffset.QuadPart = (LONGLONG)0;
270 
271  Signature = 0xFEFF;
272  Status = ZwWriteFile(FileHandle,
273  NULL,
274  NULL,
275  NULL,
276  &IoStatusBlock,
277  (PVOID)&Signature,
278  sizeof(WCHAR),
279  &ByteOffset,
280  NULL);
281  if (!NT_SUCCESS(Status))
282  {
283  DPRINT1("ZwWriteKey() failed (Status %lx)\n", Status);
284  }
285 
287 
288  return Status;
289 }
290 
291 
292 VOID
294 {
296  WCHAR ValueNameBuffer[8];
303  ULONG i;
305 
306  if (IopBootLogCreate == FALSE)
307  return;
308 
309  DPRINT("IopSaveBootLogToFile() called\n");
310 
312 
314  if (!NT_SUCCESS(Status))
315  {
316  DPRINT1("IopCreateLogFile() failed (Status %lx)\n", Status);
318  return;
319  }
320 
321  //Status = IopWriteLogFile(L"ReactOS "KERNEL_VERSION_STR);
322 
323  if (!NT_SUCCESS(Status))
324  {
325  DPRINT1("IopWriteLogFile() failed (Status %lx)\n", Status);
327  return;
328  }
329 
331  if (!NT_SUCCESS(Status))
332  {
333  DPRINT1("IopWriteLogFile() failed (Status %lx)\n", Status);
335  return;
336  }
337 
338 
339  BufferSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + 256 * sizeof(WCHAR);
340  KeyInfo = ExAllocatePool(PagedPool,
341  BufferSize);
342  if (KeyInfo == NULL)
343  {
345  return;
346  }
347 
349  L"\\Registry\\Machine\\System\\CurrentControlSet\\BootLog");
351  &KeyName,
353  NULL,
354  NULL);
355  Status = ZwOpenKey(&KeyHandle,
358  if (!NT_SUCCESS(Status))
359  {
360  ExFreePool(KeyInfo);
362  return;
363  }
364 
365  for (i = 0; ; i++)
366  {
367  swprintf(ValueNameBuffer,
368  L"%lu", i);
369 
371  ValueNameBuffer);
372 
373  Status = ZwQueryValueKey(KeyHandle,
374  &ValueName,
376  KeyInfo,
377  BufferSize,
378  &ResultLength);
380  {
381  break;
382  }
383 
384  if (!NT_SUCCESS(Status))
385  {
387  ExFreePool(KeyInfo);
389  return;
390  }
391 
392  Status = IopWriteLogFile((PWSTR)&KeyInfo->Data);
393  if (!NT_SUCCESS(Status))
394  {
396  ExFreePool(KeyInfo);
398  return;
399  }
400 
401  /* Delete keys */
402  ZwDeleteValueKey(KeyHandle,
403  &ValueName);
404  }
405 
407 
408  ExFreePool(KeyInfo);
409 
412 
413  DPRINT("IopSaveBootLogToFile() done\n");
414 }
415 
416 /* EOF */
IN CINT OUT PVOID IN ULONG OUT PULONG ResultLength
Definition: conport.c:47
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING KeyName
Definition: ndis.h:4693
VOID IopSaveBootLogToFile(VOID)
Definition: bootlog.c:293
VOID INIT_FUNCTION IopInitBootLog(BOOLEAN StartBootLog)
Definition: bootlog.c:34
#define TRUE
Definition: types.h:120
#define FILE_ALL_ACCESS
Definition: nt_native.h:651
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4693
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
uint16_t * PWSTR
Definition: typedefs.h:54
LONG NTSTATUS
Definition: precomp.h:26
static BOOLEAN IopBootLogCreate
Definition: bootlog.c:23
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
static ULONG IopLogEntryCount
Definition: bootlog.c:26
static ERESOURCE IopBootLogResource
Definition: bootlog.c:27
#define FILE_APPEND_DATA
Definition: nt_native.h:634
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
#define OBJ_OPENIF
Definition: winternl.h:229
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
HANDLE FileHandle
Definition: stats.c:38
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static BOOLEAN IopBootLogEnabled
Definition: bootlog.c:24
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1057
int64_t LONGLONG
Definition: typedefs.h:66
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define swprintf(buf, format,...)
Definition: sprintf.c:56
#define BufferSize
Definition: classpnp.h:419
VOID INIT_FUNCTION IopStartBootLog(VOID)
Definition: bootlog.c:43
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
static const WCHAR L[]
Definition: oid.c:1250
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
#define SYNCHRONIZE
Definition: nt_native.h:61
VOID IopBootLog(PUNICODE_STRING DriverName, BOOLEAN Success)
Definition: bootlog.c:58
static BOOLEAN IopLogFileEnabled
Definition: bootlog.c:25
Status
Definition: gdiplustypes.h:24
#define FILE_OPEN
Definition: from_kernel.h:54
struct _FileName FileName
Definition: fatprocs.h:884
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
struct _KEY_VALUE_PARTIAL_INFORMATION KEY_VALUE_PARTIAL_INFORMATION
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
static NTSTATUS IopCreateLogFile(VOID)
Definition: bootlog.c:230
#define DPRINT1
Definition: precomp.h:8
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
ULONG ERESOURCE
Definition: env_spec_w32.h:594
unsigned int ULONG
Definition: retypes.h:1
#define FILE_SUPERSEDE
Definition: from_kernel.h:53
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
VOID IopStopBootLog(VOID)
Definition: bootlog.c:51
static const WCHAR Signature[]
Definition: parser.c:141
static NTSTATUS IopWriteLogFile(PWSTR LogText)
Definition: bootlog.c:151
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
IN PDCB IN PCCB IN VBO IN OUT PULONG OUT PDIRENT OUT PBCB OUT PVBO ByteOffset
Definition: fatprocs.h:716
#define REG_SZ
Definition: layer.c:22