Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed an issue with DokanUnmount() failing to unmount a drive #79

Merged
merged 4 commits into from
Oct 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions dokan/dokan.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
</ClCompile>
<Link>
<ModuleDefinitionFile>dokan.def</ModuleDefinitionFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand All @@ -109,6 +110,7 @@
</ClCompile>
<Link>
<ModuleDefinitionFile>dokan.def</ModuleDefinitionFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
Expand Down
2 changes: 1 addition & 1 deletion dokan_mirror/mirror.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ static void DbgPrint(LPCWSTR format, ...)
}

static WCHAR RootDirectory[MAX_PATH] = L"C:";
static WCHAR MountPoint[MAX_PATH] = L"M:";
static WCHAR MountPoint[MAX_PATH] = L"M:\\";

static void
GetFilePath(
Expand Down
51 changes: 51 additions & 0 deletions dokan_mount/mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,54 @@ DokanControlUnmount(

return FALSE;
}

VOID
NormalizeMountPoint(WCHAR *mountPoint, size_t mountPointMaxLength)
{
size_t mountPointLength = wcslen(mountPoint);

if(mountPointMaxLength >= 4) {

if(mountPointLength == 1) {
mountPoint[0] = towupper(mountPoint[0]);
mountPoint[1] = L':';
mountPoint[2] = L'\\';
mountPoint[3] = 0;
}
else if(mountPointLength == 2 && mountPoint[1] == L':') {
mountPoint[0] = towupper(mountPoint[0]);
mountPoint[2] = L'\\';
mountPoint[3] = 0;
}
else if(mountPointLength == 3
&& mountPoint[1] == L':'
&& mountPoint[2] == L'\\') {

mountPoint[0] = towupper(mountPoint[0]);
}
}
else {
DbgPrintW(L"Failed to normalize mount point because the input buffer has a max length < 4!\n");
}
}

BOOL
IsMountPointDriveLetter(WCHAR *mountPoint)
{
size_t mountPointLength;

if(!mountPoint || *mountPoint == 0) {
return FALSE;
}

mountPointLength = wcslen(mountPoint);

if(mountPointLength == 1
|| (mountPointLength == 2 && mountPoint[1] == L':')
|| (mountPointLength == 3 && mountPoint[1] == L':' && mountPoint[2] == L'\\')) {

return TRUE;
}

return FALSE;
}
13 changes: 13 additions & 0 deletions dokan_mount/mount.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ BOOL
DokanControlUnmount(
LPCWSTR MountPoint);

/*
* Currently this is only applicable to mount points that are a single drive letter.
* This function will ensure drive letter mount points follow the format C:\
*/
VOID
NormalizeMountPoint(WCHAR *mountPoint, size_t mountPointMaxLength);

/*
* Return TRUE if mountPoint has the format "C", "C:", or "C:\"
*/
BOOL
IsMountPointDriveLetter(WCHAR *mountPoint);

#ifdef __cplusplus
}
#endif
Expand Down
18 changes: 17 additions & 1 deletion dokan_mount/mounter.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ InsertMountEntry(PDOKAN_CONTROL DokanControl)
}
ZeroMemory(mountEntry, sizeof(MOUNT_ENTRY));
CopyMemory(&mountEntry->MountControl, DokanControl, sizeof(DOKAN_CONTROL));

NormalizeMountPoint(mountEntry->MountControl.MountPoint, sizeof(mountEntry->MountControl.MountPoint) / sizeof(WCHAR));

InitializeListHead(&mountEntry->ListEntry);

EnterCriticalSection(&g_CriticalSection);
Expand All @@ -77,17 +80,30 @@ FindMountEntry(PDOKAN_CONTROL DokanControl)
PMOUNT_ENTRY mountEntry = NULL;
BOOL useMountPoint = DokanControl->MountPoint[0] != L'\0';
BOOL found = FALSE;
WCHAR mountPointDefaultTemplate[4] = L"C:\\";
PWCHAR mountPoint = DokanControl->MountPoint;

if (!useMountPoint && DokanControl->DeviceName[0] == L'\0') {
return NULL;
}

/* NOTE: g_MountList expects MountPoint to have the format of C:\ */

if(useMountPoint && IsMountPointDriveLetter(DokanControl->MountPoint)) {

mountPointDefaultTemplate[0] = DokanControl->MountPoint[0];

NormalizeMountPoint(mountPointDefaultTemplate, sizeof(mountPointDefaultTemplate) / sizeof(WCHAR));

mountPoint = mountPointDefaultTemplate;
}

EnterCriticalSection(&g_CriticalSection);

for (listEntry = g_MountList.Flink; listEntry != &g_MountList; listEntry = listEntry->Flink) {
mountEntry = CONTAINING_RECORD(listEntry, MOUNT_ENTRY, ListEntry);
if (useMountPoint) {
if (wcscmp(DokanControl->MountPoint, mountEntry->MountControl.MountPoint) == 0) {
if (wcscmp(mountPoint, mountEntry->MountControl.MountPoint) == 0) {
found = TRUE;
break;
}
Expand Down
2 changes: 2 additions & 0 deletions dokan_np/dokan_np.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
</ClCompile>
<Link>
<ModuleDefinitionFile>dokannp.def</ModuleDefinitionFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand All @@ -121,6 +122,7 @@
</ClCompile>
<Link>
<ModuleDefinitionFile>dokannp.def</ModuleDefinitionFile>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
Expand Down