tape_proc.c 3.3 KB

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