The HyperNews Linux KHG Discussion Pages

## Problem with foo_write example?

  Forum: Character Device Drivers
  Keywords: foo_write
  Date: Sat, 29 Nov 1997 14:30:52 GMT
  From: Chris Arena <ccarena@mail.bcn.net>

    This is the foo_write example in
    http://www.redhat.com:8080/HyperNews/get/devices/char.html ...

    static int foo_write(struct inode * inode, struct file * file, char * buf, int count)
    {
        unsigned int minor = MINOR(inode->i_rdev);
        char ret;

        while (count > 0) {
            ret = foo_write_byte(minor);
    	if (ret < 0) {
                foo_handle_error(WRITE, ret, minor);
                continue;
            }
            buf++ = ret; count--
        }
        return count;
    }

    How does the input buffer buf have its contents accessed?
    This actually looks more like foo_read than write, but even
    so, there is nothing storing the value of ret into buf or
    reading from it.

    Also, if buf is an input buffer to the foo_write routine, why
    isn't it typed const? Same for the other input-only
    parameters not passed by value.

    What am I missing here?

    Thanks

    Chris Arena