chumeocon14l / dokan

Automatically exported from code.google.com/p/dokan
0 stars 0 forks source link

File contents are not being displayed after file is opened in any application #257

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Open a text file using notepad file>> open.
2. select the file from mounted drive.
3. click ok

What is the expected output? What do you see instead?
If I have selected a text file then its text content should appear.

What version of the product are you using? On what operating system?
0.6.0 , Windows 7

Please provide any additional information below.
We are trying to mount a linux volume dokan on windows. For data transfer 
sockets are being used. We have implemented 
CreateFile,ReadFile,FindFiles,OpenDirectory,GetFileInformation,Cleanup,Close 
etc. We can see the files and their properties.
But when we try to open the file (.txt files) in notepad/wordpad or any other 
word editor then its contens are not displayed. Although file size is exactly 
same. When file is opened in hex editor, its contents are properly shown. We 
have checked the buffer returned to "Buffer" of ReadFile,its is also properly 
filled with the read bytes. We have tried almost everything but with no 
success. 
Please help us.

For reference ReadFile function is as follows -
DokanReadFile(
    LPCWSTR             FileName,
    LPVOID              Buffer,
    DWORD               BufferLength,
    LPDWORD             ReadLength,
    LONGLONG            Offset,
    PDOKAN_FILE_INFO    DokanFileInfo)
{
    char *filePath = new char[MAX_PATH];
    WideCharToMultiByte(CP_ACP,0,FileName,-1, filePath,wcslen(FileName) +2,NULL, NULL);
    GetFilePath(filePath);

    MSG_PACKET_T msgPkt  ;
    memset(&msgPkt,0,sizeof(MSG_PACKET_T));
    msgPkt.message_type = READ_FILE ;

    COMMAND_PARMS_T cmdParam ;
    memset (&cmdParam,0,sizeof(COMMAND_PARMS_T));

    //retrieve file descriptor.
    int fileDesc = DokanFileInfo->Context ;
    int numBytesRead = 0 ;
    cmdParam.val = fileDesc ;
    cmdParam.offset = Offset;
    cmdParam.bytesToRead = BufferLength;

    memcpy(msgPkt.payload,&cmdParam,sizeof(COMMAND_PARMS_T));
    //the first 4 bytes of retBuf is number of bytes actually read and rest of the bytes are file contents.
    unsigned char *retBuf = new unsigned char[BufferLength + sizeof(int) ];
    cout << "file path : " << filePath << " file desc : " << fileDesc << " offset: " << Offset << " bufferlength : " << BufferLength << endl ;
    memset(retBuf,0,BufferLength + sizeof(int));
    if(fileDesc != 0)
    {
        //send the command to read the file content

        int err = send(sClient,(char*)&msgPkt,sizeof(MSG_PACKET_T),0);
        //send_command("",cmdArg);
        recv(sClient,(char*)retBuf,BufferLength + 4,0);
        //int *pBytesRead = (int*)retBuf ;
        int pBytesRead = 0;
        memcpy(&pBytesRead,retBuf,4);
        *ReadLength = pBytesRead;

        if(pBytesRead >  0)
        {
            memset(Buffer,0,BufferLength);

            memcpy(Buffer,retBuf+4,*ReadLength);

        }

        cout << "bytes read = " << pBytesRead << endl ;
    }
    //cleaning all the allocated buffers.
    //delete[] retBuf;
    //delete[] filePath ;
    return 0;
}

Original issue reported on code.google.com by just4tec...@gmail.com on 3 Jul 2012 at 12:23

GoogleCodeExporter commented 9 years ago
obviously, you should test whether DokanFileInfo->Context equals 0, or you have 
to open the file, and make DokanFileInfo->Context right. after reading it, 
close it.

Original comment by traum...@gmail.com on 4 Jan 2015 at 10:46