Use pread/pwrite instead of lseek followed by read/write.