Fixed LARGE_INTEGER handling
[reactos.git] / reactos / drivers / fs / ext2 / blockdev.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: services/fs/vfat/blockdev.c
5 * PURPOSE: Temporary sector reading support
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 "ext2fs.h"
20
21 /* FUNCTIONS ***************************************************************/
22
23 BOOLEAN Ext2ReadSectors(IN PDEVICE_OBJECT pDeviceObject,
24 IN ULONG DiskSector,
25 IN ULONG SectorCount,
26 IN PVOID Buffer)
27 {
28 LARGE_INTEGER sectorNumber;
29 PIRP irp;
30 IO_STATUS_BLOCK ioStatus;
31 KEVENT event;
32 NTSTATUS status;
33 ULONG sectorSize;
34 int j;
35
36 DPRINT("VFATReadSector(pDeviceObject %x, DiskSector %d, Buffer %x)\n",
37 pDeviceObject,DiskSector,Buffer);
38
39 sectorNumber.HighPart = 0;
40 sectorNumber.LowPart = DiskSector * BLOCKSIZE;
41
42 DPRINT("DiskSector:%ld BLKSZ:%ld sectorNumber:%ld:%ld\n",
43 (unsigned long) DiskSector,
44 (unsigned long) BLOCKSIZE,
45 (unsigned long) sectorNumber.HighPart,
46 (unsigned long) sectorNumber.LowPart);
47
48 KeInitializeEvent(&event, NotificationEvent, FALSE);
49
50 sectorSize = BLOCKSIZE*SectorCount;
51
52
53 DPRINT("Building synchronous FSD Request...\n");
54 irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ,
55 pDeviceObject,
56 Buffer,
57 sectorSize,
58 &sectorNumber,
59 &event,
60 &ioStatus );
61
62 if (!irp) {
63 DbgPrint("READ failed!!!\n");
64 return FALSE;
65 }
66
67 DPRINT("Calling IO Driver...\n");
68 status = IoCallDriver(pDeviceObject,
69 irp);
70
71 DPRINT("Waiting for IO Operation...\n");
72 if (status == STATUS_PENDING) {
73 KeWaitForSingleObject(&event,
74 Suspended,
75 KernelMode,
76 FALSE,
77 NULL);
78 DPRINT("Getting IO Status...\n");
79 status = ioStatus.Status;
80 }
81
82 if (!NT_SUCCESS(status)) {
83 DbgPrint("IO failed!!! Error code: %d(%x)\n", status, status);
84 return FALSE;
85 }
86
87 return TRUE;
88 }
89
90 BOOLEAN VFATWriteSectors(IN PDEVICE_OBJECT pDeviceObject,
91 IN ULONG DiskSector,
92 IN ULONG SectorCount,
93 IN UCHAR* Buffer)
94 {
95 LARGE_INTEGER sectorNumber;
96 PIRP irp;
97 IO_STATUS_BLOCK ioStatus;
98 KEVENT event;
99 NTSTATUS status;
100 ULONG sectorSize;
101 PULONG mbr;
102 int j;
103
104 DPRINT("VFATWriteSector(pDeviceObject %x, DiskSector %d, Buffer %x)\n",
105 pDeviceObject,DiskSector,Buffer);
106
107 sectorNumber.HighPart = 0;
108 sectorNumber.LowPart = DiskSector * BLOCKSIZE;
109
110 KeInitializeEvent(&event, NotificationEvent, FALSE);
111
112 sectorSize = BLOCKSIZE*SectorCount;
113
114
115 DPRINT("Building synchronous FSD Request...\n");
116 irp = IoBuildSynchronousFsdRequest(IRP_MJ_WRITE,
117 pDeviceObject,
118 Buffer,
119 sectorSize,
120 &sectorNumber,
121 &event,
122 &ioStatus );
123
124 if (!irp) {
125 DbgPrint("WRITE failed!!!\n");
126 return FALSE;
127 }
128
129 DPRINT("Calling IO Driver...\n");
130 status = IoCallDriver(pDeviceObject,
131 irp);
132
133 DPRINT("Waiting for IO Operation...\n");
134 if (status == STATUS_PENDING) {
135 KeWaitForSingleObject(&event,
136 Suspended,
137 KernelMode,
138 FALSE,
139 NULL);
140 DPRINT("Getting IO Status...\n");
141 status = ioStatus.Status;
142 }
143
144 if (!NT_SUCCESS(status)) {
145 DbgPrint("IO failed!!! Error code: %d(%x)\n", status, status);
146 return FALSE;
147 }
148
149
150 ExFreePool(mbr);
151 DPRINT("Block request succeeded\n");
152 return TRUE;
153 }
154