ReactOS  0.4.15-dev-1384-g878186b
vfdfmt.c File Reference
#include "imports.h"
#include "vfddrv.h"
#include "vfddbg.h"
Include dependency graph for vfdfmt.c:

Go to the source code of this file.

Macros

#define F3_640_512   (MEDIA_TYPE)14
 
#define F3_1Pt2_512   (MEDIA_TYPE)17
 

Functions

NTSTATUS VfdFormatCheck (PDEVICE_EXTENSION DeviceExtension, PFORMAT_PARAMETERS FormatParams, ULONG InputLength, ULONG ControlCode)
 
NTSTATUS VfdFormatTrack (IN PDEVICE_EXTENSION DeviceExtension, IN PFORMAT_PARAMETERS FormatParams)
 

Variables

DISK_GEOMETRY const geom_tbl [VFD_MEDIA_MAX]
 

Macro Definition Documentation

◆ F3_1Pt2_512

#define F3_1Pt2_512   (MEDIA_TYPE)17

Definition at line 27 of file vfdfmt.c.

◆ F3_640_512

#define F3_640_512   (MEDIA_TYPE)14

Definition at line 24 of file vfdfmt.c.

Function Documentation

◆ VfdFormatCheck()

NTSTATUS VfdFormatCheck ( PDEVICE_EXTENSION  DeviceExtension,
PFORMAT_PARAMETERS  FormatParams,
ULONG  InputLength,
ULONG  ControlCode 
)

Definition at line 73 of file vfdfmt.c.

78 {
79  const DISK_GEOMETRY *geometry;
80 
81  // Check media status
82 
83  if (!DeviceExtension->FileHandle &&
84  !DeviceExtension->FileBuffer) {
86  }
87 
88  // Media is writable?
89 
90  if (DeviceExtension->MediaFlags & VFD_FLAG_WRITE_PROTECTED) {
92  }
93 
94  // Check input parameter size
95 
96  if (InputLength < sizeof(FORMAT_PARAMETERS)) {
98  }
99 
100  // Choose appropriate DISK_GEOMETRY for current image size
101 
102  geometry = DeviceExtension->Geometry;
103 
104  if (!geometry) {
106  }
107 
108  // Input parameter sanity check
109 
110  if ((FormatParams->StartHeadNumber > geometry->TracksPerCylinder - 1) ||
111  (FormatParams->EndHeadNumber > geometry->TracksPerCylinder - 1) ||
112  (FormatParams->StartCylinderNumber > geometry->Cylinders.LowPart) ||
113  (FormatParams->EndCylinderNumber > geometry->Cylinders.LowPart) ||
114  (FormatParams->EndCylinderNumber < FormatParams->StartCylinderNumber))
115  {
117  }
118 
119  // If this is an EX request then make a couple of extra checks
120 
122 
123  PFORMAT_EX_PARAMETERS exparams;
124 
125  if (InputLength < sizeof(FORMAT_EX_PARAMETERS)) {
127  }
128 
129  exparams = (PFORMAT_EX_PARAMETERS)FormatParams;
130 
131  if (InputLength <
132  FIELD_OFFSET(FORMAT_EX_PARAMETERS, SectorNumber) +
133  exparams->SectorsPerTrack * sizeof(USHORT))
134  {
136  }
137 
138  if (exparams->FormatGapLength > geometry->SectorsPerTrack ||
139  exparams->SectorsPerTrack != geometry->SectorsPerTrack)
140  {
142  }
143  }
144 
145  return STATUS_SUCCESS;
146 }
#define STATUS_NO_MEDIA_IN_DEVICE
Definition: udferr_usr.h:141
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
ULONG TracksPerCylinder
Definition: ntdddisk.h:440
#define STATUS_MEDIA_WRITE_PROTECTED
Definition: udferr_usr.h:161
_IRQL_requires_same_ typedef _In_ ULONG ControlCode
Definition: wmitypes.h:55
ULONG StartCylinderNumber
Definition: ntdddisk.h:589
#define VFD_FLAG_WRITE_PROTECTED
Definition: vfdtypes.h:68
LARGE_INTEGER Cylinders
Definition: ntdddisk.h:438
ULONG SectorsPerTrack
Definition: ntdddisk.h:441
#define STATUS_DRIVER_INTERNAL_ERROR
Definition: udferr_usr.h:177
ULONG LowPart
Definition: typedefs.h:106
unsigned short USHORT
Definition: pedump.c:61
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define IOCTL_DISK_FORMAT_TRACKS_EX
Definition: cdrw_usr.h:173
struct _FORMAT_EX_PARAMETERS * PFORMAT_EX_PARAMETERS
ULONG EndCylinderNumber
Definition: ntdddisk.h:590
#define STATUS_SUCCESS
Definition: shellext.h:65
ULONG StartHeadNumber
Definition: ntdddisk.h:591

