ReadFile method read a file multiple times and ends up with a file of size zero byte

385 views
Skip to first unread message

Saleem Haider

unread,
Nov 24, 2009, 5:06:36 PM11/24/09
to Dokan, asa...@gmail.com
Hi,

I am having problems with ReadFile method of the DokanOperations which
is not correctly working in my code. I call a webservice from the
ReadFile method to fetch the buffered data of the file.

If I copy and paste a file from my mounted drive to some other folder
on File System, it correctly starts reading the file by calling the
ReadFile method multiple times. Once it reads all the bytes of the
file in buffers. It calls the ReadFile two times when readBytes is
returned zero. After that It starts calling the ReadFile method again
from the start and read the complete file. It happens three times, and
the file gets copied with the zero bytes in the destination folder at
the end.

I am not sure what is going wrong in my source code. I have SVN
installed on my computer, and i am seeing suffix "\\svn\\entries" at
the end of my filename parameter in some cases. Could it be the reason
behind it?

I have tested the DokanNetMirror and it works fine when I copy a file
from a mirrored drive to some other drive.

Please note that we have built the latest dlls by getting the code on
our machines and we are mounting the drive as a network drive using
dokannp.dll.

Please provide any solutions to fix the issue.

Thanks,
Saleem

joe.a.bu...@googlemail.com

unread,
Nov 25, 2009, 8:12:06 AM11/25/09
to Dokan
Hi Saleem,

Is your ReadFile ever returning -ERROR_HANDLE_EOF?
If not, sounds like that's your problem.

All .svn files/folder are coming from TortoiseSVN. It enquiries about
these files all the time.
In previous virtual filesystem where speed was an issue, I filtered
these out as invalid files to speed things up rather than query the
slow system in case they existed. I.e. the filesystem didn't support a
folder called .svn! ;-)

Joe

Saleem Haider

unread,
Nov 25, 2009, 11:03:55 AM11/25/09
to Dokan
Hi Joe,

Thanks for your response.

We are not returning -ERROR_HANDLE_EOF from our ReadFile method or any
where in our code. We started modifying the DokanNetMirror example
project for our purposes and we are not calling SetEndofFile. Also we
are returning 0 from the end of file method. We have tested if the
method is called by the proxy class but it is not being called by
proxy method as well.

Do we need to call this method from ReadFile to mark the end of file?

We have following ReadFile method implementation in our class.

public int ReadFile(String filename, Byte[] buffer, ref uint
readBytes,
long offset, DokanFileInfo info)
{
try
{
filename = filename.Replace("\\_svn\\entries",
string.Empty).Replace("\\_svn\\format", string.Empty);

if (m_FileManager.FileExists(filename) == true)
m_FileManager.GetFileInformation(filename,
offset, (long)buffer.Length, buffer, ref
readBytes);
else
return -1;


return 0;
}
else
return -1;

}
catch (Exception)
{
return -1;
}
}

m_FileManager in the code above is the instance of our class, and
GetFileInformation method sets the value in buffer and readBytes
parameters internally. buffer parameter is updated by the bytes
returned by our webservice in the GetFileInformation method. Please
suggest what we are doing wrong to get this behavior.

Thanks,
Saleem

On Nov 25, 6:12 pm, "joe.a.burmeis...@googlemail.com"

Joe Burmeister

unread,
Nov 25, 2009, 11:38:23 AM11/25/09
to do...@googlegroups.com
Hi Saleem,

Looks like I'm talking rubbish. Sorry.

ERROR_HANDLE_EOF is the error I return when a read goes past the end. That's what I expected to have to do.

But looking at \dokan\read.c  from svn, I see it doesn't matter what I return. If it's negative, STATUS_INVALID_PARAMETER is passed on to the system.

It passes on STATUS_END_OF_FILE to the system only when returned value is 0 or above and the length of bytes read is 0.

The value of number of bytes read is set to 0 by default.
So, does your GetFileInformation always set the length of bytes read to something other than 0?

Does you file reading normally work?

If you drop to the command line, go to your drive, can you use the "TYPE" command on one of your files?
I would recommend using the command line instead of explorer to debug problems as it's less noisy with calls, so less noise in your logging.

Hope some of this is helpful.

Joe




2009/11/25 Saleem Haider <saleem...@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.



Saleem Haider

unread,
Nov 25, 2009, 12:50:40 PM11/25/09
to Dokan
Dear Joe,

Thanks for your quick response. After a bit of digging in the code I
have found the culprit. Basically I had mistakenly commented the code
in the GetFileInfomation method which was setting the correct size of
the file instead it was setting to a hard-coded value zero which we
set for the case of folder.

Anyway, thanks for your responses :)

Regards,
Saleem

