mirror of
https://github.com/ApfelTeeSaft/reactos.git
synced 2026-09-02 19:26:32 +00:00
Check in of new ram disk driver, loads floppy image into ram on boot
svn path=/trunk/; revision=1986
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
# $Id: makefile,v 1.1 2001/06/18 03:10:00 phreak Exp $
|
||||
#
|
||||
#
|
||||
PATH_TO_TOP = ../../..
|
||||
|
||||
TARGET=ramdrv
|
||||
|
||||
OBJECTS = ramdrv.o ../../../ntoskrnl/ntoskrnl.a
|
||||
|
||||
CFLAGS = -I.
|
||||
|
||||
all: $(TARGET).sys
|
||||
|
||||
ramdrv.o: ramdrv.h
|
||||
|
||||
.phony: all
|
||||
|
||||
clean:
|
||||
- $(RM) floppy.o
|
||||
- $(RM) junk.tmp
|
||||
- $(RM) base.tmp
|
||||
- $(RM) temp.exp
|
||||
- $(RM) $(TARGET).sys
|
||||
- $(RM) $(TARGET).sys.unstripped
|
||||
|
||||
.phony: clean
|
||||
|
||||
install: $(FLOPPY_DIR)/drivers/$(TARGET).sys
|
||||
|
||||
$(FLOPPY_DIR)/drivers/$(TARGET).sys: $(TARGET).sys
|
||||
$(CP) $(TARGET).sys $(FLOPPY_DIR)/drivers/$(TARGET).sys
|
||||
|
||||
dist: ../../../$(DIST_DIR)/drivers/$(TARGET).sys
|
||||
|
||||
../../../$(DIST_DIR)/drivers/$(TARGET).sys: $(TARGET).sys
|
||||
$(CP) $(TARGET).sys ../../../$(DIST_DIR)/drivers/$(TARGET).sys
|
||||
|
||||
$(TARGET).sys: $(OBJECTS)
|
||||
|
||||
WITH_DEBUGGING=yes
|
||||
include ../../../rules.mak
|
||||
@@ -0,0 +1,160 @@
|
||||
#include <ntddk.h>
|
||||
#include "ramdrv.h"
|
||||
#include <debug.h>
|
||||
|
||||
NTSTATUS STDCALL RamdrvDispatchReadWrite(PDEVICE_OBJECT DeviceObject,
|
||||
PIRP Irp)
|
||||
{
|
||||
PRAMDRV_DEVICE_EXTENSION devext = (PRAMDRV_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
||||
PIO_STACK_LOCATION Stk = IoGetCurrentIrpStackLocation( Irp );
|
||||
|
||||
if( Stk->Parameters.Read.ByteOffset.u.HighPart ||
|
||||
Stk->Parameters.Read.ByteOffset.u.LowPart >= devext->Size )
|
||||
{
|
||||
Irp->IoStatus.Status = STATUS_END_OF_FILE;
|
||||
Irp->IoStatus.Information = 0;
|
||||
IoCompleteRequest( Irp, 0 );
|
||||
return STATUS_END_OF_FILE;
|
||||
}
|
||||
if( (Stk->Parameters.Read.ByteOffset.u.LowPart + Stk->Parameters.Read.Length) > devext->Size )
|
||||
Stk->Parameters.Read.Length = devext->Size - Stk->Parameters.Read.ByteOffset.u.LowPart;
|
||||
if( Stk->MajorFunction == IRP_MJ_READ )
|
||||
RtlCopyMemory( MmGetSystemAddressForMdl( Irp->MdlAddress ),
|
||||
devext->Buffer + Stk->Parameters.Read.ByteOffset.u.LowPart,
|
||||
Stk->Parameters.Read.Length );
|
||||
else RtlCopyMemory( devext->Buffer + Stk->Parameters.Read.ByteOffset.u.LowPart,
|
||||
MmGetSystemAddressForMdl( Irp->MdlAddress ),
|
||||
Stk->Parameters.Read.Length );
|
||||
Irp->IoStatus.Status = STATUS_SUCCESS;
|
||||
Irp->IoStatus.Information = Stk->Parameters.Read.Length;
|
||||
IoCompleteRequest( Irp, 0 );
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
NTSTATUS STDCALL RamdrvDispatchOpenClose(PDEVICE_OBJECT DeviceObject,
|
||||
PIRP Irp)
|
||||
{
|
||||
DPRINT("RamdrvDispatchOpenClose\n");
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
NTSTATUS STDCALL DriverEntry(IN PDRIVER_OBJECT DriverObject,
|
||||
IN PUNICODE_STRING RegistryPath)
|
||||
{
|
||||
UNICODE_STRING DeviceName;
|
||||
NTSTATUS Status;
|
||||
PDEVICE_OBJECT DeviceObject;
|
||||
PRAMDRV_DEVICE_EXTENSION devext;
|
||||
UNICODE_STRING LinkName;
|
||||
HANDLE file;
|
||||
OBJECT_ATTRIBUTES objattr;
|
||||
IO_STATUS_BLOCK iosb;
|
||||
LARGE_INTEGER allocsize;
|
||||
HANDLE event;
|
||||
|
||||
DbgPrint("Ramdisk driver\n");
|
||||
|
||||
/* Export other driver entry points... */
|
||||
DriverObject->MajorFunction[IRP_MJ_CREATE] = RamdrvDispatchOpenClose;
|
||||
DriverObject->MajorFunction[IRP_MJ_CLOSE] = RamdrvDispatchOpenClose;
|
||||
DriverObject->MajorFunction[IRP_MJ_READ] = RamdrvDispatchReadWrite;
|
||||
DriverObject->MajorFunction[IRP_MJ_WRITE] = RamdrvDispatchReadWrite;
|
||||
// DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] =
|
||||
// RamdrvDispatchDeviceControl;
|
||||
|
||||
|
||||
// create device and symbolic link
|
||||
RtlInitUnicodeString( &DeviceName, L"\\Device\\Ramdisk" );
|
||||
Status = IoCreateDevice( DriverObject,
|
||||
sizeof( RAMDRV_DEVICE_EXTENSION ),
|
||||
&DeviceName,
|
||||
FILE_DEVICE_DISK,
|
||||
0,
|
||||
FALSE,
|
||||
&DeviceObject );
|
||||
if( !NT_SUCCESS( Status ) )
|
||||
return Status;
|
||||
DeviceObject->Flags |= DO_DIRECT_IO;
|
||||
devext = (PRAMDRV_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
||||
devext->Size = 1440 * 1024;
|
||||
devext->Buffer = ExAllocatePool( PagedPool, devext->Size );
|
||||
if( !devext->Buffer )
|
||||
{
|
||||
IoDeleteDevice( DeviceObject );
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
RtlInitUnicodeString( &LinkName, L"\\ArcName\\virt(0)disk(0)ram(0)" );
|
||||
IoAssignArcName( &LinkName, &DeviceName );
|
||||
RtlInitUnicodeString( &LinkName, L"\\??\\Z:" );
|
||||
IoCreateSymbolicLink( &LinkName, &DeviceName );
|
||||
|
||||
RtlInitUnicodeString( &LinkName, L"\\Device\\Floppy0" );
|
||||
InitializeObjectAttributes( &objattr,
|
||||
&LinkName,
|
||||
0,
|
||||
0,
|
||||
0 );
|
||||
allocsize.u.LowPart = allocsize.u.HighPart = 0;
|
||||
|
||||
Status = NtCreateFile( &file,
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
&objattr,
|
||||
&iosb,
|
||||
&allocsize,
|
||||
0,
|
||||
0,
|
||||
OPEN_EXISTING,
|
||||
0,
|
||||
0,
|
||||
0 );
|
||||
if( !NT_SUCCESS( Status ) )
|
||||
{
|
||||
DPRINT( "Failed to open floppy\n" );
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
InitializeObjectAttributes( &objattr,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0 );
|
||||
Status = NtCreateEvent( &event,
|
||||
0,
|
||||
&objattr,
|
||||
TRUE,
|
||||
FALSE );
|
||||
if( !NT_SUCCESS( Status ) )
|
||||
{
|
||||
DPRINT( "Failed to create event\n" );
|
||||
NtClose( file );
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
Status = NtReadFile( file,
|
||||
event,
|
||||
0,
|
||||
0,
|
||||
&iosb,
|
||||
devext->Buffer,
|
||||
1440 * 1024,
|
||||
&allocsize,
|
||||
0 );
|
||||
if( !NT_SUCCESS( Status ) )
|
||||
{
|
||||
NtClose( file );
|
||||
NtClose( event );
|
||||
DPRINT( "Failed to read floppy\n" );
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
Status = NtWaitForSingleObject( event, FALSE, 0 );
|
||||
if( Status != STATUS_WAIT_0 || !NT_SUCCESS( iosb.Status ) )
|
||||
{
|
||||
DPRINT( "Failed to read floppy\n" );
|
||||
NtClose( file );
|
||||
NtClose( event );
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
NtClose( file );
|
||||
NtClose( event );
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
typedef struct _RAMDRV_DEVICE_EXTENSION {
|
||||
void *Buffer;
|
||||
unsigned long Size;
|
||||
} RAMDRV_DEVICE_EXTENSION, *PRAMDRV_DEVICE_EXTENSION;
|
||||
|
||||
Reference in New Issue
Block a user