Skip to content

Commit

Permalink
Merge pull request #79 from Corillian/InvestigateHang
Browse files Browse the repository at this point in the history
Fixed an issue with DokanUnmount() failing to unmount a drive
  • Loading branch information
Liryna committed Oct 10, 2015
2 parents 7579d97 + bbc6aac commit d1c8a13
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 2 deletions.
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 @@ -62,7 +62,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

0 comments on commit d1c8a13

Please sign in to comment.