ReactOS 0.4.16-dev-927-g467dec4
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
64 IN ULONGLONG LogicalSectorNumber,
66 OUT PMASTER_BOOT_RECORD BootRecord)
67{
72
73 Position.QuadPart = LogicalSectorNumber * SectorSize;
75 if (Status != ESUCCESS)
77
78 Status = ArcRead(FileId, BootRecord, SectorSize, &BytesRead);
81
82 return STATUS_SUCCESS;
83}
84
90 IN PPARTITION_TABLE_ENTRY PartitionTableEntry,
91 OUT PARTITION_INFORMATION *PartitionEntry)
92{
93 BOOLEAN IsRecognized;
94
95 IsRecognized = TRUE; /* FIXME */
96 if (!IsRecognized && ReturnRecognizedPartitions)
97 return FALSE;
98
99 PartitionEntry->StartingOffset.QuadPart = (ULONGLONG)PartitionTableEntry->SectorCountBeforePartition * SectorSize;
100 PartitionEntry->PartitionLength.QuadPart = (ULONGLONG)PartitionTableEntry->PartitionSectorCount * SectorSize;
101 PartitionEntry->HiddenSectors = 0;
102 PartitionEntry->PartitionNumber = 0; /* Will be filled later */
103 PartitionEntry->PartitionType = PartitionTableEntry->SystemIndicator;
104 PartitionEntry->BootIndicator = (PartitionTableEntry->BootIndicator & 0x80) ? TRUE : FALSE;
105 PartitionEntry->RecognizedPartition = IsRecognized;
106 PartitionEntry->RewritePartition = FALSE;
107
108 return TRUE;
109}
110
118{
120 PMASTER_BOOT_RECORD MasterBootRecord;
121 PDRIVE_LAYOUT_INFORMATION Partitions;
122 ULONG NbPartitions, i, Size;
123
125
126 if (SectorSize < sizeof(MASTER_BOOT_RECORD))
128
129 MasterBootRecord = ExAllocatePool(NonPagedPool, SectorSize);
130 if (!MasterBootRecord)
131 return STATUS_NO_MEMORY;
132
133 /* Read disk MBR */
134 Status = IopReadBootRecord(DeviceObject, 0, SectorSize, MasterBootRecord);
135 if (!NT_SUCCESS(Status))
136 {
137 ExFreePool(MasterBootRecord);
138 return Status;
139 }
140
141 /* Check validity of boot record */
142 if (MasterBootRecord->MasterBootRecordMagic != 0xaa55)
143 {
144 ExFreePool(MasterBootRecord);
146 }
147
148 /* Count number of partitions */
149 NbPartitions = 0;
150 for (i = 0; i < 4; i++)
151 {
152 NbPartitions++;
153
154 if (MasterBootRecord->PartitionTable[i].SystemIndicator == PARTITION_EXTENDED ||
156 {
157 /* FIXME: unhandled case; count number of partitions */
159 }
160 }
161
162 if (NbPartitions == 0)
163 {
164 ExFreePool(MasterBootRecord);
166 }
167
168 /* Allocation space to store partitions */
169 Size = FIELD_OFFSET(DRIVE_LAYOUT_INFORMATION, PartitionEntry) +
170 NbPartitions * sizeof(PARTITION_INFORMATION);
171 Partitions = ExAllocatePool(NonPagedPool, Size);
172 if (!Partitions)
173 {
174 ExFreePool(MasterBootRecord);
175 return STATUS_NO_MEMORY;
176 }
177
178 /* Count number of partitions */
179 NbPartitions = 0;
180 for (i = 0; i < 4; i++)
181 {
184 &MasterBootRecord->PartitionTable[i],
185 &Partitions->PartitionEntry[NbPartitions]))
186 {
187 Partitions->PartitionEntry[NbPartitions].PartitionNumber = NbPartitions + 1;
188 NbPartitions++;
189 }
190
191 if (MasterBootRecord->PartitionTable[i].SystemIndicator == PARTITION_EXTENDED ||
193 {
194 /* FIXME: unhandled case; copy partitions */
196 }
197 }
198
199 Partitions->PartitionCount = NbPartitions;
200 Partitions->Signature = MasterBootRecord->Signature;
201 ExFreePool(MasterBootRecord);
202
203 *PartitionBuffer = Partitions;
204 return STATUS_SUCCESS;
205}
206#endif // _M_AMD64
207
216{
218}
219
220VOID
221NTAPI
223 IN ULONG MicroSeconds)
224{
225 StallExecutionProcessor(MicroSeconds);
226}
unsigned char BOOLEAN
Type
Definition: Type.h:7
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:210
#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:87
NTSTATUS NTAPI IopReadBootRecord(IN PDEVICE_OBJECT DeviceObject, IN ULONGLONG LogicalSectorNumber, IN ULONG SectorSize, OUT PMASTER_BOOT_RECORD BootRecord)
Definition: ntoskrnl.c:62
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:113
#define PARTITION_EXTENDED
Definition: disk.h:92
#define PARTITION_XINT13_EXTENDED
Definition: disk.h:99
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
CHAR PartitionType
Definition: part_xbox.c:32
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: disk.h:79
PARTITION_TABLE_ENTRY PartitionTable[4]
Definition: disk.h:78
ULONG Signature
Definition: disk.h:76
Definition: disk.h:56
UCHAR SystemIndicator
Definition: disk.h:62
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:2055
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
_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