2008-06-29 02:58:05 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: Ramdisk Class Driver
|
2008-06-30 08:54:30 +00:00
|
|
|
* LICENSE: BSD - See COPYING.ARM in the top level directory
|
2008-06-29 02:58:05 +00:00
|
|
|
* FILE: drivers/storage/class/ramdisk/ramdisk.c
|
|
|
|
* PURPOSE: Main Driver Routines
|
|
|
|
* PROGRAMMERS: ReactOS Portable Systems Group
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* INCLUDES *******************************************************************/
|
|
|
|
|
2008-07-13 04:23:59 +00:00
|
|
|
#include <initguid.h>
|
2008-06-29 02:58:05 +00:00
|
|
|
#include <ntddk.h>
|
2010-03-06 18:55:27 +00:00
|
|
|
#include <ntifs.h>
|
2008-06-29 02:58:05 +00:00
|
|
|
#include <ntdddisk.h>
|
2008-07-20 06:32:23 +00:00
|
|
|
#include <ntddcdrm.h>
|
2008-06-29 02:58:05 +00:00
|
|
|
#include <scsi.h>
|
|
|
|
#include <ntddscsi.h>
|
2008-07-20 16:13:19 +00:00
|
|
|
#include <ntddvol.h>
|
2008-06-29 02:58:05 +00:00
|
|
|
#include <mountdev.h>
|
|
|
|
#include <mountmgr.h>
|
|
|
|
#include <ketypes.h>
|
2008-07-13 04:23:59 +00:00
|
|
|
#include <iotypes.h>
|
|
|
|
#include <rtlfuncs.h>
|
2008-06-29 02:58:05 +00:00
|
|
|
#include <arc/arc.h>
|
2008-07-13 04:23:59 +00:00
|
|
|
#include <reactos/drivers/ntddrdsk.h>
|
2008-07-22 05:31:24 +00:00
|
|
|
#include "../../../filesystems/fs_rec/fs_rec.h"
|
2008-07-19 22:21:38 +00:00
|
|
|
#include <stdio.h>
|
2008-06-29 02:58:05 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
[FREELDR] Include ntddk.h instead of winddk.h
[RAMDISK] Add missing DO_XIP definition (not in WDK/DDK)
[FASTFAT] Remove duplicate VOLUME_IS_DIRTY definition
[HAL] Add case stubs for missing HAL_QUERY_INFORMATION_CLASS members
[NDK] Fix DbgPrompt prototype
[NTDDK]
- Move from winddk.h: _KUSER_SHARED_DATA (updated), pHalIoAssignDriveLetters, PHAL_RESET_DISPLAY_PARAMETERS, HAL_DISPATCH, HalDispatchTable, PCREATE_PROCESS_NOTIFY_ROUTINE, PCREATE_THREAD_NOTIFY_ROUTINE, IMAGE_INFO, PLOAD_IMAGE_NOTIFY_ROUTINE, BUS_DATA_TYPE (updated), PROCESSINFOCLASS (updated), THREADINFOCLASS (updated), DISK_SIGNATURE, PTIMER_APC_ROUTINE, Exfi386InterlockedIncrementLong, Exfi386InterlockedDecrementLong, Exfi386InterlockedExchangeUlong
- Add pHalGetAcpiTable, PCI_ERROR_HANDLER_CALLBACK, pHalSetPciErrorHandlerCallback
[WDM] Add _DECL_HAL_KE_IMPORT, Reorder sections (types before functions)
svn path=/branches/header-work/; revision=46097
2010-03-11 14:49:41 +00:00
|
|
|
#define DO_XIP 0x00020000
|
|
|
|
|
2008-06-29 02:58:05 +00:00
|
|
|
/* GLOBALS ********************************************************************/
|
|
|
|
|
2008-07-21 01:12:17 +00:00
|
|
|
#define RAMDISK_SESSION_SIZE \
|
|
|
|
FIELD_OFFSET(CDROM_TOC, TrackData) + sizeof(TRACK_DATA)
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2008-07-21 01:12:17 +00:00
|
|
|
#define RAMDISK_TOC_SIZE \
|
|
|
|
FIELD_OFFSET(CDROM_TOC, TrackData) + 2 * sizeof(TRACK_DATA)
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2008-07-21 01:12:17 +00:00
|
|
|
#define TOC_DATA_TRACK (0x04)
|
|
|
|
|
2008-07-13 04:23:59 +00:00
|
|
|
typedef enum _RAMDISK_DEVICE_TYPE
|
|
|
|
{
|
2008-07-19 18:44:31 +00:00
|
|
|
RamdiskBus,
|
|
|
|
RamdiskDrive
|
2008-07-13 04:23:59 +00:00
|
|
|
} RAMDISK_DEVICE_TYPE;
|
|
|
|
|
2008-07-13 07:02:48 +00:00
|
|
|
typedef enum _RAMDISK_DEVICE_STATE
|
|
|
|
{
|
|
|
|
RamdiskStateUninitialized,
|
|
|
|
RamdiskStateStarted,
|
2008-07-13 07:16:24 +00:00
|
|
|
RamdiskStatePaused,
|
2008-07-13 07:02:48 +00:00
|
|
|
RamdiskStateStopped,
|
2008-07-13 07:16:24 +00:00
|
|
|
RamdiskStateRemoved,
|
|
|
|
RamdiskStateBusRemoved,
|
2008-07-19 18:44:31 +00:00
|
|
|
RamdiskStateEnumerated,
|
2008-07-13 07:02:48 +00:00
|
|
|
} RAMDISK_DEVICE_STATE;
|
|
|
|
|
2008-07-13 04:23:59 +00:00
|
|
|
DEFINE_GUID(RamdiskBusInterface,
|
2015-01-09 14:09:34 +00:00
|
|
|
0x5DC52DF0,
|
|
|
|
0x2F8A,
|
|
|
|
0x410F,
|
|
|
|
0x80, 0xE4, 0x05, 0xF8, 0x10, 0xE7, 0xA8, 0x8A);
|
2008-07-13 04:23:59 +00:00
|
|
|
|
2014-12-29 22:42:11 +00:00
|
|
|
DEFINE_GUID(RamdiskDiskInterface,
|
2015-01-09 14:09:34 +00:00
|
|
|
0x31D909F0,
|
|
|
|
0x2CDF,
|
|
|
|
0x4A20,
|
|
|
|
0x9E, 0xD4, 0x7D, 0x65, 0x47, 0x6C, 0xA7, 0x68);
|
2014-12-29 22:42:11 +00:00
|
|
|
|
2008-07-20 19:39:55 +00:00
|
|
|
typedef struct _RAMDISK_EXTENSION
|
|
|
|
{
|
|
|
|
RAMDISK_DEVICE_TYPE Type;
|
|
|
|
RAMDISK_DEVICE_STATE State;
|
|
|
|
PDEVICE_OBJECT DeviceObject;
|
|
|
|
PDEVICE_OBJECT PhysicalDeviceObject;
|
|
|
|
PDEVICE_OBJECT AttachedDevice;
|
|
|
|
IO_REMOVE_LOCK RemoveLock;
|
|
|
|
UNICODE_STRING DriveDeviceName;
|
|
|
|
UNICODE_STRING BusDeviceName;
|
|
|
|
FAST_MUTEX DiskListLock;
|
2008-07-19 18:44:31 +00:00
|
|
|
LIST_ENTRY DiskList;
|
2008-07-20 19:39:55 +00:00
|
|
|
} RAMDISK_EXTENSION, *PRAMDISK_EXTENSION;
|
2008-07-19 18:44:31 +00:00
|
|
|
|
|
|
|
typedef struct _RAMDISK_BUS_EXTENSION
|
2008-07-13 04:23:59 +00:00
|
|
|
{
|
2008-07-19 18:44:31 +00:00
|
|
|
RAMDISK_EXTENSION;
|
|
|
|
} RAMDISK_BUS_EXTENSION, *PRAMDISK_BUS_EXTENSION;
|
|
|
|
|
|
|
|
typedef struct _RAMDISK_DRIVE_EXTENSION
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Inherited base class */
|
2008-07-19 18:44:31 +00:00
|
|
|
RAMDISK_EXTENSION;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Data we get from the creator */
|
2008-07-19 22:42:18 +00:00
|
|
|
GUID DiskGuid;
|
|
|
|
UNICODE_STRING GuidString;
|
|
|
|
UNICODE_STRING SymbolicLinkName;
|
|
|
|
ULONG DiskType;
|
|
|
|
RAMDISK_CREATE_OPTIONS DiskOptions;
|
2008-07-22 08:52:18 +00:00
|
|
|
LARGE_INTEGER DiskLength;
|
2008-07-19 22:42:18 +00:00
|
|
|
LONG DiskOffset;
|
2008-07-19 22:21:38 +00:00
|
|
|
WCHAR DriveLetter;
|
2008-07-22 08:52:18 +00:00
|
|
|
ULONG BasePage;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Data we get from the disk */
|
2008-07-20 04:39:01 +00:00
|
|
|
ULONG BytesPerSector;
|
|
|
|
ULONG SectorsPerTrack;
|
|
|
|
ULONG NumberOfHeads;
|
2008-07-22 08:52:18 +00:00
|
|
|
ULONG Cylinders;
|
|
|
|
ULONG HiddenSectors;
|
2008-07-19 18:44:31 +00:00
|
|
|
} RAMDISK_DRIVE_EXTENSION, *PRAMDISK_DRIVE_EXTENSION;
|
2008-07-13 04:23:59 +00:00
|
|
|
|
2008-06-29 02:58:05 +00:00
|
|
|
ULONG MaximumViewLength;
|
|
|
|
ULONG MaximumPerDiskViewLength;
|
|
|
|
ULONG ReportDetectedDevice;
|
|
|
|
ULONG MarkRamdisksAsRemovable;
|
|
|
|
ULONG MinimumViewCount;
|
|
|
|
ULONG DefaultViewCount;
|
|
|
|
ULONG MaximumViewCount;
|
|
|
|
ULONG MinimumViewLength;
|
|
|
|
ULONG DefaultViewLength;
|
|
|
|
UNICODE_STRING DriverRegistryPath;
|
|
|
|
BOOLEAN ExportBootDiskAsCd;
|
|
|
|
BOOLEAN IsWinPEBoot;
|
2008-07-13 04:23:59 +00:00
|
|
|
PDEVICE_OBJECT RamdiskBusFdo;
|
2008-06-29 02:58:05 +00:00
|
|
|
|
|
|
|
/* FUNCTIONS ******************************************************************/
|
|
|
|
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
QueryParameters(IN PUNICODE_STRING RegistryPath)
|
|
|
|
{
|
|
|
|
ULONG MinView, DefView, MinViewLength, DefViewLength, MaxViewLength;
|
2019-02-13 08:33:10 +00:00
|
|
|
RTL_QUERY_REGISTRY_TABLE QueryTable[11];
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Set defaults */
|
2008-06-29 02:58:05 +00:00
|
|
|
MaximumViewLength = 0x10000000u;
|
|
|
|
MaximumPerDiskViewLength = 0x10000000u;
|
|
|
|
ReportDetectedDevice = 0;
|
|
|
|
MarkRamdisksAsRemovable = 0;
|
|
|
|
MinimumViewCount = 2;
|
|
|
|
DefaultViewCount = 16;
|
|
|
|
MaximumViewCount = 64;
|
|
|
|
MinimumViewLength = 0x10000u;
|
|
|
|
DefaultViewLength = 0x100000u;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Setup the query table and query the registry */
|
2008-06-29 02:58:05 +00:00
|
|
|
RtlZeroMemory(QueryTable, sizeof(QueryTable));
|
|
|
|
QueryTable[0].Flags = 1;
|
|
|
|
QueryTable[0].Name = L"Parameters";
|
|
|
|
QueryTable[1].Flags = 32;
|
|
|
|
QueryTable[1].Name = L"ReportDetectedDevice";
|
|
|
|
QueryTable[1].EntryContext = &ReportDetectedDevice;
|
|
|
|
QueryTable[2].Flags = 32;
|
|
|
|
QueryTable[2].Name = L"MarkRamdisksAsRemovable";
|
|
|
|
QueryTable[2].EntryContext = &MarkRamdisksAsRemovable;
|
|
|
|
QueryTable[3].Flags = 32;
|
|
|
|
QueryTable[3].Name = L"MinimumViewCount";
|
|
|
|
QueryTable[3].EntryContext = &MinimumViewCount;
|
|
|
|
QueryTable[4].Flags = 32;
|
|
|
|
QueryTable[4].Name = L"DefaultViewCount";
|
|
|
|
QueryTable[4].EntryContext = &DefaultViewCount;
|
|
|
|
QueryTable[5].Flags = 32;
|
|
|
|
QueryTable[5].Name = L"MaximumViewCount";
|
|
|
|
QueryTable[5].EntryContext = &MaximumViewCount;
|
|
|
|
QueryTable[6].Flags = 32;
|
|
|
|
QueryTable[6].Name = L"MinimumViewLength";
|
|
|
|
QueryTable[6].EntryContext = &MinimumViewLength;
|
|
|
|
QueryTable[7].Flags = 32;
|
|
|
|
QueryTable[7].Name = L"DefaultViewLength";
|
|
|
|
QueryTable[7].EntryContext = &DefaultViewLength;
|
|
|
|
QueryTable[8].Flags = 32;
|
|
|
|
QueryTable[8].Name = L"MaximumViewLength";
|
|
|
|
QueryTable[8].EntryContext = &MaximumViewLength;
|
|
|
|
QueryTable[9].Flags = 32;
|
|
|
|
QueryTable[9].Name = L"MaximumPerDiskViewLength";
|
|
|
|
QueryTable[9].EntryContext = &MaximumPerDiskViewLength;
|
|
|
|
RtlQueryRegistryValues(RTL_REGISTRY_OPTIONAL,
|
|
|
|
RegistryPath->Buffer,
|
|
|
|
QueryTable,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Parse minimum view count, cannot be bigger than 256 or smaller than 2 */
|
2008-06-29 02:58:05 +00:00
|
|
|
MinView = MinimumViewCount;
|
|
|
|
if (MinimumViewCount >= 2)
|
|
|
|
{
|
|
|
|
if (MinimumViewCount > 256) MinView = 256;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MinView = 2;
|
|
|
|
}
|
|
|
|
MinimumViewCount = MinView;
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Parse default view count, cannot be bigger than 256 or smaller than minimum */
|
2008-06-29 02:58:05 +00:00
|
|
|
DefView = DefaultViewCount;
|
|
|
|
if (DefaultViewCount >= MinView)
|
|
|
|
{
|
|
|
|
if (DefaultViewCount > 256) DefView = 256;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DefView = MinView;
|
|
|
|
}
|
|
|
|
DefaultViewCount = DefView;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Parse maximum view count, cannot be bigger than 256 or smaller than default */
|
2008-06-29 02:58:05 +00:00
|
|
|
if (MaximumViewCount >= DefView)
|
|
|
|
{
|
|
|
|
if (MaximumViewCount > 256) MaximumViewCount = 256;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MaximumViewCount = DefView;
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Parse minimum view length, cannot be bigger than 1GB or smaller than 64KB */
|
2008-06-29 02:58:05 +00:00
|
|
|
MinViewLength = MinimumViewLength;
|
|
|
|
if (MinimumViewLength >= 0x10000)
|
|
|
|
{
|
|
|
|
if (MinimumViewLength > 0x40000000) MinViewLength = 0x40000000u;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MinViewLength = 0x10000u;
|
|
|
|
}
|
|
|
|
MinimumViewLength = MinViewLength;
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Parse default view length, cannot be bigger than 1GB or smaller than minimum */
|
2008-06-29 02:58:05 +00:00
|
|
|
DefViewLength = DefaultViewLength;
|
|
|
|
if (DefaultViewLength >= MinViewLength)
|
|
|
|
{
|
|
|
|
if (DefaultViewLength > 0x40000000) DefViewLength = 0x40000000u;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DefViewLength = MinViewLength;
|
|
|
|
}
|
|
|
|
DefaultViewLength = DefViewLength;
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Parse maximum view length, cannot be bigger than 1GB or smaller than default */
|
2008-06-29 02:58:05 +00:00
|
|
|
MaxViewLength = MaximumViewLength;
|
|
|
|
if (MaximumViewLength >= DefViewLength)
|
|
|
|
{
|
|
|
|
if (MaximumViewLength > 0x40000000) MaxViewLength = 0x40000000u;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MaxViewLength = DefViewLength;
|
|
|
|
}
|
|
|
|
MaximumViewLength = MaxViewLength;
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Parse maximum view length per disk, cannot be smaller than 16MB */
|
2008-06-29 02:58:05 +00:00
|
|
|
if (MaximumPerDiskViewLength >= 0x1000000)
|
|
|
|
{
|
|
|
|
if (MaxViewLength > 0xFFFFFFFF) MaximumPerDiskViewLength = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
MaximumPerDiskViewLength = 0x1000000u;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-22 05:31:24 +00:00
|
|
|
PVOID
|
|
|
|
NTAPI
|
|
|
|
RamdiskMapPages(IN PRAMDISK_DRIVE_EXTENSION DeviceExtension,
|
|
|
|
IN LARGE_INTEGER Offset,
|
|
|
|
IN ULONG Length,
|
|
|
|
OUT PULONG OutputLength)
|
|
|
|
{
|
2008-07-22 06:21:11 +00:00
|
|
|
PHYSICAL_ADDRESS PhysicalAddress;
|
|
|
|
PVOID MappedBase;
|
2008-07-22 06:40:00 +00:00
|
|
|
ULONG PageOffset;
|
2008-07-22 06:21:11 +00:00
|
|
|
SIZE_T ActualLength;
|
|
|
|
LARGE_INTEGER ActualOffset;
|
|
|
|
LARGE_INTEGER ActualPages;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* We only support boot disks for now */
|
2008-07-22 06:21:11 +00:00
|
|
|
ASSERT(DeviceExtension->DiskType == RAMDISK_BOOT_DISK);
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Calculate the actual offset in the drive */
|
2008-07-22 06:21:11 +00:00
|
|
|
ActualOffset.QuadPart = DeviceExtension->DiskOffset + Offset.QuadPart;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Convert to pages */
|
2008-07-22 06:46:09 +00:00
|
|
|
ActualPages.QuadPart = ActualOffset.QuadPart >> PAGE_SHIFT;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Now add the base page */
|
2008-07-22 06:40:00 +00:00
|
|
|
ActualPages.QuadPart = DeviceExtension->BasePage + ActualPages.QuadPart;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Calculate final amount of bytes */
|
2008-07-22 06:21:11 +00:00
|
|
|
PhysicalAddress.QuadPart = ActualPages.QuadPart << PAGE_SHIFT;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Calculate pages spanned for the mapping */
|
2008-07-22 06:54:25 +00:00
|
|
|
ActualLength = ADDRESS_AND_SIZE_TO_SPAN_PAGES(ActualOffset.QuadPart, Length);
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* And convert this back to bytes */
|
2008-07-22 06:21:11 +00:00
|
|
|
ActualLength <<= PAGE_SHIFT;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Get the offset within the page */
|
2008-07-22 06:40:00 +00:00
|
|
|
PageOffset = BYTE_OFFSET(ActualOffset.QuadPart);
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Map the I/O Space from the loader */
|
2008-07-22 06:21:11 +00:00
|
|
|
MappedBase = MmMapIoSpace(PhysicalAddress, ActualLength, MmCached);
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Return actual offset within the page as well as the length */
|
2008-07-22 06:40:00 +00:00
|
|
|
if (MappedBase) MappedBase = (PVOID)((ULONG_PTR)MappedBase + PageOffset);
|
|
|
|
*OutputLength = Length;
|
2008-07-22 06:31:31 +00:00
|
|
|
return MappedBase;
|
2008-07-22 05:31:24 +00:00
|
|
|
}
|
|
|
|
|
2008-07-22 06:54:25 +00:00
|
|
|
VOID
|
2008-07-22 05:31:24 +00:00
|
|
|
NTAPI
|
|
|
|
RamdiskUnmapPages(IN PRAMDISK_DRIVE_EXTENSION DeviceExtension,
|
|
|
|
IN PVOID BaseAddress,
|
|
|
|
IN LARGE_INTEGER Offset,
|
|
|
|
IN ULONG Length)
|
|
|
|
{
|
2008-07-22 06:54:25 +00:00
|
|
|
LARGE_INTEGER ActualOffset;
|
|
|
|
SIZE_T ActualLength;
|
|
|
|
ULONG PageOffset;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* We only support boot disks for now */
|
2008-07-22 06:54:25 +00:00
|
|
|
ASSERT(DeviceExtension->DiskType == RAMDISK_BOOT_DISK);
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Calculate the actual offset in the drive */
|
2008-07-22 06:54:25 +00:00
|
|
|
ActualOffset.QuadPart = DeviceExtension->DiskOffset + Offset.QuadPart;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Calculate pages spanned for the mapping */
|
2008-07-22 06:54:25 +00:00
|
|
|
ActualLength = ADDRESS_AND_SIZE_TO_SPAN_PAGES(ActualOffset.QuadPart, Length);
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* And convert this back to bytes */
|
2008-07-22 06:54:25 +00:00
|
|
|
ActualLength <<= PAGE_SHIFT;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Get the offset within the page */
|
2008-07-22 06:54:25 +00:00
|
|
|
PageOffset = BYTE_OFFSET(ActualOffset.QuadPart);
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Calculate actual base address where we mapped this */
|
2008-07-22 06:54:25 +00:00
|
|
|
BaseAddress = (PVOID)((ULONG_PTR)BaseAddress - PageOffset);
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Unmap the I/O space we got from the loader */
|
2008-07-22 06:54:25 +00:00
|
|
|
MmUnmapIoSpace(BaseAddress, ActualLength);
|
2008-07-22 05:31:24 +00:00
|
|
|
}
|
|
|
|
|
2008-07-13 07:37:36 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2008-07-19 18:44:31 +00:00
|
|
|
RamdiskCreateDiskDevice(IN PRAMDISK_BUS_EXTENSION DeviceExtension,
|
2014-12-29 09:06:58 +00:00
|
|
|
IN PRAMDISK_CREATE_INPUT Input,
|
|
|
|
IN BOOLEAN ValidateOnly,
|
|
|
|
OUT PRAMDISK_DRIVE_EXTENSION *NewDriveExtension)
|
2008-07-13 07:37:36 +00:00
|
|
|
{
|
2011-09-11 00:40:20 +00:00
|
|
|
ULONG BasePage, DiskType, Length;
|
|
|
|
//ULONG ViewCount;
|
2008-07-19 22:21:38 +00:00
|
|
|
NTSTATUS Status;
|
2008-07-19 22:42:18 +00:00
|
|
|
PDEVICE_OBJECT DeviceObject;
|
2008-07-19 22:21:38 +00:00
|
|
|
PRAMDISK_DRIVE_EXTENSION DriveExtension;
|
|
|
|
PVOID Buffer;
|
|
|
|
WCHAR LocalBuffer[16];
|
|
|
|
UNICODE_STRING SymbolicLinkName, DriveString, GuidString, DeviceName;
|
2008-07-22 06:31:31 +00:00
|
|
|
PPACKED_BOOT_SECTOR BootSector;
|
2008-07-22 07:12:05 +00:00
|
|
|
BIOS_PARAMETER_BLOCK BiosBlock;
|
2008-07-22 05:31:24 +00:00
|
|
|
ULONG BytesPerSector, SectorsPerTrack, Heads, BytesRead;
|
|
|
|
PVOID BaseAddress;
|
2008-07-22 08:52:18 +00:00
|
|
|
LARGE_INTEGER CurrentOffset, CylinderSize, DiskLength;
|
|
|
|
ULONG CylinderCount, SizeByCylinders;
|
2014-12-29 09:06:58 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Check if we're a boot RAM disk */
|
2014-12-29 09:06:58 +00:00
|
|
|
DiskType = Input->DiskType;
|
|
|
|
if (DiskType >= RAMDISK_BOOT_DISK)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Check if we're an ISO */
|
2014-12-29 09:06:58 +00:00
|
|
|
if (DiskType == RAMDISK_BOOT_DISK)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* NTLDR mounted us somewhere */
|
2014-12-29 09:06:58 +00:00
|
|
|
BasePage = Input->BasePage;
|
|
|
|
if (!BasePage) return STATUS_INVALID_PARAMETER;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Sanitize disk options */
|
2014-12-29 09:06:58 +00:00
|
|
|
Input->Options.Fixed = TRUE;
|
|
|
|
Input->Options.Readonly = Input->Options.ExportAsCd |
|
2015-01-09 18:26:17 +00:00
|
|
|
Input->Options.Readonly;
|
2014-12-29 09:06:58 +00:00
|
|
|
Input->Options.Hidden = FALSE;
|
|
|
|
Input->Options.NoDosDevice = FALSE;
|
|
|
|
Input->Options.NoDriveLetter = IsWinPEBoot ? TRUE : FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* The only other possibility is a WIM disk */
|
2014-12-29 09:06:58 +00:00
|
|
|
if (DiskType != RAMDISK_WIM_DISK)
|
2008-07-22 05:49:52 +00:00
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Fail */
|
2008-07-19 18:44:31 +00:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
2008-07-22 05:49:52 +00:00
|
|
|
}
|
2011-09-11 00:40:20 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Read the view count instead */
|
2015-01-09 14:09:34 +00:00
|
|
|
// ViewCount = Input->ViewCount;
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Sanitize disk options */
|
2014-12-29 09:06:58 +00:00
|
|
|
Input->Options.Hidden = FALSE;
|
|
|
|
Input->Options.NoDosDevice = FALSE;
|
|
|
|
Input->Options.Readonly = FALSE;
|
|
|
|
Input->Options.NoDriveLetter = TRUE;
|
|
|
|
Input->Options.Fixed = TRUE;
|
|
|
|
}
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Are we just validating and returning to the user? */
|
2014-12-29 09:06:58 +00:00
|
|
|
if (ValidateOnly) return STATUS_SUCCESS;
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Build the GUID string */
|
2008-07-19 22:21:38 +00:00
|
|
|
Status = RtlStringFromGUID(&Input->DiskGuid, &GuidString);
|
|
|
|
if (!(NT_SUCCESS(Status)) || !(GuidString.Buffer))
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Fail */
|
2008-07-19 22:21:38 +00:00
|
|
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
goto FailCreate;
|
|
|
|
}
|
2014-12-29 09:06:58 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Allocate our device name */
|
2008-07-19 22:21:38 +00:00
|
|
|
Length = GuidString.Length + 32;
|
2015-01-09 16:57:24 +00:00
|
|
|
Buffer = ExAllocatePoolWithTag(NonPagedPool, Length, 'dmaR');
|
2008-07-19 22:21:38 +00:00
|
|
|
if (!Buffer)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Fail */
|
2008-07-19 22:21:38 +00:00
|
|
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
goto FailCreate;
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Build the device name string */
|
2008-07-19 22:21:38 +00:00
|
|
|
DeviceName.Buffer = Buffer;
|
|
|
|
DeviceName.Length = Length - 2;
|
|
|
|
DeviceName.MaximumLength = Length;
|
|
|
|
wcsncpy(Buffer, L"\\Device\\Ramdisk", Length / sizeof(WCHAR));
|
|
|
|
wcsncat(Buffer, GuidString.Buffer, Length / sizeof(WCHAR));
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Create the drive device */
|
2008-07-19 22:21:38 +00:00
|
|
|
Status = IoCreateDevice(DeviceExtension->DeviceObject->DriverObject,
|
|
|
|
sizeof(RAMDISK_DRIVE_EXTENSION),
|
|
|
|
&DeviceName,
|
2008-07-22 05:31:24 +00:00
|
|
|
(Input->Options.ExportAsCd) ?
|
|
|
|
FILE_DEVICE_CD_ROM : FILE_DEVICE_DISK,
|
2008-07-20 06:32:23 +00:00
|
|
|
0,
|
2008-07-19 22:21:38 +00:00
|
|
|
0,
|
2008-07-19 22:42:18 +00:00
|
|
|
&DeviceObject);
|
2008-07-19 22:21:38 +00:00
|
|
|
if (!NT_SUCCESS(Status)) goto FailCreate;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Grab the drive extension */
|
2008-07-19 22:42:18 +00:00
|
|
|
DriveExtension = DeviceObject->DeviceExtension;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Check if we need a DOS device */
|
2008-07-19 22:21:38 +00:00
|
|
|
if (!Input->Options.NoDosDevice)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Build the symbolic link name */
|
2008-07-19 22:21:38 +00:00
|
|
|
SymbolicLinkName.MaximumLength = GuidString.Length + 36;
|
|
|
|
SymbolicLinkName.Length = GuidString.Length + 34;
|
|
|
|
Buffer = ExAllocatePoolWithTag(NonPagedPool,
|
|
|
|
SymbolicLinkName.MaximumLength,
|
2009-08-24 17:12:25 +00:00
|
|
|
'dmaR');
|
2008-07-19 22:21:38 +00:00
|
|
|
SymbolicLinkName.Buffer = Buffer;
|
|
|
|
if (Buffer)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Create it */
|
2008-07-19 22:21:38 +00:00
|
|
|
wcsncpy(Buffer,
|
|
|
|
L"\\GLOBAL??\\Ramdisk",
|
|
|
|
SymbolicLinkName.MaximumLength / sizeof(WCHAR));
|
|
|
|
wcsncat(Buffer,
|
|
|
|
GuidString.Buffer,
|
|
|
|
SymbolicLinkName.MaximumLength / sizeof(WCHAR));
|
|
|
|
Status = IoCreateSymbolicLink(&SymbolicLinkName, &DeviceName);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Nevermind... */
|
2008-07-19 22:21:38 +00:00
|
|
|
Input->Options.NoDosDevice = TRUE;
|
|
|
|
ExFreePool(Buffer);
|
|
|
|
SymbolicLinkName.Buffer = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* No DOS device */
|
2008-07-19 22:21:38 +00:00
|
|
|
Input->Options.NoDosDevice = TRUE;
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Is this an ISO boot ramdisk? */
|
2008-07-22 05:49:52 +00:00
|
|
|
if (Input->DiskType == RAMDISK_BOOT_DISK)
|
2008-07-19 22:21:38 +00:00
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Does it need a drive letter? */
|
2008-07-19 22:21:38 +00:00
|
|
|
if (!Input->Options.NoDriveLetter)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Build it and take over the existing symbolic link */
|
2008-07-19 22:21:38 +00:00
|
|
|
_snwprintf(LocalBuffer,
|
|
|
|
30,
|
|
|
|
L"\\DosDevices\\%wc:",
|
|
|
|
Input->DriveLetter);
|
|
|
|
RtlInitUnicodeString(&DriveString, LocalBuffer);
|
|
|
|
IoDeleteSymbolicLink(&DriveString);
|
|
|
|
IoCreateSymbolicLink(&DriveString, &DeviceName);
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Save the drive letter */
|
2008-07-19 22:21:38 +00:00
|
|
|
DriveExtension->DriveLetter = Input->DriveLetter;
|
|
|
|
}
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2008-07-19 22:21:38 +00:00
|
|
|
}
|
2014-12-29 09:06:58 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Setup the device object flags */
|
2008-07-19 22:42:18 +00:00
|
|
|
DeviceObject->Flags |= (DO_XIP | DO_POWER_PAGABLE | DO_DIRECT_IO);
|
|
|
|
DeviceObject->AlignmentRequirement = 1;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Build the drive FDO */
|
2008-07-19 22:42:18 +00:00
|
|
|
*NewDriveExtension = DriveExtension;
|
|
|
|
DriveExtension->Type = RamdiskDrive;
|
2008-07-22 08:52:18 +00:00
|
|
|
DiskLength = Input->DiskLength;
|
2014-12-29 09:06:58 +00:00
|
|
|
ExInitializeFastMutex(&DriveExtension->DiskListLock);
|
2015-01-09 16:57:24 +00:00
|
|
|
IoInitializeRemoveLock(&DriveExtension->RemoveLock, 'dmaR', 1, 0);
|
2008-07-19 22:42:18 +00:00
|
|
|
DriveExtension->DriveDeviceName = DeviceName;
|
|
|
|
DriveExtension->SymbolicLinkName = SymbolicLinkName;
|
|
|
|
DriveExtension->GuidString = GuidString;
|
|
|
|
DriveExtension->DiskGuid = Input->DiskGuid;
|
2014-12-29 09:06:58 +00:00
|
|
|
DriveExtension->PhysicalDeviceObject = DeviceObject;
|
2014-12-30 11:53:05 +00:00
|
|
|
DriveExtension->DeviceObject = RamdiskBusFdo;
|
2008-07-19 22:42:18 +00:00
|
|
|
DriveExtension->AttachedDevice = RamdiskBusFdo;
|
|
|
|
DriveExtension->DiskType = Input->DiskType;
|
|
|
|
DriveExtension->DiskOptions = Input->Options;
|
2008-07-22 08:52:18 +00:00
|
|
|
DriveExtension->DiskLength = DiskLength;
|
2008-07-19 22:42:18 +00:00
|
|
|
DriveExtension->DiskOffset = Input->DiskOffset;
|
2008-07-22 06:21:11 +00:00
|
|
|
DriveExtension->BasePage = Input->BasePage;
|
2008-07-22 08:52:18 +00:00
|
|
|
DriveExtension->BytesPerSector = 0;
|
|
|
|
DriveExtension->SectorsPerTrack = 0;
|
|
|
|
DriveExtension->NumberOfHeads = 0;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Make sure we don't free it later */
|
2008-07-19 22:42:18 +00:00
|
|
|
DeviceName.Buffer = NULL;
|
|
|
|
SymbolicLinkName.Buffer = NULL;
|
|
|
|
GuidString.Buffer = NULL;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Check if this is a boot disk, or a registry ram drive */
|
2008-07-22 05:31:24 +00:00
|
|
|
if (!(Input->Options.ExportAsCd) &&
|
2008-07-22 05:49:52 +00:00
|
|
|
(Input->DiskType == RAMDISK_BOOT_DISK))
|
2008-07-22 05:31:24 +00:00
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Not an ISO boot, but it's a boot FS -- map it to figure out the
|
|
|
|
* drive settings */
|
2008-07-22 05:31:24 +00:00
|
|
|
CurrentOffset.QuadPart = 0;
|
|
|
|
BaseAddress = RamdiskMapPages(DriveExtension,
|
|
|
|
CurrentOffset,
|
|
|
|
PAGE_SIZE,
|
|
|
|
&BytesRead);
|
|
|
|
if (BaseAddress)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Get the data */
|
2008-07-22 06:31:31 +00:00
|
|
|
BootSector = (PPACKED_BOOT_SECTOR)BaseAddress;
|
2008-07-22 07:12:05 +00:00
|
|
|
FatUnpackBios(&BiosBlock, &BootSector->PackedBpb);
|
|
|
|
BytesPerSector = BiosBlock.BytesPerSector;
|
|
|
|
SectorsPerTrack = BiosBlock.SectorsPerTrack;
|
|
|
|
Heads = BiosBlock.Heads;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Save it */
|
2008-07-22 05:31:24 +00:00
|
|
|
DriveExtension->BytesPerSector = BytesPerSector;
|
|
|
|
DriveExtension->SectorsPerTrack = SectorsPerTrack;
|
|
|
|
DriveExtension->NumberOfHeads = Heads;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Unmap now */
|
2008-07-22 05:31:24 +00:00
|
|
|
CurrentOffset.QuadPart = 0;
|
|
|
|
RamdiskUnmapPages(DriveExtension,
|
|
|
|
BaseAddress,
|
|
|
|
CurrentOffset,
|
|
|
|
BytesRead);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Fail */
|
2008-07-22 05:31:24 +00:00
|
|
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
goto FailCreate;
|
|
|
|
}
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Check if the drive settings haven't been set yet */
|
2008-07-22 05:31:24 +00:00
|
|
|
if ((DriveExtension->BytesPerSector == 0) ||
|
|
|
|
(DriveExtension->SectorsPerTrack == 0) ||
|
|
|
|
(DriveExtension->NumberOfHeads == 0))
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Check if this is a CD */
|
2008-07-22 05:31:24 +00:00
|
|
|
if (Input->Options.ExportAsCd)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Setup partition parameters default for ISO 9660 */
|
2008-07-22 05:31:24 +00:00
|
|
|
DriveExtension->BytesPerSector = 2048;
|
|
|
|
DriveExtension->SectorsPerTrack = 32;
|
|
|
|
DriveExtension->NumberOfHeads = 64;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Setup partition parameters default for FAT */
|
2008-07-22 05:31:24 +00:00
|
|
|
DriveExtension->BytesPerSector = 512;
|
|
|
|
DriveExtension->SectorsPerTrack = 128;
|
|
|
|
DriveExtension->NumberOfHeads = 16;
|
|
|
|
}
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Calculate the cylinder size */
|
2008-07-22 08:52:18 +00:00
|
|
|
CylinderSize.QuadPart = DriveExtension->BytesPerSector *
|
|
|
|
DriveExtension->SectorsPerTrack *
|
|
|
|
DriveExtension->NumberOfHeads;
|
|
|
|
CylinderCount = DiskLength.QuadPart / CylinderSize.QuadPart;
|
|
|
|
SizeByCylinders = CylinderSize.QuadPart * CylinderCount;
|
|
|
|
DriveExtension->Cylinders = CylinderCount;
|
|
|
|
if ((DiskLength.HighPart > 0) || (SizeByCylinders < DiskLength.LowPart))
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Align cylinder size up */
|
2008-07-22 08:52:18 +00:00
|
|
|
DriveExtension->Cylinders++;
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Acquire the disk lock */
|
2008-07-20 04:39:01 +00:00
|
|
|
KeEnterCriticalRegion();
|
|
|
|
ExAcquireFastMutex(&DeviceExtension->DiskListLock);
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Insert us */
|
2008-07-20 04:39:01 +00:00
|
|
|
InsertTailList(&DeviceExtension->DiskList, &DriveExtension->DiskList);
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Release the lock */
|
2008-07-20 04:39:01 +00:00
|
|
|
ExReleaseFastMutex(&DeviceExtension->DiskListLock);
|
|
|
|
KeLeaveCriticalRegion();
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Clear init flag */
|
2008-07-20 04:39:01 +00:00
|
|
|
DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2008-07-19 22:21:38 +00:00
|
|
|
FailCreate:
|
2013-01-08 00:35:26 +00:00
|
|
|
UNIMPLEMENTED_DBGBREAK();
|
2008-07-13 07:37:36 +00:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
RamdiskCreateRamdisk(IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp,
|
2014-12-29 09:06:58 +00:00
|
|
|
IN BOOLEAN ValidateOnly)
|
2008-07-13 07:37:36 +00:00
|
|
|
{
|
2014-12-29 09:06:58 +00:00
|
|
|
PRAMDISK_CREATE_INPUT Input;
|
|
|
|
ULONG Length;
|
|
|
|
PRAMDISK_BUS_EXTENSION DeviceExtension;
|
2015-01-09 14:09:34 +00:00
|
|
|
PRAMDISK_DRIVE_EXTENSION DriveExtension;
|
2014-12-29 09:06:58 +00:00
|
|
|
ULONG DiskType;
|
|
|
|
PWCHAR FileNameStart, FileNameEnd;
|
|
|
|
NTSTATUS Status;
|
|
|
|
PIO_STACK_LOCATION IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Get the device extension and our input data */
|
2014-12-29 09:06:58 +00:00
|
|
|
DeviceExtension = DeviceObject->DeviceExtension;
|
|
|
|
Length = IoStackLocation->Parameters.DeviceIoControl.InputBufferLength;
|
|
|
|
Input = (PRAMDISK_CREATE_INPUT)Irp->AssociatedIrp.SystemBuffer;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Validate input parameters */
|
2014-12-29 09:06:58 +00:00
|
|
|
if ((Length < sizeof(RAMDISK_CREATE_INPUT)) ||
|
2015-01-09 14:09:34 +00:00
|
|
|
(Input->Version != sizeof(RAMDISK_CREATE_INPUT)))
|
2014-12-29 09:06:58 +00:00
|
|
|
{
|
2015-01-09 14:09:34 +00:00
|
|
|
return STATUS_INVALID_PARAMETER;
|
2014-12-29 09:06:58 +00:00
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Validate the disk type */
|
2014-12-29 09:06:58 +00:00
|
|
|
DiskType = Input->DiskType;
|
|
|
|
if (DiskType == RAMDISK_WIM_DISK) return STATUS_INVALID_PARAMETER;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Look at the disk type */
|
2014-12-29 09:06:58 +00:00
|
|
|
if (DiskType == RAMDISK_BOOT_DISK)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* We only allow this as an early-init boot */
|
2015-01-09 14:09:34 +00:00
|
|
|
if (!KeLoaderBlock) return STATUS_INVALID_PARAMETER;
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Save command-line flags */
|
2015-01-09 14:09:34 +00:00
|
|
|
if (ExportBootDiskAsCd) Input->Options.ExportAsCd = TRUE;
|
|
|
|
if (IsWinPEBoot) Input->Options.NoDriveLetter = TRUE;
|
2014-12-29 09:06:58 +00:00
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Validate the disk type */
|
2014-12-29 09:06:58 +00:00
|
|
|
if ((Input->Options.ExportAsCd) && (DiskType != RAMDISK_BOOT_DISK))
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* If the type isn't CDFS, it has to at least be raw CD */
|
2015-01-09 14:09:34 +00:00
|
|
|
if (DiskType != RAMDISK_MEMORY_MAPPED_DISK) return STATUS_INVALID_PARAMETER;
|
2014-12-29 09:06:58 +00:00
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Check if this is an actual file */
|
2014-12-29 09:06:58 +00:00
|
|
|
if (DiskType <= RAMDISK_MEMORY_MAPPED_DISK)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Validate the file name */
|
2015-01-09 14:09:34 +00:00
|
|
|
FileNameStart = (PWCHAR)((ULONG_PTR)Input + Length);
|
|
|
|
FileNameEnd = Input->FileName + 1;
|
|
|
|
while ((FileNameEnd < FileNameStart) && *(FileNameEnd)) FileNameEnd++;
|
|
|
|
if (FileNameEnd == FileNameStart) return STATUS_INVALID_PARAMETER;
|
2014-12-29 09:06:58 +00:00
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Create the actual device */
|
2014-12-29 09:06:58 +00:00
|
|
|
Status = RamdiskCreateDiskDevice(DeviceExtension,
|
2015-01-09 14:09:34 +00:00
|
|
|
Input,
|
2014-12-29 09:06:58 +00:00
|
|
|
ValidateOnly,
|
|
|
|
&DriveExtension);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Invalidate and set success */
|
2015-01-09 14:09:34 +00:00
|
|
|
IoInvalidateDeviceRelations(DeviceExtension->PhysicalDeviceObject, 0);
|
|
|
|
Irp->IoStatus.Information = STATUS_SUCCESS;
|
2014-12-29 09:06:58 +00:00
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2018-09-15 21:08:30 +00:00
|
|
|
/* We are done */
|
2014-12-29 09:06:58 +00:00
|
|
|
return Status;
|
2008-07-13 07:37:36 +00:00
|
|
|
}
|
|
|
|
|
2012-03-04 18:32:07 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
RamdiskGetPartitionInfo(IN PIRP Irp,
|
|
|
|
IN PRAMDISK_DRIVE_EXTENSION DeviceExtension)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
PPARTITION_INFORMATION PartitionInfo;
|
|
|
|
PVOID BaseAddress;
|
|
|
|
LARGE_INTEGER Zero = {{0, 0}};
|
|
|
|
ULONG Length;
|
|
|
|
PIO_STACK_LOCATION IoStackLocation;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Validate the length */
|
2012-03-04 18:32:07 +00:00
|
|
|
IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
if (IoStackLocation->Parameters.DeviceIoControl.
|
|
|
|
OutputBufferLength < sizeof(PARTITION_INFORMATION))
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Invalid length */
|
2012-03-04 18:32:07 +00:00
|
|
|
Status = STATUS_BUFFER_TOO_SMALL;
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
return Status;
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Map the partition table */
|
2012-03-04 18:32:07 +00:00
|
|
|
BaseAddress = RamdiskMapPages(DeviceExtension, Zero, PAGE_SIZE, &Length);
|
|
|
|
if (!BaseAddress)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* No memory */
|
2012-03-04 18:32:07 +00:00
|
|
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
return Status;
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Fill out the information */
|
2012-03-04 18:32:07 +00:00
|
|
|
PartitionInfo = Irp->AssociatedIrp.SystemBuffer;
|
|
|
|
PartitionInfo->StartingOffset.QuadPart = DeviceExtension->BytesPerSector;
|
|
|
|
PartitionInfo->PartitionLength.QuadPart = DeviceExtension->BytesPerSector *
|
|
|
|
DeviceExtension->SectorsPerTrack *
|
|
|
|
DeviceExtension->NumberOfHeads *
|
|
|
|
DeviceExtension->Cylinders;
|
|
|
|
PartitionInfo->HiddenSectors = DeviceExtension->HiddenSectors;
|
|
|
|
PartitionInfo->PartitionNumber = 0;
|
|
|
|
PartitionInfo->PartitionType = *((PCHAR)BaseAddress + 450);
|
|
|
|
PartitionInfo->BootIndicator = (DeviceExtension->DiskType ==
|
|
|
|
RAMDISK_BOOT_DISK) ? TRUE: FALSE;
|
|
|
|
PartitionInfo->RecognizedPartition = IsRecognizedPartition(PartitionInfo->
|
|
|
|
PartitionType);
|
|
|
|
PartitionInfo->RewritePartition = FALSE;
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Unmap the partition table */
|
2012-03-04 18:32:07 +00:00
|
|
|
RamdiskUnmapPages(DeviceExtension, BaseAddress, Zero, Length);
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Done */
|
2012-03-04 18:32:07 +00:00
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
Irp->IoStatus.Information = sizeof(PARTITION_INFORMATION);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
RamdiskSetPartitionInfo(IN PIRP Irp,
|
|
|
|
IN PRAMDISK_DRIVE_EXTENSION DeviceExtension)
|
|
|
|
{
|
|
|
|
ULONG BytesRead;
|
|
|
|
NTSTATUS Status;
|
|
|
|
PVOID BaseAddress;
|
|
|
|
PIO_STACK_LOCATION Stack;
|
|
|
|
LARGE_INTEGER Zero = {{0, 0}};
|
|
|
|
PPARTITION_INFORMATION PartitionInfo;
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* First validate input */
|
2012-03-04 18:32:07 +00:00
|
|
|
Stack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
if (Stack->Parameters.DeviceIoControl.InputBufferLength < sizeof(PARTITION_INFORMATION))
|
|
|
|
{
|
|
|
|
Status = STATUS_INVALID_PARAMETER;
|
|
|
|
goto SetAndQuit;
|
|
|
|
}
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Map to get MBR */
|
2012-03-04 18:32:07 +00:00
|
|
|
BaseAddress = RamdiskMapPages(DeviceExtension, Zero, PAGE_SIZE, &BytesRead);
|
|
|
|
if (BaseAddress == NULL)
|
|
|
|
{
|
|
|
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
goto SetAndQuit;
|
|
|
|
}
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Set the new partition type on partition 0, field system indicator */
|
2012-03-04 18:32:07 +00:00
|
|
|
PartitionInfo = (PPARTITION_INFORMATION)Irp->AssociatedIrp.SystemBuffer;
|
|
|
|
*((PCHAR)BaseAddress + 450) = PartitionInfo->PartitionType;
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* And unmap */
|
2012-03-04 18:32:07 +00:00
|
|
|
RamdiskUnmapPages(DeviceExtension, BaseAddress, Zero, BytesRead);
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
|
|
|
|
SetAndQuit:
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2008-07-19 21:19:41 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
RamdiskWorkerThread(IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PVOID Context)
|
|
|
|
{
|
|
|
|
PRAMDISK_BUS_EXTENSION DeviceExtension;
|
|
|
|
NTSTATUS Status;
|
|
|
|
PIO_STACK_LOCATION IoStackLocation;
|
|
|
|
PIRP Irp = Context;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Get the stack location */
|
2008-07-19 21:19:41 +00:00
|
|
|
IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Free the work item */
|
2008-07-19 21:19:41 +00:00
|
|
|
IoFreeWorkItem(Irp->Tail.Overlay.DriverContext[0]);
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Grab the device extension and lock it */
|
2008-07-19 21:19:41 +00:00
|
|
|
DeviceExtension = DeviceObject->DeviceExtension;
|
|
|
|
Status = IoAcquireRemoveLock(&DeviceExtension->RemoveLock, Irp);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Discriminate by major code */
|
2008-07-19 21:19:41 +00:00
|
|
|
switch (IoStackLocation->MajorFunction)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Device control */
|
2008-07-19 21:19:41 +00:00
|
|
|
case IRP_MJ_DEVICE_CONTROL:
|
2015-01-09 14:09:34 +00:00
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Let's take a look at the IOCTL */
|
2008-07-19 21:19:41 +00:00
|
|
|
switch (IoStackLocation->Parameters.DeviceIoControl.IoControlCode)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Ramdisk create request */
|
2008-07-19 21:19:41 +00:00
|
|
|
case FSCTL_CREATE_RAM_DISK:
|
2015-01-09 14:09:34 +00:00
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* This time we'll do it for real */
|
2008-07-19 21:19:41 +00:00
|
|
|
Status = RamdiskCreateRamdisk(DeviceObject, Irp, FALSE);
|
|
|
|
break;
|
2015-01-09 14:09:34 +00:00
|
|
|
}
|
2012-03-04 18:32:07 +00:00
|
|
|
|
2015-01-09 14:09:34 +00:00
|
|
|
case IOCTL_DISK_SET_PARTITION_INFO:
|
|
|
|
{
|
2012-03-04 18:32:07 +00:00
|
|
|
Status = RamdiskSetPartitionInfo(Irp, (PRAMDISK_DRIVE_EXTENSION)DeviceExtension);
|
2008-07-19 21:19:41 +00:00
|
|
|
break;
|
2015-01-09 14:09:34 +00:00
|
|
|
}
|
2012-03-04 18:32:07 +00:00
|
|
|
|
2008-07-19 21:19:41 +00:00
|
|
|
case IOCTL_DISK_GET_DRIVE_LAYOUT:
|
2013-01-08 00:35:26 +00:00
|
|
|
UNIMPLEMENTED_DBGBREAK("Get drive layout request\n");
|
2008-07-19 21:19:41 +00:00
|
|
|
break;
|
2012-03-04 18:32:07 +00:00
|
|
|
|
2015-01-09 14:09:34 +00:00
|
|
|
case IOCTL_DISK_GET_PARTITION_INFO:
|
|
|
|
{
|
2012-03-04 18:32:07 +00:00
|
|
|
Status = RamdiskGetPartitionInfo(Irp, (PRAMDISK_DRIVE_EXTENSION)DeviceExtension);
|
2008-07-19 21:19:41 +00:00
|
|
|
break;
|
2015-01-09 14:09:34 +00:00
|
|
|
}
|
2012-03-04 18:32:07 +00:00
|
|
|
|
2008-07-19 21:19:41 +00:00
|
|
|
default:
|
2013-01-08 00:35:26 +00:00
|
|
|
UNIMPLEMENTED_DBGBREAK("Invalid request\n");
|
2008-07-19 21:19:41 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* We're here */
|
2008-07-19 21:19:41 +00:00
|
|
|
break;
|
2015-01-09 14:09:34 +00:00
|
|
|
}
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Read or write request */
|
2008-07-19 21:19:41 +00:00
|
|
|
case IRP_MJ_READ:
|
|
|
|
case IRP_MJ_WRITE:
|
2013-01-08 00:35:26 +00:00
|
|
|
UNIMPLEMENTED_DBGBREAK("Read/Write request\n");
|
2008-07-19 21:19:41 +00:00
|
|
|
break;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Internal request (SCSI?) */
|
2008-07-19 21:19:41 +00:00
|
|
|
case IRP_MJ_INTERNAL_DEVICE_CONTROL:
|
2013-01-08 00:35:26 +00:00
|
|
|
UNIMPLEMENTED_DBGBREAK("SCSI request\n");
|
2008-07-19 21:19:41 +00:00
|
|
|
break;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Flush request */
|
2008-07-19 21:19:41 +00:00
|
|
|
case IRP_MJ_FLUSH_BUFFERS:
|
2013-01-08 00:35:26 +00:00
|
|
|
UNIMPLEMENTED_DBGBREAK("Flush request\n");
|
2008-07-19 21:19:41 +00:00
|
|
|
break;
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Anything else */
|
2008-07-19 21:19:41 +00:00
|
|
|
default:
|
2015-01-09 16:57:24 +00:00
|
|
|
UNIMPLEMENTED_DBGBREAK("Invalid request: %lx\n",
|
|
|
|
IoStackLocation->MajorFunction);
|
2008-07-19 21:19:41 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Complete the I/O */
|
2008-07-19 21:19:41 +00:00
|
|
|
IoReleaseRemoveLock(&DeviceExtension->RemoveLock, Irp);
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
Irp->IoStatus.Information = 0;
|
2009-07-25 20:24:50 +00:00
|
|
|
IoCompleteRequest(Irp, IO_DISK_INCREMENT);
|
|
|
|
return;
|
2008-07-19 21:19:41 +00:00
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Fail the I/O */
|
2008-07-19 21:19:41 +00:00
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
Irp->IoStatus.Information = 0;
|
2009-07-25 20:24:50 +00:00
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2008-07-19 21:19:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
SendIrpToThread(IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
|
|
|
PIO_WORKITEM WorkItem;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Mark the IRP pending */
|
2008-07-19 21:19:41 +00:00
|
|
|
IoMarkIrpPending(Irp);
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Allocate a work item */
|
2008-07-19 21:19:41 +00:00
|
|
|
WorkItem = IoAllocateWorkItem(DeviceObject);
|
|
|
|
if (WorkItem)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Queue it up */
|
2008-07-19 21:19:41 +00:00
|
|
|
Irp->Tail.Overlay.DriverContext[0] = WorkItem;
|
|
|
|
IoQueueWorkItem(WorkItem, RamdiskWorkerThread, DelayedWorkQueue, Irp);
|
|
|
|
return STATUS_PENDING;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Fail */
|
2008-07-19 21:19:41 +00:00
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-21 06:35:39 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
RamdiskReadWriteReal(IN PIRP Irp,
|
|
|
|
IN PRAMDISK_DRIVE_EXTENSION DeviceExtension)
|
|
|
|
{
|
|
|
|
PMDL Mdl;
|
|
|
|
PVOID CurrentBase, SystemVa, BaseAddress;
|
|
|
|
PIO_STACK_LOCATION IoStackLocation;
|
|
|
|
LARGE_INTEGER CurrentOffset;
|
|
|
|
ULONG BytesRead, BytesLeft, CopyLength;
|
|
|
|
PVOID Source, Destination;
|
|
|
|
NTSTATUS Status;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Get the MDL and check if it's mapped */
|
2008-07-21 06:35:39 +00:00
|
|
|
Mdl = Irp->MdlAddress;
|
2008-07-22 09:32:02 +00:00
|
|
|
if (Mdl->MdlFlags & (MDL_MAPPED_TO_SYSTEM_VA | MDL_SOURCE_IS_NONPAGED_POOL))
|
2008-07-21 06:35:39 +00:00
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Use the mapped address */
|
2008-07-21 06:35:39 +00:00
|
|
|
SystemVa = Mdl->MappedSystemVa;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Map it ourselves */
|
2008-07-21 06:35:39 +00:00
|
|
|
SystemVa = MmMapLockedPagesSpecifyCache(Mdl,
|
|
|
|
0,
|
|
|
|
MmCached,
|
|
|
|
NULL,
|
2015-01-09 14:09:34 +00:00
|
|
|
0,
|
2008-07-21 06:35:39 +00:00
|
|
|
NormalPagePriority);
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Make sure we were able to map it */
|
2008-07-21 06:35:39 +00:00
|
|
|
CurrentBase = SystemVa;
|
|
|
|
if (!SystemVa) return STATUS_INSUFFICIENT_RESOURCES;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Initialize default */
|
2008-07-21 06:35:39 +00:00
|
|
|
Irp->IoStatus.Information = 0;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Get the I/O Stack Location and capture the data */
|
2008-07-21 06:35:39 +00:00
|
|
|
IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
CurrentOffset = IoStackLocation->Parameters.Read.ByteOffset;
|
|
|
|
BytesLeft = IoStackLocation->Parameters.Read.Length;
|
|
|
|
if (!BytesLeft) return STATUS_INVALID_PARAMETER;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Do the copy loop */
|
2008-07-21 06:35:39 +00:00
|
|
|
while (TRUE)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Map the pages */
|
2008-07-21 06:35:39 +00:00
|
|
|
BaseAddress = RamdiskMapPages(DeviceExtension,
|
|
|
|
CurrentOffset,
|
|
|
|
BytesLeft,
|
|
|
|
&BytesRead);
|
|
|
|
if (!BaseAddress) return STATUS_INSUFFICIENT_RESOURCES;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Update our lengths */
|
2008-07-21 06:35:39 +00:00
|
|
|
Irp->IoStatus.Information += BytesRead;
|
|
|
|
CopyLength = BytesRead;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Check if this was a read or write */
|
2008-07-21 06:35:39 +00:00
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
if (IoStackLocation->MajorFunction == IRP_MJ_READ)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Set our copy parameters */
|
2008-07-21 06:35:39 +00:00
|
|
|
Destination = CurrentBase;
|
|
|
|
Source = BaseAddress;
|
|
|
|
goto DoCopy;
|
|
|
|
}
|
|
|
|
else if (IoStackLocation->MajorFunction == IRP_MJ_WRITE)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Set our copy parameters */
|
2008-07-21 06:35:39 +00:00
|
|
|
Destination = BaseAddress;
|
|
|
|
Source = CurrentBase;
|
|
|
|
DoCopy:
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Copy the data */
|
2008-07-21 06:35:39 +00:00
|
|
|
RtlCopyMemory(Destination, Source, CopyLength);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Prepare us for failure */
|
2008-07-21 06:35:39 +00:00
|
|
|
BytesLeft = CopyLength;
|
|
|
|
Status = STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Unmap the pages */
|
|
|
|
RamdiskUnmapPages(DeviceExtension, BaseAddress, CurrentOffset, BytesRead);
|
|
|
|
|
|
|
|
/* Update offset and bytes left */
|
2008-07-21 06:35:39 +00:00
|
|
|
BytesLeft -= BytesRead;
|
|
|
|
CurrentOffset.QuadPart += BytesRead;
|
|
|
|
CurrentBase = (PVOID)((ULONG_PTR)CurrentBase + BytesRead);
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2018-09-15 21:08:30 +00:00
|
|
|
/* Check if we are done */
|
2008-07-21 06:35:39 +00:00
|
|
|
if (!BytesLeft) return Status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-19 21:19:41 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
RamdiskOpenClose(IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Complete the IRP */
|
2008-07-19 21:19:41 +00:00
|
|
|
Irp->IoStatus.Information = 1;
|
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
RamdiskReadWrite(IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
2008-07-21 06:35:39 +00:00
|
|
|
PRAMDISK_DRIVE_EXTENSION DeviceExtension;
|
2015-01-09 18:26:17 +00:00
|
|
|
// ULONG Length;
|
|
|
|
// LARGE_INTEGER ByteOffset;
|
2008-07-21 06:35:39 +00:00
|
|
|
PIO_STACK_LOCATION IoStackLocation;
|
|
|
|
NTSTATUS Status, ReturnStatus;
|
2011-09-11 00:40:20 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Get the device extension and make sure this isn't a bus */
|
2008-07-21 06:35:39 +00:00
|
|
|
DeviceExtension = DeviceObject->DeviceExtension;
|
|
|
|
if (DeviceExtension->Type == RamdiskBus)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Fail */
|
2008-07-21 06:35:39 +00:00
|
|
|
Status = STATUS_INVALID_DEVICE_REQUEST;
|
|
|
|
goto Complete;
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Capture parameters */
|
2008-07-21 06:35:39 +00:00
|
|
|
IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
|
2015-01-09 18:26:17 +00:00
|
|
|
// Length = IoStackLocation->Parameters.Read.Length;
|
|
|
|
// ByteOffset = IoStackLocation->Parameters.Read.ByteOffset;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* FIXME: Validate offset */
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* FIXME: Validate sector */
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Validate write */
|
2008-07-21 06:35:39 +00:00
|
|
|
if ((IoStackLocation->MajorFunction == IRP_MJ_WRITE) &&
|
|
|
|
(DeviceExtension->DiskOptions.Readonly))
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Fail, this is read-only */
|
2008-07-21 06:35:39 +00:00
|
|
|
Status = STATUS_MEDIA_WRITE_PROTECTED;
|
|
|
|
goto Complete;
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* See if we want to do this sync or async */
|
2008-07-22 05:49:52 +00:00
|
|
|
if (DeviceExtension->DiskType > RAMDISK_MEMORY_MAPPED_DISK)
|
2008-07-21 06:35:39 +00:00
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Do it sync */
|
2008-07-21 06:35:39 +00:00
|
|
|
Status = RamdiskReadWriteReal(Irp, DeviceExtension);
|
|
|
|
goto Complete;
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Queue it to the worker */
|
2008-07-21 06:35:39 +00:00
|
|
|
Status = SendIrpToThread(DeviceObject, Irp);
|
|
|
|
ReturnStatus = STATUS_PENDING;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Check if we're pending or not */
|
2008-07-21 06:35:39 +00:00
|
|
|
if (Status != STATUS_PENDING)
|
|
|
|
{
|
|
|
|
Complete:
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Complete the IRP */
|
2008-07-21 06:35:39 +00:00
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
IoCompleteRequest(Irp, IO_DISK_INCREMENT);
|
|
|
|
ReturnStatus = Status;
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Return to caller */
|
2008-07-21 06:35:39 +00:00
|
|
|
return ReturnStatus;
|
2008-07-19 21:19:41 +00:00
|
|
|
}
|
|
|
|
|
2008-06-29 02:58:05 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
RamdiskDeviceControl(IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
2008-07-13 07:37:36 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
PIO_STACK_LOCATION IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
|
2008-07-19 18:44:31 +00:00
|
|
|
PRAMDISK_BUS_EXTENSION DeviceExtension = DeviceObject->DeviceExtension;
|
2008-07-22 08:52:18 +00:00
|
|
|
PRAMDISK_DRIVE_EXTENSION DriveExtension = (PVOID)DeviceExtension;
|
2008-07-20 16:13:19 +00:00
|
|
|
ULONG Information;
|
2008-07-21 01:12:17 +00:00
|
|
|
PCDROM_TOC Toc;
|
2008-07-22 08:52:18 +00:00
|
|
|
PDISK_GEOMETRY DiskGeometry;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Grab the remove lock */
|
2008-07-13 07:37:36 +00:00
|
|
|
Status = IoAcquireRemoveLock(&DeviceExtension->RemoveLock, Irp);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Fail the IRP */
|
2008-07-13 07:37:36 +00:00
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return Status;
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Setup some defaults */
|
2008-07-20 16:13:19 +00:00
|
|
|
Status = STATUS_INVALID_DEVICE_REQUEST;
|
|
|
|
Information = 0;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Check if this is an bus device or the drive */
|
2008-07-19 18:44:31 +00:00
|
|
|
if (DeviceExtension->Type == RamdiskBus)
|
2008-07-13 07:37:36 +00:00
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Check what the request is */
|
2008-07-13 07:37:36 +00:00
|
|
|
switch (IoStackLocation->Parameters.DeviceIoControl.IoControlCode)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Request to create a ramdisk */
|
2008-07-13 07:37:36 +00:00
|
|
|
case FSCTL_CREATE_RAM_DISK:
|
2015-01-09 14:09:34 +00:00
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Do it */
|
2008-07-13 07:37:36 +00:00
|
|
|
Status = RamdiskCreateRamdisk(DeviceObject, Irp, TRUE);
|
|
|
|
if (!NT_SUCCESS(Status)) goto CompleteRequest;
|
|
|
|
break;
|
2015-01-09 14:09:34 +00:00
|
|
|
}
|
|
|
|
|
2008-07-13 07:37:36 +00:00
|
|
|
default:
|
2015-01-09 14:09:34 +00:00
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* We don't handle anything else yet */
|
|
|
|
UNIMPLEMENTED_DBGBREAK("FSCTL: 0x%lx is UNSUPPORTED!\n",
|
|
|
|
IoStackLocation->Parameters.DeviceIoControl.IoControlCode);
|
2015-01-09 14:09:34 +00:00
|
|
|
}
|
2008-07-13 07:37:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Check what the request is */
|
2008-07-20 06:32:23 +00:00
|
|
|
switch (IoStackLocation->Parameters.DeviceIoControl.IoControlCode)
|
|
|
|
{
|
2008-07-20 16:13:19 +00:00
|
|
|
case IOCTL_DISK_CHECK_VERIFY:
|
|
|
|
case IOCTL_STORAGE_CHECK_VERIFY:
|
|
|
|
case IOCTL_STORAGE_CHECK_VERIFY2:
|
2008-07-20 06:32:23 +00:00
|
|
|
case IOCTL_CDROM_CHECK_VERIFY:
|
2015-01-09 14:09:34 +00:00
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Just pretend it's OK, don't do more */
|
2014-12-28 22:37:55 +00:00
|
|
|
Status = STATUS_SUCCESS;
|
2008-07-20 06:32:23 +00:00
|
|
|
break;
|
2015-01-09 14:09:34 +00:00
|
|
|
}
|
2008-07-20 16:13:19 +00:00
|
|
|
|
|
|
|
case IOCTL_STORAGE_GET_MEDIA_TYPES:
|
|
|
|
case IOCTL_DISK_GET_MEDIA_TYPES:
|
|
|
|
case IOCTL_DISK_GET_DRIVE_GEOMETRY:
|
2008-07-20 06:32:23 +00:00
|
|
|
case IOCTL_CDROM_GET_DRIVE_GEOMETRY:
|
2015-01-09 14:09:34 +00:00
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Validate the length */
|
2008-07-22 08:52:18 +00:00
|
|
|
if (IoStackLocation->Parameters.DeviceIoControl.
|
|
|
|
OutputBufferLength < sizeof(DISK_GEOMETRY))
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Invalid length */
|
2008-07-22 08:52:18 +00:00
|
|
|
Status = STATUS_BUFFER_TOO_SMALL;
|
|
|
|
break;
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Fill it out */
|
2008-07-22 08:52:18 +00:00
|
|
|
DiskGeometry = Irp->AssociatedIrp.SystemBuffer;
|
|
|
|
DiskGeometry->Cylinders.QuadPart = DriveExtension->Cylinders;
|
|
|
|
DiskGeometry->BytesPerSector = DriveExtension->BytesPerSector;
|
|
|
|
DiskGeometry->SectorsPerTrack = DriveExtension->SectorsPerTrack;
|
|
|
|
DiskGeometry->TracksPerCylinder = DriveExtension->NumberOfHeads;
|
|
|
|
DiskGeometry->MediaType = DriveExtension->DiskOptions.Fixed ?
|
|
|
|
FixedMedia : RemovableMedia;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2018-09-15 21:08:30 +00:00
|
|
|
/* We are done */
|
2008-07-22 08:52:18 +00:00
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
Information = sizeof(DISK_GEOMETRY);
|
2008-07-20 06:32:23 +00:00
|
|
|
break;
|
2015-01-09 14:09:34 +00:00
|
|
|
}
|
|
|
|
|
2008-07-20 06:32:23 +00:00
|
|
|
case IOCTL_CDROM_READ_TOC:
|
2015-01-09 14:09:34 +00:00
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Validate the length */
|
2008-07-21 01:12:17 +00:00
|
|
|
if (IoStackLocation->Parameters.DeviceIoControl.
|
|
|
|
OutputBufferLength < sizeof(CDROM_TOC))
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Invalid length */
|
2008-07-21 01:12:17 +00:00
|
|
|
Status = STATUS_BUFFER_TOO_SMALL;
|
|
|
|
break;
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Clear the TOC */
|
2008-07-21 01:12:17 +00:00
|
|
|
Toc = Irp->AssociatedIrp.SystemBuffer;
|
|
|
|
RtlZeroMemory(Toc, sizeof(CDROM_TOC));
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Fill it out */
|
2008-07-21 01:12:17 +00:00
|
|
|
Toc->Length[0] = 0;
|
|
|
|
Toc->Length[1] = RAMDISK_TOC_SIZE - sizeof(Toc->Length);
|
|
|
|
Toc->FirstTrack = 1;
|
|
|
|
Toc->LastTrack = 1;
|
|
|
|
Toc->TrackData[0].Adr = 1;
|
|
|
|
Toc->TrackData[0].Control = TOC_DATA_TRACK;
|
|
|
|
Toc->TrackData[0].TrackNumber = 1;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2018-09-15 21:08:30 +00:00
|
|
|
/* We are done */
|
2008-07-21 01:12:17 +00:00
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
Information = RAMDISK_TOC_SIZE;
|
2008-07-20 06:32:23 +00:00
|
|
|
break;
|
2015-01-09 14:09:34 +00:00
|
|
|
}
|
|
|
|
|
2008-07-20 16:13:19 +00:00
|
|
|
case IOCTL_DISK_SET_PARTITION_INFO:
|
2015-01-09 14:09:34 +00:00
|
|
|
{
|
2012-03-04 18:32:07 +00:00
|
|
|
Status = RamdiskSetPartitionInfo(Irp, DriveExtension);
|
2008-07-20 16:13:19 +00:00
|
|
|
break;
|
2015-01-09 14:09:34 +00:00
|
|
|
}
|
|
|
|
|
2008-07-20 16:13:19 +00:00
|
|
|
case IOCTL_DISK_GET_PARTITION_INFO:
|
2015-01-09 14:09:34 +00:00
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Validate the length */
|
2008-07-22 08:52:18 +00:00
|
|
|
if (IoStackLocation->Parameters.DeviceIoControl.
|
|
|
|
OutputBufferLength < sizeof(PARTITION_INFORMATION))
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Invalid length */
|
2008-07-22 08:52:18 +00:00
|
|
|
Status = STATUS_BUFFER_TOO_SMALL;
|
|
|
|
break;
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Check if we need to do this sync or async */
|
2008-07-22 08:52:18 +00:00
|
|
|
if (DriveExtension->DiskType > RAMDISK_MEMORY_MAPPED_DISK)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Call the helper function */
|
2008-07-22 08:52:18 +00:00
|
|
|
Status = RamdiskGetPartitionInfo(Irp, DriveExtension);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Do it asynchronously later */
|
2008-07-22 08:52:18 +00:00
|
|
|
goto CallWorker;
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2018-09-15 21:08:30 +00:00
|
|
|
/* We are done */
|
2008-07-22 08:52:18 +00:00
|
|
|
Information = Irp->IoStatus.Information;
|
2008-07-20 16:13:19 +00:00
|
|
|
break;
|
2015-01-09 14:09:34 +00:00
|
|
|
}
|
|
|
|
|
2008-07-20 16:13:19 +00:00
|
|
|
case IOCTL_DISK_GET_LENGTH_INFO:
|
2018-09-15 21:08:30 +00:00
|
|
|
{
|
|
|
|
PGET_LENGTH_INFORMATION LengthInformation = Irp->AssociatedIrp.SystemBuffer;
|
|
|
|
|
|
|
|
/* Validate the length */
|
|
|
|
if (IoStackLocation->Parameters.DeviceIoControl.OutputBufferLength < sizeof(GET_LENGTH_INFORMATION))
|
|
|
|
{
|
|
|
|
/* Invalid length */
|
|
|
|
Status = STATUS_BUFFER_TOO_SMALL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fill it out */
|
|
|
|
LengthInformation->Length = DriveExtension->DiskLength;
|
|
|
|
|
|
|
|
/* We are done */
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
Information = sizeof(GET_LENGTH_INFORMATION);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case IOCTL_VOLUME_GET_GPT_ATTRIBUTES:
|
|
|
|
{
|
|
|
|
PVOLUME_GET_GPT_ATTRIBUTES_INFORMATION GptInformation;
|
|
|
|
|
|
|
|
/* Validate the length */
|
|
|
|
if (IoStackLocation->Parameters.DeviceIoControl.OutputBufferLength < sizeof(VOLUME_GET_GPT_ATTRIBUTES_INFORMATION))
|
|
|
|
{
|
|
|
|
/* Invalid length */
|
|
|
|
Status = STATUS_BUFFER_TOO_SMALL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fill it out */
|
|
|
|
GptInformation = Irp->AssociatedIrp.SystemBuffer;
|
|
|
|
GptInformation->GptAttributes = 0;
|
|
|
|
|
|
|
|
/* Translate the Attributes */
|
|
|
|
if (DriveExtension->DiskOptions.Readonly)
|
|
|
|
GptInformation->GptAttributes |= GPT_BASIC_DATA_ATTRIBUTE_READ_ONLY;
|
|
|
|
if (DriveExtension->DiskOptions.Hidden)
|
|
|
|
GptInformation->GptAttributes |= GPT_BASIC_DATA_ATTRIBUTE_HIDDEN;
|
|
|
|
if (DriveExtension->DiskOptions.NoDriveLetter)
|
|
|
|
GptInformation->GptAttributes |= GPT_BASIC_DATA_ATTRIBUTE_NO_DRIVE_LETTER;
|
|
|
|
|
|
|
|
/* We are done */
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
Information = sizeof(VOLUME_GET_GPT_ATTRIBUTES_INFORMATION);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case IOCTL_DISK_GET_DRIVE_LAYOUT:
|
2008-07-20 16:13:19 +00:00
|
|
|
case IOCTL_DISK_IS_WRITABLE:
|
|
|
|
case IOCTL_SCSI_MINIPORT:
|
|
|
|
case IOCTL_STORAGE_QUERY_PROPERTY:
|
|
|
|
case IOCTL_MOUNTDEV_QUERY_UNIQUE_ID:
|
|
|
|
case IOCTL_MOUNTDEV_QUERY_STABLE_GUID:
|
|
|
|
case IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS:
|
|
|
|
case IOCTL_VOLUME_SET_GPT_ATTRIBUTES:
|
|
|
|
case IOCTL_VOLUME_OFFLINE:
|
2015-01-09 14:09:34 +00:00
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
UNIMPLEMENTED_DBGBREAK("IOCTL: 0x%lx is UNIMPLEMENTED!\n",
|
|
|
|
IoStackLocation->Parameters.DeviceIoControl.IoControlCode);
|
2008-07-20 16:13:19 +00:00
|
|
|
break;
|
2015-01-09 14:09:34 +00:00
|
|
|
}
|
|
|
|
|
2008-07-20 06:32:23 +00:00
|
|
|
default:
|
2015-01-09 14:09:34 +00:00
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Drive code not emulated */
|
|
|
|
DPRINT1("IOCTL: 0x%lx is UNSUPPORTED!\n",
|
|
|
|
IoStackLocation->Parameters.DeviceIoControl.IoControlCode);
|
2008-07-20 06:32:23 +00:00
|
|
|
break;
|
2015-01-09 14:09:34 +00:00
|
|
|
}
|
2008-07-20 06:32:23 +00:00
|
|
|
}
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* If requests drop down here, we just return them complete them */
|
2008-07-20 16:13:19 +00:00
|
|
|
goto CompleteRequest;
|
2008-07-13 07:37:36 +00:00
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Queue the request to our worker thread */
|
2008-07-22 08:52:18 +00:00
|
|
|
CallWorker:
|
2008-07-19 18:44:31 +00:00
|
|
|
Status = SendIrpToThread(DeviceObject, Irp);
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2008-07-13 07:37:36 +00:00
|
|
|
CompleteRequest:
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Release the lock */
|
2008-07-13 07:37:36 +00:00
|
|
|
IoReleaseRemoveLock(&DeviceExtension->RemoveLock, Irp);
|
|
|
|
if (Status != STATUS_PENDING)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Complete the request */
|
2008-07-13 07:37:36 +00:00
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
Irp->IoStatus.Information = Information;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Return status */
|
2008-07-13 07:37:36 +00:00
|
|
|
return Status;
|
2008-06-29 02:58:05 +00:00
|
|
|
}
|
|
|
|
|
2008-07-19 18:44:31 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
RamdiskQueryDeviceRelations(IN DEVICE_RELATION_TYPE Type,
|
|
|
|
IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
|
|
|
PRAMDISK_BUS_EXTENSION DeviceExtension;
|
|
|
|
PRAMDISK_DRIVE_EXTENSION DriveExtension;
|
|
|
|
PDEVICE_RELATIONS DeviceRelations, OurDeviceRelations;
|
|
|
|
ULONG Count, DiskCount, FinalCount;
|
|
|
|
PLIST_ENTRY ListHead, NextEntry;
|
|
|
|
PDEVICE_OBJECT* DriveDeviceObject;
|
|
|
|
RAMDISK_DEVICE_STATE State;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Get the device extension and check if this is a drive */
|
2008-07-19 18:44:31 +00:00
|
|
|
DeviceExtension = DeviceObject->DeviceExtension;
|
|
|
|
if (DeviceExtension->Type == RamdiskDrive)
|
|
|
|
{
|
2014-12-29 23:14:42 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
PDEVICE_RELATIONS DeviceRelations;
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* We're a child device, only handle target device relations */
|
2014-12-29 23:14:42 +00:00
|
|
|
if (Type != TargetDeviceRelation)
|
|
|
|
{
|
|
|
|
Status = Irp->IoStatus.Status;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Allocate a buffer big enough to contain only one DO */
|
|
|
|
DeviceRelations = ExAllocatePoolWithTag(PagedPool,
|
2015-01-09 18:26:17 +00:00
|
|
|
sizeof(*DeviceRelations),
|
2015-01-09 16:57:24 +00:00
|
|
|
'dmaR');
|
2014-12-29 23:14:42 +00:00
|
|
|
if (DeviceRelations != NULL)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Reference the DO and add it to the buffer */
|
2014-12-29 23:14:42 +00:00
|
|
|
ObReferenceObject(DeviceObject);
|
|
|
|
DeviceRelations->Objects[0] = DeviceObject;
|
|
|
|
DeviceRelations->Count = 1;
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Return our processing & complete */
|
2014-12-29 23:14:42 +00:00
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations;
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return Status;
|
2008-07-19 18:44:31 +00:00
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* We don't handle anything but bus relations */
|
2014-12-29 09:07:01 +00:00
|
|
|
if (Type != BusRelations) goto PassToNext;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Acquire the disk list lock */
|
2008-07-19 18:44:31 +00:00
|
|
|
KeEnterCriticalRegion();
|
|
|
|
ExAcquireFastMutex(&DeviceExtension->DiskListLock);
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Did a device already fill relations? */
|
2008-07-19 18:44:31 +00:00
|
|
|
DeviceRelations = (PDEVICE_RELATIONS)Irp->IoStatus.Information;
|
|
|
|
if (DeviceRelations)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Use the data */
|
2008-07-19 18:44:31 +00:00
|
|
|
Count = DeviceRelations->Count;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* We're the first */
|
2008-07-19 18:44:31 +00:00
|
|
|
Count = 0;
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Now loop our drives */
|
2008-07-19 18:44:31 +00:00
|
|
|
DiskCount = 0;
|
|
|
|
ListHead = &DeviceExtension->DiskList;
|
|
|
|
NextEntry = ListHead->Flink;
|
|
|
|
while (NextEntry != ListHead)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* As long as it wasn't removed, count it in */
|
2008-07-19 18:44:31 +00:00
|
|
|
DriveExtension = CONTAINING_RECORD(NextEntry,
|
|
|
|
RAMDISK_DRIVE_EXTENSION,
|
|
|
|
DiskList);
|
|
|
|
if (DriveExtension->State < RamdiskStateBusRemoved) DiskCount++;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Move to the next one */
|
2008-07-19 18:44:31 +00:00
|
|
|
NextEntry = NextEntry->Flink;
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Now we know our final count */
|
2008-07-19 18:44:31 +00:00
|
|
|
FinalCount = Count + DiskCount;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Allocate the structure */
|
2008-07-19 18:44:31 +00:00
|
|
|
OurDeviceRelations = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
FIELD_OFFSET(DEVICE_RELATIONS,
|
|
|
|
Objects) +
|
|
|
|
FinalCount *
|
|
|
|
sizeof(PDEVICE_OBJECT),
|
2009-08-24 17:12:25 +00:00
|
|
|
'dmaR');
|
2008-07-19 18:44:31 +00:00
|
|
|
if (!OurDeviceRelations)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Fail */
|
2008-07-19 18:44:31 +00:00
|
|
|
ExReleaseFastMutex(&DeviceExtension->DiskListLock);
|
|
|
|
KeLeaveCriticalRegion();
|
|
|
|
Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Check if we already had some relations */
|
2008-07-19 18:44:31 +00:00
|
|
|
if (Count)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Copy them in */
|
2008-07-19 18:44:31 +00:00
|
|
|
RtlCopyMemory(OurDeviceRelations->Objects,
|
|
|
|
DeviceRelations->Objects,
|
|
|
|
Count * sizeof(PDEVICE_OBJECT));
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Save the count */
|
2008-07-19 20:57:31 +00:00
|
|
|
OurDeviceRelations->Count = FinalCount;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Now loop our drives again */
|
2008-07-19 18:44:31 +00:00
|
|
|
ListHead = &DeviceExtension->DiskList;
|
|
|
|
NextEntry = ListHead->Flink;
|
|
|
|
while (NextEntry != ListHead)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Go to the end of the list */
|
2008-07-19 18:44:31 +00:00
|
|
|
DriveDeviceObject = &OurDeviceRelations->Objects[Count];
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Get the drive state */
|
2008-07-19 18:44:31 +00:00
|
|
|
DriveExtension = CONTAINING_RECORD(NextEntry,
|
|
|
|
RAMDISK_DRIVE_EXTENSION,
|
|
|
|
DiskList);
|
|
|
|
State = DriveExtension->State;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* If it was removed or enumerated, we don't touch the device object */
|
2008-07-19 18:44:31 +00:00
|
|
|
if (State >= RamdiskStateBusRemoved)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* If it was removed, we still have to keep track of this though */
|
2008-07-19 18:44:31 +00:00
|
|
|
if (State == RamdiskStateBusRemoved)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Mark it as enumerated now, but don't actually reference it */
|
2008-07-19 18:44:31 +00:00
|
|
|
DriveExtension->State = RamdiskStateEnumerated;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* First time it's enumerated, reference the device object */
|
2008-07-19 18:44:31 +00:00
|
|
|
ObReferenceObject(DriveExtension->DeviceObject);
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Save the object pointer and move on */
|
2014-12-30 11:53:05 +00:00
|
|
|
*DriveDeviceObject++ = DriveExtension->PhysicalDeviceObject;
|
2008-07-19 18:44:31 +00:00
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2008-07-19 18:44:31 +00:00
|
|
|
if (DriveExtension->State < RamdiskStateBusRemoved) DiskCount++;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Move to the next one */
|
2008-07-19 18:44:31 +00:00
|
|
|
NextEntry = NextEntry->Flink;
|
|
|
|
}
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Release the lock */
|
2008-07-19 18:44:31 +00:00
|
|
|
ExReleaseFastMutex(&DeviceExtension->DiskListLock);
|
|
|
|
KeLeaveCriticalRegion();
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Cleanup old relations */
|
2008-07-19 18:44:31 +00:00
|
|
|
if (DeviceRelations) ExFreePool(DeviceRelations);
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Complete our IRP */
|
2008-07-19 18:44:31 +00:00
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)OurDeviceRelations;
|
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Pass to the next driver */
|
2008-07-19 18:44:31 +00:00
|
|
|
PassToNext:
|
|
|
|
IoCopyCurrentIrpStackLocationToNext(Irp);
|
2015-01-09 14:09:34 +00:00
|
|
|
return IoCallDriver(DeviceExtension->AttachedDevice, Irp);
|
2008-07-19 18:44:31 +00:00
|
|
|
}
|
|
|
|
|
2012-03-04 23:08:33 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
RamdiskDeleteDiskDevice(IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
2013-01-08 00:35:26 +00:00
|
|
|
UNIMPLEMENTED_DBGBREAK();
|
2012-03-04 23:08:33 +00:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
RamdiskRemoveBusDevice(IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
PLIST_ENTRY ListHead, NextEntry;
|
|
|
|
PRAMDISK_BUS_EXTENSION DeviceExtension;
|
|
|
|
PRAMDISK_DRIVE_EXTENSION DriveExtension;
|
|
|
|
|
|
|
|
DeviceExtension = DeviceObject->DeviceExtension;
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Acquire disks list lock */
|
2012-03-04 23:08:33 +00:00
|
|
|
KeEnterCriticalRegion();
|
|
|
|
ExAcquireFastMutex(&DeviceExtension->DiskListLock);
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Loop over drives */
|
2012-03-04 23:08:33 +00:00
|
|
|
ListHead = &DeviceExtension->DiskList;
|
|
|
|
NextEntry = ListHead->Flink;
|
|
|
|
while (NextEntry != ListHead)
|
|
|
|
{
|
|
|
|
DriveExtension = CONTAINING_RECORD(NextEntry,
|
|
|
|
RAMDISK_DRIVE_EXTENSION,
|
|
|
|
DiskList);
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Delete the disk */
|
2012-03-04 23:08:33 +00:00
|
|
|
IoAcquireRemoveLock(&DriveExtension->RemoveLock, NULL);
|
|
|
|
RamdiskDeleteDiskDevice(DriveExtension->PhysicalDeviceObject, NULL);
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* RamdiskDeleteDiskDevice releases list lock, so reacquire it */
|
2012-03-04 23:08:33 +00:00
|
|
|
KeEnterCriticalRegion();
|
|
|
|
ExAcquireFastMutex(&DeviceExtension->DiskListLock);
|
|
|
|
}
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Release disks list lock */
|
2012-03-04 23:08:33 +00:00
|
|
|
ExReleaseFastMutex(&DeviceExtension->DiskListLock);
|
|
|
|
KeLeaveCriticalRegion();
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Prepare to pass to the lower driver */
|
2012-03-04 23:08:33 +00:00
|
|
|
IoSkipCurrentIrpStackLocation(Irp);
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Here everything went fine */
|
2012-03-04 23:08:33 +00:00
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Call lower driver */
|
2012-03-04 23:08:33 +00:00
|
|
|
Status = IoCallDriver(DeviceExtension->AttachedDevice, Irp);
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Update state */
|
2012-03-04 23:08:33 +00:00
|
|
|
DeviceExtension->State = RamdiskStateBusRemoved;
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Release the lock and ensure that everyone has finished its job before
|
|
|
|
* we continue. The lock has been acquired by the dispatcher */
|
2012-03-04 23:08:33 +00:00
|
|
|
IoReleaseRemoveLockAndWait(&DeviceExtension->RemoveLock, Irp);
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* If there's a drive name */
|
2012-03-04 23:08:33 +00:00
|
|
|
if (DeviceExtension->DriveDeviceName.Buffer)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Inform it's going to be disabled and free the drive name */
|
2012-03-04 23:08:33 +00:00
|
|
|
IoSetDeviceInterfaceState(&DeviceExtension->DriveDeviceName, FALSE);
|
|
|
|
RtlFreeUnicodeString(&DeviceExtension->DriveDeviceName);
|
|
|
|
}
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Part from the stack, detach from lower device */
|
2012-03-04 23:08:33 +00:00
|
|
|
IoDetachDevice(DeviceExtension->AttachedDevice);
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Finally, delete device */
|
2012-03-04 23:08:33 +00:00
|
|
|
RamdiskBusFdo = NULL;
|
|
|
|
IoDeleteDevice(DeviceObject);
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Return status from lower driver */
|
2012-03-04 23:08:33 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2014-12-29 18:00:50 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
RamdiskQueryId(IN PRAMDISK_DRIVE_EXTENSION DriveExtension,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
PIO_STACK_LOCATION IoStackLocation;
|
|
|
|
PWSTR OutputString = NULL;
|
|
|
|
ULONG StringLength;
|
|
|
|
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Get what is being queried */
|
2014-12-29 18:00:50 +00:00
|
|
|
switch (IoStackLocation->Parameters.QueryId.IdType)
|
|
|
|
{
|
|
|
|
case BusQueryDeviceID:
|
2015-01-09 14:09:34 +00:00
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Allocate a buffer long enough to receive Ramdisk\RamDisk in any case
|
|
|
|
* In case we don't have RAMDISK_REGISTRY_DISK, we then need two more
|
|
|
|
* chars to store Ramdisk\RamVolume instead */
|
2014-12-29 18:00:50 +00:00
|
|
|
StringLength = 4 * (DriveExtension->DiskType != RAMDISK_REGISTRY_DISK) + sizeof(L"Ramdisk\\RamDisk");
|
|
|
|
OutputString = ExAllocatePoolWithTag(PagedPool, StringLength, 'dmaR');
|
|
|
|
if (OutputString == NULL)
|
|
|
|
{
|
|
|
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
wcsncpy(OutputString, L"Ramdisk\\", StringLength / sizeof(WCHAR));
|
|
|
|
if (DriveExtension->DiskType != RAMDISK_REGISTRY_DISK)
|
|
|
|
{
|
|
|
|
wcsncat(OutputString, L"RamVolume", StringLength / sizeof(WCHAR));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wcsncat(OutputString, L"RamDisk", StringLength / sizeof(WCHAR));
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2015-01-09 14:09:34 +00:00
|
|
|
}
|
2014-12-29 18:00:50 +00:00
|
|
|
|
|
|
|
case BusQueryHardwareIDs:
|
2015-01-09 14:09:34 +00:00
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Allocate a buffer long enough to receive Ramdisk\RamDisk in any case
|
|
|
|
* In case we don't have RAMDISK_REGISTRY_DISK, we then need two more
|
|
|
|
* chars to store Ramdisk\RamVolume instead
|
|
|
|
* We also need an extra char, because it is required that the string
|
|
|
|
* is null-terminated twice */
|
2014-12-29 18:00:50 +00:00
|
|
|
StringLength = 4 * (DriveExtension->DiskType != RAMDISK_REGISTRY_DISK) +
|
|
|
|
sizeof(UNICODE_NULL) + sizeof(L"Ramdisk\\RamDisk");
|
|
|
|
OutputString = ExAllocatePoolWithTag(PagedPool, StringLength, 'dmaR');
|
|
|
|
if (OutputString == NULL)
|
|
|
|
{
|
|
|
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
wcsncpy(OutputString, L"Ramdisk\\", StringLength / sizeof(WCHAR));
|
|
|
|
if (DriveExtension->DiskType != RAMDISK_REGISTRY_DISK)
|
|
|
|
{
|
|
|
|
wcsncat(OutputString, L"RamVolume", StringLength / sizeof(WCHAR));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wcsncat(OutputString, L"RamDisk", StringLength / sizeof(WCHAR));
|
|
|
|
}
|
|
|
|
OutputString[(StringLength / sizeof(WCHAR)) - 1] = UNICODE_NULL;
|
|
|
|
|
|
|
|
break;
|
2015-01-09 14:09:34 +00:00
|
|
|
}
|
2014-12-29 18:00:50 +00:00
|
|
|
|
|
|
|
case BusQueryCompatibleIDs:
|
2015-01-09 14:09:34 +00:00
|
|
|
{
|
2014-12-29 18:00:50 +00:00
|
|
|
if (DriveExtension->DiskType != RAMDISK_REGISTRY_DISK)
|
|
|
|
{
|
|
|
|
Status = STATUS_INVALID_DEVICE_REQUEST;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
StringLength = sizeof(L"GenDisk");
|
|
|
|
OutputString = ExAllocatePoolWithTag(PagedPool, StringLength, 'dmaR');
|
|
|
|
if (OutputString == NULL)
|
|
|
|
{
|
|
|
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
wcsncpy(OutputString, L"GenDisk", StringLength / sizeof(WCHAR));
|
|
|
|
OutputString[(StringLength / sizeof(WCHAR)) - 1] = UNICODE_NULL;
|
|
|
|
|
|
|
|
break;
|
2015-01-09 14:09:34 +00:00
|
|
|
}
|
2014-12-29 18:00:50 +00:00
|
|
|
|
|
|
|
case BusQueryInstanceID:
|
2015-01-09 14:09:34 +00:00
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
OutputString = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
DriveExtension->GuidString.MaximumLength,
|
|
|
|
'dmaR');
|
2014-12-29 18:00:50 +00:00
|
|
|
if (OutputString == NULL)
|
|
|
|
{
|
|
|
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
wcsncpy(OutputString,
|
|
|
|
DriveExtension->GuidString.Buffer,
|
|
|
|
DriveExtension->GuidString.MaximumLength / sizeof(WCHAR));
|
2014-12-29 18:00:50 +00:00
|
|
|
|
|
|
|
break;
|
2015-01-09 14:09:34 +00:00
|
|
|
}
|
2014-12-29 18:00:50 +00:00
|
|
|
|
|
|
|
case BusQueryDeviceSerialNumber:
|
2015-01-09 14:09:34 +00:00
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Nothing to do */
|
2014-12-29 18:00:50 +00:00
|
|
|
break;
|
2015-01-09 14:09:34 +00:00
|
|
|
}
|
2014-12-29 18:00:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)OutputString;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2014-12-29 22:42:11 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
RamdiskQueryCapabilities(IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
PIO_STACK_LOCATION IoStackLocation;
|
|
|
|
PDEVICE_CAPABILITIES DeviceCapabilities;
|
|
|
|
PRAMDISK_DRIVE_EXTENSION DriveExtension;
|
|
|
|
|
|
|
|
IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
DeviceCapabilities = IoStackLocation->Parameters.DeviceCapabilities.Capabilities;
|
|
|
|
DriveExtension = DeviceObject->DeviceExtension;
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Validate our input buffer */
|
|
|
|
if (DeviceCapabilities->Version != 1 ||
|
|
|
|
DeviceCapabilities->Size < sizeof(DEVICE_CAPABILITIES))
|
2014-12-29 22:42:11 +00:00
|
|
|
{
|
|
|
|
Status = STATUS_UNSUCCESSFUL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* And set everything we know about our capabilities */
|
2014-12-29 22:42:11 +00:00
|
|
|
DeviceCapabilities->Removable = MarkRamdisksAsRemovable;
|
|
|
|
DeviceCapabilities->UniqueID = TRUE;
|
|
|
|
DeviceCapabilities->SilentInstall = TRUE;
|
|
|
|
DeviceCapabilities->RawDeviceOK = TRUE;
|
|
|
|
DeviceCapabilities->SurpriseRemovalOK = (DriveExtension->DiskType != RAMDISK_REGISTRY_DISK);
|
|
|
|
DeviceCapabilities->NoDisplayInUI = TRUE;
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
RamdiskQueryDeviceText(IN PRAMDISK_DRIVE_EXTENSION DriveExtension,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
|
|
|
PIO_STACK_LOCATION IoStackLocation;
|
|
|
|
DEVICE_TEXT_TYPE DeviceTextType;
|
|
|
|
PWSTR OutputString = NULL;
|
|
|
|
|
|
|
|
IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
DeviceTextType = IoStackLocation->Parameters.QueryDeviceText.DeviceTextType;
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Just copy our constants, according to the input */
|
2014-12-29 22:42:11 +00:00
|
|
|
switch (DeviceTextType)
|
|
|
|
{
|
|
|
|
case DeviceTextDescription:
|
2015-01-09 14:09:34 +00:00
|
|
|
{
|
2014-12-29 22:42:11 +00:00
|
|
|
OutputString = ExAllocatePoolWithTag(PagedPool, sizeof(L"RamDisk"), 'dmaR');
|
|
|
|
if (OutputString == NULL)
|
|
|
|
{
|
|
|
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
wcsncpy(OutputString, L"RamDisk", sizeof(L"RamDisk") / sizeof(WCHAR));
|
|
|
|
|
|
|
|
break;
|
2015-01-09 14:09:34 +00:00
|
|
|
}
|
2014-12-29 22:42:11 +00:00
|
|
|
|
|
|
|
case DeviceTextLocationInformation:
|
2015-01-09 14:09:34 +00:00
|
|
|
{
|
2014-12-29 22:42:11 +00:00
|
|
|
OutputString = ExAllocatePoolWithTag(PagedPool, sizeof(L"RamDisk\\0"), 'dmaR');
|
|
|
|
if (OutputString == NULL)
|
|
|
|
{
|
|
|
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
wcsncpy(OutputString, L"RamDisk\\0", sizeof(L"RamDisk\\0") / sizeof(WCHAR));
|
|
|
|
|
|
|
|
break;
|
2015-01-09 14:09:34 +00:00
|
|
|
}
|
2014-12-29 22:42:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)OutputString;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
RamdiskQueryBusInformation(IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
|
|
|
PPNP_BUS_INFORMATION PnpBusInfo;
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Allocate output memory */
|
2015-01-09 18:26:17 +00:00
|
|
|
PnpBusInfo = ExAllocatePoolWithTag(PagedPool, sizeof(*PnpBusInfo), 'dmaR');
|
2014-12-29 22:42:11 +00:00
|
|
|
if (PnpBusInfo == NULL)
|
|
|
|
{
|
|
|
|
Status = STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Copy our bus GUID and set our legacy type */
|
2014-12-29 22:42:11 +00:00
|
|
|
RtlCopyMemory(&PnpBusInfo->BusTypeGuid, &GUID_BUS_TYPE_RAMDISK, sizeof(GUID));
|
|
|
|
PnpBusInfo->LegacyBusType = PNPBus;
|
|
|
|
PnpBusInfo->BusNumber = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
Irp->IoStatus.Information = (ULONG_PTR)PnpBusInfo;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
RamdiskIoCompletionRoutine(IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp,
|
|
|
|
IN PVOID Context)
|
|
|
|
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Just set the event to unlock caller */
|
2014-12-29 22:42:11 +00:00
|
|
|
KeSetEvent((PKEVENT)Context, 0, FALSE);
|
|
|
|
|
|
|
|
return STATUS_MORE_PROCESSING_REQUIRED;
|
|
|
|
}
|
|
|
|
|
2008-06-29 02:58:05 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
RamdiskPnp(IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
2014-12-29 22:55:21 +00:00
|
|
|
PIO_STACK_LOCATION IoStackLocation;
|
2008-07-19 18:44:31 +00:00
|
|
|
PRAMDISK_BUS_EXTENSION DeviceExtension;
|
2008-07-13 07:02:48 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
UCHAR Minor;
|
2014-12-29 22:42:11 +00:00
|
|
|
KEVENT Event;
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Get the device extension and stack location */
|
2008-07-13 07:02:48 +00:00
|
|
|
DeviceExtension = DeviceObject->DeviceExtension;
|
|
|
|
IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
Minor = IoStackLocation->MinorFunction;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Check if the bus is removed */
|
2008-07-13 07:16:24 +00:00
|
|
|
if (DeviceExtension->State == RamdiskStateBusRemoved)
|
2008-07-13 07:02:48 +00:00
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Only remove-device and query-id are allowed */
|
2011-09-11 15:17:48 +00:00
|
|
|
if ((Minor != IRP_MN_REMOVE_DEVICE) && (Minor != IRP_MN_QUERY_ID))
|
2008-07-13 07:02:48 +00:00
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Fail anything else */
|
2008-07-13 07:02:48 +00:00
|
|
|
Status = STATUS_NO_SUCH_DEVICE;
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Acquire the remove lock */
|
2008-07-13 07:02:48 +00:00
|
|
|
Status = IoAcquireRemoveLock(&DeviceExtension->RemoveLock, Irp);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Fail the IRP */
|
2008-07-13 07:02:48 +00:00
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return Status;
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Query the IRP type */
|
2008-07-13 07:02:48 +00:00
|
|
|
switch (Minor)
|
|
|
|
{
|
|
|
|
case IRP_MN_START_DEVICE:
|
2015-01-09 14:09:34 +00:00
|
|
|
{
|
2014-12-29 22:42:11 +00:00
|
|
|
if (DeviceExtension->Type == RamdiskDrive)
|
|
|
|
{
|
|
|
|
ULONG ResultLength;
|
|
|
|
DEVICE_INSTALL_STATE InstallState;
|
|
|
|
PRAMDISK_DRIVE_EXTENSION DriveExtension = (PRAMDISK_DRIVE_EXTENSION)DeviceExtension;
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* If we already have a drive name, free it */
|
2014-12-29 22:42:11 +00:00
|
|
|
if (DriveExtension->DriveDeviceName.Buffer)
|
|
|
|
{
|
|
|
|
ExFreePool(DriveExtension->DriveDeviceName.Buffer);
|
|
|
|
}
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Register our device interface */
|
2014-12-29 22:42:11 +00:00
|
|
|
if (DriveExtension->DiskType != RAMDISK_REGISTRY_DISK)
|
|
|
|
{
|
|
|
|
Status = IoRegisterDeviceInterface(DeviceObject,
|
|
|
|
&GUID_DEVINTERFACE_VOLUME,
|
|
|
|
NULL,
|
|
|
|
&DriveExtension->DriveDeviceName);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Status = IoRegisterDeviceInterface(DeviceObject,
|
|
|
|
&RamdiskDiskInterface,
|
|
|
|
NULL,
|
|
|
|
&DriveExtension->DriveDeviceName);
|
|
|
|
}
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* If we were asked not to assign a drive letter or if getting
|
|
|
|
* a name failed, just return saying we're now started */
|
2014-12-29 22:42:11 +00:00
|
|
|
if (DriveExtension->DiskOptions.NoDriveLetter ||
|
|
|
|
DriveExtension->DriveDeviceName.Buffer == NULL)
|
|
|
|
{
|
|
|
|
DriveExtension->State = RamdiskStateStarted;
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Now get our installation state */
|
|
|
|
Status = IoGetDeviceProperty(DeviceObject,
|
|
|
|
DevicePropertyInstallState,
|
|
|
|
sizeof(InstallState),
|
|
|
|
&InstallState,
|
|
|
|
&ResultLength);
|
|
|
|
/* If querying the information failed, assume success */
|
2014-12-29 22:42:11 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
InstallState = InstallStateInstalled;
|
|
|
|
}
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* If we were properly installed, then, enable the interface */
|
2014-12-29 22:42:11 +00:00
|
|
|
if (InstallState == InstallStateInstalled)
|
|
|
|
{
|
|
|
|
Status = IoSetDeviceInterfaceState(&DriveExtension->DriveDeviceName, TRUE);
|
|
|
|
}
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* We're fine & up */
|
2014-12-29 22:42:11 +00:00
|
|
|
DriveExtension->State = RamdiskStateStarted;
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Prepare next stack to pass it down */
|
2014-12-29 22:55:21 +00:00
|
|
|
IoCopyCurrentIrpStackLocationToNext(Irp);
|
2014-12-29 22:42:11 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Initialize our notification event & our completion routine */
|
2014-12-29 22:42:11 +00:00
|
|
|
KeInitializeEvent(&Event, NotificationEvent, FALSE);
|
|
|
|
IoSetCompletionRoutine(Irp, RamdiskIoCompletionRoutine, &Event, TRUE, TRUE, TRUE);
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Call lower driver */
|
2014-12-29 22:42:11 +00:00
|
|
|
Status = IoCallDriver(DeviceExtension->AttachedDevice, Irp);
|
|
|
|
if (Status == STATUS_PENDING)
|
|
|
|
{
|
|
|
|
KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
|
|
|
|
Status = Irp->IoStatus.Status;
|
|
|
|
}
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* If it succeed to start then enable ourselves and we're up! */
|
2014-12-29 22:42:11 +00:00
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
Status = IoSetDeviceInterfaceState(&DeviceExtension->DriveDeviceName, TRUE);
|
|
|
|
DeviceExtension->State = RamdiskStateStarted;
|
|
|
|
}
|
|
|
|
|
|
|
|
Irp->IoStatus.Status = Status;
|
2008-07-13 07:02:48 +00:00
|
|
|
break;
|
2015-01-09 14:09:34 +00:00
|
|
|
}
|
|
|
|
|
2008-07-13 07:02:48 +00:00
|
|
|
case IRP_MN_QUERY_STOP_DEVICE:
|
|
|
|
case IRP_MN_CANCEL_STOP_DEVICE:
|
|
|
|
case IRP_MN_STOP_DEVICE:
|
|
|
|
case IRP_MN_QUERY_REMOVE_DEVICE:
|
|
|
|
case IRP_MN_CANCEL_REMOVE_DEVICE:
|
2015-01-09 14:09:34 +00:00
|
|
|
{
|
2013-01-08 00:35:26 +00:00
|
|
|
UNIMPLEMENTED_DBGBREAK("PnP IRP: %lx\n", Minor);
|
2008-07-13 07:02:48 +00:00
|
|
|
break;
|
2015-01-09 14:09:34 +00:00
|
|
|
}
|
2012-03-04 23:08:33 +00:00
|
|
|
|
2015-01-09 14:09:34 +00:00
|
|
|
case IRP_MN_REMOVE_DEVICE:
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Remove the proper device */
|
2012-03-04 23:08:33 +00:00
|
|
|
if (DeviceExtension->Type == RamdiskBus)
|
|
|
|
{
|
|
|
|
Status = RamdiskRemoveBusDevice(DeviceObject, Irp);
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Return here, lower device has already been called
|
|
|
|
* And remove lock released. This is needed by the function. */
|
2012-03-04 23:08:33 +00:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Status = RamdiskDeleteDiskDevice(DeviceObject, Irp);
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Complete the IRP here and return
|
|
|
|
* Here again we don't have to release remove lock
|
|
|
|
* This has already been done by the function. */
|
2012-03-04 23:08:33 +00:00
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return Status;
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
}
|
2008-07-13 07:16:24 +00:00
|
|
|
|
|
|
|
case IRP_MN_SURPRISE_REMOVAL:
|
2013-01-08 00:35:26 +00:00
|
|
|
UNIMPLEMENTED_DBGBREAK("PnP IRP: %lx\n", Minor);
|
2008-07-13 07:02:48 +00:00
|
|
|
break;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2008-07-13 07:16:24 +00:00
|
|
|
case IRP_MN_QUERY_ID:
|
2015-01-09 14:09:34 +00:00
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Are we a drive? */
|
2008-07-19 18:44:31 +00:00
|
|
|
if (DeviceExtension->Type == RamdiskDrive)
|
2008-07-13 07:16:24 +00:00
|
|
|
{
|
2014-12-29 18:00:50 +00:00
|
|
|
Status = RamdiskQueryId((PRAMDISK_DRIVE_EXTENSION)DeviceExtension, Irp);
|
2008-07-13 07:33:31 +00:00
|
|
|
}
|
2008-07-13 07:16:24 +00:00
|
|
|
break;
|
2015-01-09 14:09:34 +00:00
|
|
|
}
|
|
|
|
|
2008-07-13 07:02:48 +00:00
|
|
|
case IRP_MN_QUERY_BUS_INFORMATION:
|
2015-01-09 14:09:34 +00:00
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Are we a drive? */
|
2008-07-19 18:44:31 +00:00
|
|
|
if (DeviceExtension->Type == RamdiskDrive)
|
2008-07-13 07:33:31 +00:00
|
|
|
{
|
2014-12-29 22:42:11 +00:00
|
|
|
Status = RamdiskQueryBusInformation(DeviceObject, Irp);
|
2008-07-13 07:33:31 +00:00
|
|
|
}
|
2008-07-13 07:02:48 +00:00
|
|
|
break;
|
2015-01-09 14:09:34 +00:00
|
|
|
}
|
|
|
|
|
2008-07-13 07:02:48 +00:00
|
|
|
case IRP_MN_EJECT:
|
2013-01-08 00:35:26 +00:00
|
|
|
UNIMPLEMENTED_DBGBREAK("PnP IRP: %lx\n", Minor);
|
2008-07-13 07:02:48 +00:00
|
|
|
break;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2008-07-13 07:02:48 +00:00
|
|
|
case IRP_MN_QUERY_DEVICE_TEXT:
|
2015-01-09 14:09:34 +00:00
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Are we a drive? */
|
2008-07-19 18:44:31 +00:00
|
|
|
if (DeviceExtension->Type == RamdiskDrive)
|
2008-07-13 07:33:31 +00:00
|
|
|
{
|
2014-12-29 22:42:11 +00:00
|
|
|
Status = RamdiskQueryDeviceText((PRAMDISK_DRIVE_EXTENSION)DeviceExtension, Irp);
|
2008-07-13 07:33:31 +00:00
|
|
|
}
|
2008-07-13 07:02:48 +00:00
|
|
|
break;
|
2015-01-09 14:09:34 +00:00
|
|
|
}
|
2008-07-13 07:02:48 +00:00
|
|
|
|
2015-01-09 14:09:34 +00:00
|
|
|
case IRP_MN_QUERY_DEVICE_RELATIONS:
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Call our main routine */
|
2008-07-19 18:44:31 +00:00
|
|
|
Status = RamdiskQueryDeviceRelations(IoStackLocation->
|
|
|
|
Parameters.
|
|
|
|
QueryDeviceRelations.Type,
|
|
|
|
DeviceObject,
|
|
|
|
Irp);
|
|
|
|
goto ReleaseAndReturn;
|
2015-01-09 14:09:34 +00:00
|
|
|
}
|
|
|
|
|
2008-07-13 07:02:48 +00:00
|
|
|
case IRP_MN_QUERY_CAPABILITIES:
|
2015-01-09 14:09:34 +00:00
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Are we a drive? */
|
2008-07-19 18:44:31 +00:00
|
|
|
if (DeviceExtension->Type == RamdiskDrive)
|
2008-07-13 07:33:31 +00:00
|
|
|
{
|
2014-12-29 22:42:11 +00:00
|
|
|
Status = RamdiskQueryCapabilities(DeviceObject, Irp);
|
2008-07-13 07:33:31 +00:00
|
|
|
}
|
2008-07-13 07:02:48 +00:00
|
|
|
break;
|
2015-01-09 14:09:34 +00:00
|
|
|
}
|
|
|
|
|
2008-07-13 07:33:31 +00:00
|
|
|
case IRP_MN_QUERY_RESOURCES:
|
|
|
|
case IRP_MN_QUERY_RESOURCE_REQUIREMENTS:
|
2015-01-09 14:09:34 +00:00
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Complete immediately without touching it */
|
2008-07-13 07:33:31 +00:00
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
goto ReleaseAndReturn;
|
2015-01-09 14:09:34 +00:00
|
|
|
}
|
|
|
|
|
2008-07-13 07:02:48 +00:00
|
|
|
default:
|
|
|
|
DPRINT1("Illegal IRP: %lx\n", Minor);
|
|
|
|
break;
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Are we the bus? */
|
2008-07-19 18:44:31 +00:00
|
|
|
if (DeviceExtension->Type == RamdiskBus)
|
2008-07-13 07:16:24 +00:00
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Do we have an attached device? */
|
2008-07-13 07:16:24 +00:00
|
|
|
if (DeviceExtension->AttachedDevice)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Forward the IRP */
|
2008-07-13 07:16:24 +00:00
|
|
|
IoSkipCurrentIrpStackLocation(Irp);
|
|
|
|
Status = IoCallDriver(DeviceExtension->AttachedDevice, Irp);
|
|
|
|
}
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Release the lock and return status */
|
2008-07-13 07:33:31 +00:00
|
|
|
ReleaseAndReturn:
|
2008-07-13 07:02:48 +00:00
|
|
|
IoReleaseRemoveLock(&DeviceExtension->RemoveLock, Irp);
|
|
|
|
return Status;
|
2008-06-29 02:58:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
RamdiskPower(IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
2012-03-04 21:42:16 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
PIO_STACK_LOCATION IoStackLocation;
|
|
|
|
PRAMDISK_BUS_EXTENSION DeviceExtension;
|
|
|
|
|
|
|
|
DeviceExtension = DeviceObject->DeviceExtension;
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* If we have a device extension, take extra caution with the lower driver */
|
2012-03-04 21:42:16 +00:00
|
|
|
if (DeviceExtension != NULL)
|
|
|
|
{
|
|
|
|
PoStartNextPowerIrp(Irp);
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Device has not been removed yet, so pass to the attached/lower driver */
|
2012-03-04 21:42:16 +00:00
|
|
|
if (DeviceExtension->State < RamdiskStateBusRemoved)
|
|
|
|
{
|
|
|
|
IoSkipCurrentIrpStackLocation(Irp);
|
|
|
|
return PoCallDriver(DeviceExtension->AttachedDevice, Irp);
|
|
|
|
}
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Otherwise, simply complete the IRP notifying that deletion is pending */
|
2012-03-04 21:42:16 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
Irp->IoStatus.Status = STATUS_DELETE_PENDING;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_DELETE_PENDING;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Get stack and deal with minor functions */
|
2012-03-04 21:42:16 +00:00
|
|
|
IoStackLocation = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
switch (IoStackLocation->MinorFunction)
|
|
|
|
{
|
|
|
|
case IRP_MN_SET_POWER:
|
2015-01-09 14:09:34 +00:00
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* If setting device power state it's all fine and return success */
|
2012-03-04 21:42:16 +00:00
|
|
|
if (DevicePowerState)
|
|
|
|
{
|
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Get appropriate status for return */
|
2012-03-04 21:42:16 +00:00
|
|
|
Status = Irp->IoStatus.Status;
|
|
|
|
PoStartNextPowerIrp(Irp);
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
break;
|
2015-01-09 14:09:34 +00:00
|
|
|
}
|
2012-03-04 21:42:16 +00:00
|
|
|
|
|
|
|
case IRP_MN_QUERY_POWER:
|
2015-01-09 14:09:34 +00:00
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* We can obviously accept all states so just return success */
|
|
|
|
Status = Irp->IoStatus.Status = STATUS_SUCCESS;
|
2012-03-04 21:42:16 +00:00
|
|
|
PoStartNextPowerIrp(Irp);
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
break;
|
2015-01-09 14:09:34 +00:00
|
|
|
}
|
2012-03-04 21:42:16 +00:00
|
|
|
|
|
|
|
default:
|
2015-01-09 14:09:34 +00:00
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Just complete and save status for return */
|
2012-03-04 21:42:16 +00:00
|
|
|
Status = Irp->IoStatus.Status;
|
|
|
|
PoStartNextPowerIrp(Irp);
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
break;
|
2015-01-09 14:09:34 +00:00
|
|
|
}
|
2012-03-04 21:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
2008-06-29 02:58:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
RamdiskSystemControl(IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
2012-03-04 21:42:16 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
PRAMDISK_BUS_EXTENSION DeviceExtension;
|
|
|
|
|
|
|
|
DeviceExtension = DeviceObject->DeviceExtension;
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* If we have a device extension, forward the IRP to the attached device */
|
2012-03-04 21:42:16 +00:00
|
|
|
if (DeviceExtension != NULL)
|
|
|
|
{
|
|
|
|
IoSkipCurrentIrpStackLocation(Irp);
|
|
|
|
Status = IoCallDriver(DeviceExtension->AttachedDevice, Irp);
|
|
|
|
}
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Otherwise just complete the request
|
|
|
|
* And return the status with which we complete it */
|
2012-03-04 21:42:16 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
Status = Irp->IoStatus.Status;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
2008-06-29 02:58:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
RamdiskScsi(IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
2012-03-04 21:42:16 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
PRAMDISK_BUS_EXTENSION DeviceExtension;
|
|
|
|
|
|
|
|
DeviceExtension = DeviceObject->DeviceExtension;
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Having a proper device is mandatory */
|
2012-03-04 21:42:16 +00:00
|
|
|
if (DeviceExtension->State > RamdiskStateStopped)
|
|
|
|
{
|
|
|
|
Status = STATUS_DEVICE_DOES_NOT_EXIST;
|
|
|
|
goto CompleteIRP;
|
|
|
|
}
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Acquire the remove lock */
|
2012-03-04 21:42:16 +00:00
|
|
|
Status = IoAcquireRemoveLock(&DeviceExtension->RemoveLock, Irp);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
goto CompleteIRP;
|
|
|
|
}
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Queue the IRP for worker */
|
2012-03-04 21:42:16 +00:00
|
|
|
Status = SendIrpToThread(DeviceObject, Irp);
|
|
|
|
if (Status != STATUS_PENDING)
|
|
|
|
{
|
|
|
|
goto CompleteIRP;
|
|
|
|
}
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Release the remove lock */
|
2012-03-04 21:42:16 +00:00
|
|
|
IoReleaseRemoveLock(&DeviceExtension->RemoveLock, Irp);
|
|
|
|
goto Quit;
|
|
|
|
|
|
|
|
CompleteIRP:
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
|
|
|
|
Quit:
|
|
|
|
return Status;
|
2008-06-29 02:58:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
RamdiskFlushBuffers(IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
2012-03-04 19:48:09 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
PRAMDISK_DRIVE_EXTENSION DeviceExtension;
|
|
|
|
|
|
|
|
DeviceExtension = DeviceObject->DeviceExtension;
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Ensure we have drive extension
|
|
|
|
* Only perform flush on disks that have been created
|
|
|
|
* from registry entries */
|
2012-03-04 19:48:09 +00:00
|
|
|
if (DeviceExtension->Type != RamdiskDrive ||
|
|
|
|
DeviceExtension->DiskType > RAMDISK_MEMORY_MAPPED_DISK)
|
|
|
|
{
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Queue the IRP for worker */
|
2012-03-04 19:48:09 +00:00
|
|
|
Status = SendIrpToThread(DeviceObject, Irp);
|
|
|
|
if (Status != STATUS_PENDING)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Queuing failed - complete the IRP and return failure */
|
2012-03-04 19:48:09 +00:00
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
Irp->IoStatus.Status = Status;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
2008-06-29 02:58:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
NTAPI
|
|
|
|
RamdiskUnload(IN PDRIVER_OBJECT DriverObject)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Just release registry path if previously allocated */
|
2012-03-04 19:48:09 +00:00
|
|
|
if (DriverRegistryPath.Buffer)
|
|
|
|
{
|
|
|
|
ExFreePoolWithTag(DriverRegistryPath.Buffer, 'dmaR');
|
|
|
|
}
|
2008-06-29 02:58:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
2015-01-09 14:09:34 +00:00
|
|
|
RamdiskAddDevice(IN PDRIVER_OBJECT DriverObject,
|
2008-06-29 02:58:05 +00:00
|
|
|
IN PDEVICE_OBJECT PhysicalDeviceObject)
|
|
|
|
{
|
2014-12-29 09:06:58 +00:00
|
|
|
PRAMDISK_BUS_EXTENSION DeviceExtension;
|
|
|
|
PDEVICE_OBJECT AttachedDevice;
|
2015-01-09 14:09:34 +00:00
|
|
|
NTSTATUS Status;
|
2014-12-29 09:06:58 +00:00
|
|
|
UNICODE_STRING DeviceName;
|
|
|
|
PDEVICE_OBJECT DeviceObject;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Only create the bus FDO once */
|
2014-12-29 09:06:58 +00:00
|
|
|
if (RamdiskBusFdo) return STATUS_DEVICE_ALREADY_ATTACHED;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Create the bus FDO */
|
2014-12-29 09:06:58 +00:00
|
|
|
RtlInitUnicodeString(&DeviceName, L"\\Device\\Ramdisk");
|
|
|
|
Status = IoCreateDevice(DriverObject,
|
|
|
|
sizeof(RAMDISK_BUS_EXTENSION),
|
|
|
|
&DeviceName,
|
|
|
|
FILE_DEVICE_BUS_EXTENDER,
|
|
|
|
FILE_DEVICE_SECURE_OPEN,
|
|
|
|
0,
|
|
|
|
&DeviceObject);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Initialize the bus FDO extension */
|
2014-12-29 09:06:58 +00:00
|
|
|
DeviceExtension = DeviceObject->DeviceExtension;
|
2015-01-09 18:26:17 +00:00
|
|
|
RtlZeroMemory(DeviceExtension, sizeof(*DeviceExtension));
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Set bus FDO flags */
|
2014-12-29 09:06:58 +00:00
|
|
|
DeviceObject->Flags |= DO_POWER_PAGABLE | DO_DIRECT_IO;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Setup the bus FDO extension */
|
2014-12-29 09:06:58 +00:00
|
|
|
DeviceExtension->Type = RamdiskBus;
|
2015-01-09 14:09:34 +00:00
|
|
|
ExInitializeFastMutex(&DeviceExtension->DiskListLock);
|
2015-01-09 16:57:24 +00:00
|
|
|
IoInitializeRemoveLock(&DeviceExtension->RemoveLock, 'dmaR', 1, 0);
|
2015-01-09 14:09:34 +00:00
|
|
|
InitializeListHead(&DeviceExtension->DiskList);
|
2014-12-29 09:06:58 +00:00
|
|
|
DeviceExtension->PhysicalDeviceObject = PhysicalDeviceObject;
|
|
|
|
DeviceExtension->DeviceObject = DeviceObject;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Register the RAM disk device interface */
|
2014-12-29 09:06:58 +00:00
|
|
|
Status = IoRegisterDeviceInterface(PhysicalDeviceObject,
|
|
|
|
&RamdiskBusInterface,
|
|
|
|
NULL,
|
|
|
|
&DeviceExtension->BusDeviceName);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Fail */
|
2014-12-29 09:06:58 +00:00
|
|
|
IoDeleteDevice(DeviceObject);
|
|
|
|
return Status;
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Attach us to the device stack */
|
2014-12-29 09:06:58 +00:00
|
|
|
AttachedDevice = IoAttachDeviceToDeviceStack(DeviceObject,
|
|
|
|
PhysicalDeviceObject);
|
|
|
|
DeviceExtension->AttachedDevice = AttachedDevice;
|
|
|
|
if (!AttachedDevice)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Fail */
|
2015-01-09 14:09:34 +00:00
|
|
|
IoSetDeviceInterfaceState(&DeviceExtension->BusDeviceName, 0);
|
|
|
|
RtlFreeUnicodeString(&DeviceExtension->BusDeviceName);
|
|
|
|
IoDeleteDevice(DeviceObject);
|
|
|
|
return STATUS_NO_SUCH_DEVICE;
|
2014-12-29 09:06:58 +00:00
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Bus FDO is initialized */
|
2014-12-29 09:06:58 +00:00
|
|
|
RamdiskBusFdo = DeviceObject;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Loop for loader block */
|
2014-12-29 09:06:58 +00:00
|
|
|
if (KeLoaderBlock)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Are we being booted from setup? Not yet supported */
|
2015-01-09 14:09:34 +00:00
|
|
|
if (KeLoaderBlock->SetupLdrBlock)
|
2015-01-09 14:17:39 +00:00
|
|
|
DPRINT1("FIXME: RamdiskAddDevice is UNSUPPORTED when being started from SETUPLDR!\n");
|
2015-01-09 18:26:17 +00:00
|
|
|
// ASSERT(!KeLoaderBlock->SetupLdrBlock);
|
2014-12-29 09:06:58 +00:00
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* All done */
|
2014-12-29 09:06:58 +00:00
|
|
|
DeviceObject->Flags &= DO_DEVICE_INITIALIZING;
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Return status */
|
2014-12-29 09:06:58 +00:00
|
|
|
return Status;
|
2008-06-29 02:58:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
DriverEntry(IN PDRIVER_OBJECT DriverObject,
|
|
|
|
IN PUNICODE_STRING RegistryPath)
|
|
|
|
{
|
|
|
|
PCHAR BootDeviceName, CommandLine;
|
2008-07-13 04:23:59 +00:00
|
|
|
PDEVICE_OBJECT PhysicalDeviceObject = NULL;
|
2008-06-29 02:58:05 +00:00
|
|
|
NTSTATUS Status;
|
2009-10-16 22:03:38 +00:00
|
|
|
DPRINT("RAM Disk Driver Initialized\n");
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Query ramdisk parameters */
|
2008-06-29 02:58:05 +00:00
|
|
|
QueryParameters(RegistryPath);
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Save the registry path */
|
2008-06-29 02:58:05 +00:00
|
|
|
DriverRegistryPath = *RegistryPath;
|
|
|
|
DriverRegistryPath.Buffer = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
RegistryPath->Length +
|
2015-01-09 18:26:17 +00:00
|
|
|
sizeof(UNICODE_NULL),
|
2009-08-24 17:12:25 +00:00
|
|
|
'dmaR');
|
2008-06-29 02:58:05 +00:00
|
|
|
if (!DriverRegistryPath.Buffer) return STATUS_INSUFFICIENT_RESOURCES;
|
|
|
|
RtlCopyUnicodeString(&DriverRegistryPath, RegistryPath);
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Set device routines */
|
2008-06-29 02:58:05 +00:00
|
|
|
DriverObject->MajorFunction[IRP_MJ_CREATE] = RamdiskOpenClose;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_CLOSE] = RamdiskOpenClose;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_READ] = RamdiskReadWrite;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_WRITE] = RamdiskReadWrite;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = RamdiskDeviceControl;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_PNP] = RamdiskPnp;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_POWER] = RamdiskPower;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = RamdiskSystemControl;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_SCSI] = RamdiskScsi;
|
|
|
|
DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS] = RamdiskFlushBuffers;
|
|
|
|
DriverObject->DriverExtension->AddDevice = RamdiskAddDevice;
|
|
|
|
DriverObject->DriverUnload = RamdiskUnload;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Check for a loader block */
|
2008-06-29 02:58:05 +00:00
|
|
|
if (KeLoaderBlock)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Get the boot device name */
|
2008-06-29 02:58:05 +00:00
|
|
|
BootDeviceName = KeLoaderBlock->ArcBootDeviceName;
|
|
|
|
if (BootDeviceName)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Check if we're booting from ramdisk */
|
2008-06-29 02:58:05 +00:00
|
|
|
if ((strlen(BootDeviceName) >= 10) &&
|
|
|
|
!(_strnicmp(BootDeviceName, "ramdisk(0)", 10)))
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* We'll have to tell the PnP Manager */
|
2008-06-29 02:58:05 +00:00
|
|
|
ReportDetectedDevice = TRUE;
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Check for a command line */
|
2008-06-29 02:58:05 +00:00
|
|
|
CommandLine = KeLoaderBlock->LoadOptions;
|
|
|
|
if (CommandLine)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Check if this is an ISO boot */
|
2008-06-29 02:58:05 +00:00
|
|
|
if (strstr(CommandLine, "RDEXPORTASCD"))
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Remember for later */
|
2008-06-29 02:58:05 +00:00
|
|
|
ExportBootDiskAsCd = TRUE;
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Check if this is PE boot */
|
2008-06-29 02:58:05 +00:00
|
|
|
if (strstr(CommandLine, "MININT"))
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Remember for later */
|
2008-06-29 02:58:05 +00:00
|
|
|
IsWinPEBoot = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2008-06-29 02:58:05 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Installing from Ramdisk isn't supported yet */
|
2015-01-09 14:09:34 +00:00
|
|
|
if (KeLoaderBlock->SetupLdrBlock)
|
|
|
|
DPRINT1("FIXME: Installing from RamDisk is UNSUPPORTED!\n");
|
2015-01-09 18:26:17 +00:00
|
|
|
// ASSERT(!KeLoaderBlock->SetupLdrBlock);
|
2015-01-09 14:09:34 +00:00
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Are we reporting the device */
|
2008-06-29 02:58:05 +00:00
|
|
|
if (ReportDetectedDevice)
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Do it */
|
2008-06-29 02:58:05 +00:00
|
|
|
Status = IoReportDetectedDevice(DriverObject,
|
|
|
|
InterfaceTypeUndefined,
|
|
|
|
0xFFFFFFFF,
|
|
|
|
0xFFFFFFFF,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
&PhysicalDeviceObject);
|
|
|
|
if (NT_SUCCESS(Status))
|
2015-01-09 14:09:34 +00:00
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Create the device object */
|
2008-06-29 02:58:05 +00:00
|
|
|
Status = RamdiskAddDevice(DriverObject, PhysicalDeviceObject);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
2018-09-15 21:08:30 +00:00
|
|
|
/* We are done */
|
2008-06-29 02:58:05 +00:00
|
|
|
PhysicalDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Done */
|
2008-06-29 02:58:05 +00:00
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2015-01-09 16:57:24 +00:00
|
|
|
/* Done */
|
2008-06-29 02:58:05 +00:00
|
|
|
return Status;
|
|
|
|
}
|