0001
0002 #include <linux/fs.h>
0003 #include <linux/init.h>
0004 #include <linux/proc_fs.h>
0005 #include <linux/seq_file.h>
0006 #include <linux/blkdev.h>
0007
0008 static int devinfo_show(struct seq_file *f, void *v)
0009 {
0010 int i = *(loff_t *) v;
0011
0012 if (i < CHRDEV_MAJOR_MAX) {
0013 if (i == 0)
0014 seq_puts(f, "Character devices:\n");
0015 chrdev_show(f, i);
0016 }
0017 #ifdef CONFIG_BLOCK
0018 else {
0019 i -= CHRDEV_MAJOR_MAX;
0020 if (i == 0)
0021 seq_puts(f, "\nBlock devices:\n");
0022 blkdev_show(f, i);
0023 }
0024 #endif
0025 return 0;
0026 }
0027
0028 static void *devinfo_start(struct seq_file *f, loff_t *pos)
0029 {
0030 if (*pos < (BLKDEV_MAJOR_MAX + CHRDEV_MAJOR_MAX))
0031 return pos;
0032 return NULL;
0033 }
0034
0035 static void *devinfo_next(struct seq_file *f, void *v, loff_t *pos)
0036 {
0037 (*pos)++;
0038 if (*pos >= (BLKDEV_MAJOR_MAX + CHRDEV_MAJOR_MAX))
0039 return NULL;
0040 return pos;
0041 }
0042
0043 static void devinfo_stop(struct seq_file *f, void *v)
0044 {
0045
0046 }
0047
0048 static const struct seq_operations devinfo_ops = {
0049 .start = devinfo_start,
0050 .next = devinfo_next,
0051 .stop = devinfo_stop,
0052 .show = devinfo_show
0053 };
0054
0055 static int __init proc_devices_init(void)
0056 {
0057 proc_create_seq("devices", 0, NULL, &devinfo_ops);
0058 return 0;
0059 }
0060 fs_initcall(proc_devices_init);