On Nov 25, 9:38 pm, Joe Burmeister <joe.a.burmeis...@googlemail.com>
wrote:
> Hi Saleem,
>
> Looks like I'm talking rubbish. Sorry.
>
> ERROR_HANDLE_EOF is the error I return when a read goes past the end. That's
> what I expected to have to do.
>
> But looking at \dokan\read.c  from svn, I see it doesn't matter what I
> return. If it's negative, STATUS_INVALID_PARAMETER is passed on to the
> system.
>
> It passes on STATUS_END_OF_FILE to the system only when returned value is 0
> or above and the length of bytes read is 0.
>
> The value of number of bytes read is set to 0 by default.
> So, does your GetFileInformation always set the length of bytes read to
> something other than 0?
>
> Does you file reading normally work?
>
> If you drop to the command line, go to your drive, can you use the "TYPE"
> command on one of your files?
> I would recommend using the command line instead of explorer to debug
> problems as it's less noisy with calls, so less noise in your logging.
>
> Hope some of this is helpful.
>
> Joe
>
> 2009/11/25 Saleem Haider <saleemhai...@gmail.com>
> > dokan+un...@googlegroups.com <dokan%2Bunsu...@googlegroups.com>.

Siva

unread,
Jan 11, 2010, 9:16:41 AM1/11/10
to Dokan
Hi

I've similar problem, that is I've created a virtual directory using
Dokan library and it acts as a file system.
But when i get into the drive it automatically triggers the read file
or when i mouse hover on the file.
Is it possible for to trigger the read event only when i click the
file or folder?

Thanks
Siva

On Nov 25 2009, 10:50 pm, Saleem Haider <saleemhai...@gmail.com>
wrote:


> Dear Joe,
>
> Thanks for your quick response. After a bit of digging in the code I
> have found the culprit. Basically I had mistakenly commented the code
> in the GetFileInfomation method which was setting the correct size of
> the file instead it was setting to a hard-coded value zero which we
> set for the case of folder.
>
> Anyway, thanks for your responses :)
>
> Regards,
> Saleem
>
> On Nov 25, 9:38 pm, Joe Burmeister <joe.a.burmeis...@googlemail.com>
> wrote:
>
> > Hi Saleem,
>
> > Looks like I'm talking rubbish. Sorry.
>

> > ERROR_HANDLE_EOF is the error I return when areadgoes past the end. That's


> > what I expected to have to do.
>
> > But looking at \dokan\read.c  from svn, I see it doesn't matter what I
> > return. If it's negative, STATUS_INVALID_PARAMETER is passed on to the
> > system.
>
> > It passes on STATUS_END_OF_FILE to the system only when returned value is 0

> > or above and the length of bytesreadis 0.
>
> > The value of number of bytesreadis set to 0 by default.

> > > > > from the start andreadthe complete file. It happens three times, and

Joel Lucsy

unread,
Jan 11, 2010, 9:20:11 AM1/11/10
to do...@googlegroups.com
That behavior is caused by Explorer reading the file to determine version information to display as well as tooltips. There is no way to tell Explorer to not do this.


On Mon, Jan 11, 2010 at 9:16 AM, Siva <sivaprakas...@gmail.com> wrote:
I've similar problem, that is I've created a virtual directory using
Dokan library and it acts as a file system.
But when i get into the drive it automatically triggers the read file
or when i mouse hover on the file.
Is it possible for to trigger the read event only when i click the
file or folder?

 
--
Joel Lucsy
"The dinosaurs became extinct because they didn't have a space program." -- Larry Niven

Sivaprakash

unread,
Jan 11, 2010, 9:30:22 AM1/11/10
to do...@googlegroups.com
OK, is there any way in Dokan library to filter the events? So that i can control it.

Thanks a lot for your reply..


--
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.




--
- Prakash.
Sent from Tamil Nadu, India

Joel Lucsy

unread,
Jan 11, 2010, 9:35:26 AM1/11/10
to do...@googlegroups.com
No, Dokan is a filesystem that simply deals with reads and writes. The intent of the application, of which the filesystem is not even aware, is not forwarded down. I suspect the problem you are trying to overcome can not be easily solved through the filesystem. Perhaps you need something injected into the user application space.

Peter Siegel

unread,
Jan 11, 2010, 3:40:01 PM1/11/10
to do...@googlegroups.com
No you can't, but i think you could do this by using Shell extensions



Sivaprakash

unread,
Jan 12, 2010, 10:33:02 AM1/12/10
to Saleem Haider, do...@googlegroups.com
Hi

With the help of your comment i was able to control multiple read. I've one problem

I'm trying to mount the Virtual Folder (WebDAV Folder) from another server that time it is not able to recognize the folders but file read/write is working well. Any specific thing need to be addressed.

Thanks
Siva

On Tue, Jan 12, 2010 at 12:29 PM, Saleem Haider <saleem...@gmail.com> wrote:
Hi,

I have resolved this problem of ReadFile with the help of following two things:

1) I have used Dokan network drive but didn't set the attribute "opt.NetworkDrive" to true.
2) I have also set the "Attribute" property of "FileInformation" class to "Offline". Please see code below.

                    FileInformation fi = new FileInformation();
                    fi.Attributes = (f.IsFolder) ? System.IO.FileAttributes.Directory : System.IO.FileAttributes.Offline;
                   
Initially, my network drive was appearing as Disconnected drive, and I was unable to change the drive label. Due to this reason, I changed the "opt.NetworkDrive" to false. Now, I can change the drive volume label, and application don't call the ReadFile method when user take mouse over a file.

Thanks,
Saleem Haider
Reply all
Reply to author
Forward
0 new messages