What's wrong with my code?

78 views
Skip to first unread message

cleversight

unread,
Nov 15, 2009, 11:46:56 PM11/15/09
to Dokan
Hi people

I do believe dokan is fantastic. I've tested some stuff using the .NET
wrapper without any trouble, but since i'm doing research within the C+
+ space, i cannot make my dokan code to work properly.

Below is part of my code, the rest of it is exactly the same as the
mirror.c (example) that came with the package. I'm using a VC++
project, character-set Unicode. The thing is that i cannot get the
mount appear on my system, unless i change the value of RootDirectory
(GetFilePath function) to something like L"\\\\.\\%L:" (or any other
garbage).
I just wanna have a virtual drive where i can create/copy and use it
like a normal drive, to store different files.

Please, let me know what am i doing wrong.

static char* GetFilePath(LPCWSTR FileName)
{
WCHAR filePath[MAX_PATH];
WCHAR RootDirectory[MAX_PATH] = L"L:";
RtlZeroMemory(filePath, MAX_PATH);
wcsncpy(filePath, RootDirectory, wcslen(RootDirectory));
wcsncat(filePath, FileName, wcslen(FileName));
char* dest = (char*)malloc(MAX_PATH);
ZeroMemory(dest,MAX_PATH);
wtoc(dest,filePath);
return dest;
}

FILESYSTEM_API void initFileSystem()
{
try
{
PDOKAN_OPTIONS opt = (PDOKAN_OPTIONS)malloc(sizeof(PDOKAN_OPTIONS));
ZeroMemory(opt, sizeof(DOKAN_OPTIONS));
opt->DriveLetter = 'l';
opt->DebugMode = (UCHAR)true;
opt->UseStdErr = (UCHAR)false;
opt->ThreadCount = 1;
int status;
status = DokanMain(opt,&operations);
}
catch(char *err){}
}

static int __stdcall MirrorCreateFile(LPCWSTR FileName,DWORD
AccessMode,DWORD ShareMode,DWORD CreationDisposition,DWORD
FlagsAndAttributes,PDOKAN_FILE_INFO DokanFileInfo)
{
HANDLE handle;
char* dest = GetFilePath(FileName);
size_t s = sizeof(wchar_t)*(strlen(dest)+1);
wchar_t *filepath = (wchar_t*)_malloca(s);
RtlZeroMemory(filepath,s);
mbstowcs(filepath,dest,s);
if (GetFileAttributes(filepath) & FILE_ATTRIBUTE_DIRECTORY) {
FlagsAndAttributes |= FILE_FLAG_BACKUP_SEMANTICS;
}
handle = CreateFile(
filepath,
AccessMode,
ShareMode,
NULL,
CreationDisposition,
FlagsAndAttributes,
NULL);
log("CreateFile:");
if (handle == INVALID_HANDLE_VALUE) {
DWORD error = GetLastError();
log("invalid handle");
return error * -1;
}
// save the file handle in Context
DokanFileInfo->Context = (ULONG64)handle;
log(dest);
return 0;
}

static int __stdcall MirrorOpenDirectory(LPCWSTR
FileName,PDOKAN_FILE_INFO DokanFileInfo)
{
HANDLE handle;
char* dest = GetFilePath(FileName);
size_t s = sizeof(wchar_t)*(strlen(dest)+1);
wchar_t *filepath = (wchar_t*)_malloca(s);
RtlZeroMemory(filepath,s);
mbstowcs(filepath,dest,s);
log("OpenDirectory:");
log(dest);
handle = CreateFile(
filepath,
0,
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS,
NULL);

if (handle == INVALID_HANDLE_VALUE) {
DWORD error = GetLastError();
log("fail");
return error * -1;
}
DokanFileInfo->Context = (ULONG64)handle;
return 0;
}

Joe Burmeister

unread,
Nov 16, 2009, 8:39:45 AM11/16/09
to do...@googlegroups.com
Hi ,

Just to be clear, I take it L is not the letter of the virtual drive but is the letter of the drive you are redirecting to?
It looks like L is the virtual drive and the one your are redirecting to. If so, that's your problem, it's a loop.


Joe



