Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenbootlog.c
Go to the documentation of this file.
00001 /* 00002 * COPYRIGHT: See COPYING in the top level directory 00003 * PROJECT: ReactOS kernel 00004 * FILE: ntoskrnl/io/bootlog.c 00005 * PURPOSE: Boot log file support 00006 * 00007 * PROGRAMMERS: Eric Kohl 00008 */ 00009 00010 /* INCLUDES *****************************************************************/ 00011 00012 #include <ntoskrnl.h> 00013 #define NDEBUG 00014 #include <debug.h> 00015 00016 #if defined (ALLOC_PRAGMA) 00017 #pragma alloc_text(INIT, IopInitBootLog) 00018 #pragma alloc_text(INIT, IopStartBootLog) 00019 #endif 00020 00021 /* GLOBALS ******************************************************************/ 00022 00023 static BOOLEAN IopBootLogCreate = FALSE; 00024 static BOOLEAN IopBootLogEnabled = FALSE; 00025 static BOOLEAN IopLogFileEnabled = FALSE; 00026 static ULONG IopLogEntryCount = 0; 00027 static ERESOURCE IopBootLogResource; 00028 00029 00030 /* FUNCTIONS ****************************************************************/ 00031 00032 VOID 00033 INIT_FUNCTION 00034 IopInitBootLog(BOOLEAN StartBootLog) 00035 { 00036 ExInitializeResourceLite(&IopBootLogResource); 00037 if (StartBootLog) IopStartBootLog(); 00038 } 00039 00040 00041 VOID 00042 INIT_FUNCTION 00043 IopStartBootLog(VOID) 00044 { 00045 IopBootLogCreate = TRUE; 00046 IopBootLogEnabled = TRUE; 00047 } 00048 00049 00050 VOID 00051 IopStopBootLog(VOID) 00052 { 00053 IopBootLogEnabled = FALSE; 00054 } 00055 00056 00057 VOID 00058 IopBootLog(PUNICODE_STRING DriverName, 00059 BOOLEAN Success) 00060 { 00061 OBJECT_ATTRIBUTES ObjectAttributes; 00062 WCHAR Buffer[256]; 00063 WCHAR ValueNameBuffer[8]; 00064 UNICODE_STRING KeyName; 00065 UNICODE_STRING ValueName; 00066 HANDLE ControlSetKey; 00067 HANDLE BootLogKey; 00068 NTSTATUS Status; 00069 00070 if (IopBootLogEnabled == FALSE) 00071 return; 00072 00073 ExAcquireResourceExclusiveLite(&IopBootLogResource, TRUE); 00074 00075 DPRINT("Boot log: %wS %wZ\n", 00076 Success ? L"Loaded driver" : L"Did not load driver", 00077 DriverName); 00078 00079 swprintf(Buffer, 00080 L"%ws %wZ", 00081 Success ? L"Loaded driver" : L"Did not load driver", 00082 DriverName); 00083 00084 swprintf(ValueNameBuffer, 00085 L"%lu", 00086 IopLogEntryCount); 00087 00088 RtlInitUnicodeString(&KeyName, 00089 L"\\Registry\\Machine\\System\\CurrentControlSet"); 00090 InitializeObjectAttributes(&ObjectAttributes, 00091 &KeyName, 00092 OBJ_CASE_INSENSITIVE, 00093 NULL, 00094 NULL); 00095 Status = ZwOpenKey(&ControlSetKey, 00096 KEY_ALL_ACCESS, 00097 &ObjectAttributes); 00098 if (!NT_SUCCESS(Status)) 00099 { 00100 DPRINT1("ZwOpenKey() failed (Status %lx)\n", Status); 00101 ExReleaseResourceLite(&IopBootLogResource); 00102 return; 00103 } 00104 00105 RtlInitUnicodeString(&KeyName, L"BootLog"); 00106 InitializeObjectAttributes(&ObjectAttributes, 00107 &KeyName, 00108 OBJ_CASE_INSENSITIVE | OBJ_OPENIF, 00109 ControlSetKey, 00110 NULL); 00111 Status = ZwCreateKey(&BootLogKey, 00112 KEY_ALL_ACCESS, 00113 &ObjectAttributes, 00114 0, 00115 NULL, 00116 REG_OPTION_NON_VOLATILE, 00117 NULL); 00118 if (!NT_SUCCESS(Status)) 00119 { 00120 DPRINT1("ZwCreateKey() failed (Status %lx)\n", Status); 00121 ZwClose(ControlSetKey); 00122 ExReleaseResourceLite(&IopBootLogResource); 00123 return; 00124 } 00125 00126 RtlInitUnicodeString(&ValueName, ValueNameBuffer); 00127 Status = ZwSetValueKey(BootLogKey, 00128 &ValueName, 00129 0, 00130 REG_SZ, 00131 (PVOID)Buffer, 00132 (ULONG)(wcslen(Buffer) + 1) * sizeof(WCHAR)); 00133 ZwClose(BootLogKey); 00134 ZwClose(ControlSetKey); 00135 00136 if (!NT_SUCCESS(Status)) 00137 { 00138 DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status); 00139 } 00140 else 00141 { 00142 IopLogEntryCount++; 00143 } 00144 00145 ExReleaseResourceLite(&IopBootLogResource); 00146 } 00147 00148 00149 static 00150 NTSTATUS 00151 IopWriteLogFile(PWSTR LogText) 00152 { 00153 OBJECT_ATTRIBUTES ObjectAttributes; 00154 UNICODE_STRING FileName; 00155 IO_STATUS_BLOCK IoStatusBlock; 00156 HANDLE FileHandle; 00157 PWSTR CrLf = L"\r\n"; 00158 NTSTATUS Status; 00159 00160 DPRINT("IopWriteLogFile() called\n"); 00161 00162 RtlInitUnicodeString(&FileName, 00163 L"\\SystemRoot\\rosboot.log"); 00164 InitializeObjectAttributes(&ObjectAttributes, 00165 &FileName, 00166 OBJ_CASE_INSENSITIVE | OBJ_OPENIF, 00167 NULL, 00168 NULL); 00169 00170 Status = ZwCreateFile(&FileHandle, 00171 FILE_APPEND_DATA, 00172 &ObjectAttributes, 00173 &IoStatusBlock, 00174 NULL, 00175 0, 00176 0, 00177 FILE_OPEN, 00178 FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT, 00179 NULL, 00180 0); 00181 if (!NT_SUCCESS(Status)) 00182 { 00183 DPRINT1("ZwCreateFile() failed (Status %lx)\n", Status); 00184 return Status; 00185 } 00186 00187 if (LogText != NULL) 00188 { 00189 Status = ZwWriteFile(FileHandle, 00190 NULL, 00191 NULL, 00192 NULL, 00193 &IoStatusBlock, 00194 LogText, 00195 (ULONG)wcslen(LogText) * sizeof(WCHAR), 00196 NULL, 00197 NULL); 00198 if (!NT_SUCCESS(Status)) 00199 { 00200 DPRINT1("ZwWriteFile() failed (Status %lx)\n", Status); 00201 ZwClose(FileHandle); 00202 return Status; 00203 } 00204 } 00205 00206 /* L"\r\n" */ 00207 Status = ZwWriteFile(FileHandle, 00208 NULL, 00209 NULL, 00210 NULL, 00211 &IoStatusBlock, 00212 (PVOID)CrLf, 00213 2 * sizeof(WCHAR), 00214 NULL, 00215 NULL); 00216 00217 ZwClose(FileHandle); 00218 00219 if (!NT_SUCCESS(Status)) 00220 { 00221 DPRINT1("ZwWriteFile() failed (Status %lx)\n", Status); 00222 } 00223 00224 return Status; 00225 } 00226 00227 00228 static 00229 NTSTATUS 00230 IopCreateLogFile(VOID) 00231 { 00232 OBJECT_ATTRIBUTES ObjectAttributes; 00233 UNICODE_STRING FileName; 00234 IO_STATUS_BLOCK IoStatusBlock; 00235 HANDLE FileHandle; 00236 LARGE_INTEGER ByteOffset; 00237 WCHAR Signature; 00238 NTSTATUS Status; 00239 00240 DPRINT("IopSaveBootLogToFile() called\n"); 00241 00242 ExAcquireResourceExclusiveLite(&IopBootLogResource, TRUE); 00243 00244 RtlInitUnicodeString(&FileName, 00245 L"\\SystemRoot\\rosboot.log"); 00246 InitializeObjectAttributes(&ObjectAttributes, 00247 &FileName, 00248 OBJ_CASE_INSENSITIVE | OBJ_OPENIF, 00249 NULL, 00250 NULL); 00251 00252 Status = ZwCreateFile(&FileHandle, 00253 FILE_ALL_ACCESS, 00254 &ObjectAttributes, 00255 &IoStatusBlock, 00256 NULL, 00257 0, 00258 0, 00259 FILE_SUPERSEDE, 00260 FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT, 00261 NULL, 00262 0); 00263 if (!NT_SUCCESS(Status)) 00264 { 00265 DPRINT1("ZwCreateFile() failed (Status %lx)\n", Status); 00266 return Status; 00267 } 00268 00269 ByteOffset.QuadPart = (LONGLONG)0; 00270 00271 Signature = 0xFEFF; 00272 Status = ZwWriteFile(FileHandle, 00273 NULL, 00274 NULL, 00275 NULL, 00276 &IoStatusBlock, 00277 (PVOID)&Signature, 00278 sizeof(WCHAR), 00279 &ByteOffset, 00280 NULL); 00281 if (!NT_SUCCESS(Status)) 00282 { 00283 DPRINT1("ZwWriteKey() failed (Status %lx)\n", Status); 00284 } 00285 00286 ZwClose(FileHandle); 00287 00288 return Status; 00289 } 00290 00291 00292 VOID 00293 IopSaveBootLogToFile(VOID) 00294 { 00295 PKEY_VALUE_PARTIAL_INFORMATION KeyInfo; 00296 WCHAR ValueNameBuffer[8]; 00297 OBJECT_ATTRIBUTES ObjectAttributes; 00298 UNICODE_STRING KeyName; 00299 UNICODE_STRING ValueName; 00300 HANDLE KeyHandle; 00301 ULONG BufferSize; 00302 ULONG ResultLength; 00303 ULONG i; 00304 NTSTATUS Status; 00305 00306 if (IopBootLogCreate == FALSE) 00307 return; 00308 00309 DPRINT("IopSaveBootLogToFile() called\n"); 00310 00311 ExAcquireResourceExclusiveLite(&IopBootLogResource, TRUE); 00312 00313 Status = IopCreateLogFile(); 00314 if (!NT_SUCCESS(Status)) 00315 { 00316 DPRINT1("IopCreateLogFile() failed (Status %lx)\n", Status); 00317 ExReleaseResourceLite(&IopBootLogResource); 00318 return; 00319 } 00320 00321 //Status = IopWriteLogFile(L"ReactOS "KERNEL_VERSION_STR); 00322 00323 if (!NT_SUCCESS(Status)) 00324 { 00325 DPRINT1("IopWriteLogFile() failed (Status %lx)\n", Status); 00326 ExReleaseResourceLite(&IopBootLogResource); 00327 return; 00328 } 00329 00330 Status = IopWriteLogFile(NULL); 00331 if (!NT_SUCCESS(Status)) 00332 { 00333 DPRINT1("IopWriteLogFile() failed (Status %lx)\n", Status); 00334 ExReleaseResourceLite(&IopBootLogResource); 00335 return; 00336 } 00337 00338 00339 BufferSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + 256 * sizeof(WCHAR); 00340 KeyInfo = ExAllocatePool(PagedPool, 00341 BufferSize); 00342 if (KeyInfo == NULL) 00343 { 00344 ExReleaseResourceLite(&IopBootLogResource); 00345 return; 00346 } 00347 00348 RtlInitUnicodeString(&KeyName, 00349 L"\\Registry\\Machine\\System\\CurrentControlSet\\BootLog"); 00350 InitializeObjectAttributes(&ObjectAttributes, 00351 &KeyName, 00352 OBJ_CASE_INSENSITIVE, 00353 NULL, 00354 NULL); 00355 Status = ZwOpenKey(&KeyHandle, 00356 KEY_ALL_ACCESS, 00357 &ObjectAttributes); 00358 if (!NT_SUCCESS(Status)) 00359 { 00360 ExFreePool(KeyInfo); 00361 ExReleaseResourceLite(&IopBootLogResource); 00362 return; 00363 } 00364 00365 for (i = 0; ; i++) 00366 { 00367 swprintf(ValueNameBuffer, 00368 L"%lu", i); 00369 00370 RtlInitUnicodeString(&ValueName, 00371 ValueNameBuffer); 00372 00373 Status = ZwQueryValueKey(KeyHandle, 00374 &ValueName, 00375 KeyValuePartialInformation, 00376 KeyInfo, 00377 BufferSize, 00378 &ResultLength); 00379 if (Status == STATUS_OBJECT_NAME_NOT_FOUND) 00380 { 00381 break; 00382 } 00383 00384 if (!NT_SUCCESS(Status)) 00385 { 00386 ZwClose(KeyHandle); 00387 ExFreePool(KeyInfo); 00388 ExReleaseResourceLite(&IopBootLogResource); 00389 return; 00390 } 00391 00392 Status = IopWriteLogFile((PWSTR)&KeyInfo->Data); 00393 if (!NT_SUCCESS(Status)) 00394 { 00395 ZwClose(KeyHandle); 00396 ExFreePool(KeyInfo); 00397 ExReleaseResourceLite(&IopBootLogResource); 00398 return; 00399 } 00400 00401 /* Delete keys */ 00402 ZwDeleteValueKey(KeyHandle, 00403 &ValueName); 00404 } 00405 00406 ZwClose(KeyHandle); 00407 00408 ExFreePool(KeyInfo); 00409 00410 IopLogFileEnabled = TRUE; 00411 ExReleaseResourceLite(&IopBootLogResource); 00412 00413 DPRINT("IopSaveBootLogToFile() done\n"); 00414 } 00415 00416 /* EOF */ Generated on Sat May 26 2012 04:36:08 for ReactOS by
1.7.6.1
|