◆ VfdFormatTrack()

NTSTATUS VfdFormatTrack ( IN PDEVICE_EXTENSION  DeviceExtension,
IN PFORMAT_PARAMETERS  FormatParams 
)

Definition at line 153 of file vfdfmt.c.

156 {
157  const DISK_GEOMETRY *geometry;
158  ULONG track_length;
159  PUCHAR format_buffer;
160  LARGE_INTEGER start_offset;
161  LARGE_INTEGER end_offset;
163 
164  VFDTRACE(0, ("[VFD] VfdFormatTrack - IN\n"));
165 
166  ASSERT(DeviceExtension != NULL);
167 
168  geometry = DeviceExtension->Geometry;
169 
170  if (!geometry) {
172  }
173 
174  track_length = geometry->BytesPerSector * geometry->SectorsPerTrack;
175 
176  format_buffer = (PUCHAR)ExAllocatePoolWithTag(
177  PagedPool, track_length, VFD_POOL_TAG);
178 
179  if (format_buffer == NULL) {
180  VFDTRACE(0, ("[VFD] cannot allocate a format buffer\n"));
182  }
183 
184  RtlFillMemory(format_buffer, track_length, VFD_FORMAT_FILL_DATA);
185 
186  start_offset.QuadPart =
187  FormatParams->StartCylinderNumber * geometry->TracksPerCylinder * track_length +
188  FormatParams->StartHeadNumber * track_length;
189 
190  end_offset.QuadPart =
191  FormatParams->EndCylinderNumber * geometry->TracksPerCylinder * track_length +
192  FormatParams->EndHeadNumber * track_length;
193 
194  do {
195  if (DeviceExtension->FileHandle) {
197 
198  status = ZwWriteFile(
199  DeviceExtension->FileHandle,
200  NULL,
201  NULL,
202  NULL,
203  &io_status,
204  format_buffer,
205  track_length,
206  &start_offset,
207  NULL);
208 
209  if (!NT_SUCCESS(status)) {
210  VFDTRACE(0, ("[VFD] ZwWriteFile - %s\n",
211  GetStatusName(status)));
212  break;
213  }
214  }
215  else {
217  DeviceExtension->FileBuffer + start_offset.QuadPart,
218  format_buffer,
219  track_length);
220 
222  }
223 
224  start_offset.QuadPart += track_length;
225  }
226  while (start_offset.QuadPart <= end_offset.QuadPart);
227 
228  ExFreePool(format_buffer);
229 
230  VFDTRACE(0, ("[VFD] VfdFormatTrack - OUT\n"));
231 
232  return status;
233 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
static HANDLE PIO_APC_ROUTINE void PIO_STATUS_BLOCK io_status
Definition: comm.c:54
ULONG BytesPerSector
Definition: ntdddisk.h:442
ULONG TracksPerCylinder
Definition: ntdddisk.h:440
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
#define VFD_FORMAT_FILL_DATA
Definition: vfdio.h:51
#define ASSERT(a)
Definition: mode.c:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define RtlFillMemory(Dest, Length, Fill)
Definition: winternl.h:593
ULONG SectorsPerTrack
Definition: ntdddisk.h:441
#define VFDTRACE(LEVEL, STRING)
Definition: vfddbg.h:72
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define STATUS_DRIVER_INTERNAL_ERROR
Definition: udferr_usr.h:177
#define VFD_POOL_TAG
Definition: vfddrv.h:25
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
static SERVICE_STATUS status
Definition: service.c:31
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
LONGLONG QuadPart
Definition: typedefs.h:114
Definition: ps.c:97

Referenced by VfdIoCtlThread().

Variable Documentation

◆ geom_tbl