static VOID DokanControl(PDOKAN_CONTROL Control) { DWORD written = 0; DbgPrint("DokanControl\n"); Control->Status = DOKAN_CONTROL_FAIL; switch (Control->Type) { case DOKAN_CONTROL_MOUNT: DbgPrintW(L"DokanControl Mount\n"); if (DokanControlMount(Control->Mount.Device, Control->Mount.Drive)) { // DeviceNumber is zero origin // add 1 to avoid to be the same number with DOKAN_CONTROL_FAIL g_MountTable[towlower(Control->Mount.Drive) - L'a'] = (unsigned char)Control->Mount.Device + 1; Control->Status = DOKAN_CONTROL_SUCCESS; } else { Control->Status = DOKAN_CONTROL_FAIL; } break; case DOKAN_CONTROL_UNMOUNT: DbgPrintW(L"DokanControl Unmount\n"); if (DokanControlUnmount(Control->Unmount.Drive)) { g_MountTable[towlower(Control->Mount.Drive) - L'a'] = 0; Control->Status = DOKAN_CONTROL_SUCCESS; } else { Control->Status = DOKAN_CONTROL_FAIL; } break; case DOKAN_CONTROL_CHECK: { unsigned char device = g_MountTable[towlower(Control->Check.Drive) - L'a']; DbgPrintW(L"DokanControl Check : %d\n", device); Control->Status = device; } break; default: DbgPrintW(L"DokanControl UnknownType %u\n", Control->Type); } return; }
int wmain(int argc, WCHAR *argv[]) { if (argc < 2) { Usage: fprintf(stderr, "Usage: %ws -m mountPoint deviceName\n"); fprintf(stderr, "Usage: %ws -u mountPoint\n"); return(1); } if (!wcscmp(argv[1], L"-m")) { if (argc < 4) goto Usage; WCHAR* MountPoint = argv[2]; WCHAR* DeviceName = argv[3]; if (!DokanControlMount(MountPoint, DeviceName)) { fprintf(stderr, "failed to mount\n"); return(1); } else printf("Device mounted\n"); } else if (!wcscmp(argv[1], L"-u")) { if (argc < 3) goto Usage; WCHAR* MountPoint = argv[2]; if (!DokanControlUnmount(MountPoint)) { fprintf(stderr, "failed to unmount\n"); return(1); } else printf("Device unmounted\n"); } else goto Usage; return(0); }
static VOID DokanControl(PDOKAN_CONTROL Control) { PMOUNT_ENTRY mountEntry; Control->Status = DOKAN_CONTROL_FAIL; switch (Control->Type) { case DOKAN_CONTROL_MOUNT: DbgPrintW(L"DokanControl Mount\n"); if (DokanControlMount(Control->MountPoint, Control->DeviceName)) { Control->Status = DOKAN_CONTROL_SUCCESS; InsertMountEntry(Control); } else { Control->Status = DOKAN_CONTROL_FAIL; } break; case DOKAN_CONTROL_UNMOUNT: DbgPrintW(L"DokanControl Unmount\n"); mountEntry = FindMountEntry(Control); if (mountEntry == NULL) { if (!wcslen(Control->MountPoint)) FindMountPoint(Control); DbgPrintW(L"DokanControl MountEntry not found. Try unmount '%s' force: %d\n", Control->MountPoint, Control->Option); if (Control->Option == DOKAN_CONTROL_OPTION_FORCE_UNMOUNT && DokanControlUnmount(Control->MountPoint)) { Control->Status = DOKAN_CONTROL_SUCCESS; break; } Control->Status = DOKAN_CONTROL_FAIL; break; } if (DokanControlUnmount(mountEntry->MountControl.MountPoint)) { Control->Status = DOKAN_CONTROL_SUCCESS; if (Control->DeviceName[0] == L'\0') { wcscpy_s(Control->DeviceName, sizeof(Control->DeviceName) / sizeof(WCHAR), mountEntry->MountControl.DeviceName); } RemoveMountEntry(mountEntry); } else { mountEntry->MountControl.Status = DOKAN_CONTROL_FAIL; Control->Status = DOKAN_CONTROL_FAIL; } break; case DOKAN_CONTROL_CHECK: { DbgPrint("DokanControl Check\n"); Control->Status = 0; } break; case DOKAN_CONTROL_FIND: { DbgPrintW(L"DokanControl Find\n"); DokanControlFind(Control); } break; case DOKAN_CONTROL_LIST: { DbgPrintW(L"DokanControl List\n"); DokanControlList(Control); } break; default: DbgPrintW(L"DokanControl UnknownType %u\n", Control->Type); } return; }