Register CDFS as a disk filesystem too in order to flash our ISOs directly to USB drives and boot from them. Also fix some DPRINTs in the course of that.

One step closer towards CORE-13184: This gets qemu -hda bootcd.iso to work.
What still doesn't work is qemu -hda livecd.iso and booting from a flashed USB drive on real hardware.
Further changes are also required in fs_rec, but this code isn't ready yet and doesn't seem to be the current blocker either.

Credits go to the entire Hackfest Team for helping on this!!

svn path=/trunk/; revision=75579
This commit is contained in:
Colin Finck 2017-08-16 20:04:55 +00:00
parent 03d7bcb26c
commit 3c64b4cbe9
8 changed files with 66 additions and 38 deletions

View file

@ -55,9 +55,11 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
* RETURNS: Success or failure
*/
{
PDEVICE_OBJECT DeviceObject;
NTSTATUS Status;
UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Cdfs");
PDEVICE_OBJECT CdFsDeviceObject;
PDEVICE_OBJECT HddFsDeviceObject;
UNICODE_STRING CdFsDeviceName = RTL_CONSTANT_STRING(L"\\Cdfs");
UNICODE_STRING HddFsDeviceName = RTL_CONSTANT_STRING(L"\\CdfsHdd");
UNREFERENCED_PARAMETER(RegistryPath);
@ -65,25 +67,38 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
Status = IoCreateDevice(DriverObject,
sizeof(CDFS_GLOBAL_DATA),
&DeviceName,
&CdFsDeviceName,
FILE_DEVICE_CD_ROM_FILE_SYSTEM,
0,
FALSE,
&DeviceObject);
&CdFsDeviceObject);
if (!NT_SUCCESS(Status))
{
return(Status);
}
Status = IoCreateDevice(DriverObject,
0,
&HddFsDeviceName,
FILE_DEVICE_DISK_FILE_SYSTEM,
0,
FALSE,
&HddFsDeviceObject);
if (!NT_SUCCESS(Status))
{
return(Status);
}
/* Initialize global data */
CdfsGlobalData = DeviceObject->DeviceExtension;
CdfsGlobalData = CdFsDeviceObject->DeviceExtension;
RtlZeroMemory(CdfsGlobalData,
sizeof(CDFS_GLOBAL_DATA));
CdfsGlobalData->DriverObject = DriverObject;
CdfsGlobalData->DeviceObject = DeviceObject;
CdfsGlobalData->CdFsDeviceObject = CdFsDeviceObject;
CdfsGlobalData->HddFsDeviceObject = HddFsDeviceObject;
HddFsDeviceObject->DeviceExtension = CdfsGlobalData;
/* Initialize driver data */
DeviceObject->Flags = DO_DIRECT_IO;
DriverObject->MajorFunction[IRP_MJ_CLOSE] = CdfsFsdDispatch;
DriverObject->MajorFunction[IRP_MJ_CLEANUP] = CdfsFsdDispatch;
DriverObject->MajorFunction[IRP_MJ_CREATE] = CdfsFsdDispatch;
@ -116,12 +131,11 @@ DriverEntry(PDRIVER_OBJECT DriverObject,
CdfsGlobalData->CacheMgrCallbacks.AcquireForReadAhead = CdfsAcquireForLazyWrite;
CdfsGlobalData->CacheMgrCallbacks.ReleaseFromReadAhead = CdfsReleaseFromLazyWrite;
DeviceObject->Flags |= DO_LOW_PRIORITY_FILESYSTEM;
CdFsDeviceObject->Flags |= DO_DIRECT_IO | DO_LOW_PRIORITY_FILESYSTEM;
HddFsDeviceObject->Flags |= DO_DIRECT_IO | DO_LOW_PRIORITY_FILESYSTEM;
IoRegisterFileSystem(DeviceObject);
DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
IoRegisterFileSystem(CdFsDeviceObject);
IoRegisterFileSystem(HddFsDeviceObject);
return(STATUS_SUCCESS);
}

View file

