Copy wininet to branch
[reactos.git] / reactos / drivers / dd / sdisk / sdisk.c
1 /*
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)
7 * UPDATE HISTORY:
8 */
9
10 /* INCLUDES ****************************************************************/
11
12 #include <ddk/ntddk.h>
13 #include <internal/halio.h>
14
15 #define NDEBUG
16 #include <internal/debug.h>
17
18 /* FUNCTIONS **************************************************************/
19
20 #define PORT (0x3ec)
21
22 static VOID SdWriteOffset(ULONG Offset)
23 {
24 outl_p(PORT,Offset);
25 }
26
27 NTSTATUS STDCALL
28 Dispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp)
29 /*
30 * FUNCTION: Handles user mode requests
31 * ARGUMENTS:
32 * DeviceObject = Device for request
33 * Irp = I/O request packet describing request
34 * RETURNS: Success or failure
35 */
36 {
37 PIO_STACK_LOCATION Stack = IoGetCurrentIrpStackLocation(Irp);
38 NTSTATUS status;
39 int i;
40 PCH Buffer;
41 ULONG Length;
42 ULONG Information = 0;
43
44 switch (Stack->MajorFunction)
45 {
46 case IRP_MJ_CREATE:
47 DPRINT("Creating\n",0);
48 status = STATUS_SUCCESS;
49 break;
50
51 case IRP_MJ_CLOSE:
52 status = STATUS_SUCCESS;
53 break;
54
55 case IRP_MJ_WRITE:
56 DPRINT("Writing %d bytes\n",
57 Stack->Parameters.Write.Length);
58 Length = Stack->Parameters.Write.Length;
59 if ((Length%512)>0)
60 {
61 Length = Length - (Length%512);
62 }
63 Buffer = MmGetSystemAddressForMdl(Irp->MdlAddress);
64 DPRINT("Buffer %x\n",Buffer);
65 #if 0
66 for (i=0;i<Length;i++)
67 {
68 if ((i%512)==0)
69 {
70 DPRINT("Offset %x\n",
71 Stack->Parameters.Write.ByteOffset.LowPart+i);
72 SdWriteOffset(Stack->Parameters.Write.ByteOffset.LowPart+i);
73 }
74 outb_p(PORT,Buffer[i]);
75 DbgPrint("%c",Buffer[i]);
76 }
77 #endif
78 for (i=0;i<(Length/512);i++)
79 {
80 DPRINT("Offset %x\n",
81 Stack->Parameters.Write.ByteOffset.LowPart+i);
82 SdWriteOffset(Stack->Parameters.Write.ByteOffset.LowPart+i);
83 outsb(PORT,Buffer,512);
84 }
85 status = STATUS_SUCCESS;
86 Information = Length;
87 break;
88
89 case IRP_MJ_READ:
90 DPRINT("Reading %d bytes\n",
91 Stack->Parameters.Write.Length);
92 Length = Stack->Parameters.Write.Length;
93 if ((Length%512)>0)
94 {
95 Length = Length - (Length%512);
96 }
97 Buffer = MmGetSystemAddressForMdl(Irp->MdlAddress);
98 for (i=0;i<Length;i++)
99 {
100 if ((i%512)==0)
101 {
102 DPRINT("Offset %d\n",
103 Stack->Parameters.Write.ByteOffset.LowPart+i);
104 SdWriteOffset(Stack->Parameters.Write.ByteOffset.LowPart+i);
105 }
106 Buffer[i]=inb_p(PORT);
107 }
108 status = STATUS_SUCCESS;
109 break;
110
111 default:
112 status = STATUS_NOT_IMPLEMENTED;
113 break;
114 }
115
116 Irp->IoStatus.Status = status;
117 Irp->IoStatus.Information = Information;
118
119 IoCompleteRequest(Irp, IO_NO_INCREMENT);
120 return(status);
121 }
122
123 NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
124 /*
125 * FUNCTION: Called by the system to initalize the driver
126 * ARGUMENTS:
127 * DriverObject = object describing this driver
128 * RegistryPath = path to our configuration entries
129 * RETURNS: Success or failure
130 */
131 {
132 PDEVICE_OBJECT DeviceObject;
133 NTSTATUS ret;
134 ANSI_STRING astr;
135 UNICODE_STRING ustr;
136 ANSI_STRING asymlink;
137 UNICODE_STRING usymlink;
138
139 DbgPrint("Simple Disk Driver 0.0.1\n");
140
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)
146 {
147 return(ret);
148 }
149
150 RtlInitAnsiString(&asymlink,"\\??\\C:");
151 RtlAnsiStringToUnicodeString(&usymlink,&asymlink,TRUE);
152 IoCreateSymbolicLink(&usymlink,&ustr);
153
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;
160
161 return(STATUS_SUCCESS);
162 }
163