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