|
1 | 1 | #include <linux/kernel.h> |
2 | 2 | #include <linux/ide.h> |
| 3 | +#include <linux/seq_file.h> |
3 | 4 |
|
4 | 5 | #include "ide-disk.h" |
5 | 6 |
|
@@ -37,77 +38,117 @@ static int get_smart_data(ide_drive_t *drive, u8 *buf, u8 sub_cmd) |
37 | 38 | return ide_raw_taskfile(drive, &cmd, buf, 1); |
38 | 39 | } |
39 | 40 |
|
40 | | -static int proc_idedisk_read_cache |
41 | | - (char *page, char **start, off_t off, int count, int *eof, void *data) |
| 41 | +static int idedisk_cache_proc_show(struct seq_file *m, void *v) |
42 | 42 | { |
43 | | - ide_drive_t *drive = (ide_drive_t *) data; |
44 | | - char *out = page; |
45 | | - int len; |
| 43 | + ide_drive_t *drive = (ide_drive_t *) m->private; |
46 | 44 |
|
47 | 45 | if (drive->dev_flags & IDE_DFLAG_ID_READ) |
48 | | - len = sprintf(out, "%i\n", drive->id[ATA_ID_BUF_SIZE] / 2); |
| 46 | + seq_printf(m, "%i\n", drive->id[ATA_ID_BUF_SIZE] / 2); |
49 | 47 | else |
50 | | - len = sprintf(out, "(none)\n"); |
| 48 | + seq_printf(m, "(none)\n"); |
| 49 | + return 0; |
| 50 | +} |
51 | 51 |
|
52 | | - PROC_IDE_READ_RETURN(page, start, off, count, eof, len); |
| 52 | +static int idedisk_cache_proc_open(struct inode *inode, struct file *file) |
| 53 | +{ |
| 54 | + return single_open(file, idedisk_cache_proc_show, PDE(inode)->data); |
53 | 55 | } |
54 | 56 |
|
55 | | -static int proc_idedisk_read_capacity |
56 | | - (char *page, char **start, off_t off, int count, int *eof, void *data) |
| 57 | +static const struct file_operations idedisk_cache_proc_fops = { |
| 58 | + .owner = THIS_MODULE, |
| 59 | + .open = idedisk_cache_proc_open, |
| 60 | + .read = seq_read, |
| 61 | + .llseek = seq_lseek, |
| 62 | + .release = single_release, |
| 63 | +}; |
| 64 | + |
| 65 | +static int idedisk_capacity_proc_show(struct seq_file *m, void *v) |
57 | 66 | { |
58 | | - ide_drive_t*drive = (ide_drive_t *)data; |
59 | | - int len; |
| 67 | + ide_drive_t*drive = (ide_drive_t *)m->private; |
60 | 68 |
|
61 | | - len = sprintf(page, "%llu\n", (long long)ide_gd_capacity(drive)); |
| 69 | + seq_printf(m, "%llu\n", (long long)ide_gd_capacity(drive)); |
| 70 | + return 0; |
| 71 | +} |
62 | 72 |
|
63 | | - PROC_IDE_READ_RETURN(page, start, off, count, eof, len); |
| 73 | +static int idedisk_capacity_proc_open(struct inode *inode, struct file *file) |
| 74 | +{ |
| 75 | + return single_open(file, idedisk_capacity_proc_show, PDE(inode)->data); |
64 | 76 | } |
65 | 77 |
|
66 | | -static int proc_idedisk_read_smart(char *page, char **start, off_t off, |
67 | | - int count, int *eof, void *data, u8 sub_cmd) |
| 78 | +static const struct file_operations idedisk_capacity_proc_fops = { |
| 79 | + .owner = THIS_MODULE, |
| 80 | + .open = idedisk_capacity_proc_open, |
| 81 | + .read = seq_read, |
| 82 | + .llseek = seq_lseek, |
| 83 | + .release = single_release, |
| 84 | +}; |
| 85 | + |
| 86 | +static int __idedisk_proc_show(struct seq_file *m, ide_drive_t *drive, u8 sub_cmd) |
68 | 87 | { |
69 | | - ide_drive_t *drive = (ide_drive_t *)data; |
70 | | - int len = 0, i = 0; |
| 88 | + u8 *buf; |
| 89 | + |
| 90 | + buf = kmalloc(SECTOR_SIZE, GFP_KERNEL); |
| 91 | + if (!buf) |
| 92 | + return -ENOMEM; |
71 | 93 |
|
72 | 94 | (void)smart_enable(drive); |
73 | 95 |
|
74 | | - if (get_smart_data(drive, page, sub_cmd) == 0) { |
75 | | - unsigned short *val = (unsigned short *) page; |
76 | | - char *out = (char *)val + SECTOR_SIZE; |
77 | | - |
78 | | - page = out; |
79 | | - do { |
80 | | - out += sprintf(out, "%04x%c", le16_to_cpu(*val), |
81 | | - (++i & 7) ? ' ' : '\n'); |
82 | | - val += 1; |
83 | | - } while (i < SECTOR_SIZE / 2); |
84 | | - len = out - page; |
| 96 | + if (get_smart_data(drive, buf, sub_cmd) == 0) { |
| 97 | + __le16 *val = (__le16 *)buf; |
| 98 | + int i; |
| 99 | + |
| 100 | + for (i = 0; i < SECTOR_SIZE / 2; i++) { |
| 101 | + seq_printf(m, "%04x%c", le16_to_cpu(val[i]), |
| 102 | + (i % 8) == 7 ? '\n' : ' '); |
| 103 | + } |
85 | 104 | } |
| 105 | + kfree(buf); |
| 106 | + return 0; |
| 107 | +} |
86 | 108 |
|
87 | | - PROC_IDE_READ_RETURN(page, start, off, count, eof, len); |
| 109 | +static int idedisk_sv_proc_show(struct seq_file *m, void *v) |
| 110 | +{ |
| 111 | + return __idedisk_proc_show(m, m->private, ATA_SMART_READ_VALUES); |
88 | 112 | } |
89 | 113 |
|
90 | | -static int proc_idedisk_read_sv |
91 | | - (char *page, char **start, off_t off, int count, int *eof, void *data) |
| 114 | +static int idedisk_sv_proc_open(struct inode *inode, struct file *file) |
92 | 115 | { |
93 | | - return proc_idedisk_read_smart(page, start, off, count, eof, data, |
94 | | - ATA_SMART_READ_VALUES); |
| 116 | + return single_open(file, idedisk_sv_proc_show, PDE(inode)->data); |
95 | 117 | } |
96 | 118 |
|
97 | | -static int proc_idedisk_read_st |
98 | | - (char *page, char **start, off_t off, int count, int *eof, void *data) |
| 119 | +static const struct file_operations idedisk_sv_proc_fops = { |
| 120 | + .owner = THIS_MODULE, |
| 121 | + .open = idedisk_sv_proc_open, |
| 122 | + .read = seq_read, |
| 123 | + .llseek = seq_lseek, |
| 124 | + .release = single_release, |
| 125 | +}; |
| 126 | + |
| 127 | +static int idedisk_st_proc_show(struct seq_file *m, void *v) |
99 | 128 | { |
100 | | - return proc_idedisk_read_smart(page, start, off, count, eof, data, |
101 | | - ATA_SMART_READ_THRESHOLDS); |
| 129 | + return __idedisk_proc_show(m, m->private, ATA_SMART_READ_THRESHOLDS); |
102 | 130 | } |
103 | 131 |
|
| 132 | +static int idedisk_st_proc_open(struct inode *inode, struct file *file) |
| 133 | +{ |
| 134 | + return single_open(file, idedisk_st_proc_show, PDE(inode)->data); |
| 135 | +} |
| 136 | + |
| 137 | +static const struct file_operations idedisk_st_proc_fops = { |
| 138 | + .owner = THIS_MODULE, |
| 139 | + .open = idedisk_st_proc_open, |
| 140 | + .read = seq_read, |
| 141 | + .llseek = seq_lseek, |
| 142 | + .release = single_release, |
| 143 | +}; |
| 144 | + |
104 | 145 | ide_proc_entry_t ide_disk_proc[] = { |
105 | | - { "cache", S_IFREG|S_IRUGO, proc_idedisk_read_cache, NULL }, |
106 | | - { "capacity", S_IFREG|S_IRUGO, proc_idedisk_read_capacity, NULL }, |
107 | | - { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL }, |
108 | | - { "smart_values", S_IFREG|S_IRUSR, proc_idedisk_read_sv, NULL }, |
109 | | - { "smart_thresholds", S_IFREG|S_IRUSR, proc_idedisk_read_st, NULL }, |
110 | | - { NULL, 0, NULL, NULL } |
| 146 | + { "cache", S_IFREG|S_IRUGO, &idedisk_cache_proc_fops }, |
| 147 | + { "capacity", S_IFREG|S_IRUGO, &idedisk_capacity_proc_fops }, |
| 148 | + { "geometry", S_IFREG|S_IRUGO, &ide_geometry_proc_fops }, |
| 149 | + { "smart_values", S_IFREG|S_IRUSR, &idedisk_sv_proc_fops }, |
| 150 | + { "smart_thresholds", S_IFREG|S_IRUSR, &idedisk_st_proc_fops }, |
| 151 | + {} |
111 | 152 | }; |
112 | 153 |
|
113 | 154 | ide_devset_rw_field(bios_cyl, bios_cyl); |
|
0 commit comments