aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide/ide-proc.c
diff options
context:
space:
mode:
authorAlexey Dobriyan <adobriyan@gmail.com>2009-09-01 20:52:57 -0400
committerDavid S. Miller <davem@davemloft.net>2009-09-01 20:52:57 -0400
commit6d703a81ad5fdd102334751ddacb053ecc6ff046 (patch)
tree1bebde3a0c34677296dc4784e800445ea02b4f0a /drivers/ide/ide-proc.c
parent76fbebfbb593bd66780db0a808afe1d21c7ff6d6 (diff)
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>
Diffstat (limited to 'drivers/ide/ide-proc.c')
-rw-r--r--drivers/ide/ide-proc.c330
1 files changed, 215 insertions, 115 deletions
diff --git a/drivers/ide/ide-proc.c b/drivers/ide/ide-proc.c
index 021de41655e6..28d09a5d8450 100644
--- a/drivers/ide/ide-proc.c
+++ b/drivers/ide/ide-proc.c
@@ -30,11 +30,9 @@
30 30
31static struct proc_dir_entry *proc_ide_root; 31static struct proc_dir_entry *proc_ide_root;
32 32
33static int proc_ide_read_imodel 33static int ide_imodel_proc_show(struct seq_file *m, void *v)
34 (char *page, char **start, off_t off, int count, int *eof, void *data)
35{ 34{
36 ide_hwif_t *hwif = (ide_hwif_t *) data; 35 ide_hwif_t *hwif = (ide_hwif_t *) m->private;
37 int len;
38 const char *name; 36 const char *name;
39 37
40 switch (hwif->chipset) { 38 switch (hwif->chipset) {
@@ -53,63 +51,108 @@ static int proc_ide_read_imodel
53 case ide_acorn: name = "acorn"; break; 51 case ide_acorn: name = "acorn"; break;
54 default: name = "(unknown)"; break; 52 default: name = "(unknown)"; break;
55 } 53 }
56 len = sprintf(page, "%s\n", name); 54 seq_printf(m, "%s\n", name);
57 PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 55 return 0;
58} 56}
59 57
60static int proc_ide_read_mate 58static int ide_imodel_proc_open(struct inode *inode, struct file *file)
61 (char *page, char **start, off_t off, int count, int *eof, void *data)
62{ 59{
63 ide_hwif_t *hwif = (ide_hwif_t *) data; 60 return single_open(file, ide_imodel_proc_show, PDE(inode)->data);
64 int len; 61}
62
63static const struct file_operations ide_imodel_proc_fops = {
64 .owner = THIS_MODULE,
65 .open = ide_imodel_proc_open,
66 .read = seq_read,
67 .llseek = seq_lseek,
68 .release = single_release,
69};
70
71static int ide_mate_proc_show(struct seq_file *m, void *v)
72{
73 ide_hwif_t *hwif = (ide_hwif_t *) m->private;
65 74
66 if (hwif && hwif->mate) 75 if (hwif && hwif->mate)
67 len = sprintf(page, "%s\n", hwif->mate->name); 76 seq_printf(m, "%s\n", hwif->mate->name);
68 else 77 else
69 len = sprintf(page, "(none)\n"); 78 seq_printf(m, "(none)\n");
70 PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 79 return 0;
80}
81
82static int ide_mate_proc_open(struct inode *inode, struct file *file)
83{
84 return single_open(file, ide_mate_proc_show, PDE(inode)->data);
71} 85}
72 86
73static int proc_ide_read_channel 87static const struct file_operations ide_mate_proc_fops = {
74 (char *page, char **start, off_t off, int count, int *eof, void *data) 88 .owner = THIS_MODULE,
89 .open = ide_mate_proc_open,
90 .read = seq_read,
91 .llseek = seq_lseek,
92 .release = single_release,
93};
94
95static int ide_channel_proc_show(struct seq_file *m, void *v)
75{ 96{
76 ide_hwif_t *hwif = (ide_hwif_t *) data; 97 ide_hwif_t *hwif = (ide_hwif_t *) m->private;
77 int len;
78 98
79 page[0] = hwif->channel ? '1' : '0'; 99 seq_printf(m, "%c\n", hwif->channel ? '1' : '0');
80 page[1] = '\n'; 100 return 0;
81 len = 2;
82 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
83} 101}
84 102
85static int proc_ide_read_identify 103static int ide_channel_proc_open(struct inode *inode, struct file *file)
86 (char *page, char **start, off_t off, int count, int *eof, void *data)
87{ 104{
88 ide_drive_t *drive = (ide_drive_t *)data; 105 return single_open(file, ide_channel_proc_show, PDE(inode)->data);
89 int len = 0, i = 0; 106}
90 int err = 0;
91 107
92 len = sprintf(page, "\n"); 108static const struct file_operations ide_channel_proc_fops = {
109 .owner = THIS_MODULE,
110 .open = ide_channel_proc_open,
111 .read = seq_read,
112 .llseek = seq_lseek,
113 .release = single_release,
114};
93 115
94 if (drive) { 116static int ide_identify_proc_show(struct seq_file *m, void *v)
95 __le16 *val = (__le16 *)page; 117{
118 ide_drive_t *drive = (ide_drive_t *)m->private;
119 u8 *buf;
96 120
97 err = taskfile_lib_get_identify(drive, page); 121 if (!drive) {
98 if (!err) { 122 seq_putc(m, '\n');
99 char *out = (char *)page + SECTOR_SIZE; 123 return 0;
124 }
100 125
101 page = out; 126 buf = kmalloc(SECTOR_SIZE, GFP_KERNEL);
102 do { 127 if (!buf)
103 out += sprintf(out, "%04x%c", 128 return -ENOMEM;
104 le16_to_cpup(val), (++i & 7) ? ' ' : '\n'); 129 if (taskfile_lib_get_identify(drive, buf) == 0) {
105 val += 1; 130 __le16 *val = (__le16 *)buf;
106 } while (i < SECTOR_SIZE / 2); 131 int i;
107 len = out - page; 132
133 for (i = 0; i < SECTOR_SIZE / 2; i++) {
134 seq_printf(m, "%04x%c", le16_to_cpu(val[i]),
135 (i % 8) == 7 ? '\n' : ' ');
108 } 136 }
109 } 137 } else
110 PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 138 seq_putc(m, buf[0]);
139 kfree(buf);
140 return 0;
141}
142
143static int ide_identify_proc_open(struct inode *inode, struct file *file)
144{
145 return single_open(file, ide_identify_proc_show, PDE(inode)->data);
111} 146}
112 147
148static const struct file_operations ide_identify_proc_fops = {
149 .owner = THIS_MODULE,
150 .open = ide_identify_proc_open,
151 .read = seq_read,
152 .llseek = seq_lseek,
153 .release = single_release,
154};
155
113/** 156/**
114 * ide_find_setting - find a specific setting 157 * ide_find_setting - find a specific setting
115 * @st: setting table pointer 158 * @st: setting table pointer
@@ -240,22 +283,20 @@ static void proc_ide_settings_warn(void)
240 warned = 1; 283 warned = 1;
241} 284}
242 285
243static int proc_ide_read_settings 286static int ide_settings_proc_show(struct seq_file *m, void *v)
244 (char *page, char **start, off_t off, int count, int *eof, void *data)
245{ 287{
246 const struct ide_proc_devset *setting, *g, *d; 288 const struct ide_proc_devset *setting, *g, *d;
247 const struct ide_devset *ds; 289 const struct ide_devset *ds;
248 ide_drive_t *drive = (ide_drive_t *) data; 290 ide_drive_t *drive = (ide_drive_t *) m->private;
249 char *out = page; 291 int rc, mul_factor, div_factor;
250 int len, rc, mul_factor, div_factor;
251 292
252 proc_ide_settings_warn(); 293 proc_ide_settings_warn();
253 294
254 mutex_lock(&ide_setting_mtx); 295 mutex_lock(&ide_setting_mtx);
255 g = ide_generic_settings; 296 g = ide_generic_settings;
256 d = drive->settings; 297 d = drive->settings;
257 out += sprintf(out, "name\t\t\tvalue\t\tmin\t\tmax\t\tmode\n"); 298 seq_printf(m, "name\t\t\tvalue\t\tmin\t\tmax\t\tmode\n");
258 out += sprintf(out, "----\t\t\t-----\t\t---\t\t---\t\t----\n"); 299 seq_printf(m, "----\t\t\t-----\t\t---\t\t---\t\t----\n");
259 while (g->name || (d && d->name)) { 300 while (g->name || (d && d->name)) {
260 /* read settings in the alphabetical order */ 301 /* read settings in the alphabetical order */
261 if (g->name && d && d->name) { 302 if (g->name && d && d->name) {
@@ -269,31 +310,35 @@ static int proc_ide_read_settings
269 setting = g++; 310 setting = g++;
270 mul_factor = setting->mulf ? setting->mulf(drive) : 1; 311 mul_factor = setting->mulf ? setting->mulf(drive) : 1;
271 div_factor = setting->divf ? setting->divf(drive) : 1; 312 div_factor = setting->divf ? setting->divf(drive) : 1;
272 out += sprintf(out, "%-24s", setting->name); 313 seq_printf(m, "%-24s", setting->name);
273 rc = ide_read_setting(drive, setting); 314 rc = ide_read_setting(drive, setting);
274 if (rc >= 0) 315 if (rc >= 0)
275 out += sprintf(out, "%-16d", rc * mul_factor / div_factor); 316 seq_printf(m, "%-16d", rc * mul_factor / div_factor);
276 else 317 else
277 out += sprintf(out, "%-16s", "write-only"); 318 seq_printf(m, "%-16s", "write-only");
278 out += sprintf(out, "%-16d%-16d", (setting->min * mul_factor + div_factor - 1) / div_factor, setting->max * mul_factor / div_factor); 319 seq_printf(m, "%-16d%-16d", (setting->min * mul_factor + div_factor - 1) / div_factor, setting->max * mul_factor / div_factor);
279 ds = setting->setting; 320 ds = setting->setting;
280 if (ds->get) 321 if (ds->get)
281 out += sprintf(out, "r"); 322 seq_printf(m, "r");
282 if (ds->set) 323 if (ds->set)
283 out += sprintf(out, "w"); 324 seq_printf(m, "w");
284 out += sprintf(out, "\n"); 325 seq_printf(m, "\n");
285 } 326 }
286 len = out - page;
287 mutex_unlock(&ide_setting_mtx); 327 mutex_unlock(&ide_setting_mtx);
288 PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 328 return 0;
329}
330
331static int ide_settings_proc_open(struct inode *inode, struct file *file)
332{
333 return single_open(file, ide_settings_proc_show, PDE(inode)->data);
289} 334}
290 335
291#define MAX_LEN 30 336#define MAX_LEN 30
292 337
293static int proc_ide_write_settings(struct file *file, const char __user *buffer, 338static ssize_t ide_settings_proc_write(struct file *file, const char __user *buffer,
294 unsigned long count, void *data) 339 size_t count, loff_t *pos)
295{ 340{
296 ide_drive_t *drive = (ide_drive_t *) data; 341 ide_drive_t *drive = (ide_drive_t *) PDE(file->f_path.dentry->d_inode)->data;
297 char name[MAX_LEN + 1]; 342 char name[MAX_LEN + 1];
298 int for_real = 0, mul_factor, div_factor; 343 int for_real = 0, mul_factor, div_factor;
299 unsigned long n; 344 unsigned long n;
@@ -388,63 +433,104 @@ static int proc_ide_write_settings(struct file *file, const char __user *buffer,
388 return count; 433 return count;
389parse_error: 434parse_error:
390 free_page((unsigned long)buf); 435 free_page((unsigned long)buf);
391 printk("proc_ide_write_settings(): parse error\n"); 436 printk("%s(): parse error\n", __func__);
392 return -EINVAL; 437 return -EINVAL;
393} 438}
394 439
395int proc_ide_read_capacity 440static const struct file_operations ide_settings_proc_fops = {
396 (char *page, char **start, off_t off, int count, int *eof, void *data) 441 .owner = THIS_MODULE,
442 .open = ide_settings_proc_open,
443 .read = seq_read,
444 .llseek = seq_lseek,
445 .release = single_release,
446 .write = ide_settings_proc_write,
447};
448
449static int ide_capacity_proc_show(struct seq_file *m, void *v)
397{ 450{
398 int len = sprintf(page, "%llu\n", (long long)0x7fffffff); 451 seq_printf(m, "%llu\n", (long long)0x7fffffff);
399 PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 452 return 0;
400} 453}
401 454
402EXPORT_SYMBOL_GPL(proc_ide_read_capacity); 455static int ide_capacity_proc_open(struct inode *inode, struct file *file)
456{
457 return single_open(file, ide_capacity_proc_show, NULL);
458}
403 459
404int proc_ide_read_geometry 460const struct file_operations ide_capacity_proc_fops = {
405 (char *page, char **start, off_t off, int count, int *eof, void *data) 461 .owner = THIS_MODULE,
462 .open = ide_capacity_proc_open,
463 .read = seq_read,
464 .llseek = seq_lseek,
465 .release = single_release,
466};
467EXPORT_SYMBOL_GPL(ide_capacity_proc_fops);
468
469static int ide_geometry_proc_show(struct seq_file *m, void *v)
406{ 470{
407 ide_drive_t *drive = (ide_drive_t *) data; 471 ide_drive_t *drive = (ide_drive_t *) m->private;
408 char *out = page;
409 int len;
410 472
411 out += sprintf(out, "physical %d/%d/%d\n", 473 seq_printf(m, "physical %d/%d/%d\n",
412 drive->cyl, drive->head, drive->sect); 474 drive->cyl, drive->head, drive->sect);
413 out += sprintf(out, "logical %d/%d/%d\n", 475 seq_printf(m, "logical %d/%d/%d\n",
414 drive->bios_cyl, drive->bios_head, drive->bios_sect); 476 drive->bios_cyl, drive->bios_head, drive->bios_sect);
477 return 0;
478}
415 479
416 len = out - page; 480static int ide_geometry_proc_open(struct inode *inode, struct file *file)
417 PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 481{
482 return single_open(file, ide_geometry_proc_show, PDE(inode)->data);
418} 483}
419 484
420EXPORT_SYMBOL(proc_ide_read_geometry); 485const struct file_operations ide_geometry_proc_fops = {
486 .owner = THIS_MODULE,
487 .open = ide_geometry_proc_open,
488 .read = seq_read,
489 .llseek = seq_lseek,
490 .release = single_release,
491};
492EXPORT_SYMBOL(ide_geometry_proc_fops);
421 493
422static int proc_ide_read_dmodel 494static int ide_dmodel_proc_show(struct seq_file *seq, void *v)
423 (char *page, char **start, off_t off, int count, int *eof, void *data)
424{ 495{
425 ide_drive_t *drive = (ide_drive_t *) data; 496 ide_drive_t *drive = (ide_drive_t *) seq->private;
426 char *m = (char *)&drive->id[ATA_ID_PROD]; 497 char *m = (char *)&drive->id[ATA_ID_PROD];
427 int len;
428 498
429 len = sprintf(page, "%.40s\n", m[0] ? m : "(none)"); 499 seq_printf(seq, "%.40s\n", m[0] ? m : "(none)");
430 PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 500 return 0;
501}
502
503static int ide_dmodel_proc_open(struct inode *inode, struct file *file)
504{
505 return single_open(file, ide_dmodel_proc_show, PDE(inode)->data);
431} 506}
432 507
433static int proc_ide_read_driver 508static const struct file_operations ide_dmodel_proc_fops = {
434 (char *page, char **start, off_t off, int count, int *eof, void *data) 509 .owner = THIS_MODULE,
510 .open = ide_dmodel_proc_open,
511 .read = seq_read,
512 .llseek = seq_lseek,
513 .release = single_release,
514};
515
516static int ide_driver_proc_show(struct seq_file *m, void *v)
435{ 517{
436 ide_drive_t *drive = (ide_drive_t *)data; 518 ide_drive_t *drive = (ide_drive_t *)m->private;
437 struct device *dev = &drive->gendev; 519 struct device *dev = &drive->gendev;
438 struct ide_driver *ide_drv; 520 struct ide_driver *ide_drv;
439 int len;
440 521
441 if (dev->driver) { 522 if (dev->driver) {
442 ide_drv = to_ide_driver(dev->driver); 523 ide_drv = to_ide_driver(dev->driver);
443 len = sprintf(page, "%s version %s\n", 524 seq_printf(m, "%s version %s\n",
444 dev->driver->name, ide_drv->version); 525 dev->driver->name, ide_drv->version);
445 } else 526 } else
446 len = sprintf(page, "ide-default version 0.9.newide\n"); 527 seq_printf(m, "ide-default version 0.9.newide\n");
447 PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 528 return 0;
529}
530
531static int ide_driver_proc_open(struct inode *inode, struct file *file)
532{
533 return single_open(file, ide_driver_proc_show, PDE(inode)->data);
448} 534}
449 535
450static int ide_replace_subdriver(ide_drive_t *drive, const char *driver) 536static int ide_replace_subdriver(ide_drive_t *drive, const char *driver)
@@ -474,10 +560,10 @@ static int ide_replace_subdriver(ide_drive_t *drive, const char *driver)
474 return ret; 560 return ret;
475} 561}
476 562
477static int proc_ide_write_driver 563static ssize_t ide_driver_proc_write(struct file *file, const char __user *buffer,
478 (struct file *file, const char __user *buffer, unsigned long count, void *data) 564 size_t count, loff_t *pos)
479{ 565{
480 ide_drive_t *drive = (ide_drive_t *) data; 566 ide_drive_t *drive = (ide_drive_t *) PDE(file->f_path.dentry->d_inode)->data;
481 char name[32]; 567 char name[32];
482 568
483 if (!capable(CAP_SYS_ADMIN)) 569 if (!capable(CAP_SYS_ADMIN))
@@ -492,12 +578,19 @@ static int proc_ide_write_driver
492 return count; 578 return count;
493} 579}
494 580
495static int proc_ide_read_media 581static const struct file_operations ide_driver_proc_fops = {
496 (char *page, char **start, off_t off, int count, int *eof, void *data) 582 .owner = THIS_MODULE,
583 .open = ide_driver_proc_open,
584 .read = seq_read,
585 .llseek = seq_lseek,
586 .release = single_release,
587 .write = ide_driver_proc_write,
588};
589
590static int ide_media_proc_show(struct seq_file *m, void *v)
497{ 591{
498 ide_drive_t *drive = (ide_drive_t *) data; 592 ide_drive_t *drive = (ide_drive_t *) m->private;
499 const char *media; 593 const char *media;
500 int len;
501 594
502 switch (drive->media) { 595 switch (drive->media) {
503 case ide_disk: media = "disk\n"; break; 596 case ide_disk: media = "disk\n"; break;
@@ -507,20 +600,30 @@ static int proc_ide_read_media
507 case ide_optical: media = "optical\n"; break; 600 case ide_optical: media = "optical\n"; break;
508 default: media = "UNKNOWN\n"; break; 601 default: media = "UNKNOWN\n"; break;
509 } 602 }
510 strcpy(page, media); 603 seq_puts(m, media);
511 len = strlen(media); 604 return 0;
512 PROC_IDE_READ_RETURN(page, start, off, count, eof, len); 605}
606
607static int ide_media_proc_open(struct inode *inode, struct file *file)
608{
609 return single_open(file, ide_media_proc_show, PDE(inode)->data);
513} 610}
514 611
612static const struct file_operations ide_media_proc_fops = {
613 .owner = THIS_MODULE,
614 .open = ide_media_proc_open,
615 .read = seq_read,
616 .llseek = seq_lseek,
617 .release = single_release,
618};
619
515static ide_proc_entry_t generic_drive_entries[] = { 620static ide_proc_entry_t generic_drive_entries[] = {
516 { "driver", S_IFREG|S_IRUGO, proc_ide_read_driver, 621 { "driver", S_IFREG|S_IRUGO, &ide_driver_proc_fops },
517 proc_ide_write_driver }, 622 { "identify", S_IFREG|S_IRUSR, &ide_identify_proc_fops},
518 { "identify", S_IFREG|S_IRUSR, proc_ide_read_identify, NULL }, 623 { "media", S_IFREG|S_IRUGO, &ide_media_proc_fops },
519 { "media", S_IFREG|S_IRUGO, proc_ide_read_media, NULL }, 624 { "model", S_IFREG|S_IRUGO, &ide_dmodel_proc_fops },
520 { "model", S_IFREG|S_IRUGO, proc_ide_read_dmodel, NULL }, 625 { "settings", S_IFREG|S_IRUSR|S_IWUSR, &ide_settings_proc_fops},
521 { "settings", S_IFREG|S_IRUSR|S_IWUSR, proc_ide_read_settings, 626 {}
522 proc_ide_write_settings },
523 { NULL, 0, NULL, NULL }
524}; 627};
525 628
526static void ide_add_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p, void *data) 629static void ide_add_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p, void *data)
@@ -530,11 +633,8 @@ static void ide_add_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p
530 if (!dir || !p) 633 if (!dir || !p)
531 return; 634 return;
532 while (p->name != NULL) { 635 while (p->name != NULL) {
533 ent = create_proc_entry(p->name, p->mode, dir); 636 ent = proc_create_data(p->name, p->mode, dir, p->proc_fops, data);
534 if (!ent) return; 637 if (!ent) return;
535 ent->data = data;
536 ent->read_proc = p->read_proc;
537 ent->write_proc = p->write_proc;
538 p++; 638 p++;
539 } 639 }
540} 640}
@@ -617,10 +717,10 @@ void ide_proc_unregister_device(ide_drive_t *drive)
617} 717}
618 718
619static ide_proc_entry_t hwif_entries[] = { 719static ide_proc_entry_t hwif_entries[] = {
620 { "channel", S_IFREG|S_IRUGO, proc_ide_read_channel, NULL }, 720 { "channel", S_IFREG|S_IRUGO, &ide_channel_proc_fops },
621 { "mate", S_IFREG|S_IRUGO, proc_ide_read_mate, NULL }, 721 { "mate", S_IFREG|S_IRUGO, &ide_mate_proc_fops },
622 { "model", S_IFREG|S_IRUGO, proc_ide_read_imodel, NULL }, 722 { "model", S_IFREG|S_IRUGO, &ide_imodel_proc_fops },
623 { NULL, 0, NULL, NULL } 723 {}
624}; 724};
625 725
626void ide_proc_register_port(ide_hwif_t *hwif) 726void ide_proc_register_port(ide_hwif_t *hwif)