tape_proc.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * drivers/s390/char/tape.c
  3. * tape device driver for S/390 and zSeries tapes.
  4. *
  5. * S390 and zSeries version
  6. * Copyright (C) 2001 IBM Corporation
  7. * Author(s): Carsten Otte <cotte@de.ibm.com>
  8. * Michael Holzheu <holzheu@de.ibm.com>
  9. * Tuan Ngo-Anh <ngoanh@de.ibm.com>
  10. *
  11. * PROCFS Functions
  12. */
  13. #include <linux/module.h>
  14. #include <linux/vmalloc.h>
  15. #include <linux/seq_file.h>
  16. #include <linux/proc_fs.h>
  17. #define TAPE_DBF_AREA tape_core_dbf
  18. #include "tape.h"
  19. static const char *tape_med_st_verbose[MS_SIZE] =
  20. {
  21. [MS_UNKNOWN] = "UNKNOWN ",
  22. [MS_LOADED] = "LOADED ",
  23. [MS_UNLOADED] = "UNLOADED"
  24. };
  25. /* our proc tapedevices entry */
  26. static struct proc_dir_entry *tape_proc_devices;
  27. /*
  28. * Show function for /proc/tapedevices
  29. */
  30. static int tape_proc_show(struct seq_file *m, void *v)
  31. {
  32. struct tape_device *device;
  33. struct tape_request *request;
  34. const char *str;
  35. unsigned long n;
  36. n = (unsigned long) v - 1;
  37. if (!n) {
  38. seq_printf(m, "TapeNo\tBusID CuType/Model\t"
  39. "DevType/Model\tBlkSize\tState\tOp\tMedState\n");
  40. }
  41. device = tape_get_device(n);
  42. if (IS_ERR(device))
  43. return 0;
  44. spin_lock_irq(get_ccwdev_lock(device->cdev));
  45. seq_printf(m, "%d\t", (int) n);
  46. seq_printf(m, "%-10.10s ", dev_name(&device->cdev->dev));
  47. seq_printf(m, "%04X/", device->cdev->id.cu_type);
  48. seq_printf(m, "%02X\t", device->cdev->id.cu_model);
  49. seq_printf(m, "%04X/", device->cdev->id.dev_type);
  50. seq_printf(m, "%02X\t\t", device->cdev->id.dev_model);
  51. if (device->char_data.block_size == 0)
  52. seq_printf(m, "auto\t");
  53. else
  54. seq_printf(m, "%i\t", device->char_data.block_size);
  55. if (device->tape_state >= 0 &&
  56. device->tape_state < TS_SIZE)
  57. str = tape_state_verbose[device->tape_state];
  58. else
  59. str = "UNKNOWN";
  60. seq_printf(m, "%s\t", str);
  61. if (!list_empty(&device->req_queue)) {
  62. request = list_entry(device->req_queue.next,
  63. struct tape_request, list);
  64. str = tape_op_verbose[request->op];
  65. } else
  66. str = "---";
  67. seq_printf(m, "%s\t", str);
  68. seq_printf(m, "%s\n", tape_med_st_verbose[device->medium_state]);
  69. spin_unlock_irq(get_ccwdev_lock(device->cdev));
  70. tape_put_device(device);
  71. return 0;
  72. }
  73. static void *tape_proc_start(struct seq_file *m, loff_t *pos)
  74. {
  75. if (*pos >= 256 / TAPE_MINORS_PER_DEV)
  76. return NULL;
  77. return (void *)((unsigned long) *pos + 1);
  78. }
  79. static void *tape_proc_next(struct seq_file *m, void *v, loff_t *pos)
  80. {
  81. ++*pos;
  82. return tape_proc_start(m, pos);
  83. }
  84. static void tape_proc_stop(struct seq_file *m, void *v)
  85. {
  86. }
  87. static const struct seq_operations tape_proc_seq = {
  88. .start = tape_proc_start,
  89. .next = tape_proc_next,
  90. .stop = tape_proc_stop,
  91. .show = tape_proc_show,
  92. };
  93. static int tape_proc_open(struct inode *inode, struct file *file)
  94. {
  95. return seq_open(file, &tape_proc_seq);
  96. }
  97. static const struct file_operations tape_proc_ops =
  98. {
  99. .owner = THIS_MODULE,
  100. .open = tape_proc_open,
  101. .read = seq_read,
  102. .llseek = seq_lseek,
  103. .release = seq_release,
  104. };
  105. /*
  106. * Initialize procfs stuff on startup
  107. */
  108. void
  109. tape_proc_init(void)
  110. {
  111. tape_proc_devices =
  112. proc_create("tapedevices", S_IFREG | S_IRUGO | S_IWUSR, NULL,
  113. &tape_proc_ops);
  114. if (tape_proc_devices == NULL) {
  115. return;
  116. }
  117. }
  118. /*
  119. * Cleanup all stuff registered to the procfs
  120. */
  121. void
  122. tape_proc_cleanup(void)
  123. {
  124. if (tape_proc_devices != NULL)
  125. remove_proc_entry ("tapedevices", NULL);
  126. }