2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: services/sdisk/sdisk.c
5 * PURPOSE: Disk driver for Bochs
6 * PROGRAMMER: David Welch (welch@mcmail.com)
10 /* INCLUDES ****************************************************************/
12 #include <ddk/ntddk.h>
13 #include <internal/halio.h>
16 #include <internal/debug.h>
18 /* FUNCTIONS **************************************************************/
22 static VOID
SdWriteOffset(ULONG Offset
)
28 Dispatch(PDEVICE_OBJECT DeviceObject
, PIRP Irp
)
30 * FUNCTION: Handles user mode requests
32 * DeviceObject = Device for request
33 * Irp = I/O request packet describing request
34 * RETURNS: Success or failure
37 PIO_STACK_LOCATION Stack
= IoGetCurrentIrpStackLocation(Irp
);
42 ULONG Information
= 0;
44 switch (Stack
->MajorFunction
)
47 DPRINT("Creating\n",0);
48 status
= STATUS_SUCCESS
;
52 status
= STATUS_SUCCESS
;
56 DPRINT("Writing %d bytes\n",
57 Stack
->Parameters
.Write
.Length
);
58 Length
= Stack
->Parameters
.Write
.Length
;
61 Length
= Length
- (Length
%512);
63 Buffer
= MmGetSystemAddressForMdl(Irp
->MdlAddress
);
64 DPRINT("Buffer %x\n",Buffer
);
66 for (i
=0;i
<Length
;i
++)
71 Stack
->Parameters
.Write
.ByteOffset
.LowPart
+i
);
72 SdWriteOffset(Stack
->Parameters
.Write
.ByteOffset
.LowPart
+i
);
74 outb_p(PORT
,Buffer
[i
]);
75 DbgPrint("%c",Buffer
[i
]);
78 for (i
=0;i
<(Length
/512);i
++)
81 Stack
->Parameters
.Write
.ByteOffset
.LowPart
+i
);
82 SdWriteOffset(Stack
->Parameters
.Write
.ByteOffset
.LowPart
+i
);
83 outsb(PORT
,Buffer
,512);
85 status
= STATUS_SUCCESS
;
90 DPRINT("Reading %d bytes\n",
91 Stack
->Parameters
.Write
.Length
);
92 Length
= Stack
->Parameters
.Write
.Length
;
95 Length
= Length
- (Length
%512);
97 Buffer
= MmGetSystemAddressForMdl(Irp
->MdlAddress
);
98 for (i
=0;i
<Length
;i
++)
102 DPRINT("Offset %d\n",
103 Stack
->Parameters
.Write
.ByteOffset
.LowPart
+i
);
104 SdWriteOffset(Stack
->Parameters
.Write
.ByteOffset
.LowPart
+i
);
106 Buffer
[i
]=inb_p(PORT
);
108 status
= STATUS_SUCCESS
;
112 status
= STATUS_NOT_IMPLEMENTED
;
116 Irp
->IoStatus
.Status
= status
;
117 Irp
->IoStatus
.Information
= Information
;
119 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
123 NTSTATUS
DriverEntry(PDRIVER_OBJECT DriverObject
, PUNICODE_STRING RegistryPath
)
125 * FUNCTION: Called by the system to initalize the driver
127 * DriverObject = object describing this driver
128 * RegistryPath = path to our configuration entries
129 * RETURNS: Success or failure
132 PDEVICE_OBJECT DeviceObject
;
136 ANSI_STRING asymlink
;
137 UNICODE_STRING usymlink
;
139 DbgPrint("Simple Disk Driver 0.0.1\n");
141 RtlInitAnsiString(&astr
,"\\Device\\SDisk");
142 RtlAnsiStringToUnicodeString(&ustr
,&astr
,TRUE
);
143 ret
= IoCreateDevice(DriverObject
,0,&ustr
,
144 FILE_DEVICE_DISK
,0,FALSE
,&DeviceObject
);
145 if (ret
!=STATUS_SUCCESS
)
150 RtlInitAnsiString(&asymlink
,"\\??\\C:");
151 RtlAnsiStringToUnicodeString(&usymlink
,&asymlink
,TRUE
);
152 IoCreateSymbolicLink(&usymlink
,&ustr
);
154 DeviceObject
->Flags
=DO_DIRECT_IO
;
155 DriverObject
->MajorFunction
[IRP_MJ_CLOSE
] = Dispatch
;
156 DriverObject
->MajorFunction
[IRP_MJ_CREATE
] = Dispatch
;
157 DriverObject
->MajorFunction
[IRP_MJ_READ
] = Dispatch
;
158 DriverObject
->MajorFunction
[IRP_MJ_WRITE
] = Dispatch
;
159 DriverObject
->DriverUnload
= NULL
;
161 return(STATUS_SUCCESS
);