Implement image_write():
For every sector in the buffer, find the chunk that contains it
and break it up (if it's not already a memory chunk) so that we
have have a new chunk for every sector being written. We don't
write to chunks for type file, because we may not be able to
write and we don't want to clobber partition data.

We don't try to combine adjacent chunks of type memory into a
single one. It doesn't seem to have any significant upsides
other than reducing syscall overhead. The downsides includes
"excessive" copying and memory fragmantation. Without any kind
of benchmarking, simplicity wins.