c8008bb907a1396f61024bc55f9b6c7175271fb1
[reactos.git] / reactos / drivers / fs / fs_rec / blockdev.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 2002 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /* $Id: blockdev.c,v 1.1 2002/05/15 09:40:47 ekohl Exp $
20 *
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
23 * FILE: services/fs/fs_rec/blockdev.c
24 * PURPOSE: Filesystem recognizer driver
25 * PROGRAMMER: Eric Kohl
26 */
27
28 /* INCLUDES *****************************************************************/
29
30 #include <ddk/ntddk.h>
31
32 #define NDEBUG
33 #include <debug.h>
34
35 #include "fs_rec.h"
36
37
38 /* FUNCTIONS ****************************************************************/
39
40 NTSTATUS
41 FsRecReadSectors(IN PDEVICE_OBJECT DeviceObject,
42 IN ULONG DiskSector,
43 IN ULONG SectorCount,
44 IN ULONG SectorSize,
45 IN OUT PUCHAR Buffer)
46 {
47 PIO_STACK_LOCATION Stack;
48 IO_STATUS_BLOCK IoStatus;
49 LARGE_INTEGER Offset;
50 ULONG BlockSize;
51 KEVENT Event;
52 PIRP Irp;
53 NTSTATUS Status;
54
55 KeInitializeEvent(&Event,
56 NotificationEvent,
57 FALSE);
58
59 Offset.QuadPart = (LONGLONG)DiskSector * (LONGLONG)SectorSize;
60 BlockSize = SectorCount * SectorSize;
61
62 DPRINT("FsrecReadSectors(DeviceObject %x, DiskSector %d, Buffer %x)\n",
63 DeviceObject, DiskSector, Buffer);
64 DPRINT("Offset %I64x BlockSize %ld\n",
65 Offset.QuadPart,
66 BlockSize);
67
68 DPRINT("Building synchronous FSD Request...\n");
69 Irp = IoBuildSynchronousFsdRequest(IRP_MJ_READ,
70 DeviceObject,
71 Buffer,
72 BlockSize,
73 &Offset,
74 &Event,
75 &IoStatus);
76 if (Irp == NULL)
77 {
78 DPRINT("IoBuildSynchronousFsdRequest failed\n");
79 return(STATUS_INSUFFICIENT_RESOURCES);
80 }
81
82 DPRINT("Calling IO Driver... with irp %x\n", Irp);
83 Status = IoCallDriver(DeviceObject, Irp);
84
85 DPRINT("Waiting for IO Operation for %x\n", Irp);
86 if (Status == STATUS_PENDING)
87 {
88 DPRINT("Operation pending\n");
89 KeWaitForSingleObject(&Event, Suspended, KernelMode, FALSE, NULL);
90 DPRINT("Getting IO Status... for %x\n", Irp);
91 Status = IoStatus.Status;
92 }
93
94 if (!NT_SUCCESS(Status))
95 {
96 DPRINT("FsrecReadSectors() failed (Status %x)\n", Status);
97 DPRINT("(DeviceObject %x, DiskSector %x, Buffer %x, Offset 0x%I64x)\n",
98 DeviceObject, DiskSector, Buffer,
99 Offset.QuadPart);
100 return(Status);
101 }
102
103 DPRINT("Block request succeeded for %x\n", Irp);
104
105 return(STATUS_SUCCESS);
106 }
107
108 /* EOF */