ReactOS 0.4.15-dev-5669-g09dde2c
bootdata.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Runtime Library
3 * LICENSE: See COPYING in the top level directory
4 * FILE: lib/rtl/bootdata.c
5 * PURPOSE: Boot Status Data Implementation
6 * PROGRAMMERS: Alex Ionescu (alex.ionescu@reactos.org)
7 * Eric Kohl
8 */
9
10/* INCLUDES *****************************************************************/
11
12#include <rtl.h>
13#define NDEBUG
14#include <debug.h>
15
17{
21
22/* FUNCTIONS *****************************************************************/
23
26{
27 {
29 sizeof(&DummyBsd->Version)
30 }, // RtlBsdItemVersionNumber
31 {
32 FIELD_OFFSET(RTL_BSD_DATA, ProductType),
33 sizeof(&DummyBsd->ProductType)
34 }, // RtlBsdItemProductType
35 {
36 FIELD_OFFSET(RTL_BSD_DATA, AabEnabled),
37 sizeof(&DummyBsd->AabEnabled)
38 }, // RtlBsdItemAabEnabled
39 {
40 FIELD_OFFSET(RTL_BSD_DATA, AabTimeout),
41 sizeof(&DummyBsd->AabTimeout)
42 }, // RtlBsdItemAabTimeout
43 {
44 FIELD_OFFSET(RTL_BSD_DATA, LastBootSucceeded),
46 }, // RtlBsdItemBootGood
47 {
48 FIELD_OFFSET(RTL_BSD_DATA, LastBootShutdown),
50 }, // RtlBsdItemBootShutdown
51 {
52 FIELD_OFFSET(RTL_BSD_DATA, SleepInProgress),
54 }, // RtlBsdSleepInProgress
55 {
56 FIELD_OFFSET(RTL_BSD_DATA, PowerTransition),
58 }, // RtlBsdPowerTransition
59 {
60 FIELD_OFFSET(RTL_BSD_DATA, BootAttemptCount),
62 }, // RtlBsdItemBootAttemptCount
63 {
64 FIELD_OFFSET(RTL_BSD_DATA, LastBootCheckpoint),
66 }, // RtlBsdItemBootCheckpoint
67 {
68 FIELD_OFFSET(RTL_BSD_DATA, LastBootId),
69 sizeof(&DummyBsd->LastBootId)
70 }, // RtlBsdItemBootId
71 {
72 FIELD_OFFSET(RTL_BSD_DATA, LastSuccessfulShutdownBootId),
74 }, // RtlBsdItemShutdownBootId
75 {
76 FIELD_OFFSET(RTL_BSD_DATA, LastReportedAbnormalShutdownBootId),
78 }, // RtlBsdItemReportedAbnormalShutdownBootId
79 {
80 FIELD_OFFSET(RTL_BSD_DATA, ErrorInfo),
81 sizeof(&DummyBsd->ErrorInfo)
82 }, // RtlBsdItemErrorInfo
83 {
84 FIELD_OFFSET(RTL_BSD_DATA, PowerButtonPressInfo),
86 }, // RtlBsdItemPowerButtonPressInfo
87 {
88 FIELD_OFFSET(RTL_BSD_DATA, Checksum),
89 sizeof(&DummyBsd->Checksum)
90 }, // RtlBsdItemChecksum
91};
92
93/*
94 * @implemented
95 */
99 VOID
100 )
101{
106 RTL_CONSTANT_STRING(L"\\SystemRoot\\bootstat.dat");
111 RTL_BSD_DATA InitialBsd;
112
113 /* Create the boot status data file */
114 AllocationSize.QuadPart = 0x800;
116 Status = ZwCreateFile(&FileHandle,
120 NULL, //&AllocationSize,
122 0,
125 NULL,
126 0);
127 if (NT_SUCCESS(Status))
128 {
129 /* Setup a sane looking initial BSD */
130 RtlZeroMemory(&InitialBsd, sizeof(InitialBsd));
131 InitialBsd.Version = sizeof(InitialBsd);
132 InitialBsd.ProductType = NtProductWinNt;
133 InitialBsd.AabEnabled = 1;
134 InitialBsd.AabTimeout = 30;
135 InitialBsd.LastBootSucceeded = TRUE;
136
137 /* Write it to disk */
138 ByteOffset.QuadPart = 0;
139 Status = ZwWriteFile(FileHandle,
140 NULL,
141 NULL,
142 NULL,
144 &InitialBsd,
145 sizeof(InitialBsd),
146 &ByteOffset,
147 NULL);
148 }
149
150 /* Close the file */
152
153 return Status;
154}
155
156/*
157 * @implemented
158 */
160NTAPI
164 _In_ RTL_BSD_ITEM_TYPE DataClass,
168 )
169{
173
174 DPRINT("RtlGetSetBootStatusData (%p %u %d %p %lu %p)\n",
176
177 if (DataClass >= RtlBsdItemMax)
178 {
180 }
181
182 if (BufferSize > BsdItemTable[DataClass].Size)
183 {
185 }
186
187 ByteOffset.HighPart = 0;
188 ByteOffset.LowPart = BsdItemTable[DataClass].Offset;
189
190 if (Read)
191 {
192 Status = ZwReadFile(FileHandle,
193 NULL,
194 NULL,
195 NULL,
197 Buffer,
199 &ByteOffset,
200 NULL);
201 }
202 else
203 {
204 Status = ZwWriteFile(FileHandle,
205 NULL,
206 NULL,
207 NULL,
209 Buffer,
211 &ByteOffset,
212 NULL);
213 }
214
215 if (NT_SUCCESS(Status))
216 {
217 if (ReturnLength)
218 {
219 *ReturnLength = BsdItemTable[DataClass].Size;
220 }
221 }
222
223 return Status;
224}
225
226/*
227 * @implemented
228 */
230NTAPI
233 )
234{
236 RTL_CONSTANT_STRING(L"\\SystemRoot\\bootstat.dat");
239 HANDLE LocalFileHandle;
242
243 /* Intialize the file handle */
244 *FileHandle = NULL;
245
246 /* Open the boot status data file */
247 Status = ZwOpenFile(&LocalFileHandle,
251 0,
253 if (NT_SUCCESS(Status))
254 {
255 /* Return the file handle */
256 *FileHandle = LocalFileHandle;
257 }
258
259 return Status;
260}
261
262/*
263 * @implemented
264 */
266NTAPI
269 )
270{
272
273 /* Flush the file and close it */
275 return ZwClose(FileHandle);
276}
277
278/* EOF */
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:45
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
@ NtProductWinNt
Definition: shellpath.c:64
IN CINT OUT PVOID IN ULONG OUT PULONG ReturnLength
Definition: dumpinfo.c:43
IN PDCB IN PCCB IN VBO IN OUT PULONG OUT PDIRENT OUT PBCB OUT PVBO ByteOffset
Definition: fatprocs.h:731
IN PFCB IN PFILE_OBJECT FileObject IN ULONG AllocationSize
Definition: fatprocs.h:322
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
#define FILE_CREATE
Definition: from_kernel.h:55
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
Status
Definition: gdiplustypes.h:25
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define _Out_opt_
Definition: ms_sal.h:346
#define _Out_
Definition: ms_sal.h:345
#define _In_
Definition: ms_sal.h:308
NTSYSAPI NTSTATUS NTAPI ZwOpenFile(_Out_ PHANDLE FileHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes, _Out_ PIO_STATUS_BLOCK IoStatusBlock, _In_ ULONG ShareAccess, _In_ ULONG OpenOptions)
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
enum _RTL_BSD_ITEM_TYPE RTL_BSD_ITEM_TYPE
@ RtlBsdItemMax
Definition: rtltypes.h:442
#define FILE_ATTRIBUTE_SYSTEM
Definition: nt_native.h:704
#define FILE_ALL_ACCESS
Definition: nt_native.h:651
#define FILE_GENERIC_READ
Definition: nt_native.h:653
#define FILE_GENERIC_WRITE
Definition: nt_native.h:660
#define DBG_UNREFERENCED_LOCAL_VARIABLE(L)
Definition: ntbasedef.h:319
#define RTL_CONSTANT_OBJECT_ATTRIBUTES(n, a)
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:455
#define L(x)
Definition: ntvdm.h:50
NTSTATUS NTAPI RtlLockBootStatusData(_Out_ PHANDLE FileHandle)
Definition: bootdata.c:231
NTSTATUS NTAPI RtlGetSetBootStatusData(_In_ HANDLE FileHandle, _In_ BOOLEAN Read, _In_ RTL_BSD_ITEM_TYPE DataClass, _In_ PVOID Buffer, _In_ ULONG BufferSize, _Out_opt_ PULONG ReturnLength)
Definition: bootdata.c:161
NTSTATUS NTAPI RtlUnlockBootStatusData(_In_ HANDLE FileHandle)
Definition: bootdata.c:267
PRTL_BSD_DATA DummyBsd
Definition: bootdata.c:24
RTL_BSD_ITEM_TABLE_ENTRY BsdItemTable[RtlBsdItemMax]
Definition: bootdata.c:25
struct _RTL_BSD_ITEM_TABLE_ENTRY RTL_BSD_ITEM_TABLE_ENTRY
NTSTATUS NTAPI RtlCreateBootStatusDataFile(VOID)
Definition: bootdata.c:98
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define DPRINT
Definition: sndvol32.h:71
_In_ BOOLEAN Read
Definition: strmini.h:479
UCHAR AabTimeout
Definition: rtltypes.h:1337
RTL_BSD_POWER_BUTTON_PRESS_INFO PowerButtonPressInfo
Definition: rtltypes.h:1349
ULONG ProductType
Definition: rtltypes.h:1335
BOOLEAN LastBootShutdown
Definition: rtltypes.h:1339
ULONG LastSuccessfulShutdownBootId
Definition: rtltypes.h:1346
RTL_BSD_DATA_ERROR_INFO ErrorInfo
Definition: rtltypes.h:1348
UCHAR BootAttemptCount
Definition: rtltypes.h:1342
UCHAR LastBootCheckpoint
Definition: rtltypes.h:1343
BOOLEAN SleepInProgress
Definition: rtltypes.h:1340
ULONG LastBootId
Definition: rtltypes.h:1345
BOOLEAN LastBootSucceeded
Definition: rtltypes.h:1338
ULONG LastReportedAbnormalShutdownBootId
Definition: rtltypes.h:1347
BOOLEAN AabEnabled
Definition: rtltypes.h:1336
UCHAR Checksum
Definition: rtltypes.h:1344
ULONG Version
Definition: rtltypes.h:1334
RTL_BSD_DATA_POWER_TRANSITION PowerTransition
Definition: rtltypes.h:1341
Definition: bootdata.c:17
UCHAR Size
Definition: bootdata.c:19
UCHAR Offset
Definition: bootdata.c:18
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14
uint32_t * PULONG
Definition: typedefs.h:59
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define NTAPI
Definition: typedefs.h:36
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE _In_ USHORT _In_ USHORT Version
Definition: wdffdo.h:469
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254
unsigned char UCHAR
Definition: xmlstorage.h:181
NTSYSAPI NTSTATUS NTAPI ZwFlushBuffersFile(_In_ HANDLE FileHandle, _Out_ PIO_STATUS_BLOCK IoStatusBlock)