proc.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * /proc interface for comedi
  3. *
  4. * COMEDI - Linux Control and Measurement Device Interface
  5. * Copyright (C) 1998 David A. Schleef <ds@schleef.org>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. /*
  18. * This is some serious bloatware.
  19. *
  20. * Taken from Dave A.'s PCL-711 driver, 'cuz I thought it
  21. * was cool.
  22. */
  23. #include "comedidev.h"
  24. #include "comedi_internal.h"
  25. #include <linux/proc_fs.h>
  26. #include <linux/seq_file.h>
  27. static int comedi_read(struct seq_file *m, void *v)
  28. {
  29. int i;
  30. int devices_q = 0;
  31. struct comedi_driver *driv;
  32. seq_printf(m, "comedi version " COMEDI_RELEASE "\nformat string: %s\n",
  33. "\"%2d: %-20s %-20s %4d\", i, driver_name, board_name, n_subdevices");
  34. for (i = 0; i < COMEDI_NUM_BOARD_MINORS; i++) {
  35. struct comedi_device *dev = comedi_dev_get_from_minor(i);
  36. if (!dev)
  37. continue;
  38. down_read(&dev->attach_lock);
  39. if (dev->attached) {
  40. devices_q = 1;
  41. seq_printf(m, "%2d: %-20s %-20s %4d\n",
  42. i, dev->driver->driver_name,
  43. dev->board_name, dev->n_subdevices);
  44. }
  45. up_read(&dev->attach_lock);
  46. comedi_dev_put(dev);
  47. }
  48. if (!devices_q)
  49. seq_puts(m, "no devices\n");
  50. mutex_lock(&comedi_drivers_list_lock);
  51. for (driv = comedi_drivers; driv; driv = driv->next) {
  52. seq_printf(m, "%s:\n", driv->driver_name);
  53. for (i = 0; i < driv->num_names; i++)
  54. seq_printf(m, " %s\n",
  55. *(char **)((char *)driv->board_name +
  56. i * driv->offset));
  57. if (!driv->num_names)
  58. seq_printf(m, " %s\n", driv->driver_name);
  59. }
  60. mutex_unlock(&comedi_drivers_list_lock);
  61. return 0;
  62. }
  63. /*
  64. * seq_file wrappers for procfile show routines.
  65. */
  66. static int comedi_proc_open(struct inode *inode, struct file *file)
  67. {
  68. return single_open(file, comedi_read, NULL);
  69. }
  70. static const struct file_operations comedi_proc_fops = {
  71. .open = comedi_proc_open,
  72. .read = seq_read,
  73. .llseek = seq_lseek,
  74. .release = single_release,
  75. };
  76. void comedi_proc_init(void)
  77. {
  78. proc_create("comedi", 0644, NULL, &comedi_proc_fops);
  79. }
  80. void comedi_proc_cleanup(void)
  81. {
  82. remove_proc_entry("comedi", NULL);
  83. }