|
33 | 33 | #endif /* CONFIG_ISDN_CAPI_MIDDLEWARE */ |
34 | 34 | #include <linux/skbuff.h> |
35 | 35 | #include <linux/proc_fs.h> |
| 36 | +#include <linux/seq_file.h> |
36 | 37 | #include <linux/poll.h> |
37 | 38 | #include <linux/capi.h> |
38 | 39 | #include <linux/kernelcapi.h> |
@@ -1407,114 +1408,84 @@ static void capinc_tty_exit(void) |
1407 | 1408 | * /proc/capi/capi20: |
1408 | 1409 | * minor applid nrecvctlpkt nrecvdatapkt nsendctlpkt nsenddatapkt |
1409 | 1410 | */ |
1410 | | -static int proc_capidev_read_proc(char *page, char **start, off_t off, |
1411 | | - int count, int *eof, void *data) |
| 1411 | +static int capi20_proc_show(struct seq_file *m, void *v) |
1412 | 1412 | { |
1413 | 1413 | struct capidev *cdev; |
1414 | 1414 | struct list_head *l; |
1415 | | - int len = 0; |
1416 | 1415 |
|
1417 | 1416 | read_lock(&capidev_list_lock); |
1418 | 1417 | list_for_each(l, &capidev_list) { |
1419 | 1418 | cdev = list_entry(l, struct capidev, list); |
1420 | | - len += sprintf(page+len, "0 %d %lu %lu %lu %lu\n", |
| 1419 | + seq_printf(m, "0 %d %lu %lu %lu %lu\n", |
1421 | 1420 | cdev->ap.applid, |
1422 | 1421 | cdev->ap.nrecvctlpkt, |
1423 | 1422 | cdev->ap.nrecvdatapkt, |
1424 | 1423 | cdev->ap.nsentctlpkt, |
1425 | 1424 | cdev->ap.nsentdatapkt); |
1426 | | - if (len <= off) { |
1427 | | - off -= len; |
1428 | | - len = 0; |
1429 | | - } else { |
1430 | | - if (len-off > count) |
1431 | | - goto endloop; |
1432 | | - } |
1433 | 1425 | } |
1434 | | - |
1435 | | -endloop: |
1436 | 1426 | read_unlock(&capidev_list_lock); |
1437 | | - if (len < count) |
1438 | | - *eof = 1; |
1439 | | - if (len > count) len = count; |
1440 | | - if (len < 0) len = 0; |
1441 | | - return len; |
| 1427 | + return 0; |
1442 | 1428 | } |
1443 | 1429 |
|
| 1430 | +static int capi20_proc_open(struct inode *inode, struct file *file) |
| 1431 | +{ |
| 1432 | + return single_open(file, capi20_proc_show, NULL); |
| 1433 | +} |
| 1434 | + |
| 1435 | +static const struct file_operations capi20_proc_fops = { |
| 1436 | + .owner = THIS_MODULE, |
| 1437 | + .open = capi20_proc_open, |
| 1438 | + .read = seq_read, |
| 1439 | + .llseek = seq_lseek, |
| 1440 | + .release = single_release, |
| 1441 | +}; |
| 1442 | + |
1444 | 1443 | /* |
1445 | 1444 | * /proc/capi/capi20ncci: |
1446 | 1445 | * applid ncci |
1447 | 1446 | */ |
1448 | | -static int proc_capincci_read_proc(char *page, char **start, off_t off, |
1449 | | - int count, int *eof, void *data) |
| 1447 | +static int capi20ncci_proc_show(struct seq_file *m, void *v) |
1450 | 1448 | { |
1451 | 1449 | struct capidev *cdev; |
1452 | 1450 | struct capincci *np; |
1453 | 1451 | struct list_head *l; |
1454 | | - int len = 0; |
1455 | 1452 |
|
1456 | 1453 | read_lock(&capidev_list_lock); |
1457 | 1454 | list_for_each(l, &capidev_list) { |
1458 | 1455 | cdev = list_entry(l, struct capidev, list); |
1459 | 1456 | for (np=cdev->nccis; np; np = np->next) { |
1460 | | - len += sprintf(page+len, "%d 0x%x\n", |
| 1457 | + seq_printf(m, "%d 0x%x\n", |
1461 | 1458 | cdev->ap.applid, |
1462 | 1459 | np->ncci); |
1463 | | - if (len <= off) { |
1464 | | - off -= len; |
1465 | | - len = 0; |
1466 | | - } else { |
1467 | | - if (len-off > count) |
1468 | | - goto endloop; |
1469 | | - } |
1470 | 1460 | } |
1471 | 1461 | } |
1472 | | -endloop: |
1473 | 1462 | read_unlock(&capidev_list_lock); |
1474 | | - *start = page+off; |
1475 | | - if (len < count) |
1476 | | - *eof = 1; |
1477 | | - if (len>count) len = count; |
1478 | | - if (len<0) len = 0; |
1479 | | - return len; |
| 1463 | + return 0; |
1480 | 1464 | } |
1481 | 1465 |
|
1482 | | -static struct procfsentries { |
1483 | | - char *name; |
1484 | | - mode_t mode; |
1485 | | - int (*read_proc)(char *page, char **start, off_t off, |
1486 | | - int count, int *eof, void *data); |
1487 | | - struct proc_dir_entry *procent; |
1488 | | -} procfsentries[] = { |
1489 | | - /* { "capi", S_IFDIR, 0 }, */ |
1490 | | - { "capi/capi20", 0 , proc_capidev_read_proc }, |
1491 | | - { "capi/capi20ncci", 0 , proc_capincci_read_proc }, |
| 1466 | +static int capi20ncci_proc_open(struct inode *inode, struct file *file) |
| 1467 | +{ |
| 1468 | + return single_open(file, capi20ncci_proc_show, NULL); |
| 1469 | +} |
| 1470 | + |
| 1471 | +static const struct file_operations capi20ncci_proc_fops = { |
| 1472 | + .owner = THIS_MODULE, |
| 1473 | + .open = capi20ncci_proc_open, |
| 1474 | + .read = seq_read, |
| 1475 | + .llseek = seq_lseek, |
| 1476 | + .release = single_release, |
1492 | 1477 | }; |
1493 | 1478 |
|
1494 | 1479 | static void __init proc_init(void) |
1495 | 1480 | { |
1496 | | - int nelem = ARRAY_SIZE(procfsentries); |
1497 | | - int i; |
1498 | | - |
1499 | | - for (i=0; i < nelem; i++) { |
1500 | | - struct procfsentries *p = procfsentries + i; |
1501 | | - p->procent = create_proc_entry(p->name, p->mode, NULL); |
1502 | | - if (p->procent) p->procent->read_proc = p->read_proc; |
1503 | | - } |
| 1481 | + proc_create("capi/capi20", 0, NULL, &capi20_proc_fops); |
| 1482 | + proc_create("capi/capi20ncci", 0, NULL, &capi20ncci_proc_fops); |
1504 | 1483 | } |
1505 | 1484 |
|
1506 | 1485 | static void __exit proc_exit(void) |
1507 | 1486 | { |
1508 | | - int nelem = ARRAY_SIZE(procfsentries); |
1509 | | - int i; |
1510 | | - |
1511 | | - for (i=nelem-1; i >= 0; i--) { |
1512 | | - struct procfsentries *p = procfsentries + i; |
1513 | | - if (p->procent) { |
1514 | | - remove_proc_entry(p->name, NULL); |
1515 | | - p->procent = NULL; |
1516 | | - } |
1517 | | - } |
| 1487 | + remove_proc_entry("capi/capi20", NULL); |
| 1488 | + remove_proc_entry("capi/capi20ncci", NULL); |
1518 | 1489 | } |
1519 | 1490 |
|
1520 | 1491 | /* -------- init function and module interface ---------------------- */ |
|
0 commit comments