2 * PROJECT: Ramdisk Class Driver
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: drivers/storage/class/ramdisk/ramdisk.c
5 * PURPOSE: Main Driver Routines
6 * PROGRAMMERS: ReactOS Portable Systems Group
9 /* INCLUDES *******************************************************************/
23 /* GLOBALS ********************************************************************/
25 ULONG MaximumViewLength
;
26 ULONG MaximumPerDiskViewLength
;
27 ULONG ReportDetectedDevice
;
28 ULONG MarkRamdisksAsRemovable
;
29 ULONG MinimumViewCount
;
30 ULONG DefaultViewCount
;
31 ULONG MaximumViewCount
;
32 ULONG MinimumViewLength
;
33 ULONG DefaultViewLength
;
34 UNICODE_STRING DriverRegistryPath
;
35 BOOLEAN ExportBootDiskAsCd
;
38 /* FUNCTIONS ******************************************************************/
42 QueryParameters(IN PUNICODE_STRING RegistryPath
)
44 ULONG MinView
, DefView
, MinViewLength
, DefViewLength
, MaxViewLength
;
45 RTL_QUERY_REGISTRY_TABLE QueryTable
[10];
50 MaximumViewLength
= 0x10000000u
;
51 MaximumPerDiskViewLength
= 0x10000000u
;
52 ReportDetectedDevice
= 0;
53 MarkRamdisksAsRemovable
= 0;
55 DefaultViewCount
= 16;
56 MaximumViewCount
= 64;
57 MinimumViewLength
= 0x10000u
;
58 DefaultViewLength
= 0x100000u
;
61 // Setup the query table and query the registry
63 RtlZeroMemory(QueryTable
, sizeof(QueryTable
));
64 QueryTable
[0].Flags
= 1;
65 QueryTable
[0].Name
= L
"Parameters";
66 QueryTable
[1].Flags
= 32;
67 QueryTable
[1].Name
= L
"ReportDetectedDevice";
68 QueryTable
[1].EntryContext
= &ReportDetectedDevice
;
69 QueryTable
[2].Flags
= 32;
70 QueryTable
[2].Name
= L
"MarkRamdisksAsRemovable";
71 QueryTable
[2].EntryContext
= &MarkRamdisksAsRemovable
;
72 QueryTable
[3].Flags
= 32;
73 QueryTable
[3].Name
= L
"MinimumViewCount";
74 QueryTable
[3].EntryContext
= &MinimumViewCount
;
75 QueryTable
[4].Flags
= 32;
76 QueryTable
[4].Name
= L
"DefaultViewCount";
77 QueryTable
[4].EntryContext
= &DefaultViewCount
;
78 QueryTable
[5].Flags
= 32;
79 QueryTable
[5].Name
= L
"MaximumViewCount";
80 QueryTable
[5].EntryContext
= &MaximumViewCount
;
81 QueryTable
[6].Flags
= 32;
82 QueryTable
[6].Name
= L
"MinimumViewLength";
83 QueryTable
[6].EntryContext
= &MinimumViewLength
;
84 QueryTable
[7].Flags
= 32;
85 QueryTable
[7].Name
= L
"DefaultViewLength";
86 QueryTable
[7].EntryContext
= &DefaultViewLength
;
87 QueryTable
[8].Flags
= 32;
88 QueryTable
[8].Name
= L
"MaximumViewLength";
89 QueryTable
[8].EntryContext
= &MaximumViewLength
;
90 QueryTable
[9].Flags
= 32;
91 QueryTable
[9].Name
= L
"MaximumPerDiskViewLength";
92 QueryTable
[9].EntryContext
= &MaximumPerDiskViewLength
;
93 RtlQueryRegistryValues(RTL_REGISTRY_OPTIONAL
,
100 // Parse minimum view count, cannot be bigger than 256 or smaller than 2
102 MinView
= MinimumViewCount
;
103 if (MinimumViewCount
>= 2)
105 if (MinimumViewCount
> 256) MinView
= 256;
111 MinimumViewCount
= MinView
;
114 // Parse default view count, cannot be bigger than 256 or smaller than minimum
116 DefView
= DefaultViewCount
;
117 if (DefaultViewCount
>= MinView
)
119 if (DefaultViewCount
> 256) DefView
= 256;
125 DefaultViewCount
= DefView
;
128 // Parse maximum view count, cannot be bigger than 256 or smaller than default
130 if (MaximumViewCount
>= DefView
)
132 if (MaximumViewCount
> 256) MaximumViewCount
= 256;
136 MaximumViewCount
= DefView
;
140 // Parse minimum view length, cannot be bigger than 1GB or smaller than 64KB
142 MinViewLength
= MinimumViewLength
;
143 if (MinimumViewLength
>= 0x10000)
145 if (MinimumViewLength
> 0x40000000) MinViewLength
= 0x40000000u
;
149 MinViewLength
= 0x10000u
;
151 MinimumViewLength
= MinViewLength
;
154 // Parse default view length, cannot be bigger than 1GB or smaller than minimum
156 DefViewLength
= DefaultViewLength
;
157 if (DefaultViewLength
>= MinViewLength
)
159 if (DefaultViewLength
> 0x40000000) DefViewLength
= 0x40000000u
;
163 DefViewLength
= MinViewLength
;
165 DefaultViewLength
= DefViewLength
;
168 // Parse maximum view length, cannot be bigger than 1GB or smaller than default
170 MaxViewLength
= MaximumViewLength
;
171 if (MaximumViewLength
>= DefViewLength
)
173 if (MaximumViewLength
> 0x40000000) MaxViewLength
= 0x40000000u
;
177 MaxViewLength
= DefViewLength
;
179 MaximumViewLength
= MaxViewLength
;
182 // Parse maximum view length per disk, cannot be smaller than 16MB
184 if (MaximumPerDiskViewLength
>= 0x1000000)
186 if (MaxViewLength
> 0xFFFFFFFF) MaximumPerDiskViewLength
= -1;
190 MaximumPerDiskViewLength
= 0x1000000u
;
196 RamdiskOpenClose(IN PDEVICE_OBJECT DeviceObject
,
201 return STATUS_SUCCESS
;
206 RamdiskReadWrite(IN PDEVICE_OBJECT DeviceObject
,
211 return STATUS_SUCCESS
;
216 RamdiskDeviceControl(IN PDEVICE_OBJECT DeviceObject
,
221 return STATUS_SUCCESS
;
226 RamdiskPnp(IN PDEVICE_OBJECT DeviceObject
,
231 return STATUS_SUCCESS
;
236 RamdiskPower(IN PDEVICE_OBJECT DeviceObject
,
241 return STATUS_SUCCESS
;
246 RamdiskSystemControl(IN PDEVICE_OBJECT DeviceObject
,
251 return STATUS_SUCCESS
;
256 RamdiskScsi(IN PDEVICE_OBJECT DeviceObject
,
261 return STATUS_SUCCESS
;
266 RamdiskFlushBuffers(IN PDEVICE_OBJECT DeviceObject
,
271 return STATUS_SUCCESS
;
276 RamdiskUnload(IN PDRIVER_OBJECT DriverObject
)
284 RamdiskAddDevice(IN PDRIVER_OBJECT DriverObject
,
285 IN PDEVICE_OBJECT PhysicalDeviceObject
)
289 return STATUS_SUCCESS
;
294 DriverEntry(IN PDRIVER_OBJECT DriverObject
,
295 IN PUNICODE_STRING RegistryPath
)
297 PCHAR BootDeviceName
, CommandLine
;
298 PDEVICE_OBJECT PhysicalDeviceObject
;
300 DPRINT1("RAMDISK Class Driver\n");
303 // Query ramdisk parameters
305 QueryParameters(RegistryPath
);
308 // Save the registry path
310 DriverRegistryPath
= *RegistryPath
;
311 DriverRegistryPath
.Buffer
= ExAllocatePoolWithTag(PagedPool
,
312 RegistryPath
->Length
+
314 TAG('R', 'a', 'm', 'd'));
315 if (!DriverRegistryPath
.Buffer
) return STATUS_INSUFFICIENT_RESOURCES
;
316 RtlCopyUnicodeString(&DriverRegistryPath
, RegistryPath
);
319 // Set device routines
321 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = RamdiskOpenClose
;
322 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = RamdiskOpenClose
;
323 DriverObject
->MajorFunction
[IRP_MJ_READ
] = RamdiskReadWrite
;
324 DriverObject
->MajorFunction
[IRP_MJ_WRITE
] = RamdiskReadWrite
;
325 DriverObject
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
] = RamdiskDeviceControl
;
326 DriverObject
->MajorFunction
[IRP_MJ_PNP
] = RamdiskPnp
;
327 DriverObject
->MajorFunction
[IRP_MJ_POWER
] = RamdiskPower
;
328 DriverObject
->MajorFunction
[IRP_MJ_SYSTEM_CONTROL
] = RamdiskSystemControl
;
329 DriverObject
->MajorFunction
[IRP_MJ_SCSI
] = RamdiskScsi
;
330 DriverObject
->MajorFunction
[IRP_MJ_FLUSH_BUFFERS
] = RamdiskFlushBuffers
;
331 DriverObject
->DriverExtension
->AddDevice
= RamdiskAddDevice
;
332 DriverObject
->DriverUnload
= RamdiskUnload
;
335 // Check for a loader block
340 // Get the boot device name
342 BootDeviceName
= KeLoaderBlock
->ArcBootDeviceName
;
346 // Check if we're booting from ramdisk
348 if ((strlen(BootDeviceName
) >= 10) &&
349 !(_strnicmp(BootDeviceName
, "ramdisk(0)", 10)))
352 // We'll have to tell the PnP Manager
354 ReportDetectedDevice
= TRUE
;
357 // Check for a command line
359 CommandLine
= KeLoaderBlock
->LoadOptions
;
363 // Check if this is an ISO boot
365 if (strstr(CommandLine
, "RDEXPORTASCD"))
368 // Remember for later
370 ExportBootDiskAsCd
= TRUE
;
374 // Check if this is PE boot
376 if (strstr(CommandLine
, "MININT"))
379 // Remember for later
390 // Installing from Ramdisk isn't supported yet
392 ASSERT(KeLoaderBlock
->SetupLdrBlock
);
395 // Are we reporting the device
397 if (ReportDetectedDevice
)
402 Status
= IoReportDetectedDevice(DriverObject
,
403 InterfaceTypeUndefined
,
409 &PhysicalDeviceObject
);
410 if (NT_SUCCESS(Status
))
413 // Create the device object
415 Status
= RamdiskAddDevice(DriverObject
, PhysicalDeviceObject
);
416 if (NT_SUCCESS(Status
))
421 PhysicalDeviceObject
->Flags
&= ~DO_DEVICE_INITIALIZING
;
422 Status
= STATUS_SUCCESS
;
431 Status
= STATUS_SUCCESS
;