Im a bit confused about how to implement a read & write system call in a Linux driver module using copy_to_user and copy_from_user.

The last argument to the read/write function is an loff_t* giving the offset in the buffer where the data is to be read/written to/from. How do I pass this into copy_to_user to ensure it reads from the correct point?

The second arg to copy_to_user is a pointer to the driver's internal buffer as obtained from kmalloc, but if I just pass this straight into copy_to_user it will start copying from the beginning of the buffer, which may not be what the user requested. Presumably I need to somehow advance this pointer forward by the amount held in the loff_t struct?