ReactOS 0.4.16-dev-91-g764881a
blockdev.c File Reference
#include "fs_rec.h"
#include <ntdddisk.h>
#include <ntddcdrm.h>
#include <debug.h>
Include dependency graph for blockdev.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

BOOLEAN NTAPI FsRecGetDeviceSectors (IN PDEVICE_OBJECT DeviceObject, IN ULONG SectorSize, OUT PLARGE_INTEGER SectorCount)
 
BOOLEAN NTAPI FsRecGetDeviceSectorSize (IN PDEVICE_OBJECT DeviceObject, OUT PULONG SectorSize)
 
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)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 17 of file blockdev.c.

Function Documentation

◆ FsRecGetDeviceSectors()

BOOLEAN NTAPI FsRecGetDeviceSectors ( IN PDEVICE_OBJECT  DeviceObject,
IN ULONG  SectorSize,
OUT PLARGE_INTEGER  SectorCount 
)

Definition at line 24 of file blockdev.c.

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}
#define PAGED_CODE()
LONG NTSTATUS
Definition: precomp.h:26
_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:33
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
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_DISK_GET_PARTITION_INFO
Definition: ntdddisk.h:106
@ SynchronizationEvent
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_DISK
Definition: winioctl.h:52
uint32_t ULONG
Definition: typedefs.h:59
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_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
_In_ LARGE_INTEGER _Out_opt_ PLARGE_INTEGER Remainder
Definition: rtlfuncs.h:3059

Referenced by FsRecNtfsFsControl().

◆ FsRecGetDeviceSectorSize()

BOOLEAN NTAPI FsRecGetDeviceSectorSize ( IN PDEVICE_OBJECT  DeviceObject,
OUT PULONG  SectorSize 
)

Definition at line 80 of file blockdev.c.

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}
#define IOCTL_DISK_GET_DRIVE_GEOMETRY
Definition: cdrw_usr.h:169
#define IOCTL_CDROM_GET_DRIVE_GEOMETRY
Definition: ntddcdrm.h:73
#define FILE_DEVICE_CD_ROM
Definition: winioctl.h:47
ULONG BytesPerSector
Definition: ntdddisk.h:404
_IRQL_requires_same_ typedef _In_ ULONG ControlCode
Definition: wmitypes.h:55

Referenced by FsRecBtrfsFsControl(), FsRecCdfsFsControl(), FsRecExt2FsControl(), FsRecFatxFsControl(), FsRecFfsFsControl(), FsRecNtfsFsControl(), FsRecReiserfsFsControl(), FsRecUdfsFsControl(), and FsRecVfatFsControl().

◆ FsRecReadBlock()

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 at line 152 of file blockdev.c.

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}
Definition: bufpool.h:45
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define NonPagedPool
Definition: env_spec_w32.h:307
#define ROUND_UP(n, align)
Definition: eventvwr.h:34
#define FSREC_TAG
Definition: fs_rec.h:16
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
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
#define IRP_MJ_READ
Definition: rdpdr.c:46
#define ROUND_TO_PAGES(Size)

Referenced by FsRecBtrfsFsControl(), FsRecExt2FsControl(), FsRecFatxFsControl(), FsRecFfsFsControl(), FsRecIsCdfsVolume(), FsRecIsUdfsVolume(), FsRecNtfsFsControl(), FsRecReiserfsFsControl(), and FsRecVfatFsControl().