linux-old/drivers/usb/drivers.c
<<
>>
Prefs
   1/*
   2 * drivers.c
   3 * (C) Copyright 1999 Randy Dunlap.
   4 * (C) Copyright 1999, 2000 Thomas Sailer <sailer@ife.ee.ethz.ch>. (proc file per device)
   5 * (C) Copyright 1999 Deti Fliegl (new USB architecture)
   6 *
   7 * $id$
   8 *
   9 * This program is free software; you can redistribute it and/or modify
  10 * it under the terms of the GNU General Public License as published by
  11 * the Free Software Foundation; either version 2 of the License, or
  12 * (at your option) any later version.
  13 *
  14 * This program is distributed in the hope that it will be useful,
  15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17 * GNU General Public License for more details.
  18 *
  19 * You should have received a copy of the GNU General Public License
  20 * along with this program; if not, write to the Free Software
  21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  22 *
  23 *************************************************************
  24 *
  25 * 1999-12-16: Thomas Sailer <sailer@ife.ee.ethz.ch>
  26 *   Converted the whole proc stuff to real
  27 *   read methods. Now not the whole device list needs to fit
  28 *   into one page, only the device list for one bus.
  29 *   Added a poll method to /proc/bus/usb/devices, to wake
  30 *   up an eventual usbd
  31 * 2000-01-04: Thomas Sailer <sailer@ife.ee.ethz.ch>
  32 *   Turned into its own filesystem
  33 *
  34 * $Id: drivers.c,v 1.3 2000/01/11 13:58:24 tom Exp $
  35 */
  36
  37#include <linux/fs.h>
  38#include <linux/mm.h>
  39#include <linux/usb.h>
  40#include <linux/usbdevice_fs.h>
  41#include <asm/uaccess.h>
  42
  43/*****************************************************************/
  44
  45/*
  46 * Dump usb_driver_list.
  47 *
  48 * We now walk the list of registered USB drivers.
  49 */
  50static ssize_t usb_driver_read(struct file *file, char *buf, size_t nbytes, loff_t *ppos)
  51{
  52        struct list_head *tmp = usb_driver_list.next;
  53        char *page, *start, *end;
  54        ssize_t ret = 0;
  55        loff_t n = *ppos;
  56        unsigned int pos = n, len;
  57
  58        if (pos != n)
  59                return -EINVAL;
  60        if (nbytes <= 0)
  61                return 0;
  62        if (!access_ok(VERIFY_WRITE, buf, nbytes))
  63                return -EFAULT;
  64        if (!(page = (char*) __get_free_page(GFP_KERNEL)))
  65                return -ENOMEM;
  66        start = page;
  67        end = page + (PAGE_SIZE - 100);
  68        for (; tmp != &usb_driver_list; tmp = tmp->next) {
  69                struct usb_driver *driver = list_entry(tmp, struct usb_driver, driver_list);
  70                int minor = driver->fops ? driver->minor : -1;
  71                if (minor == -1)
  72                        start += sprintf (start, "         %s\n", driver->name);
  73                else
  74                        start += sprintf (start, "%3d-%3d: %s\n", minor, minor + 15, driver->name);
  75                if (start > end) {
  76                        start += sprintf(start, "(truncated)\n");
  77                        break;
  78                }
  79        }
  80        if (start == page)
  81                start += sprintf(start, "(none)\n");
  82        len = start - page;
  83        if (len > pos) {
  84                len -= pos;
  85                if (len > nbytes)
  86                        len = nbytes;
  87                ret = len;
  88                if (copy_to_user(buf, page + pos, len))
  89                        ret = -EFAULT;
  90                else
  91                        *ppos = pos + len;
  92        }
  93        free_page((unsigned long)page);
  94        return ret;
  95}
  96
  97static loff_t usb_driver_lseek(struct file * file, loff_t offset, int orig)
  98{
  99        switch (orig) {
 100        case 0:
 101                file->f_pos = offset;
 102                return file->f_pos;
 103
 104        case 1:
 105                file->f_pos += offset;
 106                return file->f_pos;
 107
 108        case 2:
 109                return -EINVAL;
 110
 111        default:
 112                return -EINVAL;
 113        }
 114}
 115
 116struct file_operations usbdevfs_drivers_fops = {
 117        llseek:         usb_driver_lseek,
 118        read:           usb_driver_read,
 119};
 120
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.