ReactOS 0.4.16-dev-2617-g01a0906
ntoskrnl.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Kernel
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: boot/freeldr/freeldr/arch/i386/ntoskrnl.c
5 * PURPOSE: NTOS glue routines for the MINIHAL library
6 * PROGRAMMERS: Hervé Poussineau <hpoussin@reactos.org>
7 */
8
9/* INCLUDES ******************************************************************/
10
11#include <freeldr.h>
12#include <ntoskrnl.h>
13
14#ifndef UNIMPLEMENTED
15#define UNIMPLEMENTED ASSERT(FALSE)
16#endif
17
18/* FUNCTIONS *****************************************************************/
19
20VOID
26{
27 RtlZeroMemory(Event, sizeof(*Event));
28}
29
30VOID
33 IN ULONG MaxIncrement,
34 IN ULONG MinIncrement)
35{
36}
37
38VOID
41 IN struct _LOADER_PARAMETER_BLOCK *LoaderBlock,
42 IN PSTRING NtDeviceName,
43 OUT PUCHAR NtSystemPath,
44 OUT PSTRING NtSystemPathString)
45{
46}
47
55{
57}
58
59#ifndef _M_AMD64
60#include "disk/part_mbr.h" // For PARTITION_TABLE_ENTRY and MASTER_BOOT_RECORD
61
66 IN ULONGLONG LogicalSectorNumber,
68 OUT PMASTER_BOOT_RECORD BootRecord)
69{
74
75 Position.QuadPart = LogicalSectorNumber * SectorSize;
77 if (Status != ESUCCESS)
79
80 Status = ArcRead(FileId, BootRecord, SectorSize, &BytesRead);
83
84 return STATUS_SUCCESS;
85}
86
92 IN PPARTITION_TABLE_ENTRY PartitionTableEntry,
93 OUT PARTITION_INFORMATION *PartitionEntry)
94{
95 BOOLEAN IsRecognized;
96
97 IsRecognized = TRUE; /* FIXME */
98 if (!IsRecognized && ReturnRecognizedPartitions)
99 return FALSE;
100
101 PartitionEntry->StartingOffset.QuadPart = (ULONGLONG)PartitionTableEntry->SectorCountBeforePartition * SectorSize;
102 PartitionEntry->PartitionLength.QuadPart = (ULONGLONG)PartitionTableEntry->PartitionSectorCount * SectorSize;
103 PartitionEntry->HiddenSectors = 0;
104 PartitionEntry->PartitionNumber = 0; /* Will be filled later */
105 PartitionEntry->PartitionType = PartitionTableEntry->SystemIndicator;
106 PartitionEntry->BootIndicator = (PartitionTableEntry->BootIndicator & 0x80) ? TRUE : FALSE;
107 PartitionEntry->RecognizedPartition = IsRecognized;
108 PartitionEntry->RewritePartition = FALSE;
109
110 return TRUE;
111}
112
120{
122 PMASTER_BOOT_RECORD MasterBootRecord;
123 PDRIVE_LAYOUT_INFORMATION Partitions;
124 ULONG NbPartitions, i, Size;
125
127
128 if (SectorSize < sizeof(MASTER_BOOT_RECORD))
130
131 MasterBootRecord = ExAllocatePool(NonPagedPool, SectorSize);
132 if (!MasterBootRecord)
133 return STATUS_NO_MEMORY;
134
135 /* Read disk MBR */
136 Status = IopReadBootRecord(DeviceObject, 0, SectorSize, MasterBootRecord);
137 if (!NT_SUCCESS(Status))
138 {
139 ExFreePool(MasterBootRecord);
140 return Status;
141 }
142
143 /* Check validity of boot record */
144 if (MasterBootRecord->MasterBootRecordMagic != 0xaa55)
145 {
146 ExFreePool(MasterBootRecord);
148 }
149
150 /* Count number of partitions */
151 NbPartitions = 0;
152 for (i = 0; i < 4; i++)
153 {
154 NbPartitions++;
155
156 if (MasterBootRecord->PartitionTable[i].SystemIndicator == PARTITION_EXTENDED ||
158 {
159 /* FIXME: unhandled case; count number of partitions */
161 }
162 }
163
164 if (NbPartitions == 0)
165 {
166 ExFreePool(MasterBootRecord);
168 }
169
170 /* Allocation space to store partitions */
171 Size = FIELD_OFFSET(DRIVE_LAYOUT_INFORMATION, PartitionEntry) +
172 NbPartitions * sizeof(PARTITION_INFORMATION);
173 Partitions = ExAllocatePool(NonPagedPool, Size);
174 if (!Partitions)
175 {
176 ExFreePool(MasterBootRecord);
177 return STATUS_NO_MEMORY;
178 }
179
180 /* Count number of partitions */
181 NbPartitions = 0;
182 for (i = 0; i < 4; i++)
183 {
186 &MasterBootRecord->PartitionTable[i],
187 &Partitions->PartitionEntry[NbPartitions]))
188 {
189 Partitions->PartitionEntry[NbPartitions].PartitionNumber = NbPartitions + 1;
190 NbPartitions++;
191 }
192
193 if (MasterBootRecord->PartitionTable[i].SystemIndicator == PARTITION_EXTENDED ||
195 {
196 /* FIXME: unhandled case; copy partitions */
198 }
199 }
200
201 Partitions->PartitionCount = NbPartitions;
202 Partitions->Signature = MasterBootRecord->Signature;
203 ExFreePool(MasterBootRecord);
204
205 *PartitionBuffer = Partitions;
206 return STATUS_SUCCESS;
207}
208#endif // !_M_AMD64
209
218{
220}
221
222VOID
223NTAPI
225 IN ULONG MicroSeconds)
226{
227 StallExecutionProcessor(MicroSeconds);
228}
Type
Definition: Type.h:7
unsigned char BOOLEAN
Definition: actypes.h:127
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI KeSetTimeIncrement(IN ULONG MaxIncrement, IN ULONG MinIncrement)
Definition: ntoskrnl.c:32
VOID FASTCALL IoAssignDriveLetters(IN struct _LOADER_PARAMETER_BLOCK *LoaderBlock, IN PSTRING NtDeviceName, OUT PUCHAR NtSystemPath, OUT PSTRING NtSystemPathString)
Definition: ntoskrnl.c:40
NTSTATUS FASTCALL IoWritePartitionTable(IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, IN ULONG SectorsPerTrack, IN ULONG NumberOfHeads, IN PDRIVE_LAYOUT_INFORMATION PartitionBuffer)
Definition: ntoskrnl.c:212
#define UNIMPLEMENTED
Definition: ntoskrnl.c:15
BOOLEAN NTAPI IopCopyPartitionRecord(IN BOOLEAN ReturnRecognizedPartitions, IN ULONG SectorSize, IN PPARTITION_TABLE_ENTRY PartitionTableEntry, OUT PARTITION_INFORMATION *PartitionEntry)
Definition: ntoskrnl.c:89
NTSTATUS NTAPI IopReadBootRecord(IN PDEVICE_OBJECT DeviceObject, IN ULONGLONG LogicalSectorNumber, IN ULONG SectorSize, OUT PMASTER_BOOT_RECORD BootRecord)
Definition: ntoskrnl.c:64
NTSTATUS FASTCALL IoSetPartitionInformation(IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, IN ULONG PartitionNumber, IN ULONG PartitionType)
Definition: ntoskrnl.c:50
NTSTATUS FASTCALL IoReadPartitionTable(IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, IN BOOLEAN ReturnRecognizedPartitions, OUT PDRIVE_LAYOUT_INFORMATION *PartitionBuffer)
Definition: ntoskrnl.c:115
ARC_STATUS ArcSeek(ULONG FileId, LARGE_INTEGER *Position, SEEKMODE SeekMode)
Definition: fs.c:455
ARC_STATUS ArcRead(ULONG FileId, VOID *Buffer, ULONG N, ULONG *Count)
Definition: fs.c:448
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define ULONG_PTR
Definition: config.h:101
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
#define NonPagedPool
Definition: env_spec_w32.h:307
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
Status
Definition: gdiplustypes.h:25
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define KeStallExecutionProcessor(MicroSeconds)
Definition: precomp.h:27
#define FASTCALL
Definition: nt_native.h:50
struct _PARTITION_INFORMATION PARTITION_INFORMATION
enum _EVENT_TYPE EVENT_TYPE
UCHAR PartitionType
Definition: part_brfr.c:23
#define PARTITION_EXTENDED
Definition: part_mbr.h:55
#define PARTITION_XINT13_EXTENDED
Definition: part_mbr.h:62
VOID StallExecutionProcessor(ULONG Microseconds)
Definition: pchw.c:60
@ ESUCCESS
Definition: arc.h:32
ULONG ARC_STATUS
Definition: arc.h:4
@ SeekAbsolute
Definition: arc.h:59
#define STATUS_SUCCESS
Definition: shellext.h:65
PARTITION_INFORMATION PartitionEntry[1]
Definition: ntdddisk.h:421
USHORT MasterBootRecordMagic
Definition: part_mbr.h:40
PARTITION_TABLE_ENTRY PartitionTable[4]
Definition: part_mbr.h:39
Definition: part_mbr.h:16
UCHAR SystemIndicator
Definition: part_mbr.h:22
static COORD Position
Definition: mouse.c:34
#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_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
#define OUT
Definition: typedefs.h:40
#define STATUS_IO_DEVICE_ERROR
Definition: udferr_usr.h:179
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2061
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4539
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesRead
Definition: wdfiotarget.h:870
_In_ ULONG SectorSize
Definition: halfuncs.h:291
_In_ ULONG _In_ ULONG _In_ ULONG NumberOfHeads
Definition: iofuncs.h:2072
_In_ ULONG _In_ BOOLEAN ReturnRecognizedPartitions
Definition: iofuncs.h:2051
_In_ ULONG _In_ ULONG SectorsPerTrack
Definition: iofuncs.h:2071
_In_ ULONG _In_ BOOLEAN _Out_ struct _DRIVE_LAYOUT_INFORMATION ** PartitionBuffer
Definition: iofuncs.h:2052
_In_ ULONG _In_ ULONG PartitionNumber
Definition: iofuncs.h:2061