ReactOS  0.4.12-dev-685-gf36cbf7
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),
45  sizeof(&DummyBsd->LastBootSucceeded)
46  }, // RtlBsdItemBootGood
47  {
48  FIELD_OFFSET(RTL_BSD_DATA, LastBootShutdown),
49  sizeof(&DummyBsd->LastBootShutdown)
50  }, // RtlBsdItemBootShutdown
51  {
52  FIELD_OFFSET(RTL_BSD_DATA, SleepInProgress),
53  sizeof(&DummyBsd->SleepInProgress)
54  }, // RtlBsdSleepInProgress
55  {
56  FIELD_OFFSET(RTL_BSD_DATA, PowerTransition),
57  sizeof(&DummyBsd->PowerTransition)
58  }, // RtlBsdPowerTransition
59  {
60  FIELD_OFFSET(RTL_BSD_DATA, BootAttemptCount),
61  sizeof(&DummyBsd->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  */
97 NTAPI
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,
119  &IoStatusBlock,
120  NULL, //&AllocationSize,
122  0,
123  FILE_CREATE,
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,
143  &IoStatusBlock,
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  */
159 NTSTATUS
160 NTAPI
163  _In_ BOOLEAN Read,
164  _In_ RTL_BSD_ITEM_TYPE DataClass,
165  _In_ PVOID Buffer,
168  )
169 {
173 
174  DPRINT("RtlGetSetBootStatusData (%p %u %d %p %lu %p)\n",
175  FileHandle, Read, DataClass, Buffer, BufferSize, ReturnLength);
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,
196  &IoStatusBlock,
197  Buffer,
198  BufferSize,
199  &ByteOffset,
200  NULL);
201  }
202  else
203  {
204  Status = ZwWriteFile(FileHandle,
205  NULL,
206  NULL,
207  NULL,
208  &IoStatusBlock,
209  Buffer,
210  BufferSize,
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  */
229 NTSTATUS
230 NTAPI
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,
250  &IoStatusBlock,
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  */
265 NTSTATUS
266 NTAPI
269  )
270 {
272 
273  /* Flush the file and close it */
275  return ZwClose(FileHandle);
276 }
277 
278 /* EOF */
UCHAR BootAttemptCount
Definition: rtltypes.h:1336
#define FILE_GENERIC_READ
Definition: nt_native.h:653
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
IN CINT OUT PVOID IN ULONG OUT PULONG ReturnLength
Definition: dumpinfo.c:39
_In_ BOOLEAN Read
Definition: strmini.h:479
UCHAR Offset
Definition: bootdata.c:18
#define TRUE
Definition: types.h:120
IN PVOID IN PVOID IN USHORT Version
Definition: pci.h:359
NTSTATUS NTAPI RtlLockBootStatusData(_Out_ PHANDLE FileHandle)
Definition: bootdata.c:231
BOOLEAN LastBootShutdown
Definition: rtltypes.h:1333
#define FILE_ALL_ACCESS
Definition: nt_native.h:651
NTSYSAPI NTSTATUS NTAPI ZwFlushBuffersFile(_In_ HANDLE FileHandle, _Out_ PIO_STATUS_BLOCK IoStatusBlock)
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define FILE_ATTRIBUTE_SYSTEM
Definition: nt_native.h:704
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
LONG NTSTATUS
Definition: precomp.h:26
PRTL_BSD_DATA DummyBsd
Definition: bootdata.c:24
#define FILE_CREATE
Definition: from_kernel.h:55
UCHAR Checksum
Definition: rtltypes.h:1338
NTSTATUS NTAPI RtlUnlockBootStatusData(_In_ HANDLE FileHandle)
Definition: bootdata.c:267
ULONG LastReportedAbnormalShutdownBootId
Definition: rtltypes.h:1341
ULONG Version
Definition: rtltypes.h:1328
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:64
RTL_BSD_DATA_ERROR_INFO ErrorInfo
Definition: rtltypes.h:1342
HANDLE FileHandle
Definition: stats.c:38
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
BOOLEAN SleepInProgress
Definition: rtltypes.h:1334
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
#define _Out_
Definition: no_sal2.h:323
enum _RTL_BSD_ITEM_TYPE RTL_BSD_ITEM_TYPE
void DPRINT(...)
Definition: polytest.cpp:61
Definition: bufpool.h:45
UCHAR LastBootCheckpoint
Definition: rtltypes.h:1337
struct _RTL_BSD_ITEM_TABLE_ENTRY RTL_BSD_ITEM_TABLE_ENTRY
#define DBG_UNREFERENCED_LOCAL_VARIABLE(L)
Definition: ntbasedef.h:326
#define _Out_opt_
Definition: no_sal2.h:339
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
RTL_BSD_POWER_BUTTON_PRESS_INFO PowerButtonPressInfo
Definition: rtltypes.h:1343
BOOLEAN AabEnabled
Definition: rtltypes.h:1330
#define BufferSize
Definition: classpnp.h:419
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
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)
unsigned char UCHAR
Definition: xmlstorage.h:181
static const WCHAR L[]
Definition: oid.c:1250
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:414
BOOLEAN LastBootSucceeded
Definition: rtltypes.h:1332
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
Status
Definition: gdiplustypes.h:24
#define FILE_GENERIC_WRITE
Definition: nt_native.h:660
#define _In_
Definition: no_sal2.h:204
IN PFCB IN PFILE_OBJECT FileObject IN ULONG AllocationSize
Definition: fatprocs.h:310
UCHAR AabTimeout
Definition: rtltypes.h:1331
#define RTL_CONSTANT_OBJECT_ATTRIBUTES(n, a)
NTSTATUS NTAPI RtlCreateBootStatusDataFile(VOID)
Definition: bootdata.c:98
ULONG LastSuccessfulShutdownBootId
Definition: rtltypes.h:1340
RTL_BSD_DATA_POWER_TRANSITION PowerTransition
Definition: rtltypes.h:1335
Definition: bootdata.c:16
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
unsigned int * PULONG
Definition: retypes.h:1
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
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
ULONG LastBootId
Definition: rtltypes.h:1339
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
ULONG ProductType
Definition: rtltypes.h:1329
UCHAR Size
Definition: bootdata.c:19
RTL_BSD_ITEM_TABLE_ENTRY BsdItemTable[RtlBsdItemMax]
Definition: bootdata.c:25
IN PDCB IN PCCB IN VBO IN OUT PULONG OUT PDIRENT OUT PBCB OUT PVBO ByteOffset
Definition: fatprocs.h:716
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14