ReactOS 0.4.17-dev-116-ga4b6fe9
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/* GLOBALS ******************************************************************/
17
23
24
25/* FUNCTIONS ****************************************************************/
26
27CODE_SEG("INIT")
28VOID
30{
32 if (StartBootLog) IopStartBootLog();
33}
34
35
36CODE_SEG("INIT")
37VOID
39{
42}
43
44
45VOID
47{
49}
50
51
52VOID
55{
57 WCHAR Buffer[256];
58 WCHAR ValueNameBuffer[8];
61 HANDLE ControlSetKey;
62 HANDLE BootLogKey;
64
66 return;
67
69
70 DPRINT("Boot log: %wS %wZ\n",
71 Success ? L"Loaded driver" : L"Did not load driver",
72 DriverName);
73
75 L"%ws %wZ",
76 Success ? L"Loaded driver" : L"Did not load driver",
77 DriverName);
78
79 _swprintf(ValueNameBuffer, L"%lu", IopLogEntryCount);
80
82 L"\\Registry\\Machine\\System\\CurrentControlSet");
84 &KeyName,
86 NULL,
87 NULL);
88 Status = ZwOpenKey(&ControlSetKey,
91 if (!NT_SUCCESS(Status))
92 {
93 DPRINT1("ZwOpenKey() failed (Status %lx)\n", Status);
95 return;
96 }
97
98 RtlInitUnicodeString(&KeyName, L"BootLog");
100 &KeyName,
102 ControlSetKey,
103 NULL);
104 Status = ZwCreateKey(&BootLogKey,
107 0,
108 NULL,
110 NULL);
111 if (!NT_SUCCESS(Status))
112 {
113 DPRINT1("ZwCreateKey() failed (Status %lx)\n", Status);
114 ZwClose(ControlSetKey);
116 return;
117 }
118
119 RtlInitUnicodeString(&ValueName, ValueNameBuffer);
120 Status = ZwSetValueKey(BootLogKey,
121 &ValueName,
122 0,
123 REG_SZ,
124 (PVOID)Buffer,
125 (ULONG)(wcslen(Buffer) + 1) * sizeof(WCHAR));
126 ZwClose(BootLogKey);
127 ZwClose(ControlSetKey);
128
129 if (!NT_SUCCESS(Status))
130 {
131 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status);
132 }
133 else
134 {
136 }
137
139}
140
141
142static
145{
150 PWSTR CrLf = L"\r\n";
152
153 DPRINT("IopWriteLogFile() called\n");
154
156 L"\\SystemRoot\\rosboot.log");
158 &FileName,
160 NULL,
161 NULL);
162
163 Status = ZwCreateFile(&FileHandle,
167 NULL,
168 0,
169 0,
170 FILE_OPEN,
172 NULL,
173 0);
174 if (!NT_SUCCESS(Status))
175 {
176 DPRINT1("ZwCreateFile() failed (Status %lx)\n", Status);
177 return Status;
178 }
179
180 if (LogText != NULL)
181 {
182 Status = ZwWriteFile(FileHandle,
183 NULL,
184 NULL,
185 NULL,
187 LogText,
188 (ULONG)wcslen(LogText) * sizeof(WCHAR),
189 NULL,
190 NULL);
191 if (!NT_SUCCESS(Status))
192 {
193 DPRINT1("ZwWriteFile() failed (Status %lx)\n", Status);
195 return Status;
196 }
197 }
198
199 /* L"\r\n" */
200 Status = ZwWriteFile(FileHandle,
201 NULL,
202 NULL,
203 NULL,
205 (PVOID)CrLf,
206 2 * sizeof(WCHAR),
207 NULL,
208 NULL);
209
211
212 if (!NT_SUCCESS(Status))
213 {
214 DPRINT1("ZwWriteFile() failed (Status %lx)\n", Status);
215 }
216
217 return Status;
218}
219
220
221static
224{
232
233 DPRINT("IopSaveBootLogToFile() called\n");
234
236
238 L"\\SystemRoot\\rosboot.log");
240 &FileName,
242 NULL,
243 NULL);
244
245 Status = ZwCreateFile(&FileHandle,
249 NULL,
250 0,
251 0,
254 NULL,
255 0);
256 if (!NT_SUCCESS(Status))
257 {
258 DPRINT1("ZwCreateFile() failed (Status %lx)\n", Status);
259 return Status;
260 }
261
262 ByteOffset.QuadPart = (LONGLONG)0;
263
264 Signature = 0xFEFF;
265 Status = ZwWriteFile(FileHandle,
266 NULL,
267 NULL,
268 NULL,
271 sizeof(WCHAR),
272 &ByteOffset,
273 NULL);
274 if (!NT_SUCCESS(Status))
275 {
276 DPRINT1("ZwWriteKey() failed (Status %lx)\n", Status);
277 }
278
280
281 return Status;
282}
283
284
285VOID
287{
289 WCHAR ValueNameBuffer[8];
296 ULONG i;
298
299 if (IopBootLogCreate == FALSE)
300 return;
301
302 DPRINT("IopSaveBootLogToFile() called\n");
303
305
307 if (!NT_SUCCESS(Status))
308 {
309 DPRINT1("IopCreateLogFile() failed (Status %lx)\n", Status);
311 return;
312 }
313
314 //Status = IopWriteLogFile(L"ReactOS "KERNEL_VERSION_STR);
315
316 if (!NT_SUCCESS(Status))
317 {
318 DPRINT1("IopWriteLogFile() failed (Status %lx)\n", Status);
320 return;
321 }
322
324 if (!NT_SUCCESS(Status))
325 {
326 DPRINT1("IopWriteLogFile() failed (Status %lx)\n", Status);
328 return;
329 }
330
331
332 BufferSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + 256 * sizeof(WCHAR);
333 KeyInfo = ExAllocatePool(PagedPool,
334 BufferSize);
335 if (KeyInfo == NULL)
336 {
338 return;
339 }
340
342 L"\\Registry\\Machine\\System\\CurrentControlSet\\BootLog");
344 &KeyName,
346 NULL,
347 NULL);
348 Status = ZwOpenKey(&KeyHandle,
351 if (!NT_SUCCESS(Status))
352 {
353 ExFreePool(KeyInfo);
355 return;
356 }
357
358 for (i = 0; ; i++)
359 {
360 _swprintf(ValueNameBuffer, L"%lu", i);
361
363 ValueNameBuffer);
364
365 Status = ZwQueryValueKey(KeyHandle,
366 &ValueName,
368 KeyInfo,
370 &ResultLength);
372 {
373 break;
374 }
375
376 if (!NT_SUCCESS(Status))
377 {
379 ExFreePool(KeyInfo);
381 return;
382 }
383
384 Status = IopWriteLogFile((PWSTR)&KeyInfo->Data);
385 if (!NT_SUCCESS(Status))
386 {
388 ExFreePool(KeyInfo);
390 return;
391 }
392
393 /* Delete keys */
395 &ValueName);
396 }
397
399
400 ExFreePool(KeyInfo);
401
404
405 DPRINT("IopSaveBootLogToFile() done\n");
406}
407
408/* EOF */
#define CODE_SEG(...)
unsigned char BOOLEAN
Definition: actypes.h:127
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_NON_DIRECTORY_FILE
Definition: constants.h:492
#define DPRINT1
Definition: precomp.h:8
static ULONG IopLogEntryCount
Definition: bootlog.c:21
static NTSTATUS IopCreateLogFile(VOID)
Definition: bootlog.c:223
VOID IopStartBootLog(VOID)
Definition: bootlog.c:38
static NTSTATUS IopWriteLogFile(PWSTR LogText)
Definition: bootlog.c:144
VOID IopSaveBootLogToFile(VOID)
Definition: bootlog.c:286
static ERESOURCE IopBootLogResource
Definition: bootlog.c:22
static BOOLEAN IopLogFileEnabled
Definition: bootlog.c:20
VOID IopInitBootLog(BOOLEAN StartBootLog)
Definition: bootlog.c:29
VOID IopStopBootLog(VOID)
Definition: bootlog.c:46
static BOOLEAN IopBootLogCreate
Definition: bootlog.c:18
VOID IopBootLog(PUNICODE_STRING DriverName, BOOLEAN Success)
Definition: bootlog.c:53
static BOOLEAN IopBootLogEnabled
Definition: bootlog.c:19
Definition: bufpool.h:45
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define BufferSize
Definition: mmc.h:75
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2983
static const WCHAR Signature[]
Definition: parser.c:141
#define L(x)
Definition: resources.c:13
NTSTATUS ExInitializeResourceLite(PULONG res)
Definition: env_spec_w32.h:641
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define ExAcquireResourceExclusiveLite(res, wait)
Definition: env_spec_w32.h:615
ULONG ERESOURCE
Definition: env_spec_w32.h:594
#define PagedPool
Definition: env_spec_w32.h:308
@ Success
Definition: eventcreate.c:712
IN PDCB IN PCCB IN VBO IN OUT PULONG OUT PDIRENT OUT PBCB OUT PVBO ByteOffset
Definition: fatprocs.h:732
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
struct _FileName FileName
Definition: fatprocs.h:897
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
#define FILE_OPEN
Definition: from_kernel.h:54
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
#define FILE_SUPERSEDE
Definition: from_kernel.h:53
NTSYSAPI NTSTATUS NTAPI ZwDeleteValueKey(__in IN HANDLE Key, __in IN PUNICODE_STRING ValueName)
Status
Definition: gdiplustypes.h:25
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
#define REG_SZ
Definition: layer.c:22
#define _swprintf(buf, format,...)
Definition: sprintf.c:56
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:115
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define SYNCHRONIZE
Definition: nt_native.h:61
@ KeyValuePartialInformation
Definition: nt_native.h:1185
#define KEY_ALL_ACCESS
Definition: nt_native.h:1044
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1060
struct _KEY_VALUE_PARTIAL_INFORMATION KEY_VALUE_PARTIAL_INFORMATION
#define FILE_APPEND_DATA
Definition: nt_native.h:634
#define FILE_ALL_ACCESS
Definition: nt_native.h:651
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:100
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1822
short WCHAR
Definition: pedump.c:58
#define OBJ_OPENIF
Definition: winternl.h:229
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define DPRINT
Definition: sndvol32.h:73
uint16_t * PWSTR
Definition: typedefs.h:56
int64_t LONGLONG
Definition: typedefs.h:68
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
Definition: wdfdevice.h:3782
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2705
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243