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)
27 NTSTATUS Dispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp)
29 * FUNCTION: Handles user mode requests
31 * DeviceObject = Device for request
32 * Irp = I/O request packet describing request
33 * RETURNS: Success or failure
36 PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
41 ULONG Information = 0;
43 switch (Stack->MajorFunction)
46 DPRINT("Creating\n",0);
47 status = STATUS_SUCCESS;
51 status = STATUS_SUCCESS;
55 DPRINT("Writing %d bytes\n",
56 Stack->Parameters.Write.Length);
57 Length = Stack->Parameters.Write.Length;
60 Length = Length - (Length%512);
62 Buffer = MmGetSystemAddressForMdl(Irp->MdlAddress);
63 DPRINT("Buffer %x\n",Buffer);
65 for (i=0;i<Length;i++)
70 Stack->Parameters.Write.ByteOffset.LowPart+i);
71 SdWriteOffset(Stack->Parameters.Write.ByteOffset.LowPart+i);
73 outb_p(PORT,Buffer[i]);
74 DbgPrint("%c",Buffer[i]);
77 for (i=0;i<(Length/512);i++)
80 Stack->Parameters.Write.ByteOffset.LowPart+i);
81 SdWriteOffset(Stack->Parameters.Write.ByteOffset.LowPart+i);
82 outsb(PORT,Buffer,512);
84 status = STATUS_SUCCESS;
89 DPRINT("Reading %d bytes\n",
90 Stack->Parameters.Write.Length);
91 Length = Stack->Parameters.Write.Length;
94 Length = Length - (Length%512);
96 Buffer = MmGetSystemAddressForMdl(Irp->MdlAddress);
97 for (i=0;i<Length;i++)
101 DPRINT("Offset %d\n",
102 Stack->Parameters.Write.ByteOffset.LowPart+i);
103 SdWriteOffset(Stack->Parameters.Write.ByteOffset.LowPart+i);
105 Buffer[i]=inb_p(PORT);
107 status = STATUS_SUCCESS;
111 status = STATUS_NOT_IMPLEMENTED;
115 Irp->IoStatus.Status = status;
116 Irp->IoStatus.Information = Information;
118 IoCompleteRequest(Irp, IO_NO_INCREMENT);
122 NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
124 * FUNCTION: Called by the system to initalize the driver
126 * DriverObject = object describing this driver
127 * RegistryPath = path to our configuration entries
128 * RETURNS: Success or failure
131 PDEVICE_OBJECT DeviceObject;
135 ANSI_STRING asymlink;
136 UNICODE_STRING usymlink;
138 DbgPrint("Simple Disk Driver 0.0.1\n");
140 RtlInitAnsiString(&astr,"\\Device\\SDisk");
141 RtlAnsiStringToUnicodeString(&ustr,&astr,TRUE);
142 ret = IoCreateDevice(DriverObject,0,&ustr,
143 FILE_DEVICE_DISK,0,FALSE,&DeviceObject);
144 if (ret!=STATUS_SUCCESS)
149 RtlInitAnsiString(&asymlink,"\\??\\C:");
150 RtlAnsiStringToUnicodeString(&usymlink,&asymlink,TRUE);
151 IoCreateSymbolicLink(&usymlink,&ustr);
153 DeviceObject->Flags=DO_DIRECT_IO;
154 DriverObject->MajorFunction[IRP_MJ_CLOSE] = Dispatch;
155 DriverObject->MajorFunction[IRP_MJ_CREATE] = Dispatch;
156 DriverObject->MajorFunction[IRP_MJ_READ] = Dispatch;
157 DriverObject->MajorFunction[IRP_MJ_WRITE] = Dispatch;
158 DriverObject->DriverUnload = NULL;
160 return(STATUS_SUCCESS);