Fixed LARGE_INTEGER handling
[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 #include <internal/string.h>
15
16 #define NDEBUG
17 #include <internal/debug.h>
18
19 #include "minix.h"
20
21 /* FUNCTIONS ***************************************************************/
22
23 BOOLEAN MinixReadSector(IN PDEVICE_OBJECT pDeviceObject,
24 IN ULONG DiskSector,
25 IN UCHAR* Buffer)
26 {
27 LARGE_INTEGER sectorNumber;
28 PIRP irp;
29 IO_STATUS_BLOCK ioStatus;
30 KEVENT event;
31 NTSTATUS status;
32 ULONG sectorSize;
33 PULONG mbr;
34
35 DPRINT("MinixReadSector(pDeviceObject %x, DiskSector %d, Buffer %x)\n",
36 pDeviceObject,DiskSector,Buffer);
37
38 sectorNumber.HighPart = 0;
39 sectorNumber.LowPart = DiskSector * BLOCKSIZE;
40
41 KeInitializeEvent(&event, NotificationEvent, FALSE);
42
43 sectorSize = BLOCKSIZE;
44
45 mbr = ExAllocatePool(NonPagedPool, sectorSize);
46
47 if (!mbr) {
48 return FALSE;
49 }
50
51
52 irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ,
53 pDeviceObject,
54 mbr,
55 sectorSize,
56 &sectorNumber,
57 &event,
58 &ioStatus );
59
60 if (!irp) {
61 ExFreePool(mbr);
62 return FALSE;
63 }
64
65 status = IoCallDriver(pDeviceObject,
66 irp);
67
68 if (status == STATUS_PENDING) {
69 KeWaitForSingleObject(&event,
70 Suspended,
71 KernelMode,
72 FALSE,
73 NULL);
74 status = ioStatus.Status;
75 }
76
77 if (!NT_SUCCESS(status)) {
78 ExFreePool(mbr);
79 return FALSE;
80 }
81
82 RtlCopyMemory(Buffer,mbr,sectorSize);
83
84 ExFreePool(mbr);
85 return TRUE;
86 }
87
88 BOOLEAN MinixWriteSector(IN PDEVICE_OBJECT pDeviceObject,
89 IN ULONG DiskSector,
90 IN UCHAR* Buffer)
91 {
92 LARGE_INTEGER sectorNumber;
93 PIRP irp;
94 IO_STATUS_BLOCK ioStatus;
95 KEVENT event;
96 NTSTATUS status;
97 ULONG sectorSize;
98
99 DPRINT("MinixWriteSector(pDeviceObject %x, DiskSector %d, Buffer %x)\n",
100 pDeviceObject,DiskSector,Buffer);
101
102 sectorNumber.HighPart = 0;
103 sectorNumber.LowPart = DiskSector * BLOCKSIZE;
104
105 KeInitializeEvent(&event, NotificationEvent, FALSE);
106
107 sectorSize = BLOCKSIZE;
108
109 irp = IoBuildSynchronousFsdRequest(IRP_MJ_WRITE,
110 pDeviceObject,
111 Buffer,
112 sectorSize,
113 &sectorNumber,
114 &event,
115 &ioStatus );
116
117
118 status = IoCallDriver(pDeviceObject,
119 irp);
120
121 if (status == STATUS_PENDING) {
122 KeWaitForSingleObject(&event,
123 Suspended,
124 KernelMode,
125 FALSE,
126 NULL);
127 status = ioStatus.Status;
128 }
129
130 if (!NT_SUCCESS(status)) {
131 return FALSE;
132 }
133
134 return TRUE;
135 }