Which system calls to move data on a device with mounted partitions?

I need to be able to move data around a disk that has mounted partitions. I am not touching the data on the mounted partition, the MBR or any other disk metadata, only the freespace and unmounted partitions. At the moment I am using libparted but it causes data corruption sometimes although there are no reported errors.

I am experimenting now with open() on, for example, /dev/sdc while /dev/sdc2 is mounted. That also sometimes seems to have problems with busy partitions on the disk. No errors are reported.

Any suggestions?

Thank you.

Moving data on unmounted partitions by access to the raw device is a very dicey operation. Reading and writing are pretty much the same in any mode, in the end, so why can't you just use 'cp -rp'?