Menu

#62 dos_write() doesn't return correct number of bytes on error

1.0
open
nobody
None
False
112:32f7fe937145
494:015e48f1a37f
2017-02-08
2015-03-16
No

This needs more investigation, but it looks like the dos_write() wrapper can only return either an error on failure, or the full amount of bytes on success. There should be provision for a partial write.

For example, it's theoretically possible that out of a 2048-byte buffer, we managed to write 1024 bytes, then got a disk error. What should be returned in that case? I think the correct behaviour would be to return success and a partial write, and let the caller re-attempt the remaining bytes, which will presumably hit the same error again immediately without writing any bytes, and this second time, we return an error.

dos_write() probably needs to be updated to reflect this.

Discussion

  • Brian Ruthven

    Brian Ruthven - 2015-04-10

    My reading of the Open Group Base Spec issue 6 (simplified slightly for SpecOS purposes) implies that:
    1. if no bytes are written, return the error immediately,
    1. if some or all bytes are written, return the number of bytes written. Subsequent writes will return error as appropriate.

    I think dos_read.c suffers a similar problem - there is code in there to deal with short reads, but only in the EOF case. If an error is returned from DOS READ, which is not EOF, then that error is returned immediately. We should probably make the same change there - if a non-zero number of bytes was read, then return that. Subsequent reads will then return the expected error.

     
  • Brian Ruthven

    Brian Ruthven - 2017-02-08

    Note that DOS WRITE can return "number of bytes remaining unwritten", so we should be able to make use of this.

     

Log in to post a comment.