@ -248,7 +248,8 @@ typedef struct _CCB
typedef struct _CDFS_GLOBAL_DATA
{
PDRIVER_OBJECT DriverObject;
PDEVICE_OBJECT DeviceObject;
PDEVICE_OBJECT CdFsDeviceObject;
PDEVICE_OBJECT HddFsDeviceObject;
ULONG Flags;
CACHE_MANAGER_CALLBACKS CacheMgrCallbacks;
FAST_IO_DISPATCH FastIoDispatch;

View file

@ -97,7 +97,7 @@ CdfsCleanup(
DeviceObject = IrpContext->DeviceObject;
Stack = IrpContext->Stack;
if (DeviceObject == CdfsGlobalData->DeviceObject)
if (DeviceObject == CdfsGlobalData->CdFsDeviceObject || DeviceObject == CdfsGlobalData->HddFsDeviceObject)
{
DPRINT("Closing file system\n");
Status = STATUS_SUCCESS;

View file

@ -94,7 +94,7 @@ CdfsClose(
DeviceObject = IrpContext->DeviceObject;
Stack = IrpContext->Stack;
if (DeviceObject == CdfsGlobalData->DeviceObject)
if (DeviceObject == CdfsGlobalData->CdFsDeviceObject || DeviceObject == CdfsGlobalData->HddFsDeviceObject)
{
DPRINT("Closing file system\n");
Status = STATUS_SUCCESS;

View file

@ -266,7 +266,7 @@ CdfsCreate(
ASSERT(IrpContext);
DeviceObject = IrpContext->DeviceObject;
if (DeviceObject == CdfsGlobalData->DeviceObject)
if (DeviceObject == CdfsGlobalData->CdFsDeviceObject || DeviceObject == CdfsGlobalData->HddFsDeviceObject)
{
/* DeviceObject represents FileSystem instead of logical volume */
DPRINT("Opening file system\n");

View file

@ -63,7 +63,7 @@ CdfsLockControl(
DPRINT("CdfsLockControl(IrpContext %p)\n", IrpContext);
if (IrpContext->DeviceObject == CdfsGlobalData->DeviceObject)
if (IrpContext->DeviceObject == CdfsGlobalData->CdFsDeviceObject || IrpContext->DeviceObject == CdfsGlobalData->HddFsDeviceObject)
{
return STATUS_INVALID_DEVICE_REQUEST;
}

View file

@ -138,9 +138,9 @@ CdfsGrabFCB(PDEVICE_EXTENSION Vcb,
{
KIRQL oldIrql;
DPRINT("grabbing FCB at %p: %S, refCount:%d\n",
DPRINT("grabbing FCB at %p: %wZ, refCount:%d\n",
Fcb,
Fcb->PathName,
&Fcb->PathName,
Fcb->RefCount);
KeAcquireSpinLock(&Vcb->FcbListLock, &oldIrql);
@ -208,7 +208,8 @@ CdfsGrabFCBFromTable(PDEVICE_EXTENSION Vcb,
{
Fcb = CONTAINING_RECORD(current_entry, FCB, FcbListEntry);
DPRINT("Comparing '%wZ' and '%wZ'\n", FileName, &Fcb->PathName);
// Disabled the DPRINT! Can't be called at DISPATCH_LEVEL!
//DPRINT("Comparing '%wZ' and '%wZ'\n", FileName, &Fcb->PathName);
if (RtlCompareUnicodeString(FileName, &Fcb->PathName, TRUE) == 0)
{
Fcb->RefCount++;

View file

@ -222,26 +222,29 @@ CdfsGetVolumeData(
&Toc,
&Size,
TRUE);
if (!NT_SUCCESS(Status))
if (NT_SUCCESS(Status))
{
ExFreePoolWithTag(Buffer, CDFS_TAG);
return Status;
DPRINT("FirstTrack %u, LastTrack %u, TrackNumber %u\n",
Toc.FirstTrack, Toc.LastTrack, Toc.TrackData[0].TrackNumber);
Offset = Toc.TrackData[0].Address[1] * 60 * 75;
Offset += Toc.TrackData[0].Address[2] * 75;
Offset += Toc.TrackData[0].Address[3];
if (Offset >= 150)
{
/* Remove MSF numbering offset of first frame */
/* FIXME: should be done only for real cdroms? */
Offset -= 150;
}
CdInfo->VolumeOffset = Offset;
}
DPRINT("FirstTrack %u, LastTrack %u, TrackNumber %u\n",
Toc.FirstTrack, Toc.LastTrack, Toc.TrackData[0].TrackNumber);
Offset = Toc.TrackData[0].Address[1] * 60 * 75;
Offset += Toc.TrackData[0].Address[2] * 75;
Offset += Toc.TrackData[0].Address[3];
if (Offset >= 150)
else
{
/* Remove MSF numbering offset of first frame */
/* FIXME: should be done only for real cdroms? */
Offset -= 150;
DPRINT1("Allowing mount of CDFS volume on non-CD device\n");
CdInfo->VolumeOffset = 0;
}
CdInfo->VolumeOffset = Offset;
DPRINT("Offset of first track in last session %u\n", Offset);
CdInfo->JolietLevel = 0;
@ -325,10 +328,19 @@ CdfsMountVolume(
PVPB Vpb;
NTSTATUS Status;
CDINFO CdInfo;
DEVICE_TYPE FilesystemDeviceType;
DPRINT("CdfsMountVolume() called\n");
if (DeviceObject != CdfsGlobalData->DeviceObject)
if (DeviceObject == CdfsGlobalData->CdFsDeviceObject)
{
FilesystemDeviceType = FILE_DEVICE_CD_ROM_FILE_SYSTEM;
}
else if (DeviceObject == CdfsGlobalData->HddFsDeviceObject)
{
FilesystemDeviceType = FILE_DEVICE_DISK_FILE_SYSTEM;
}
else
{
Status = STATUS_INVALID_DEVICE_REQUEST;
goto ByeBye;
@ -347,7 +359,7 @@ CdfsMountVolume(
Status = IoCreateDevice(CdfsGlobalData->DriverObject,
sizeof(DEVICE_EXTENSION),
NULL,
FILE_DEVICE_CD_ROM_FILE_SYSTEM,
FilesystemDeviceType,
DeviceToMount->Characteristics,
FALSE,
&NewDeviceObject);