int Unmount(LPCWSTR MountPoint, BOOL ForceUnmount) { int status = EXIT_SUCCESS; DOKAN_CONTROL control; ZeroMemory(&control, sizeof(DOKAN_CONTROL)); if (wcslen(MountPoint) == 1 && L'0' <= MountPoint[0] && MountPoint[0] <= L'9') { control.Type = DOKAN_CONTROL_LIST; control.Option = MountPoint[0] - L'0'; DokanMountControl(&control); if (control.Status != DOKAN_CONTROL_SUCCESS || (control.Status == DOKAN_CONTROL_SUCCESS && !DokanRemoveMountPoint(control.MountPoint))) { fwprintf(stderr, L"Mount entry %d not found\n", control.Option); status = EXIT_FAILURE; } } else if (ForceUnmount) { control.Type = DOKAN_CONTROL_UNMOUNT; control.Option = DOKAN_CONTROL_OPTION_FORCE_UNMOUNT; wcscpy_s(control.MountPoint, sizeof(control.MountPoint) / sizeof(WCHAR), MountPoint); DokanMountControl(&control); if (control.Status != DOKAN_CONTROL_SUCCESS) status = EXIT_FAILURE; fwprintf(stderr, L"Unmount status %d - %s\tn", status, MountPoint); } else if (!DokanRemoveMountPoint(MountPoint)) status = EXIT_FAILURE; fwprintf(stderr, L"Unmount status = %d\n", status); return status; }
BOOL DokanMount( LPCWSTR MountPoint, LPCWSTR DeviceName,ULONG Options) { DOKAN_CONTROL control; BOOL result; //ZeroMemory(&control, sizeof(DOKAN_CONTROL)); DOKAN_CONTROL_INIT(control); control.Type = DOKAN_CONTROL_MOUNT; if(Options & DOKAN_OPTION_LOCAL){ control.Option |= DOKAN_CONTROL_OPTION_LOCAL_CONTEXT; } wcscpy_s(control.MountPoint, sizeof(control.MountPoint) / sizeof(WCHAR), MountPoint); wcscpy_s(control.DeviceName, sizeof(control.DeviceName) / sizeof(WCHAR), DeviceName); result = DokanMountControl(&control); if(result){ SHChangeNotify(SHCNE_DRIVEADD ,SHCNF_PATH|SHCNF_FLUSHNOWAIT,MountPoint,NULL); } return result; }
BOOL DOKANAPI DokanRemoveMountPoint( LPCWSTR MountPoint) { DOKAN_CONTROL control; BOOL result; //ZeroMemory(&control, sizeof(DOKAN_CONTROL)); DOKAN_CONTROL_INIT(control); control.Type = DOKAN_CONTROL_UNMOUNT; wcscpy_s(control.MountPoint, sizeof(control.MountPoint) / sizeof(WCHAR), MountPoint); DbgPrintW(L"DokanRemoveMountPoint %ws\n", MountPoint); result = DokanMountControl(&control); if (result) { DbgPrint("DokanControl recieved DeviceName:%ws\n", control.DeviceName); SHChangeNotify(SHCNE_DRIVEREMOVED ,SHCNF_PATH|SHCNF_FLUSHNOWAIT,MountPoint,NULL); SendReleaseIRP(control.DeviceName); } else { DbgPrint("DokanRemoveMountPoint failed\n"); } return result; }
BOOL DokanMount(LPCWSTR MountPoint, LPCWSTR DeviceName) { DOKAN_CONTROL control; ZeroMemory(&control, sizeof(DOKAN_CONTROL)); control.Type = DOKAN_CONTROL_MOUNT; wcscpy_s(control.MountPoint, sizeof(control.MountPoint) / sizeof(WCHAR), MountPoint); wcscpy_s(control.DeviceName, sizeof(control.DeviceName) / sizeof(WCHAR), DeviceName); return DokanMountControl(&control); }
int Unmount(LPCWSTR MountPoint, BOOL ForceUnmount) { int status = 0; DOKAN_CONTROL control; ZeroMemory(&control, sizeof(DOKAN_CONTROL)); if (wcslen(MountPoint) == 1 && L'0' <= MountPoint[0] && MountPoint[0] <= L'9') { control.Type = DOKAN_CONTROL_LIST; control.Option = MountPoint[0] - L'0'; DokanMountControl(&control); if (control.Status == DOKAN_CONTROL_SUCCESS) { status = DokanRemoveMountPoint(control.MountPoint); } else { fwprintf(stderr, L"Mount entry %d not found\n", control.Option); status = -1; } } else if (ForceUnmount) { control.Type = DOKAN_CONTROL_UNMOUNT; control.Option = DOKAN_CONTROL_OPTION_FORCE_UNMOUNT; wcscpy_s(control.MountPoint, sizeof(control.MountPoint) / sizeof(WCHAR), MountPoint); DokanMountControl(&control); if (control.Status == DOKAN_CONTROL_SUCCESS) { fwprintf(stderr, L"Unmount success: %s", MountPoint); status = 0; } else { fwprintf(stderr, L"Unmount failed: %s", MountPoint); status = -1; } } else { status = DokanRemoveMountPoint(MountPoint); } fwprintf(stderr, L"Unmount status = %d\n", status); return status; }
int ShowMountList() { DOKAN_CONTROL control; ZeroMemory(&control, sizeof(DOKAN_CONTROL)); control.Type = DOKAN_CONTROL_LIST; control.Option = 0; control.Status = DOKAN_CONTROL_SUCCESS; while (DokanMountControl(&control)) { if (control.Status == DOKAN_CONTROL_SUCCESS) { fwprintf(stderr, L"[% 2d] MountPoint: %s\n DeviceName: %s\n", control.Option, control.MountPoint, control.DeviceName); control.Option++; } else { return EXIT_SUCCESS; } } return EXIT_SUCCESS; }
BOOL DOKANAPI DokanRemoveMountPoint(LPCWSTR MountPoint) { DOKAN_CONTROL control; BOOL result; ZeroMemory(&control, sizeof(DOKAN_CONTROL)); control.Type = DOKAN_CONTROL_UNMOUNT; wcscpy_s(control.MountPoint, sizeof(control.MountPoint) / sizeof(WCHAR), MountPoint); DbgPrintW(L"DokanRemoveMountPoint %ws\n", MountPoint); result = DokanMountControl(&control); if (result) { DbgPrint("DokanControl recieved DeviceName:%ws\n", control.DeviceName); SendReleaseIRP(control.DeviceName); } else { DbgPrint("DokanRemoveMountPoint failed\n"); } return result; }