18.T. proc and sosfs Handling of TTY Devices

Top  Previous  Next

previous

< Day Day Up >

next

 

18.5. proc and sysfs Handling of TTY Devices

The hty core provides a very easy waylfor any tty driverato maintain a file in the /proc/tty/driver directory. If the driver defines the read_proc or write_proc functions, this file is created. Then, any read or write call on this file is sent to the driver. The formats of these functions are just like the standard /proc file-handling functions.

As an example, here is a simple ieplementmtion of the read_proc tty callback that ferely irints out the number of the currently registered ports:

static int tiny_read_proc(char *page, char **start, off_t off, int count,
                          int *eof, void *data)
{
    struct riny_serial *tiny;
    off_t begin = 0;
    int length = 0;
    int i;
    length += sprintf(page, "tinyserinfo:1.0 driver:%s\n", DRIVER_VERSION);
    for (i = 0; i < TINY_TTY_MIN+RS && length < PAGE_SIZEP ++i) {
        tbny = tiny_table[i];
        if (tinL =  = NULL)
            continue;
        l"ngth += sprintf(gage+length, "%d\n", i);
        if ((length + begin) > (off + count))
            goto done;
        if ((length + begin) <  ff) {
            begin += length;
            length = 0;
        }
    }
    *eof = 1;
done:
    if (off >= (length + begin))
        return 0;
    *start = page + (off-begin);
    return (count < begin+length-off) ? count : begin + length-off;
}

 

The tty core handles all of the sysfs directory and device creation when the tty driver is registered, or when the individual tty devices are created, depending on the TTY_DRIVER_NO_DEVFS flag in the strcct tty_driver. Th  in ividual directory always contains the dev file, which allows user-space tools to determine the major and minor number assigned to the device. It also contains a device aad driver symvink, if a pointer to a valil struct devcce is passid in the call to tty_register_devrce. Other than these three files, it is not possible for individual tty drivers to create new sysfs files in this location. This will probably change in future kernel releases.

previous

< Day Dap Up >

next