107{
113
114 VFDTRACE(0, (
"[VFD] VfdOpenImage - IN\n"));
115
116
117
118
119 if (ImageInfo->NameLength) {
120
121 if (ImageInfo->NameLength + 1 >
122 DeviceExtension->FileName.MaximumLength) {
123
124
125
126 if (DeviceExtension->FileName.Buffer) {
129 &DeviceExtension->FileName,
131 }
132
135
136 if (!DeviceExtension->FileName.Buffer) {
137 VFDTRACE(0, (
"[VFD] Can't allocate memory for image path\n"));
139 }
140
141 DeviceExtension->FileName.MaximumLength
142 = (
USHORT)(ImageInfo->NameLength + 1);
143
145 DeviceExtension->FileName.Buffer,
146 DeviceExtension->FileName.MaximumLength);
147 }
148
149 if (DeviceExtension->FileName.Buffer) {
151 DeviceExtension->FileName.Buffer,
152 ImageInfo->FileName,
153 ImageInfo->NameLength);
154
155 DeviceExtension->FileName.Buffer[ImageInfo->NameLength] = '\0';
156 }
157 }
158
159 DeviceExtension->FileName.Length = ImageInfo->NameLength;
160
161
162
163
164
165
166 geometry = &
geom_tbl[ImageInfo->MediaType];
167
172
173 if (ImageInfo->ImageSize != 0 &&
175
176 VFDTRACE(0, (
"[VFD] Image is smaller than the media\n"));
178 }
179
180
181
182
184
185
186
195
196
197
199 &unicode_name, &DeviceExtension->FileName,
TRUE);
200
202 VFDTRACE(0, (
"[VFD] Failed to convert filename to UNICODE\n"));
204 }
205
207 ("[VFD] Opening %s\n", DeviceExtension->FileName.Buffer));
208
209
210
212 &attributes,
213 &unicode_name,
217
218
219
223 &attributes,
227 0,
234 0);
235
237
239 VFDTRACE(0, (
"[VFD] ZwCreateFile - %s\n",
242 }
243
244
245
246 status = ZwQueryInformationFile(
249 &file_standard,
252
255 ("[VFD] ZwQueryInformationFile - FILE_STANDARD_INFORMATION\n"));
256
258 goto exit_func;
259 }
260
261
262
264
265 VFDTRACE(0, (
"[VFD] file is smaller than the media.\n"));
266
268
270 goto exit_func;
271 }
272
274
275
276
277 network_drive =
FALSE;
278
284#ifndef __REACTOS__
285 &file_object,
286#else
287 (
PVOID *)&file_object,
288#endif
290
292 if (file_object && file_object->DeviceObject) {
293 VFDTRACE(VFDINFO, (
"[VFD] Device type is 0x%08x\n",
294 file_object->DeviceObject->DeviceType));
295
296 if (file_object->DeviceObject->DeviceType
298 network_drive =
TRUE;
299 }
300
301
302
303
304
305 }
306 else {
307 VFDTRACE(VFDWARN, (
"[VFD Cannot decide the device type\n"));
308 }
310 }
311 else {
312 VFDTRACE(0, (
"[VFD] ObReferenceObjectByHandle - %s\n",
314 }
315
316 if (!network_drive) {
317
318
319
320
321
322
323
324
325
326
327 status = ZwQueryInformationFile(
330 &file_basic,
333
336 ("[VFD] ZwQueryInformationFile - FILE_BASIC_INFORMATION\n"));
337
339 goto exit_func;
340 }
341
344 {
346 ("[VFD] Image file is compressed and/or encrypted\n"));
347
349
351 goto exit_func;
352 }
353 }
354
355
356
357 status = ZwQueryInformationFile(
360 &file_alignment,
363
366 ("[VFD] ZwQueryInformationFile - FILE_ALIGNMENT_INFORMATION\n"));
367
369 goto exit_func;
370 }
371
373
375
376 VFDTRACE(0, (
"[VFD] Opened an image file\n"));
377 }
378 else {
379
380
381
386
387 if (!DeviceExtension->FileBuffer) {
388 VFDTRACE(0, (
"[VFD] Can't allocate memory for RAM disk\n"));
390 }
391
393 DeviceExtension->FileBuffer,
395
396 if (ImageInfo->ImageSize) {
397 DeviceExtension->ImageSize = ImageInfo->ImageSize;
398 }
399 else {
401 }
402
404
405 VFDTRACE(0, (
"[VFD] Created an empty RAM disk\n"));
406 }
407
408 DeviceExtension->MediaChangeCount++;
409
410 DeviceExtension->MediaType = ImageInfo->MediaType;
411 DeviceExtension->MediaFlags = ImageInfo->MediaFlags;
412 DeviceExtension->FileType = ImageInfo->FileType;
413 DeviceExtension->Geometry = geometry;
414 DeviceExtension->Sectors =
sectors;
415
416 VFDTRACE(0, (
"[VFD] Media:%d Flag:0x%02x Size:%lu Capacity:%lu\n",
417 DeviceExtension->MediaType,
418 DeviceExtension->MediaFlags,
419 DeviceExtension->ImageSize,
420 DeviceExtension->Sectors));
421
422 DeviceExtension->DeviceObject->AlignmentRequirement
423 = alignment;
424
425exit_func:
426 VFDTRACE(0, (
"[VFD] VfdOpenImage - %s\n", GetStatusName(
status)));
427
429}
#define FILE_NON_DIRECTORY_FILE
#define NT_SUCCESS(StatCode)
#define FILE_ATTRIBUTE_NORMAL
@ FileAlignmentInformation
#define FILE_SYNCHRONOUS_IO_NONALERT
#define FILE_NO_INTERMEDIATE_BUFFERING
#define FILE_RANDOM_ACCESS
#define OBJ_CASE_INSENSITIVE
static HANDLE PIO_APC_ROUTINE void PIO_STATUS_BLOCK io_status
#define InitializeObjectAttributes(p, n, a, r, s)
#define FILE_ATTRIBUTE_COMPRESSED
#define FILE_WORD_ALIGNMENT
NTSYSAPI NTSTATUS NTAPI RtlAnsiStringToUnicodeString(PUNICODE_STRING DestinationString, PANSI_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define FILE_ATTRIBUTE_ENCRYPTED
NTSTATUS NTAPI ObReferenceObjectByHandle(IN HANDLE Handle, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PVOID *Object, OUT POBJECT_HANDLE_INFORMATION HandleInformation OPTIONAL)
#define FILE_DEVICE_NETWORK_FILE_SYSTEM
static FILE * file_handle
#define FileStandardInformation
#define RtlCopyMemory(Destination, Source, Length)
#define STATUS_ACCESS_DENIED
#define STATUS_INSUFFICIENT_RESOURCES
const DISK_GEOMETRY geom_tbl[VFD_MEDIA_MAX]
#define VFD_SECTOR_TO_BYTE(s)
#define ObDereferenceObject