2009/11/16 cleversight <nfigl...@gmail.com>

--

You received this message because you are subscribed to the Google Groups "Dokan" group.
To post to this group, send email to do...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/dokan?hl=.



Hiroki Asakawa

unread,
Nov 16, 2009, 8:53:17 AM11/16/09
to do...@googlegroups.com
Hi,


On Mon, Nov 16, 2009 at 1:46 PM, cleversight <nfigl...@gmail.com> wrote:
> Hi people
>
> I do believe dokan is fantastic. I've tested some stuff using the .NET
> wrapper without any trouble, but since i'm doing research within the C+
> + space, i cannot make my dokan code to work properly.
>
> Below is part of my code, the rest of it is exactly the same as the
> mirror.c (example) that came with the package. I'm using a VC++
> project, character-set Unicode. The thing is that i cannot get the
> mount appear on my system, unless i change the value of RootDirectory
> (GetFilePath function) to something like L"\\\\.\\%L:" (or any other
> garbage).
> I just wanna have a virtual drive where i can create/copy and use it
> like a normal drive, to store different files.

You need to use an existing path as RootDirectory.
There are also some mistakes in your code.

> Please, let me know what am i doing wrong.
>
> static char* GetFilePath(LPCWSTR FileName)
> {
>    WCHAR filePath[MAX_PATH];
>    WCHAR RootDirectory[MAX_PATH] = L"L:";
>        RtlZeroMemory(filePath, MAX_PATH);
>    wcsncpy(filePath, RootDirectory, wcslen(RootDirectory));
>    wcsncat(filePath, FileName, wcslen(FileName));
>    char* dest = (char*)malloc(MAX_PATH);
>    ZeroMemory(dest,MAX_PATH);
>    wtoc(dest,filePath);
>    return dest;
> }
>
> FILESYSTEM_API void initFileSystem()
> {
>        try
>        {
>                PDOKAN_OPTIONS opt = (PDOKAN_OPTIONS)malloc(sizeof(PDOKAN_OPTIONS));

PDOKAN_OPTIONS opt = (PDOKAN_OPTIONS)malloc(sizeof(DOKAN_OPTIONS));
free(dest);

cleversight

unread,
Nov 16, 2009, 6:08:45 PM11/16/09
to Dokan
Yes, i did realize that i couldn't get "disk space" magically, that i
would need to attach the virtual drive to an existing path. I'm now
enjoying and playing; i'm involved in a personal project that i will
share with you guys as soon as it's ready. If you like it, you can
join the development team: i plan to deploy both Linux/Mac versions.
Anyway, i'll tell you when i have something.

All my best, and thanks for your tips.

Nicolas Iglesias,

http://www.cleversight.com

cleversight

unread,
Nov 21, 2009, 10:27:51 AM11/21/09
to Dokan
Well, i'm almost there to the final stage of my development process.
But, i still have a few questions/issues awaiting to be attended:

1 - Why i cannot see a normal context menu? When i browse my new
drive, i right-click in the explorer window and the "New" submenu in
the context menu just shows the "Create folder" option.
2 - I cannot rename a file, it says "it already exists" when i choose
a new name (obviously, it doesn't). The same happens when i move a
file into another directory (same dokan drive).

Please, i think if i have this issues solved, i will be in place of
telling you that i know how to use dokan. I repeat: it's a great
solution.

THanks all and regards,
Nicolas

cleversight

unread,
Nov 21, 2009, 10:40:50 AM11/21/09
to Dokan
Posting parts of my code which is mostly similar to the mirror.c
example:
---------------------------------------------------------------------------------------------------------

static int __stdcall MirrorMoveFile(LPCWSTR FileName, LPCWSTR
NewFileName, BOOL ReplaceIfExisting,PDOKAN_FILE_INFO DokanFileInfo)
{
BOOL status;
char* dest = GetFilePath(FileName);
size_t s = sizeof(wchar_t)*(strlen(dest)+1);
wchar_t *filepath = (wchar_t*)_malloca(s);
memset(filepath,0,s);
mbstowcs(filepath,dest,s);
char* newdest = GetFilePath(NewFileName);
size_t ns = sizeof(wchar_t)*(strlen(newdest)+1);
wchar_t *newfilepath = (wchar_t*)_malloca(ns);
memset(newfilepath,0,ns);
mbstowcs(newfilepath,newdest,ns);
log("MoveFile:");
log(newdest);
if (DokanFileInfo->Context) {
// should close? or rename at closing?
CloseHandle((HANDLE)DokanFileInfo->Context);
DokanFileInfo->Context = 0;
}
if (ReplaceIfExisting)
status = MoveFileEx(filepath, newfilepath,
MOVEFILE_REPLACE_EXISTING);
else
status = MoveFile(filepath, newfilepath);
if (status == FALSE) {
DWORD error = GetLastError();
return -(int)error;
}
return 0;
}


static int __stdcall MirrorFindFiles(LPCWSTR FileName,PFillFindData
FillFindData, PDOKAN_FILE_INFO DokanFileInfo)
{
HANDLE hFind;
WIN32_FIND_DATAW findData;
DWORD error;
wchar_t* yenStar = L"\*";
int count = 0;
char* dest = GetFilePath(FileName);
size_t s = sizeof(wchar_t)*(strlen(dest)+1);
wchar_t *filepath = (wchar_t*)_malloca(s);
memset(filepath,0,s);
mbstowcs(filepath,dest,s);
wcsncat(filepath, yenStar, wcslen(yenStar));
hFind = FindFirstFile(filepath, &findData);
log("FindFiles:");
log(dest);
if (hFind == INVALID_HANDLE_VALUE) {
log("invalid handle");
return -1;
}
FillFindData(&findData, DokanFileInfo);
count++;

while (FindNextFile(hFind, &findData) != 0) {
FillFindData(&findData, DokanFileInfo);
count++;
}
error = GetLastError();
FindClose(hFind);
if (error != ERROR_NO_MORE_FILES) {
log("no more files");
return -1;
}
log("ok");
return 0;

cleversight

unread,
Dec 1, 2009, 10:09:38 AM12/1/09
to Dokan
This is very strange:

When i try to rename a file or a folder, i cannot write more than one
character.

cleversight

unread,
Dec 1, 2009, 10:12:44 AM12/1/09
to Dokan
Oh what a stupid guy i am

Sooo lame... ignore this issue

Joe Burmeister

unread,
Dec 1, 2009, 10:14:27 AM12/1/09
to do...@googlegroups.com
No worries, we all have those moments. ;-)


2009/12/1 cleversight <nfigl...@gmail.com>
--

You received this message because you are subscribed to the Google Groups "Dokan" group.
To post to this group, send email to do...@googlegroups.com.
To unsubscribe from this group, send email to dokan+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/dokan?hl=en.



cleversight

unread,
Dec 1, 2009, 10:34:39 AM12/1/09
to Dokan
Hi Joe

I haven't had a chance to give you my thanks for your attention, is
nice to see someone takes care of Dokan :-)

Well... i think i found some kind of bug, and i cannot guess why it
happens.

Please, first take a look at this video and you'll understand my
point:

http://screencast.com/t/ZjU3YzIz

Translate "Nuevo" with "New" (it is the common windows explorer
context menu, where you can choose to create new folder, documents,
shortcuts, etc).

The context menu is not properly displayed. When i go to a sub-folder,
i can see it right. But, on the root folder i need to make some tricks
with....... MOUSE CLICKS! yes... the last second, you'll see the
context menu because i clicked both mouse buttons.

Weird... trying to guess what is it.

My kindest regards,
Nicolas Iglesias

Joe Burmeister

unread,
Dec 1, 2009, 11:17:07 AM12/1/09
to do...@googlegroups.com
Hi Nicolas,

Off the top of my head can't think of anything that would cause this, unless the file system isn't returning consistent results.

No custom Explorer namespace I take it.

The dokan mirror example isn't doing it for me, neither is my dokan filesystems, so I don't think it's a Dokan bug.

In you logging, print out the paths too.

Might give more insight into what is going on.

Sorry I can't help more.

Joe






2009/12/1 cleversight <nfigl...@gmail.com>
Reply all
Reply to author
Forward
0 new messages