void WINAPI GenerateBMPA(LPSTR fileName, LPSTR text, int margin, int size) { if (fileName == NULL) return; if (text == NULL) return; LPWSTR fileNameW = AllocateUnicodeString(fileName); LPWSTR textW = AllocateUnicodeString(text); GenerateBMPW(fileNameW, textW, margin, size); FreeUnicodeString(fileNameW); FreeUnicodeString(textW); }
VOID DokanDeleteDeviceObject( __in PDokanDCB Dcb) { UNICODE_STRING symbolicLinkName; WCHAR symbolicLinkBuf[MAXIMUM_FILENAME_LENGTH]; PDokanVCB vcb; ASSERT(GetIdentifierType(Dcb) == DCB); vcb = Dcb->Vcb; if (Dcb->MupHandle) { FsRtlDeregisterUncProvider(Dcb->MupHandle); } DDbgPrint(" Delete Symbolic Name: %wZ\n", Dcb->SymbolicLinkName); IoDeleteSymbolicLink(Dcb->SymbolicLinkName); FreeUnicodeString(Dcb->SymbolicLinkName); FreeUnicodeString(Dcb->DiskDeviceName); FreeUnicodeString(Dcb->FileSystemDeviceName); Dcb->SymbolicLinkName = NULL; Dcb->DiskDeviceName = NULL; Dcb->FileSystemDeviceName = NULL; if (Dcb->DeviceObject->Vpb) { Dcb->DeviceObject->Vpb->DeviceObject = NULL; Dcb->DeviceObject->Vpb->RealDevice = NULL; Dcb->DeviceObject->Vpb->Flags = 0; } //IoUnregisterFileSystem(vcb->DeviceObject); DDbgPrint(" FCB allocated: %d\n", vcb->FcbAllocated); DDbgPrint(" FCB freed: %d\n", vcb->FcbFreed); DDbgPrint(" CCB allocated: %d\n", vcb->CcbAllocated); DDbgPrint(" CCB freed: %d\n", vcb->CcbFreed); // delete diskDeviceObject DDbgPrint(" Delete DeviceObject\n"); IoDeleteDevice(vcb->DeviceObject); // delete DeviceObject DDbgPrint(" Delete Disk DeviceObject\n"); IoDeleteDevice(Dcb->DeviceObject); }
HBITMAP WINAPI GetHBitmapA(LPSTR text, int margin, int size) { if (text == NULL) return NULL; LPWSTR textW = AllocateUnicodeString(text); HBITMAP result = GetHBitmapW(textW, margin, size); FreeUnicodeString(textW); return result; }
static VOID FreeDcbNames(__in PDokanDCB Dcb) { if (Dcb->MountPoint != NULL) { FreeUnicodeString(Dcb->MountPoint); Dcb->MountPoint = NULL; } if (Dcb->SymbolicLinkName != NULL) { FreeUnicodeString(Dcb->SymbolicLinkName); Dcb->SymbolicLinkName = NULL; } if (Dcb->DiskDeviceName != NULL) { FreeUnicodeString(Dcb->DiskDeviceName); Dcb->DiskDeviceName = NULL; } if (Dcb->UNCName != NULL) { FreeUnicodeString(Dcb->UNCName); Dcb->UNCName = NULL; } }
NTSTATUS mvolQueryMountPoint(PVOLUME_EXTENSION pvext) { ULONG mplen = pvext->PhysicalDeviceNameLength + sizeof(MOUNTMGR_MOUNT_POINT); ULONG mpslen = 4096 * 2; PCHAR inbuf = kmalloc(mplen, 0, '56DW'); PCHAR otbuf = kmalloc(mpslen, 0, '56DW'); if (!inbuf || !otbuf) { return STATUS_MEMORY_NOT_ALLOCATED; } PMOUNTMGR_MOUNT_POINT pmp = (PMOUNTMGR_MOUNT_POINT)inbuf; PMOUNTMGR_MOUNT_POINTS pmps = (PMOUNTMGR_MOUNT_POINTS)otbuf; pmp->DeviceNameLength = pvext->PhysicalDeviceNameLength; pmp->DeviceNameOffset = sizeof(MOUNTMGR_MOUNT_POINT); RtlCopyMemory(inbuf + pmp->DeviceNameOffset, pvext->PhysicalDeviceName, pvext->PhysicalDeviceNameLength); NTSTATUS status = QueryMountPoint(pmp, mplen, pmps, &mpslen); if (!NT_SUCCESS(status)) { goto cleanup; } for (int i = 0; i < pmps->NumberOfMountPoints; i++) { PMOUNTMGR_MOUNT_POINT p = pmps->MountPoints + i; PUNICODE_STRING link = NULL; UNICODE_STRING name = { .Length = p->SymbolicLinkNameLength, .MaximumLength = p->SymbolicLinkNameLength, .Buffer = (PWCH)(otbuf + p->SymbolicLinkNameOffset) }; if (MOUNTMGR_IS_DRIVE_LETTER(&name)) { name.Length = strlen(" :") * sizeof(WCHAR); name.Buffer += strlen("\\DosDevices\\"); pvext->VolIndex = name.Buffer[0] - 'C'; link = &pvext->MountPoint; FreeUnicodeString(link); } else if (MOUNTMGR_IS_VOLUME_NAME(&name)) { link = &pvext->VolumeGuid; } link && ucsdup(link, name.Buffer, name.Length); } cleanup: kfree(inbuf); kfree(otbuf); return status; } #ifdef _WIN32_GetDiskPerf NTSTATUS mvolGetDiskPerf(PDEVICE_OBJECT TargetDeviceObject, PDISK_PERFORMANCE pDiskPerf) { NTSTATUS status; KEVENT event; IO_STATUS_BLOCK ioStatus; PIRP newIrp; KeInitializeEvent(&event, NotificationEvent, FALSE); newIrp = IoBuildDeviceIoControlRequest(IOCTL_DISK_PERFORMANCE, TargetDeviceObject, NULL, 0, pDiskPerf, sizeof(DISK_PERFORMANCE), FALSE, &event, &ioStatus); if (!newIrp) { return STATUS_INSUFFICIENT_RESOURCES; } status = IoCallDriver(TargetDeviceObject, newIrp); if (status == STATUS_PENDING) { KeWaitForSingleObject(&event, Executive, KernelMode, FALSE, (PLARGE_INTEGER) NULL); status = ioStatus.Status; } return status; }
NTSTATUS mvolRemoveDevice(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp) { NTSTATUS status; PVOLUME_EXTENSION VolumeExtension = DeviceObject->DeviceExtension; // we should call acuire removelock before pass down irp. // if acuire-removelock fail, we should return fail(STATUS_DELETE_PENDING). if (KeGetCurrentIrql() <= DISPATCH_LEVEL) { status = IoAcquireRemoveLock(&VolumeExtension->RemoveLock, NULL); if(!NT_SUCCESS(status)) { Irp->IoStatus.Status = status; Irp->IoStatus.Information = 0; IoCompleteRequest(Irp, IO_NO_INCREMENT); return status; } } status = mvolRunIrpSynchronous(DeviceObject, Irp); if (!NT_SUCCESS(status)) { WDRBD_ERROR("cannot remove device, status=0x%x\n", status); } IoReleaseRemoveLockAndWait(&VolumeExtension->RemoveLock, NULL); //wait remove lock IoDetachDevice(VolumeExtension->TargetDeviceObject); IoDeleteDevice(DeviceObject); #ifdef MULTI_WRITE_HOOKER_THREADS { int i = 0; for (i = 0; i < 5; i++) { if (deviceExtension->WorkThreadInfo[i].Active) { mvolTerminateThread(&deviceExtension->WorkThreadInfo); WDRBD_TRACE("[%ws]: WorkThread Terminate Completely\n", deviceExtension->PhysicalDeviceName); } } } #else if (VolumeExtension->WorkThreadInfo.Active) { mvolTerminateThread(&VolumeExtension->WorkThreadInfo); WDRBD_TRACE("[%ws]: WorkThread Terminate Completely\n", VolumeExtension->PhysicalDeviceName); } #endif if (VolumeExtension->dev) { struct drbd_device *device = minor_to_device(VolumeExtension->VolIndex); if (device) { // DRBD-UPGRADE: if primary, check umount first? maybe umounted already? struct drbd_resource *resource = device->resource; int ret; // DW-876: The function 'drbd_adm_down_from_engine' performs down operation with specified resource, it does clean up all it needs(including disconnecting connections..) // It should be called per resource. Do not call with the resource which is already down. ret = drbd_adm_down_from_engine(resource); if (ret != NO_ERROR) { WDRBD_ERROR("drbd_adm_down_from_engine failed. ret=%d\n", ret); // EVENTLOG! // error ignored. } } } FreeUnicodeString(&VolumeExtension->MountPoint); FreeUnicodeString(&VolumeExtension->VolumeGuid); MVOL_LOCK(); mvolDeleteDeviceList(VolumeExtension); MVOL_UNLOCK(); Irp->IoStatus.Status = status; IoCompleteRequest(Irp, IO_NO_INCREMENT); return status; }