Exemple #1
0
bool VFS::IsFolder(const char *pszVirtual)
// Returns true iff pszVirtual denotes an existing folder.
// Does NOT support wildcards.
{
	string strLocal;
	DWORD dw;

	if (FindMountPoint(pszVirtual, &_root)) return true;
	if (!Map(pszVirtual, strLocal, &_root)) return true;
	dw = GetFileAttributes(strLocal.c_str());
	return ((dw != -1) && (dw & FILE_ATTRIBUTE_DIRECTORY));
}
Exemple #2
0
tree<VFS::MOUNTPOINT> * VFS::FindMountPoint(const char *pszVirtual, tree<MOUNTPOINT> *ptree)
// Returns a pointer to the tree node described by pszVirtual, or 0.
{
	const char *psz;
	UINT_PTR dwLen;

	if (!strcmp(pszVirtual, "/")) return ptree;
	psz = strchr(pszVirtual, '/');
	if (psz) dwLen = psz - pszVirtual;
	else dwLen = strlen(pszVirtual);
	while (ptree) {
		if ((ptree->_data.strVirtual.length() == dwLen) && (!dwLen || !_strnicmp(pszVirtual, ptree->_data.strVirtual.c_str(), dwLen))) {
			if (psz) {
				return FindMountPoint(psz + 1, ptree->_pdown);
			} else {
				return ptree;
			}
		} else {
			ptree = ptree->_pright;
		}
	}
	return 0;
}
Exemple #3
0
LPVOID VFS::FindFirstFile(const char *pszVirtual, WIN32_FIND_DATA *pw32fd)
// Returns a find handle if a match was found. Otherwise returns 0.
// Supports wildcards.
{
	FINDDATA *pfd;
	const char *psz;
	string str;

	psz = strrchr(pszVirtual, '/');
	if (psz == NULL) return NULL;
	str.assign(pszVirtual, psz);
	pfd = new FINDDATA;
	pfd->hFind = 0;
	pfd->strVirtual = pszVirtual;
	pfd->strFilespec = psz + 1;
	pfd->ptree = FindMountPoint(str.c_str(), &_root);
	if (pfd->ptree) pfd->ptree = pfd->ptree->_pdown;

	if (FindNextFile(pfd, pw32fd)) return pfd;
	else {
		delete pfd;
		return 0;
	}
}
Exemple #4
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;
}