I'm probably missing something, but why not update the size before doing the write? What problems does that cause?