remove whitespace from end of lines
[reactos.git] / reactos / drivers / fs / minix / blockdev.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: services/fs/minix/minix.c
5 * PURPOSE: Minix FSD
6 * PROGRAMMER: David Welch (welch@mcmail.com)
7 * UPDATE HISTORY:
8 */
9
10 /* INCLUDES *****************************************************************/
11
12 #include <ddk/ntddk.h>
13 #include <string.h>
14
15 #define NDEBUG
16 #include <debug.h>
17
18 #include "minix.h"
19
20 /* FUNCTIONS ***************************************************************/
21
22 BOOLEAN MinixReadPage(PDEVICE_OBJECT DeviceObject,
23 ULONG Offset,
24 PVOID Buffer)
25 {
26 ULONG i;
27 BOOLEAN Result;
28
29 for (i=0; i<4; i++)
30 {
31 Result = MinixReadSector(DeviceObject,
32 (Offset + (i * PAGE_SIZE)) / BLOCKSIZE,
33 (Buffer + (i * PAGE_SIZE)));
34 if (!Result)
35 {
36 return(Result);
37 }
38 }
39 return(TRUE);
40 }
41
42 BOOLEAN MinixReadSector(IN PDEVICE_OBJECT pDeviceObject,
43 IN ULONG DiskSector,
44 IN PVOID Buffer)
45 {
46 LARGE_INTEGER sectorNumber;
47 PIRP irp;
48 IO_STATUS_BLOCK ioStatus;
49 KEVENT event;
50 NTSTATUS status;
51 ULONG sectorSize;
52 PULONG mbr;
53
54 DPRINT("MinixReadSector(pDeviceObject %x, DiskSector %d, Buffer %x)\n",
55 pDeviceObject,DiskSector,Buffer);
56
57 sectorNumber.u.HighPart = 0;
58 sectorNumber.u.LowPart = DiskSector * BLOCKSIZE;
59
60 KeInitializeEvent(&event, NotificationEvent, FALSE);
61
62 sectorSize = BLOCKSIZE;
63
64 mbr = ExAllocatePool(NonPagedPool, sectorSize);
65
66 if (!mbr) {
67 return FALSE;
68 }
69
70
71 irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ,
72 pDeviceObject,
73 mbr,
74 sectorSize,
75 &sectorNumber,
76 &event,
77 &ioStatus );
78
79 if (!irp) {
80 ExFreePool(mbr);
81 return FALSE;
82 }
83
84 status = IoCallDriver(pDeviceObject,
85 irp);
86
87 if (status == STATUS_PENDING) {
88 KeWaitForSingleObject(&event,
89 Suspended,
90 KernelMode,
91 FALSE,
92 NULL);
93 status = ioStatus.Status;
94 }
95
96 if (!NT_SUCCESS(status)) {
97 ExFreePool(mbr);
98 return FALSE;
99 }
100
101 RtlCopyMemory(Buffer,mbr,sectorSize);
102
103 ExFreePool(mbr);
104 return TRUE;
105 }
106
107 BOOLEAN MinixWriteSector(IN PDEVICE_OBJECT pDeviceObject,
108 IN ULONG DiskSector,
109 IN PVOID Buffer)
110 {
111 LARGE_INTEGER sectorNumber;
112 PIRP irp;
113 IO_STATUS_BLOCK ioStatus;
114 KEVENT event;
115 NTSTATUS status;
116 ULONG sectorSize;
117
118 DPRINT("MinixWriteSector(pDeviceObject %x, DiskSector %d, Buffer %x)\n",
119 pDeviceObject,DiskSector,Buffer);
120
121 sectorNumber.u.HighPart = 0;
122 sectorNumber.u.LowPart = DiskSector * BLOCKSIZE;
123
124 KeInitializeEvent(&event, NotificationEvent, FALSE);
125
126 sectorSize = BLOCKSIZE;
127
128 irp = IoBuildSynchronousFsdRequest(IRP_MJ_WRITE,
129 pDeviceObject,
130 Buffer,
131 sectorSize,
132 &sectorNumber,
133 &event,
134 &ioStatus );
135
136
137 status = IoCallDriver(pDeviceObject,
138 irp);
139
140 if (status == STATUS_PENDING) {
141 KeWaitForSingleObject(&event,
142 Suspended,
143 KernelMode,
144 FALSE,
145 NULL);
146 status = ioStatus.Status;
147 }
148
149 if (!NT_SUCCESS(status)) {
150 return FALSE;
151 }
152
153 return TRUE;
154 }