ReactOS  0.4.15-dev-2947-g59e1b78
bootcode.c File Reference
#include "precomp.h"
#include "bootcode.h"
#include <debug.h>
Include dependency graph for bootcode.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS ReadBootCodeByHandle (IN OUT PBOOTCODE BootCodeInfo, IN HANDLE FileHandle, IN ULONG Length OPTIONAL)
 
NTSTATUS ReadBootCodeFromFile (IN OUT PBOOTCODE BootCodeInfo, IN PUNICODE_STRING FilePath, IN ULONG Length OPTIONAL)
 
VOID FreeBootCode (IN OUT PBOOTCODE BootCodeInfo)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 14 of file bootcode.c.

Function Documentation

◆ FreeBootCode()

VOID FreeBootCode ( IN OUT PBOOTCODE  BootCodeInfo)

Definition at line 104 of file bootcode.c.

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 }
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
#define ASSERT(a)
Definition: mode.c:44
HANDLE ProcessHeap
Definition: servman.c:15
#define NULL
Definition: types.h:112

Referenced by InstallBtrfsBootCode(), InstallFat32BootCode(), InstallFatBootCode(), InstallMbrBootCode(), IsThereAValidBootSector(), and SaveBootSector().

◆ ReadBootCodeByHandle()

NTSTATUS ReadBootCodeByHandle ( IN OUT PBOOTCODE  BootCodeInfo,
IN HANDLE  FileHandle,
IN ULONG Length  OPTIONAL 
)

Definition at line 21 of file bootcode.c.

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,
51  &FileOffset,
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 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
HANDLE FileHandle
Definition: stats.c:38
#define ULL(a, b)
Definition: format_msg.c:27
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
HANDLE ProcessHeap
Definition: servman.c:15
_In_ PFCB _In_ LONGLONG FileOffset
Definition: cdprocs.h:159
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define NULL
Definition: types.h:112
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
#define SECTORSIZE
Definition: bootcode.h:13
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)

Referenced by InstallFat32BootCode(), InstallFatBootCode(), InstallMbrBootCode(), and ReadBootCodeFromFile().

◆ ReadBootCodeFromFile()

NTSTATUS ReadBootCodeFromFile ( IN OUT PBOOTCODE  BootCodeInfo,
IN PUNICODE_STRING  FilePath,
IN ULONG Length  OPTIONAL 
)

Definition at line 69 of file bootcode.c.

73 {
78 
79  ASSERT(BootCodeInfo);
80 
81  /* Open the file */
83  FilePath,
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 
96  Status = ReadBootCodeByHandle(BootCodeInfo, FileHandle, Length);
97 
98  /* Close the file and return */
100  return Status;
101 }
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_READ
Definition: compat.h:136
PCWSTR FilePath
HANDLE FileHandle
Definition: stats.c:38
Status
Definition: gdiplustypes.h:24
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:3951
#define ASSERT(a)
Definition: mode.c:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3398
#define GENERIC_READ
Definition: compat.h:135
#define SYNCHRONIZE
Definition: nt_native.h:61
NTSTATUS ReadBootCodeByHandle(IN OUT PBOOTCODE BootCodeInfo, IN HANDLE FileHandle, IN ULONG Length OPTIONAL)
Definition: bootcode.c:21
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define NULL
Definition: types.h:112
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106

Referenced by InstallBtrfsBootCode(), InstallFat32BootCode(), InstallFatBootCode(), InstallMbrBootCode(), IsThereAValidBootSector(), and SaveBootSector().