Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ide: convert to ->proc_fops

->read_proc, ->write_proc are going away, ->proc_fops should be used instead.

The only tricky place is IDENTIFY handling: if for some reason
taskfile_lib_get_identify() fails, buffer _is_ changed and at least
first byte is overwritten. Emulate old behaviour with returning
that first byte to userspace and reporting length=1 despite overall -E.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Alexey Dobriyan and committed by
David S. Miller
6d703a81 76fbebfb

+372 -214
+20 -8
drivers/ide/ide-cd.c
··· 30 30 #include <linux/kernel.h> 31 31 #include <linux/delay.h> 32 32 #include <linux/timer.h> 33 + #include <linux/seq_file.h> 33 34 #include <linux/slab.h> 34 35 #include <linux/interrupt.h> 35 36 #include <linux/errno.h> ··· 1390 1389 return capacity * sectors_per_frame; 1391 1390 } 1392 1391 1393 - static int proc_idecd_read_capacity(char *page, char **start, off_t off, 1394 - int count, int *eof, void *data) 1392 + static int idecd_capacity_proc_show(struct seq_file *m, void *v) 1395 1393 { 1396 - ide_drive_t *drive = data; 1397 - int len; 1394 + ide_drive_t *drive = m->private; 1398 1395 1399 - len = sprintf(page, "%llu\n", (long long)ide_cdrom_capacity(drive)); 1400 - PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 1396 + seq_printf(m, "%llu\n", (long long)ide_cdrom_capacity(drive)); 1397 + return 0; 1401 1398 } 1402 1399 1400 + static int idecd_capacity_proc_open(struct inode *inode, struct file *file) 1401 + { 1402 + return single_open(file, idecd_capacity_proc_show, PDE(inode)->data); 1403 + } 1404 + 1405 + static const struct file_operations idecd_capacity_proc_fops = { 1406 + .owner = THIS_MODULE, 1407 + .open = idecd_capacity_proc_open, 1408 + .read = seq_read, 1409 + .llseek = seq_lseek, 1410 + .release = single_release, 1411 + }; 1412 + 1403 1413 static ide_proc_entry_t idecd_proc[] = { 1404 - { "capacity", S_IFREG|S_IRUGO, proc_idecd_read_capacity, NULL }, 1405 - { NULL, 0, NULL, NULL } 1414 + { "capacity", S_IFREG|S_IRUGO, &idecd_capacity_proc_fops }, 1415 + {} 1406 1416 }; 1407 1417 1408 1418 static ide_proc_entry_t *ide_cd_proc_entries(ide_drive_t *drive)
+88 -47
drivers/ide/ide-disk_proc.c
··· 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 ··· 38 37 return ide_raw_taskfile(drive, &cmd, buf, 1); 39 38 } 40 39 41 - static int proc_idedisk_read_cache 42 - (char *page, char **start, off_t off, int count, int *eof, void *data) 40 + static int idedisk_cache_proc_show(struct seq_file *m, void *v) 43 41 { 44 - ide_drive_t *drive = (ide_drive_t *) data; 45 - char *out = page; 46 - int len; 42 + ide_drive_t *drive = (ide_drive_t *) m->private; 47 43 48 44 if (drive->dev_flags & IDE_DFLAG_ID_READ) 49 - len = sprintf(out, "%i\n", drive->id[ATA_ID_BUF_SIZE] / 2); 45 + seq_printf(m, "%i\n", drive->id[ATA_ID_BUF_SIZE] / 2); 50 46 else 51 - len = sprintf(out, "(none)\n"); 52 - 53 - PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 47 + seq_printf(m, "(none)\n"); 48 + return 0; 54 49 } 55 50 56 - static int proc_idedisk_read_capacity 57 - (char *page, char **start, off_t off, int count, int *eof, void *data) 51 + static int idedisk_cache_proc_open(struct inode *inode, struct file *file) 58 52 { 59 - ide_drive_t*drive = (ide_drive_t *)data; 60 - int len; 61 - 62 - len = sprintf(page, "%llu\n", (long long)ide_gd_capacity(drive)); 63 - 64 - PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 53 + return single_open(file, idedisk_cache_proc_show, PDE(inode)->data); 65 54 } 66 55 67 - static int proc_idedisk_read_smart(char *page, char **start, off_t off, 68 - int count, int *eof, void *data, u8 sub_cmd) 56 + static const struct file_operations idedisk_cache_proc_fops = { 57 + .owner = THIS_MODULE, 58 + .open = idedisk_cache_proc_open, 59 + .read = seq_read, 60 + .llseek = seq_lseek, 61 + .release = single_release, 62 + }; 63 + 64 + static int idedisk_capacity_proc_show(struct seq_file *m, void *v) 69 65 { 70 - ide_drive_t *drive = (ide_drive_t *)data; 71 - int len = 0, i = 0; 66 + ide_drive_t*drive = (ide_drive_t *)m->private; 67 + 68 + seq_printf(m, "%llu\n", (long long)ide_gd_capacity(drive)); 69 + return 0; 70 + } 71 + 72 + static int idedisk_capacity_proc_open(struct inode *inode, struct file *file) 73 + { 74 + return single_open(file, idedisk_capacity_proc_show, PDE(inode)->data); 75 + } 76 + 77 + static const struct file_operations idedisk_capacity_proc_fops = { 78 + .owner = THIS_MODULE, 79 + .open = idedisk_capacity_proc_open, 80 + .read = seq_read, 81 + .llseek = seq_lseek, 82 + .release = single_release, 83 + }; 84 + 85 + static int __idedisk_proc_show(struct seq_file *m, ide_drive_t *drive, u8 sub_cmd) 86 + { 87 + u8 *buf; 88 + 89 + buf = kmalloc(SECTOR_SIZE, GFP_KERNEL); 90 + if (!buf) 91 + return -ENOMEM; 72 92 73 93 (void)smart_enable(drive); 74 94 75 - if (get_smart_data(drive, page, sub_cmd) == 0) { 76 - unsigned short *val = (unsigned short *) page; 77 - char *out = (char *)val + SECTOR_SIZE; 95 + if (get_smart_data(drive, buf, sub_cmd) == 0) { 96 + __le16 *val = (__le16 *)buf; 97 + int i; 78 98 79 - page = out; 80 - do { 81 - out += sprintf(out, "%04x%c", le16_to_cpu(*val), 82 - (++i & 7) ? ' ' : '\n'); 83 - val += 1; 84 - } while (i < SECTOR_SIZE / 2); 85 - len = out - page; 99 + for (i = 0; i < SECTOR_SIZE / 2; i++) { 100 + seq_printf(m, "%04x%c", le16_to_cpu(val[i]), 101 + (i % 8) == 7 ? '\n' : ' '); 102 + } 86 103 } 87 - 88 - PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 104 + kfree(buf); 105 + return 0; 89 106 } 90 107 91 - static int proc_idedisk_read_sv 92 - (char *page, char **start, off_t off, int count, int *eof, void *data) 108 + static int idedisk_sv_proc_show(struct seq_file *m, void *v) 93 109 { 94 - return proc_idedisk_read_smart(page, start, off, count, eof, data, 95 - ATA_SMART_READ_VALUES); 110 + return __idedisk_proc_show(m, m->private, ATA_SMART_READ_VALUES); 96 111 } 97 112 98 - static int proc_idedisk_read_st 99 - (char *page, char **start, off_t off, int count, int *eof, void *data) 113 + static int idedisk_sv_proc_open(struct inode *inode, struct file *file) 100 114 { 101 - return proc_idedisk_read_smart(page, start, off, count, eof, data, 102 - ATA_SMART_READ_THRESHOLDS); 115 + return single_open(file, idedisk_sv_proc_show, PDE(inode)->data); 103 116 } 117 + 118 + static const struct file_operations idedisk_sv_proc_fops = { 119 + .owner = THIS_MODULE, 120 + .open = idedisk_sv_proc_open, 121 + .read = seq_read, 122 + .llseek = seq_lseek, 123 + .release = single_release, 124 + }; 125 + 126 + static int idedisk_st_proc_show(struct seq_file *m, void *v) 127 + { 128 + return __idedisk_proc_show(m, m->private, ATA_SMART_READ_THRESHOLDS); 129 + } 130 + 131 + static int idedisk_st_proc_open(struct inode *inode, struct file *file) 132 + { 133 + return single_open(file, idedisk_st_proc_show, PDE(inode)->data); 134 + } 135 + 136 + static const struct file_operations idedisk_st_proc_fops = { 137 + .owner = THIS_MODULE, 138 + .open = idedisk_st_proc_open, 139 + .read = seq_read, 140 + .llseek = seq_lseek, 141 + .release = single_release, 142 + }; 104 143 105 144 ide_proc_entry_t ide_disk_proc[] = { 106 - { "cache", S_IFREG|S_IRUGO, proc_idedisk_read_cache, NULL }, 107 - { "capacity", S_IFREG|S_IRUGO, proc_idedisk_read_capacity, NULL }, 108 - { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL }, 109 - { "smart_values", S_IFREG|S_IRUSR, proc_idedisk_read_sv, NULL }, 110 - { "smart_thresholds", S_IFREG|S_IRUSR, proc_idedisk_read_st, NULL }, 111 - { NULL, 0, NULL, NULL } 145 + { "cache", S_IFREG|S_IRUGO, &idedisk_cache_proc_fops }, 146 + { "capacity", S_IFREG|S_IRUGO, &idedisk_capacity_proc_fops }, 147 + { "geometry", S_IFREG|S_IRUGO, &ide_geometry_proc_fops }, 148 + { "smart_values", S_IFREG|S_IRUSR, &idedisk_sv_proc_fops }, 149 + { "smart_thresholds", S_IFREG|S_IRUSR, &idedisk_st_proc_fops }, 150 + {} 112 151 }; 113 152 114 153 ide_devset_rw_field(bios_cyl, bios_cyl);
+21 -9
drivers/ide/ide-floppy_proc.c
··· 1 1 #include <linux/kernel.h> 2 2 #include <linux/ide.h> 3 + #include <linux/seq_file.h> 3 4 4 5 #include "ide-floppy.h" 5 6 6 - static int proc_idefloppy_read_capacity(char *page, char **start, off_t off, 7 - int count, int *eof, void *data) 7 + static int idefloppy_capacity_proc_show(struct seq_file *m, void *v) 8 8 { 9 - ide_drive_t*drive = (ide_drive_t *)data; 10 - int len; 9 + ide_drive_t*drive = (ide_drive_t *)m->private; 11 10 12 - len = sprintf(page, "%llu\n", (long long)ide_gd_capacity(drive)); 13 - PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 11 + seq_printf(m, "%llu\n", (long long)ide_gd_capacity(drive)); 12 + return 0; 14 13 } 15 14 15 + static int idefloppy_capacity_proc_open(struct inode *inode, struct file *file) 16 + { 17 + return single_open(file, idefloppy_capacity_proc_show, PDE(inode)->data); 18 + } 19 + 20 + static const struct file_operations idefloppy_capacity_proc_fops = { 21 + .owner = THIS_MODULE, 22 + .open = idefloppy_capacity_proc_open, 23 + .read = seq_read, 24 + .llseek = seq_lseek, 25 + .release = single_release, 26 + }; 27 + 16 28 ide_proc_entry_t ide_floppy_proc[] = { 17 - { "capacity", S_IFREG|S_IRUGO, proc_idefloppy_read_capacity, NULL }, 18 - { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL }, 19 - { NULL, 0, NULL, NULL } 29 + { "capacity", S_IFREG|S_IRUGO, &idefloppy_capacity_proc_fops }, 30 + { "geometry", S_IFREG|S_IRUGO, &ide_geometry_proc_fops }, 31 + {} 20 32 }; 21 33 22 34 ide_devset_rw_field(bios_cyl, bios_cyl);
+219 -119
drivers/ide/ide-proc.c
··· 30 30 31 31 static struct proc_dir_entry *proc_ide_root; 32 32 33 - static int proc_ide_read_imodel 34 - (char *page, char **start, off_t off, int count, int *eof, void *data) 33 + static int ide_imodel_proc_show(struct seq_file *m, void *v) 35 34 { 36 - ide_hwif_t *hwif = (ide_hwif_t *) data; 37 - int len; 35 + ide_hwif_t *hwif = (ide_hwif_t *) m->private; 38 36 const char *name; 39 37 40 38 switch (hwif->chipset) { ··· 51 53 case ide_acorn: name = "acorn"; break; 52 54 default: name = "(unknown)"; break; 53 55 } 54 - len = sprintf(page, "%s\n", name); 55 - PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 56 + seq_printf(m, "%s\n", name); 57 + return 0; 56 58 } 57 59 58 - static int proc_ide_read_mate 59 - (char *page, char **start, off_t off, int count, int *eof, void *data) 60 + static int ide_imodel_proc_open(struct inode *inode, struct file *file) 60 61 { 61 - ide_hwif_t *hwif = (ide_hwif_t *) data; 62 - int len; 62 + return single_open(file, ide_imodel_proc_show, PDE(inode)->data); 63 + } 64 + 65 + static const struct file_operations ide_imodel_proc_fops = { 66 + .owner = THIS_MODULE, 67 + .open = ide_imodel_proc_open, 68 + .read = seq_read, 69 + .llseek = seq_lseek, 70 + .release = single_release, 71 + }; 72 + 73 + static int ide_mate_proc_show(struct seq_file *m, void *v) 74 + { 75 + ide_hwif_t *hwif = (ide_hwif_t *) m->private; 63 76 64 77 if (hwif && hwif->mate) 65 - len = sprintf(page, "%s\n", hwif->mate->name); 78 + seq_printf(m, "%s\n", hwif->mate->name); 66 79 else 67 - len = sprintf(page, "(none)\n"); 68 - PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 80 + seq_printf(m, "(none)\n"); 81 + return 0; 69 82 } 70 83 71 - static int proc_ide_read_channel 72 - (char *page, char **start, off_t off, int count, int *eof, void *data) 84 + static int ide_mate_proc_open(struct inode *inode, struct file *file) 73 85 { 74 - ide_hwif_t *hwif = (ide_hwif_t *) data; 75 - int len; 76 - 77 - page[0] = hwif->channel ? '1' : '0'; 78 - page[1] = '\n'; 79 - len = 2; 80 - PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 86 + return single_open(file, ide_mate_proc_show, PDE(inode)->data); 81 87 } 82 88 83 - static int proc_ide_read_identify 84 - (char *page, char **start, off_t off, int count, int *eof, void *data) 89 + static const struct file_operations ide_mate_proc_fops = { 90 + .owner = THIS_MODULE, 91 + .open = ide_mate_proc_open, 92 + .read = seq_read, 93 + .llseek = seq_lseek, 94 + .release = single_release, 95 + }; 96 + 97 + static int ide_channel_proc_show(struct seq_file *m, void *v) 85 98 { 86 - ide_drive_t *drive = (ide_drive_t *)data; 87 - int len = 0, i = 0; 88 - int err = 0; 99 + ide_hwif_t *hwif = (ide_hwif_t *) m->private; 89 100 90 - len = sprintf(page, "\n"); 101 + seq_printf(m, "%c\n", hwif->channel ? '1' : '0'); 102 + return 0; 103 + } 91 104 92 - if (drive) { 93 - __le16 *val = (__le16 *)page; 105 + static int ide_channel_proc_open(struct inode *inode, struct file *file) 106 + { 107 + return single_open(file, ide_channel_proc_show, PDE(inode)->data); 108 + } 94 109 95 - err = taskfile_lib_get_identify(drive, page); 96 - if (!err) { 97 - char *out = (char *)page + SECTOR_SIZE; 110 + static const struct file_operations ide_channel_proc_fops = { 111 + .owner = THIS_MODULE, 112 + .open = ide_channel_proc_open, 113 + .read = seq_read, 114 + .llseek = seq_lseek, 115 + .release = single_release, 116 + }; 98 117 99 - page = out; 100 - do { 101 - out += sprintf(out, "%04x%c", 102 - le16_to_cpup(val), (++i & 7) ? ' ' : '\n'); 103 - val += 1; 104 - } while (i < SECTOR_SIZE / 2); 105 - len = out - page; 106 - } 118 + static int ide_identify_proc_show(struct seq_file *m, void *v) 119 + { 120 + ide_drive_t *drive = (ide_drive_t *)m->private; 121 + u8 *buf; 122 + 123 + if (!drive) { 124 + seq_putc(m, '\n'); 125 + return 0; 107 126 } 108 - PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 127 + 128 + buf = kmalloc(SECTOR_SIZE, GFP_KERNEL); 129 + if (!buf) 130 + return -ENOMEM; 131 + if (taskfile_lib_get_identify(drive, buf) == 0) { 132 + __le16 *val = (__le16 *)buf; 133 + int i; 134 + 135 + for (i = 0; i < SECTOR_SIZE / 2; i++) { 136 + seq_printf(m, "%04x%c", le16_to_cpu(val[i]), 137 + (i % 8) == 7 ? '\n' : ' '); 138 + } 139 + } else 140 + seq_putc(m, buf[0]); 141 + kfree(buf); 142 + return 0; 109 143 } 144 + 145 + static int ide_identify_proc_open(struct inode *inode, struct file *file) 146 + { 147 + return single_open(file, ide_identify_proc_show, PDE(inode)->data); 148 + } 149 + 150 + static const struct file_operations ide_identify_proc_fops = { 151 + .owner = THIS_MODULE, 152 + .open = ide_identify_proc_open, 153 + .read = seq_read, 154 + .llseek = seq_lseek, 155 + .release = single_release, 156 + }; 110 157 111 158 /** 112 159 * ide_find_setting - find a specific setting ··· 283 240 warned = 1; 284 241 } 285 242 286 - static int proc_ide_read_settings 287 - (char *page, char **start, off_t off, int count, int *eof, void *data) 243 + static int ide_settings_proc_show(struct seq_file *m, void *v) 288 244 { 289 245 const struct ide_proc_devset *setting, *g, *d; 290 246 const struct ide_devset *ds; 291 - ide_drive_t *drive = (ide_drive_t *) data; 292 - char *out = page; 293 - int len, rc, mul_factor, div_factor; 247 + ide_drive_t *drive = (ide_drive_t *) m->private; 248 + int rc, mul_factor, div_factor; 294 249 295 250 proc_ide_settings_warn(); 296 251 297 252 mutex_lock(&ide_setting_mtx); 298 253 g = ide_generic_settings; 299 254 d = drive->settings; 300 - out += sprintf(out, "name\t\t\tvalue\t\tmin\t\tmax\t\tmode\n"); 301 - out += sprintf(out, "----\t\t\t-----\t\t---\t\t---\t\t----\n"); 255 + seq_printf(m, "name\t\t\tvalue\t\tmin\t\tmax\t\tmode\n"); 256 + seq_printf(m, "----\t\t\t-----\t\t---\t\t---\t\t----\n"); 302 257 while (g->name || (d && d->name)) { 303 258 /* read settings in the alphabetical order */ 304 259 if (g->name && d && d->name) { ··· 310 269 setting = g++; 311 270 mul_factor = setting->mulf ? setting->mulf(drive) : 1; 312 271 div_factor = setting->divf ? setting->divf(drive) : 1; 313 - out += sprintf(out, "%-24s", setting->name); 272 + seq_printf(m, "%-24s", setting->name); 314 273 rc = ide_read_setting(drive, setting); 315 274 if (rc >= 0) 316 - out += sprintf(out, "%-16d", rc * mul_factor / div_factor); 275 + seq_printf(m, "%-16d", rc * mul_factor / div_factor); 317 276 else 318 - out += sprintf(out, "%-16s", "write-only"); 319 - out += sprintf(out, "%-16d%-16d", (setting->min * mul_factor + div_factor - 1) / div_factor, setting->max * mul_factor / div_factor); 277 + seq_printf(m, "%-16s", "write-only"); 278 + seq_printf(m, "%-16d%-16d", (setting->min * mul_factor + div_factor - 1) / div_factor, setting->max * mul_factor / div_factor); 320 279 ds = setting->setting; 321 280 if (ds->get) 322 - out += sprintf(out, "r"); 281 + seq_printf(m, "r"); 323 282 if (ds->set) 324 - out += sprintf(out, "w"); 325 - out += sprintf(out, "\n"); 283 + seq_printf(m, "w"); 284 + seq_printf(m, "\n"); 326 285 } 327 - len = out - page; 328 286 mutex_unlock(&ide_setting_mtx); 329 - PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 287 + return 0; 288 + } 289 + 290 + static int ide_settings_proc_open(struct inode *inode, struct file *file) 291 + { 292 + return single_open(file, ide_settings_proc_show, PDE(inode)->data); 330 293 } 331 294 332 295 #define MAX_LEN 30 333 296 334 - static int proc_ide_write_settings(struct file *file, const char __user *buffer, 335 - unsigned long count, void *data) 297 + static ssize_t ide_settings_proc_write(struct file *file, const char __user *buffer, 298 + size_t count, loff_t *pos) 336 299 { 337 - ide_drive_t *drive = (ide_drive_t *) data; 300 + ide_drive_t *drive = (ide_drive_t *) PDE(file->f_path.dentry->d_inode)->data; 338 301 char name[MAX_LEN + 1]; 339 302 int for_real = 0, mul_factor, div_factor; 340 303 unsigned long n; ··· 433 388 return count; 434 389 parse_error: 435 390 free_page((unsigned long)buf); 436 - printk("proc_ide_write_settings(): parse error\n"); 391 + printk("%s(): parse error\n", __func__); 437 392 return -EINVAL; 438 393 } 439 394 440 - int proc_ide_read_capacity 441 - (char *page, char **start, off_t off, int count, int *eof, void *data) 395 + static const struct file_operations ide_settings_proc_fops = { 396 + .owner = THIS_MODULE, 397 + .open = ide_settings_proc_open, 398 + .read = seq_read, 399 + .llseek = seq_lseek, 400 + .release = single_release, 401 + .write = ide_settings_proc_write, 402 + }; 403 + 404 + static int ide_capacity_proc_show(struct seq_file *m, void *v) 442 405 { 443 - int len = sprintf(page, "%llu\n", (long long)0x7fffffff); 444 - PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 406 + seq_printf(m, "%llu\n", (long long)0x7fffffff); 407 + return 0; 445 408 } 446 409 447 - EXPORT_SYMBOL_GPL(proc_ide_read_capacity); 448 - 449 - int proc_ide_read_geometry 450 - (char *page, char **start, off_t off, int count, int *eof, void *data) 410 + static int ide_capacity_proc_open(struct inode *inode, struct file *file) 451 411 { 452 - ide_drive_t *drive = (ide_drive_t *) data; 453 - char *out = page; 454 - int len; 412 + return single_open(file, ide_capacity_proc_show, NULL); 413 + } 455 414 456 - out += sprintf(out, "physical %d/%d/%d\n", 415 + const struct file_operations ide_capacity_proc_fops = { 416 + .owner = THIS_MODULE, 417 + .open = ide_capacity_proc_open, 418 + .read = seq_read, 419 + .llseek = seq_lseek, 420 + .release = single_release, 421 + }; 422 + EXPORT_SYMBOL_GPL(ide_capacity_proc_fops); 423 + 424 + static int ide_geometry_proc_show(struct seq_file *m, void *v) 425 + { 426 + ide_drive_t *drive = (ide_drive_t *) m->private; 427 + 428 + seq_printf(m, "physical %d/%d/%d\n", 457 429 drive->cyl, drive->head, drive->sect); 458 - out += sprintf(out, "logical %d/%d/%d\n", 430 + seq_printf(m, "logical %d/%d/%d\n", 459 431 drive->bios_cyl, drive->bios_head, drive->bios_sect); 460 - 461 - len = out - page; 462 - PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 432 + return 0; 463 433 } 464 434 465 - EXPORT_SYMBOL(proc_ide_read_geometry); 466 - 467 - static int proc_ide_read_dmodel 468 - (char *page, char **start, off_t off, int count, int *eof, void *data) 435 + static int ide_geometry_proc_open(struct inode *inode, struct file *file) 469 436 { 470 - ide_drive_t *drive = (ide_drive_t *) data; 437 + return single_open(file, ide_geometry_proc_show, PDE(inode)->data); 438 + } 439 + 440 + const struct file_operations ide_geometry_proc_fops = { 441 + .owner = THIS_MODULE, 442 + .open = ide_geometry_proc_open, 443 + .read = seq_read, 444 + .llseek = seq_lseek, 445 + .release = single_release, 446 + }; 447 + EXPORT_SYMBOL(ide_geometry_proc_fops); 448 + 449 + static int ide_dmodel_proc_show(struct seq_file *seq, void *v) 450 + { 451 + ide_drive_t *drive = (ide_drive_t *) seq->private; 471 452 char *m = (char *)&drive->id[ATA_ID_PROD]; 472 - int len; 473 453 474 - len = sprintf(page, "%.40s\n", m[0] ? m : "(none)"); 475 - PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 454 + seq_printf(seq, "%.40s\n", m[0] ? m : "(none)"); 455 + return 0; 476 456 } 477 457 478 - static int proc_ide_read_driver 479 - (char *page, char **start, off_t off, int count, int *eof, void *data) 458 + static int ide_dmodel_proc_open(struct inode *inode, struct file *file) 480 459 { 481 - ide_drive_t *drive = (ide_drive_t *)data; 460 + return single_open(file, ide_dmodel_proc_show, PDE(inode)->data); 461 + } 462 + 463 + static const struct file_operations ide_dmodel_proc_fops = { 464 + .owner = THIS_MODULE, 465 + .open = ide_dmodel_proc_open, 466 + .read = seq_read, 467 + .llseek = seq_lseek, 468 + .release = single_release, 469 + }; 470 + 471 + static int ide_driver_proc_show(struct seq_file *m, void *v) 472 + { 473 + ide_drive_t *drive = (ide_drive_t *)m->private; 482 474 struct device *dev = &drive->gendev; 483 475 struct ide_driver *ide_drv; 484 - int len; 485 476 486 477 if (dev->driver) { 487 478 ide_drv = to_ide_driver(dev->driver); 488 - len = sprintf(page, "%s version %s\n", 479 + seq_printf(m, "%s version %s\n", 489 480 dev->driver->name, ide_drv->version); 490 481 } else 491 - len = sprintf(page, "ide-default version 0.9.newide\n"); 492 - PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 482 + seq_printf(m, "ide-default version 0.9.newide\n"); 483 + return 0; 484 + } 485 + 486 + static int ide_driver_proc_open(struct inode *inode, struct file *file) 487 + { 488 + return single_open(file, ide_driver_proc_show, PDE(inode)->data); 493 489 } 494 490 495 491 static int ide_replace_subdriver(ide_drive_t *drive, const char *driver) ··· 560 474 return ret; 561 475 } 562 476 563 - static int proc_ide_write_driver 564 - (struct file *file, const char __user *buffer, unsigned long count, void *data) 477 + static ssize_t ide_driver_proc_write(struct file *file, const char __user *buffer, 478 + size_t count, loff_t *pos) 565 479 { 566 - ide_drive_t *drive = (ide_drive_t *) data; 480 + ide_drive_t *drive = (ide_drive_t *) PDE(file->f_path.dentry->d_inode)->data; 567 481 char name[32]; 568 482 569 483 if (!capable(CAP_SYS_ADMIN)) ··· 578 492 return count; 579 493 } 580 494 581 - static int proc_ide_read_media 582 - (char *page, char **start, off_t off, int count, int *eof, void *data) 495 + static const struct file_operations ide_driver_proc_fops = { 496 + .owner = THIS_MODULE, 497 + .open = ide_driver_proc_open, 498 + .read = seq_read, 499 + .llseek = seq_lseek, 500 + .release = single_release, 501 + .write = ide_driver_proc_write, 502 + }; 503 + 504 + static int ide_media_proc_show(struct seq_file *m, void *v) 583 505 { 584 - ide_drive_t *drive = (ide_drive_t *) data; 506 + ide_drive_t *drive = (ide_drive_t *) m->private; 585 507 const char *media; 586 - int len; 587 508 588 509 switch (drive->media) { 589 510 case ide_disk: media = "disk\n"; break; ··· 600 507 case ide_optical: media = "optical\n"; break; 601 508 default: media = "UNKNOWN\n"; break; 602 509 } 603 - strcpy(page, media); 604 - len = strlen(media); 605 - PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 510 + seq_puts(m, media); 511 + return 0; 606 512 } 607 513 514 + static int ide_media_proc_open(struct inode *inode, struct file *file) 515 + { 516 + return single_open(file, ide_media_proc_show, PDE(inode)->data); 517 + } 518 + 519 + static const struct file_operations ide_media_proc_fops = { 520 + .owner = THIS_MODULE, 521 + .open = ide_media_proc_open, 522 + .read = seq_read, 523 + .llseek = seq_lseek, 524 + .release = single_release, 525 + }; 526 + 608 527 static ide_proc_entry_t generic_drive_entries[] = { 609 - { "driver", S_IFREG|S_IRUGO, proc_ide_read_driver, 610 - proc_ide_write_driver }, 611 - { "identify", S_IFREG|S_IRUSR, proc_ide_read_identify, NULL }, 612 - { "media", S_IFREG|S_IRUGO, proc_ide_read_media, NULL }, 613 - { "model", S_IFREG|S_IRUGO, proc_ide_read_dmodel, NULL }, 614 - { "settings", S_IFREG|S_IRUSR|S_IWUSR, proc_ide_read_settings, 615 - proc_ide_write_settings }, 616 - { NULL, 0, NULL, NULL } 528 + { "driver", S_IFREG|S_IRUGO, &ide_driver_proc_fops }, 529 + { "identify", S_IFREG|S_IRUSR, &ide_identify_proc_fops}, 530 + { "media", S_IFREG|S_IRUGO, &ide_media_proc_fops }, 531 + { "model", S_IFREG|S_IRUGO, &ide_dmodel_proc_fops }, 532 + { "settings", S_IFREG|S_IRUSR|S_IWUSR, &ide_settings_proc_fops}, 533 + {} 617 534 }; 618 535 619 536 static void ide_add_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p, void *data) ··· 633 530 if (!dir || !p) 634 531 return; 635 532 while (p->name != NULL) { 636 - ent = create_proc_entry(p->name, p->mode, dir); 533 + ent = proc_create_data(p->name, p->mode, dir, p->proc_fops, data); 637 534 if (!ent) return; 638 - ent->data = data; 639 - ent->read_proc = p->read_proc; 640 - ent->write_proc = p->write_proc; 641 535 p++; 642 536 } 643 537 } ··· 717 617 } 718 618 719 619 static ide_proc_entry_t hwif_entries[] = { 720 - { "channel", S_IFREG|S_IRUGO, proc_ide_read_channel, NULL }, 721 - { "mate", S_IFREG|S_IRUGO, proc_ide_read_mate, NULL }, 722 - { "model", S_IFREG|S_IRUGO, proc_ide_read_imodel, NULL }, 723 - { NULL, 0, NULL, NULL } 620 + { "channel", S_IFREG|S_IRUGO, &ide_channel_proc_fops }, 621 + { "mate", S_IFREG|S_IRUGO, &ide_mate_proc_fops }, 622 + { "model", S_IFREG|S_IRUGO, &ide_imodel_proc_fops }, 623 + {} 724 624 }; 725 625 726 626 void ide_proc_register_port(ide_hwif_t *hwif)
+21 -10
drivers/ide/ide-tape.c
··· 31 31 #include <linux/major.h> 32 32 #include <linux/errno.h> 33 33 #include <linux/genhd.h> 34 + #include <linux/seq_file.h> 34 35 #include <linux/slab.h> 35 36 #include <linux/pci.h> 36 37 #include <linux/ide.h> ··· 1817 1816 } 1818 1817 1819 1818 #ifdef CONFIG_IDE_PROC_FS 1820 - static int proc_idetape_read_name 1821 - (char *page, char **start, off_t off, int count, int *eof, void *data) 1819 + static int idetape_name_proc_show(struct seq_file *m, void *v) 1822 1820 { 1823 - ide_drive_t *drive = (ide_drive_t *) data; 1821 + ide_drive_t *drive = (ide_drive_t *) m->private; 1824 1822 idetape_tape_t *tape = drive->driver_data; 1825 - char *out = page; 1826 - int len; 1827 1823 1828 - len = sprintf(out, "%s\n", tape->name); 1829 - PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 1824 + seq_printf(m, "%s\n", tape->name); 1825 + return 0; 1830 1826 } 1831 1827 1828 + static int idetape_name_proc_open(struct inode *inode, struct file *file) 1829 + { 1830 + return single_open(file, idetape_name_proc_show, PDE(inode)->data); 1831 + } 1832 + 1833 + static const struct file_operations idetape_name_proc_fops = { 1834 + .owner = THIS_MODULE, 1835 + .open = idetape_name_proc_open, 1836 + .read = seq_read, 1837 + .llseek = seq_lseek, 1838 + .release = single_release, 1839 + }; 1840 + 1832 1841 static ide_proc_entry_t idetape_proc[] = { 1833 - { "capacity", S_IFREG|S_IRUGO, proc_ide_read_capacity, NULL }, 1834 - { "name", S_IFREG|S_IRUGO, proc_idetape_read_name, NULL }, 1835 - { NULL, 0, NULL, NULL } 1842 + { "capacity", S_IFREG|S_IRUGO, &ide_capacity_proc_fops }, 1843 + { "name", S_IFREG|S_IRUGO, &idetape_name_proc_fops }, 1844 + {} 1836 1845 }; 1837 1846 1838 1847 static ide_proc_entry_t *ide_tape_proc_entries(ide_drive_t *drive)
+3 -21
include/linux/ide.h
··· 919 919 typedef struct { 920 920 const char *name; 921 921 mode_t mode; 922 - read_proc_t *read_proc; 923 - write_proc_t *write_proc; 922 + const struct file_operations *proc_fops; 924 923 } ide_proc_entry_t; 925 924 926 925 void proc_ide_create(void); ··· 931 932 void ide_proc_register_driver(ide_drive_t *, struct ide_driver *); 932 933 void ide_proc_unregister_driver(ide_drive_t *, struct ide_driver *); 933 934 934 - read_proc_t proc_ide_read_capacity; 935 - read_proc_t proc_ide_read_geometry; 936 - 937 - /* 938 - * Standard exit stuff: 939 - */ 940 - #define PROC_IDE_READ_RETURN(page,start,off,count,eof,len) \ 941 - { \ 942 - len -= off; \ 943 - if (len < count) { \ 944 - *eof = 1; \ 945 - if (len <= 0) \ 946 - return 0; \ 947 - } else \ 948 - len = count; \ 949 - *start = page + off; \ 950 - return len; \ 951 - } 935 + extern const struct file_operations ide_capacity_proc_fops; 936 + extern const struct file_operations ide_geometry_proc_fops; 952 937 #else 953 938 static inline void proc_ide_create(void) { ; } 954 939 static inline void proc_ide_destroy(void) { ; } ··· 944 961 struct ide_driver *driver) { ; } 945 962 static inline void ide_proc_unregister_driver(ide_drive_t *drive, 946 963 struct ide_driver *driver) { ; } 947 - #define PROC_IDE_READ_RETURN(page,start,off,count,eof,len) return 0; 948 964 #endif 949 965 950 966 enum {