PFCB CdfsMakeRootFCB(PDEVICE_EXTENSION Vcb) { PFCB Fcb; Fcb = CdfsCreateFCB(L"\\"); Fcb->Entry.DataLengthL = Vcb->CdInfo.RootSize; Fcb->Entry.ExtentLocationL = Vcb->CdInfo.RootStart; Fcb->Entry.FileFlags = FILE_FLAG_DIRECTORY; Fcb->IndexNumber.QuadPart = 0LL; Fcb->RefCount = 1; Fcb->DirIndex = 0; Fcb->RFCB.FileSize.QuadPart = Vcb->CdInfo.RootSize; Fcb->RFCB.ValidDataLength.QuadPart = Vcb->CdInfo.RootSize; Fcb->RFCB.AllocationSize.QuadPart = Vcb->CdInfo.RootSize; CdfsFCBInitializeCache(Vcb, Fcb); CdfsAddFCBToTable(Vcb, Fcb); CdfsGrabFCB(Vcb, Fcb); return(Fcb); }
NTSTATUS CdfsMakeFCBFromDirEntry(PVCB Vcb, PFCB DirectoryFCB, PWSTR LongName, PWSTR ShortName, PDIR_RECORD Record, ULONG DirectorySector, ULONG DirectoryOffset, PFCB * fileFCB) { WCHAR pathName[MAX_PATH]; PFCB rcFCB; ULONG Size; if (LongName [0] != 0 && wcslen (DirectoryFCB->PathName) + sizeof(WCHAR) + wcslen (LongName) > MAX_PATH) { return(STATUS_OBJECT_NAME_INVALID); } wcscpy(pathName, DirectoryFCB->PathName); if (!CdfsFCBIsRoot(DirectoryFCB)) { wcscat(pathName, L"\\"); } if (LongName[0] != 0) { wcscat(pathName, LongName); } else { WCHAR entryName[MAX_PATH]; CdfsGetDirEntryName(Vcb, Record, entryName); wcscat(pathName, entryName); } rcFCB = CdfsCreateFCB(pathName); memcpy(&rcFCB->Entry, Record, sizeof(DIR_RECORD)); /* Copy short name into FCB */ rcFCB->ShortNameU.Length = wcslen(ShortName) * sizeof(WCHAR); rcFCB->ShortNameU.MaximumLength = rcFCB->ShortNameU.Length; rcFCB->ShortNameU.Buffer = rcFCB->ShortNameBuffer; wcscpy(rcFCB->ShortNameBuffer, ShortName); Size = rcFCB->Entry.DataLengthL; rcFCB->RFCB.FileSize.QuadPart = Size; rcFCB->RFCB.ValidDataLength.QuadPart = Size; rcFCB->RFCB.AllocationSize.QuadPart = ROUND_UP(Size, BLOCKSIZE); if (CdfsFCBIsDirectory(rcFCB)) { CdfsFCBInitializeCache(Vcb, rcFCB); } rcFCB->IndexNumber.u.HighPart = DirectorySector; rcFCB->IndexNumber.u.LowPart = DirectoryOffset; rcFCB->RefCount++; CdfsAddFCBToTable(Vcb, rcFCB); *fileFCB = rcFCB; DPRINT("%S %d %I64d\n", LongName, Size, rcFCB->RFCB.AllocationSize.QuadPart); return(STATUS_SUCCESS); }
static NTSTATUS CdfsMountVolume(PDEVICE_OBJECT DeviceObject, PIRP Irp) { PDEVICE_EXTENSION DeviceExt = NULL; PDEVICE_OBJECT NewDeviceObject = NULL; PDEVICE_OBJECT DeviceToMount; PIO_STACK_LOCATION Stack; PFCB Fcb = NULL; PCCB Ccb = NULL; PVPB Vpb; NTSTATUS Status; CDINFO CdInfo; DPRINT("CdfsMountVolume() called\n"); if (DeviceObject != CdfsGlobalData->DeviceObject) { Status = STATUS_INVALID_DEVICE_REQUEST; goto ByeBye; } Stack = IoGetCurrentIrpStackLocation(Irp); DeviceToMount = Stack->Parameters.MountVolume.DeviceObject; Vpb = Stack->Parameters.MountVolume.Vpb; Status = CdfsGetVolumeData(DeviceToMount, &CdInfo); if (!NT_SUCCESS(Status)) { goto ByeBye; } Status = IoCreateDevice(CdfsGlobalData->DriverObject, sizeof(DEVICE_EXTENSION), NULL, FILE_DEVICE_CD_ROM_FILE_SYSTEM, DeviceToMount->Characteristics, FALSE, &NewDeviceObject); if (!NT_SUCCESS(Status)) goto ByeBye; NewDeviceObject->Flags = NewDeviceObject->Flags | DO_DIRECT_IO; NewDeviceObject->Flags &= ~DO_VERIFY_VOLUME; DeviceExt = (PVOID)NewDeviceObject->DeviceExtension; RtlZeroMemory(DeviceExt, sizeof(DEVICE_EXTENSION)); Vpb->SerialNumber = CdInfo.SerialNumber; Vpb->VolumeLabelLength = CdInfo.VolumeLabelLength; RtlCopyMemory(Vpb->VolumeLabel, CdInfo.VolumeLabel, CdInfo.VolumeLabelLength); RtlCopyMemory(&DeviceExt->CdInfo, &CdInfo, sizeof(CDINFO)); NewDeviceObject->Vpb = DeviceToMount->Vpb; DeviceExt->VolumeDevice = NewDeviceObject; DeviceExt->StorageDevice = DeviceToMount; DeviceExt->StorageDevice->Vpb->DeviceObject = NewDeviceObject; DeviceExt->StorageDevice->Vpb->RealDevice = DeviceExt->StorageDevice; DeviceExt->StorageDevice->Vpb->Flags |= VPB_MOUNTED; NewDeviceObject->StackSize = DeviceExt->StorageDevice->StackSize + 1; NewDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING; /* Close (and cleanup) might be called from IoCreateStreamFileObject * but we use this resource from CdfsCleanup, therefore it should be * initialized no later than this. */ ExInitializeResourceLite(&DeviceExt->DirResource); DeviceExt->StreamFileObject = IoCreateStreamFileObject(NULL, DeviceExt->StorageDevice); Fcb = CdfsCreateFCB(NULL); if (Fcb == NULL) { Status = STATUS_INSUFFICIENT_RESOURCES; goto ByeBye; } Ccb = ExAllocatePoolWithTag(NonPagedPool, sizeof(CCB), TAG_CCB); if (Ccb == NULL) { Status = STATUS_INSUFFICIENT_RESOURCES; goto ByeBye; } RtlZeroMemory(Ccb, sizeof(CCB)); DeviceExt->StreamFileObject->ReadAccess = TRUE; DeviceExt->StreamFileObject->WriteAccess = FALSE; DeviceExt->StreamFileObject->DeleteAccess = FALSE; DeviceExt->StreamFileObject->FsContext = Fcb; DeviceExt->StreamFileObject->FsContext2 = Ccb; DeviceExt->StreamFileObject->SectionObjectPointer = &Fcb->SectionObjectPointers; DeviceExt->StreamFileObject->PrivateCacheMap = NULL; DeviceExt->StreamFileObject->Vpb = DeviceExt->Vpb; Ccb->PtrFileObject = DeviceExt->StreamFileObject; Fcb->FileObject = DeviceExt->StreamFileObject; Fcb->DevExt = (PDEVICE_EXTENSION)DeviceExt->StorageDevice; Fcb->Flags = FCB_IS_VOLUME_STREAM; Fcb->RFCB.FileSize.QuadPart = (DeviceExt->CdInfo.VolumeSpaceSize + DeviceExt->CdInfo.VolumeOffset) * BLOCKSIZE; Fcb->RFCB.ValidDataLength = Fcb->RFCB.AllocationSize = Fcb->RFCB.FileSize; Fcb->Entry.ExtentLocationL = 0; Fcb->Entry.DataLengthL = (DeviceExt->CdInfo.VolumeSpaceSize + DeviceExt->CdInfo.VolumeOffset) * BLOCKSIZE; CcInitializeCacheMap(DeviceExt->StreamFileObject, (PCC_FILE_SIZES)(&Fcb->RFCB.AllocationSize), TRUE, &(CdfsGlobalData->CacheMgrCallbacks), Fcb); ExInitializeResourceLite(&DeviceExt->VcbResource); KeInitializeSpinLock(&DeviceExt->FcbListLock); InitializeListHead(&DeviceExt->FcbListHead); FsRtlNotifyInitializeSync(&DeviceExt->NotifySync); InitializeListHead(&DeviceExt->NotifyList); Status = STATUS_SUCCESS; ByeBye: if (!NT_SUCCESS(Status)) { /* Cleanup */ if (DeviceExt && DeviceExt->StreamFileObject) ObDereferenceObject(DeviceExt->StreamFileObject); if (Fcb) ExFreePool(Fcb); if (NewDeviceObject) IoDeleteDevice(NewDeviceObject); } DPRINT("CdfsMountVolume() done (Status: %lx)\n", Status); return(Status); }