Correct write() if it fails to write whole block

Thanks to Sebastian for mentioning this.
Correct mmap-pattern, too

Thanks again to Sebastian.