-
Notifications
You must be signed in to change notification settings - Fork 116
Description
Just spent a couple of hours trying to figure out an issue with my FS.
Turned out that Dokan expects the implementation of ReadFile to always fill the entire buffer when offset + buffer.Length are within the file length, and read exactly remaining bytes when offset + buffer.Length are more than file length.
I was calling .NET Stream.Read with the buffer, and my filesystem would return garbage to some programs. The reason is Stream.Read by its contract does not have to fill your entire buffer. For example, when reading from a TCP connection if you specify 1MiB buffer and 1KiB packet arrives, NetworkStream will fill 1KiB and return 1024 even though the connection is still open and it will be possible to read more data in the future.
Now I don't know what the kernel APIs expect in this case, but IMHO one of the following should be done:
- documenting this behavior
- if this behavior is the result of a bug (perhaps the value returned in
bytesReadis not used everywhere it should be), fixing that bug - considering changing .NET wrapper code to repeat
ReadFilecalls until eitherbufferis filled or end of file reached (this would remove the need for documenting the discrepancy)