10648e35670a09c62aca1f33961646865578af0d
[reactos.git] / reactos / ntoskrnl / io / xhaldrv.c
1 /* $Id: xhaldrv.c,v 1.1 2000/06/30 22:52:49 ekohl Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: ntoskrnl/io/xhaldrv.c
6 * PURPOSE: Hal drive routines
7 * PROGRAMMER: Eric Kohl (ekohl@rz-online.de)
8 * UPDATE HISTORY:
9 * Created 19/06/2000
10 */
11
12 /* INCLUDES *****************************************************************/
13
14 #include <ddk/ntddk.h>
15 #include <internal/xhal.h>
16
17 //#define NDEBUG
18 #include <internal/debug.h>
19
20 /* FUNCTIONS *****************************************************************/
21
22 VOID
23 FASTCALL
24 xHalExamineMBR (
25 IN PDEVICE_OBJECT DeviceObject,
26 IN ULONG SectorSize,
27 IN ULONG MBRTypeIdentifier,
28 OUT PVOID * Buffer
29 )
30 {
31 KEVENT Event;
32 IO_STATUS_BLOCK StatusBlock;
33 LARGE_INTEGER Offset;
34 PUCHAR LocalBuffer;
35 PIRP Irp;
36 NTSTATUS Status;
37
38 DPRINT ("xHalExamineMBR()\n");
39 *Buffer = NULL;
40
41 if (SectorSize < 512)
42 SectorSize = 512;
43 if (SectorSize > 4096)
44 SectorSize = 4096;
45
46 LocalBuffer = (PUCHAR)ExAllocatePool (PagedPool,
47 SectorSize);
48 if (LocalBuffer == NULL)
49 return;
50
51 KeInitializeEvent (&Event,
52 NotificationEvent,
53 FALSE);
54
55 Offset.QuadPart = 0;
56
57 Irp = IoBuildSynchronousFsdRequest (IRP_MJ_READ,
58 DeviceObject,
59 LocalBuffer,
60 SectorSize,
61 &Offset,
62 &Event,
63 &StatusBlock);
64
65 Status = IoCallDriver (DeviceObject,
66 Irp);
67 if (Status == STATUS_PENDING)
68 {
69 KeWaitForSingleObject (&Event,
70 Executive,
71 KernelMode,
72 FALSE,
73 NULL);
74 Status = StatusBlock.Status;
75 }
76
77 if (!NT_SUCCESS(Status))
78 {
79 DPRINT ("xHalExamineMBR failed (Status = 0x%08lx)\n",
80 Status);
81 ExFreePool (LocalBuffer);
82 return;
83 }
84
85 if (LocalBuffer[0x1FE] != 0x55 || LocalBuffer[0x1FF] != 0xAA)
86 {
87 DPRINT ("xHalExamineMBR: invalid MBR signature\n");
88 ExFreePool (LocalBuffer);
89 return;
90 }
91
92 if (LocalBuffer[0x1C2] != MBRTypeIdentifier)
93 {
94 DPRINT ("xHalExamineMBR: invalid MBRTypeIdentifier\n");
95 ExFreePool (LocalBuffer);
96 return;
97 }
98
99 *Buffer = (PVOID)LocalBuffer;
100 }
101
102 VOID
103 FASTCALL
104 xHalIoAssignDriveLetters (
105 IN PLOADER_PARAMETER_BLOCK LoaderBlock,
106 IN PSTRING NtDeviceName,
107 OUT PUCHAR NtSystemPath,
108 OUT PSTRING NtSystemPathString
109 )
110 {
111 PCONFIGURATION_INFORMATION ConfigInfo;
112 OBJECT_ATTRIBUTES ObjectAttributes;
113 IO_STATUS_BLOCK StatusBlock;
114 UNICODE_STRING UnicodeString1;
115 UNICODE_STRING UnicodeString2;
116 HANDLE FileHandle;
117 PWSTR Buffer1;
118 PWSTR Buffer2;
119 ULONG i;
120 NTSTATUS Status;
121
122 DPRINT ("xHalIoAssignDriveLetters()\n");
123
124 ConfigInfo = IoGetConfigurationInformation ();
125
126 Buffer1 = (PWSTR)ExAllocatePool (PagedPool,
127 64 * sizeof(WCHAR));
128 Buffer2 = (PWSTR)ExAllocatePool (PagedPool,
129 32 * sizeof(WCHAR));
130
131 // Create PhysicalDrive links
132 DPRINT ("Physical disk drives: %d\n", ConfigInfo->DiskCount);
133
134 for (i = 0; i < ConfigInfo->DiskCount; i++)
135 {
136 swprintf (Buffer1,
137 L"\\Device\\Harddisk%d\\Partition0",
138 i);
139 RtlInitUnicodeString (&UnicodeString1,
140 Buffer1);
141
142 InitializeObjectAttributes (&ObjectAttributes,
143 &UnicodeString1,
144 0,
145 NULL,
146 NULL);
147
148 Status = NtOpenFile (&FileHandle,
149 0x10001,
150 &ObjectAttributes,
151 &StatusBlock,
152 1,
153 0x20);
154 if (NT_SUCCESS(Status))
155 {
156 swprintf (Buffer2,
157 L"\\??\\PhysicalDrive%d",
158 i);
159 RtlInitUnicodeString (&UnicodeString2,
160 Buffer2);
161
162 DPRINT ("Creating link: %S ==> %S\n",
163 Buffer2,
164 Buffer1);
165
166 IoCreateSymbolicLink (&UnicodeString2,
167 &UnicodeString1);
168
169 NtClose (FileHandle);
170 }
171 }
172 ExFreePool (Buffer2);
173 ExFreePool (Buffer1);
174
175 // Assign pre-assigned (registry) partitions
176
177 // Assign bootable partitions
178
179 // Assign remaining primary partitions
180
181 // Assign extended (logical) partitions
182
183 // Assign floppy drives
184 DPRINT("Floppy drives: %d\n", ConfigInfo->FloppyCount);
185
186 // Assign cdrom drives
187 DPRINT("CD-Rom drives: %d\n", ConfigInfo->CDRomCount);
188
189 // Any more ??
190
191 }
192
193 /* EOF */