Change order of fstat() and pwrite()