ReactOS 0.4.15-dev-7924-g5949c20
bootcode.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Setup Library
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: BootCode support functions.
5 * COPYRIGHT: Copyright 2020 Hermes Belusca-Maito
6 */
7
8/* INCLUDES *****************************************************************/
9
10#include "precomp.h"
11
12#include "bootcode.h"
13
14#define NDEBUG
15#include <debug.h>
16
17
18/* FUNCTIONS ****************************************************************/
19
22 IN OUT PBOOTCODE BootCodeInfo,
25{
27 PVOID BootCode;
30
31 ASSERT(BootCodeInfo);
32
33 /* Normalize the bootcode length */
34 if (Length == 0 || Length == (ULONG)-1)
36
37 /* Allocate a buffer for the bootcode */
39 if (BootCode == NULL)
41
42 /* Read the bootcode from the file into the buffer */
43 FileOffset.QuadPart = 0ULL;
45 NULL,
46 NULL,
47 NULL,
49 BootCode,
50 Length,
52 NULL);
53 if (!NT_SUCCESS(Status))
54 {
55 RtlFreeHeap(ProcessHeap, 0, BootCode);
56 return Status;
57 }
58
59 /* Update the bootcode information */
60 if (BootCodeInfo->BootCode)
61 RtlFreeHeap(ProcessHeap, 0, BootCodeInfo->BootCode);
62 BootCodeInfo->BootCode = BootCode;
63 BootCodeInfo->Length = Length;
64
65 return STATUS_SUCCESS;
66}
67
70 IN OUT PBOOTCODE BootCodeInfo,
73{
78
79 ASSERT(BootCodeInfo);
80
81 /* Open the file */
85 NULL,
86 NULL);
91 FILE_SHARE_READ | FILE_SHARE_WRITE, // Is FILE_SHARE_WRITE necessary?
93 if (!NT_SUCCESS(Status))
94 return Status;
95
97
98 /* Close the file and return */
100 return Status;
101}
102
103VOID
105 IN OUT PBOOTCODE BootCodeInfo)
106{
107 ASSERT(BootCodeInfo);
108
109 /* Update the bootcode information */
110 if (BootCodeInfo->BootCode)
111 RtlFreeHeap(ProcessHeap, 0, BootCodeInfo->BootCode);
112 BootCodeInfo->BootCode = NULL;
113 BootCodeInfo->Length = 0;
114}
115
116/* EOF */
PCWSTR FilePath
LONG NTSTATUS
Definition: precomp.h:26
HANDLE ProcessHeap
Definition: servman.c:15
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
VOID FreeBootCode(IN OUT PBOOTCODE BootCodeInfo)
Definition: bootcode.c:104
NTSTATUS ReadBootCodeByHandle(IN OUT PBOOTCODE BootCodeInfo, IN HANDLE FileHandle, IN ULONG Length OPTIONAL)
Definition: bootcode.c:21
NTSTATUS ReadBootCodeFromFile(IN OUT PBOOTCODE BootCodeInfo, IN PUNICODE_STRING FilePath, IN ULONG Length OPTIONAL)
Definition: bootcode.c:69
#define SECTORSIZE
Definition: bootcode.h:13
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:160
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define GENERIC_READ
Definition: compat.h:135
#define FILE_SHARE_READ
Definition: compat.h:136
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
Status
Definition: gdiplustypes.h:25
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define ASSERT(a)
Definition: mode.c:44
#define ULL(a, b)
Definition: format_msg.c:27
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
Definition: file.c:3952
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define SYNCHRONIZE
Definition: nt_native.h:61
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define STATUS_SUCCESS
Definition: shellext.h:65
NTSTATUS NTAPI NtReadFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, PVOID Buffer, ULONG Length, PLARGE_INTEGER ByteOffset, PULONG Key)
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158