7 static NTSTATUS STDCALL
RamdrvDispatchDeviceControl(PDEVICE_OBJECT DeviceObject
,
10 PIO_STACK_LOCATION IrpStack
;
11 ULONG ControlCode
, InputLength
, OutputLength
;
14 DPRINT("RamdrvDispatchDeviceControl\n");
16 IrpStack
= IoGetCurrentIrpStackLocation(Irp
);
17 ControlCode
= IrpStack
->Parameters
.DeviceIoControl
.IoControlCode
;
18 InputLength
= IrpStack
->Parameters
.DeviceIoControl
.InputBufferLength
;
19 OutputLength
= IrpStack
->Parameters
.DeviceIoControl
.OutputBufferLength
;
23 case IOCTL_DISK_GET_DRIVE_GEOMETRY
:
24 if (OutputLength
< sizeof(DISK_GEOMETRY
))
26 Status
= STATUS_INVALID_PARAMETER
;
30 PDISK_GEOMETRY Geometry
= Irp
->AssociatedIrp
.SystemBuffer
;
31 Geometry
->MediaType
= F3_1Pt44_512
;
32 Geometry
->Cylinders
.QuadPart
= 80;
33 Geometry
->TracksPerCylinder
= 2 * 18;
34 Geometry
->SectorsPerTrack
= 18;
35 Geometry
->BytesPerSector
= 512;
36 Status
= STATUS_SUCCESS
;
37 Irp
->IoStatus
.Information
= sizeof(DISK_GEOMETRY
);
41 Status
= STATUS_INVALID_DEVICE_REQUEST
;
43 Irp
->IoStatus
.Status
= Status
;
44 IoCompleteRequest(Irp
, NT_SUCCESS(Status
) ? IO_DISK_INCREMENT
: IO_NO_INCREMENT
);
48 static NTSTATUS STDCALL
RamdrvDispatchReadWrite(PDEVICE_OBJECT DeviceObject
,
51 PRAMDRV_DEVICE_EXTENSION devext
= (PRAMDRV_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
52 PIO_STACK_LOCATION Stk
= IoGetCurrentIrpStackLocation( Irp
);
54 if( Stk
->Parameters
.Read
.ByteOffset
.u
.HighPart
||
55 Stk
->Parameters
.Read
.ByteOffset
.u
.LowPart
>= devext
->Size
)
57 Irp
->IoStatus
.Status
= STATUS_END_OF_FILE
;
58 Irp
->IoStatus
.Information
= 0;
59 IoCompleteRequest( Irp
, 0 );
60 return STATUS_END_OF_FILE
;
62 if( (Stk
->Parameters
.Read
.ByteOffset
.u
.LowPart
+ Stk
->Parameters
.Read
.Length
) > devext
->Size
)
63 Stk
->Parameters
.Read
.Length
= devext
->Size
- Stk
->Parameters
.Read
.ByteOffset
.u
.LowPart
;
64 if( Stk
->MajorFunction
== IRP_MJ_READ
)
65 RtlCopyMemory( MmGetSystemAddressForMdl( Irp
->MdlAddress
),
66 (PVOID
)((ULONG_PTR
)devext
->Buffer
+ Stk
->Parameters
.Read
.ByteOffset
.u
.LowPart
),
67 Stk
->Parameters
.Read
.Length
);
68 else RtlCopyMemory( (PVOID
)((ULONG_PTR
)devext
->Buffer
+ Stk
->Parameters
.Read
.ByteOffset
.u
.LowPart
),
69 MmGetSystemAddressForMdl( Irp
->MdlAddress
),
70 Stk
->Parameters
.Read
.Length
);
71 Irp
->IoStatus
.Status
= STATUS_SUCCESS
;
72 Irp
->IoStatus
.Information
= Stk
->Parameters
.Read
.Length
;
73 IoCompleteRequest( Irp
, 0 );
74 return STATUS_SUCCESS
;
77 static NTSTATUS STDCALL
RamdrvDispatchOpenClose(PDEVICE_OBJECT DeviceObject
,
80 DPRINT("RamdrvDispatchOpenClose\n");
81 return STATUS_SUCCESS
;
84 NTSTATUS STDCALL
DriverEntry(IN PDRIVER_OBJECT DriverObject
,
85 IN PUNICODE_STRING RegistryPath
)
87 UNICODE_STRING DeviceName
= RTL_CONSTANT_STRING(L
"\\Device\\Ramdisk");
89 PDEVICE_OBJECT DeviceObject
;
90 PRAMDRV_DEVICE_EXTENSION devext
;
91 UNICODE_STRING LinkName
= RTL_CONSTANT_STRING(L
"\\??\\Z:");
92 UNICODE_STRING ImageName
= RTL_CONSTANT_STRING(L
"\\Device\\Floppy0\\ramdisk.bz2");
94 OBJECT_ATTRIBUTES objattr
;
96 LARGE_INTEGER allocsize
;
99 unsigned int dstlen
= 1024 * 1440;
100 FILE_STANDARD_INFORMATION finfo
;
103 DPRINT("Ramdisk driver\n");
105 /* Export other driver entry points... */
106 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = RamdrvDispatchOpenClose
;
107 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = RamdrvDispatchOpenClose
;
108 DriverObject
->MajorFunction
[IRP_MJ_READ
] = RamdrvDispatchReadWrite
;
109 DriverObject
->MajorFunction
[IRP_MJ_WRITE
] = RamdrvDispatchReadWrite
;
110 DriverObject
->MajorFunction
[IRP_MJ_DEVICE_CONTROL
] = RamdrvDispatchDeviceControl
;
113 // create device and symbolic link
114 Status
= IoCreateDevice( DriverObject
,
115 sizeof( RAMDRV_DEVICE_EXTENSION
),
121 if( !NT_SUCCESS( Status
) )
123 DeviceObject
->Flags
|= DO_DIRECT_IO
;
124 devext
= (PRAMDRV_DEVICE_EXTENSION
)DeviceObject
->DeviceExtension
;
125 devext
->Size
= 1440 * 1024;
126 devext
->Buffer
= ExAllocatePool( PagedPool
, devext
->Size
);
127 if( !devext
->Buffer
)
129 Status
= STATUS_INSUFFICIENT_RESOURCES
;
132 IoCreateSymbolicLink( &LinkName
, &DeviceName
);
134 InitializeObjectAttributes( &objattr
,
139 allocsize
.u
.LowPart
= allocsize
.u
.HighPart
= 0;
141 Status
= ZwOpenFile( &file
,
146 FILE_NO_INTERMEDIATE_BUFFERING
);
148 if( !NT_SUCCESS( Status
) )
150 DPRINT( "Failed to open floppy\n" );
154 InitializeObjectAttributes( &objattr
,
159 Status
= ZwCreateEvent( &event
,
164 if( !NT_SUCCESS( Status
) )
166 DPRINT( "Failed to create event\n" );
170 Status
= ZwQueryInformationFile( file
,
174 FileStandardInformation
);
176 if( !NT_SUCCESS( Status
) )
178 DPRINT1( "Failed to query file information\n" );
181 tbuff
= ExAllocatePool( PagedPool
, finfo
.EndOfFile
.u
.LowPart
);
184 DPRINT1( "Failed to allocate buffer of size %d\n", finfo
.EndOfFile
.u
.LowPart
);
185 Status
= STATUS_INSUFFICIENT_RESOURCES
;
189 Status
= ZwReadFile( file
,
195 finfo
.EndOfFile
.u
.LowPart
,
199 if( !NT_SUCCESS( Status
) )
201 DPRINT( "Failed to read floppy\n" );
204 Status
= ZwWaitForSingleObject( event
, FALSE
, 0 );
205 if( Status
!= STATUS_WAIT_0
|| !NT_SUCCESS( iosb
.Status
) )
207 DPRINT( "Failed to read floppy\n" );
210 DPRINT( "RAMDRV: Read in %d bytes, decompressing now\n", iosb
.Information
);
211 err
= BZ2_bzBuffToBuffDecompress( devext
->Buffer
,
219 DPRINT( "RAMDRV: Image Decompressed\n");
221 else DbgPrint( "RAMDRV: Failed to decomparess image, error: %d\n", err
);
225 return STATUS_SUCCESS
;
234 ExFreePool( devext
->Buffer
);
237 IoDeleteDevice( DeviceObject
);