ReactOS 0.4.15-dev-8191-gbc6c731
blockdev.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS File System Recognizer
4 * FILE: drivers/filesystems/fs_rec/blockdev.c
5 * PURPOSE: Generic Helper Functions
6 * PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
7 * Eric Kohl
8 */
9
10/* INCLUDES *****************************************************************/
11
12#include "fs_rec.h"
13
14#include <ntdddisk.h>
15#include <ntddcdrm.h>
16
17#define NDEBUG
18#include <debug.h>
19
20/* FUNCTIONS ****************************************************************/
21
27{
31 PIRP Irp;
34 PAGED_CODE();
35
36 /* Only needed for disks */
37 if (DeviceObject->DeviceType != FILE_DEVICE_DISK) return FALSE;
38
39 /* Build the information IRP */
43 NULL,
44 0,
47 FALSE,
48 &Event,
50 if (!Irp) return FALSE;
51
52 /* Override verification */
54
55 /* Do the request */
58 {
59 /* Wait for completion */
63 FALSE,
64 NULL);
66 }
67
68 /* Fail if we couldn't get the data */
69 if (!NT_SUCCESS(Status)) return FALSE;
70
71 /* Otherwise, return the number of sectors */
74 &Remainder);
75 return TRUE;
76}
77
82{
83 DISK_GEOMETRY DiskGeometry;
86 PIRP Irp;
89 PAGED_CODE();
90
91 /* Check what device we have */
92 switch (DeviceObject->DeviceType)
93 {
95
96 /* Use the CD IOCTL */
98 break;
99
100 case FILE_DEVICE_DISK:
101
102 /* Use the Disk IOCTL */
104 break;
105
106 default:
107
108 /* Invalid device type */
109 return FALSE;
110 }
111
112 /* Build the information IRP */
116 NULL,
117 0,
118 &DiskGeometry,
119 sizeof(DISK_GEOMETRY),
120 FALSE,
121 &Event,
123 if (!Irp) return FALSE;
124
125 /* Override verification */
127
128 /* Do the request */
130 if (Status == STATUS_PENDING)
131 {
132 /* Wait for completion */
134 Executive,
136 FALSE,
137 NULL);
139 }
140
141 /* Fail if we couldn't get the data */
142 if (!NT_SUCCESS(Status)) return FALSE;
143
144 /* Return the sector size if it's valid */
145 if (!DiskGeometry.BytesPerSector) return FALSE;
146 *SectorSize = DiskGeometry.BytesPerSector;
147 return TRUE;
148}
149
151NTAPI
157 OUT PBOOLEAN DeviceError OPTIONAL)
158{
161 PIRP Irp;
163 PAGED_CODE();
164
165 /* Assume failure */
166 if (DeviceError) *DeviceError = FALSE;
167
168 /* Check if the caller requested too little */
169 if (Length < SectorSize)
170 {
171 /* Read at least the sector size */
173 }
174 else
175 {
176 /* Otherwise, just round up the request to sector size */
178 }
179
180 /* Check if the caller gave us a buffer */
181 if (!*Buffer)
182 {
183 /* He didn't, allocate one */
186 FSREC_TAG);
187 if (!*Buffer) return FALSE;
188 }
189
190 /* Build the IRP */
194 *Buffer,
195 Length,
196 Offset,
197 &Event,
199 if (!Irp) return FALSE;
200
201 /* Override verification */
203
204 /* Do the request */
206 if (Status == STATUS_PENDING)
207 {
208 /* Wait for completion */
210 Executive,
212 FALSE,
213 NULL);
215 }
216
217 /* Check if we couldn't get the data */
218 if (!NT_SUCCESS(Status))
219 {
220 /* Check if caller wanted to know about the device and fail */
221 if (DeviceError) *DeviceError = TRUE;
222 return FALSE;
223 }
224
225 /* All went well */
226 return TRUE;
227}
#define PAGED_CODE()
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
#define IOCTL_DISK_GET_DRIVE_GEOMETRY
Definition: cdrw_usr.h:169
Definition: bufpool.h:45
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define NonPagedPool
Definition: env_spec_w32.h:307
#define ROUND_UP(n, align)
Definition: eventvwr.h:34
BOOLEAN NTAPI FsRecReadBlock(IN PDEVICE_OBJECT DeviceObject, IN PLARGE_INTEGER Offset, IN ULONG Length, IN ULONG SectorSize, IN OUT PVOID *Buffer, OUT PBOOLEAN DeviceError OPTIONAL)
Definition: blockdev.c:152
BOOLEAN NTAPI FsRecGetDeviceSectors(IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, OUT PLARGE_INTEGER SectorCount)
Definition: blockdev.c:24
BOOLEAN NTAPI FsRecGetDeviceSectorSize(IN PDEVICE_OBJECT DeviceObject, OUT PULONG SectorSize)
Definition: blockdev.c:80
#define FSREC_TAG
Definition: fs_rec.h:16
Status
Definition: gdiplustypes.h:25
NTSYSAPI LONGLONG WINAPI RtlExtendedLargeIntegerDivide(LONGLONG, INT, INT *)
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
#define KernelMode
Definition: asm.h:34
#define IOCTL_CDROM_GET_DRIVE_GEOMETRY
Definition: ntddcdrm.h:73
#define IOCTL_DISK_GET_PARTITION_INFO
Definition: ntdddisk.h:106
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
@ SynchronizationEvent
PIRP NTAPI IoBuildSynchronousFsdRequest(IN ULONG MajorFunction, IN PDEVICE_OBJECT DeviceObject, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER StartingOffset, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:1069
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
#define IoCallDriver
Definition: irp.c:1225
#define STATUS_PENDING
Definition: ntstatus.h:82
ULONG SectorCount
Definition: part_xbox.c:31
#define FILE_DEVICE_CD_ROM
Definition: winioctl.h:108
#define FILE_DEVICE_DISK
Definition: winioctl.h:113
#define IRP_MJ_READ
Definition: rdpdr.c:46
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
ULONG BytesPerSector
Definition: ntdddisk.h:409
uint32_t * PULONG
Definition: typedefs.h:59
unsigned char * PBOOLEAN
Definition: typedefs.h:53
#define NTAPI
Definition: typedefs.h:36
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_IRQL_requires_same_ typedef _In_ ULONG ControlCode
Definition: wmitypes.h:55
_In_ ULONG SectorSize
Definition: halfuncs.h:291
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
_In_ ULONG _In_ struct _SET_PARTITION_INFORMATION_EX * PartitionInfo
Definition: iofuncs.h:2105
#define SL_OVERRIDE_VERIFY_VOLUME
Definition: iotypes.h:1823
@ Executive
Definition: ketypes.h:415
#define ROUND_TO_PAGES(Size)
_In_ LARGE_INTEGER _Out_opt_ PLARGE_INTEGER Remainder
Definition: rtlfuncs.h:3045