Previous Next Table of Contents

4. lp_write(struct file * file, const char * buf, size_t count, loff_t *ppos)

4.1 General info.

Function: lp_write interfaces the lp driver to write()

Called from: write (Base driver operation).

Files: drivers/char/lp.c, include/linux/lp.h

4.2 Code description

lp_write is the main interface between the Linux write() operation and the lp code. The arguments are: file, the actual file that this routine was called upon (eg, /dev/lp0); buf, the data that we wish to write; count, the length of the data; and ppos(not used, apparently).

static ssize_t lp_write(struct file * file, const char * buf, size_t count, loff_t *ppos)

Work out which inode corresponds to this file, then get the minor device number that this inode is pointing at.

        struct inode *inode = file->f_dentry->d_inode;
        unsigned int minor = MINOR(inode->i_rdev);
        int retv;

Check how much time the previous call took. Not sure what this is for.

        if (jiffies-lp_table[minor].lastcall > LP_TIME(minor))
                lp_table[minor].runchars = 0;

        lp_table[minor].lastcall = jiffies;

Claim the parport (as it says ;). The parport code allows one parallel port to be shared by several device drivers (so you can use certain devices all plugged into one port -- eg, a ZIP drive with a "through" connector. Claiming a parport prevents any other device drivers from being able to use the device while this driver is.

        /* Claim Parport or sleep until it becomes available
         * (see lp_wakeup() for details)
        lp_parport_claim (minor);

Write the contents of the buffer to the device, and then release the parport.

        retv = lp_write_buf(minor, buf, count);
        lp_parport_release (minor);
        return retv;

Previous Next Table of Contents