Quantcast

uiomove question

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

uiomove question

Anindya Mukherjee
Hi, I have been reading Joseph Kong's book: "FreeBSD Device Drivers - A Guide for the Intrepid". I have a confusion about the way uiomove() is being used in the code examples, such as the xxx_read() and xxx_write() routines.

As I understand, from reading /usr/src/sys/kern/subr_uio.c around line 248, uiomove() does not offset the kernel buffer automatically. The programmer has to add the offset from the uio structure. In the xxx_read() code in the book, this offset is applied correctly.

However, in all the xxx_write() examples, the amount to be written is calculated assuming the write is going to happen at a certain offset in the buffer, but in the actual call to uiomove() the offset is not applied. Is this a typo or am I missing something here?

Thanks for reading!
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-drivers
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

RE: uiomove question

Anindya Mukherjee
An example of the usage I am talking about:

xxx_write(...)
{
...
amount = MIN(uio->uio_resid,  // 0. This is the no of bytes in the uio left to write
             (BUFFER_SIZE - 1 - uio->uio_offset > 0) ?
             BUFFER_SIZE - 1 - uio->uio_offset : 0); // 1. amount to write is computed
//assuming write will happen at uio_offset in sc_buffer
if (amount == 0)
  return (error);
error = uiomove(sc->sc_buffer, amount, uio);  // 2. sc_buffer is not offset
...
}

xxx_read(...)
{
...
amount = MIN(uio->uio_resid,
             (sc->sc_length - uio->uio_offset > 0) ?
             sc->sc_length - uio->uio_offset : 0); // 3. Same as comment 1 above
error = uiomove(sc->sc_buffer + uio->uio_offset, amount, uio); // 4. Here buffer is offset
...
}

Anindya
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-drivers
To unsubscribe, send any mail to "[hidden email]"
Loading...