blob: 837971e741097832d4033c24dc77749ae9bf82ce [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Alexey Dobriyanfe251042008-10-04 23:11:37 +04002#include <linux/fs.h>
3#include <linux/init.h>
4#include <linux/proc_fs.h>
5#include <linux/seq_file.h>
Christoph Hellwig3f1266f2020-06-20 09:16:41 +02006#include <linux/blkdev.h>
Alexey Dobriyanfe251042008-10-04 23:11:37 +04007
8static int devinfo_show(struct seq_file *f, void *v)
9{
10 int i = *(loff_t *) v;
11
Logan Gunthorpe8a932f72017-06-15 14:05:21 -060012 if (i < CHRDEV_MAJOR_MAX) {
Alexey Dobriyanfe251042008-10-04 23:11:37 +040013 if (i == 0)
Alexey Dobriyan9d6de122011-01-12 17:00:32 -080014 seq_puts(f, "Character devices:\n");
Alexey Dobriyanfe251042008-10-04 23:11:37 +040015 chrdev_show(f, i);
16 }
17#ifdef CONFIG_BLOCK
18 else {
Logan Gunthorpe8a932f72017-06-15 14:05:21 -060019 i -= CHRDEV_MAJOR_MAX;
Alexey Dobriyanfe251042008-10-04 23:11:37 +040020 if (i == 0)
Alexey Dobriyan9d6de122011-01-12 17:00:32 -080021 seq_puts(f, "\nBlock devices:\n");
Alexey Dobriyanfe251042008-10-04 23:11:37 +040022 blkdev_show(f, i);
23 }
24#endif
25 return 0;
26}
27
28static void *devinfo_start(struct seq_file *f, loff_t *pos)
29{
Logan Gunthorpe133d55c2017-06-16 17:48:21 -060030 if (*pos < (BLKDEV_MAJOR_MAX + CHRDEV_MAJOR_MAX))
Alexey Dobriyanfe251042008-10-04 23:11:37 +040031 return pos;
32 return NULL;
33}
34
35static void *devinfo_next(struct seq_file *f, void *v, loff_t *pos)
36{
37 (*pos)++;
Logan Gunthorpe133d55c2017-06-16 17:48:21 -060038 if (*pos >= (BLKDEV_MAJOR_MAX + CHRDEV_MAJOR_MAX))
Alexey Dobriyanfe251042008-10-04 23:11:37 +040039 return NULL;
40 return pos;
41}
42
43static void devinfo_stop(struct seq_file *f, void *v)
44{
45 /* Nothing to do */
46}
47
48static const struct seq_operations devinfo_ops = {
49 .start = devinfo_start,
50 .next = devinfo_next,
51 .stop = devinfo_stop,
52 .show = devinfo_show
53};
54
Alexey Dobriyanfe251042008-10-04 23:11:37 +040055static int __init proc_devices_init(void)
56{
Christoph Hellwigfddda2b2018-04-13 19:44:18 +020057 proc_create_seq("devices", 0, NULL, &devinfo_ops);
Alexey Dobriyanfe251042008-10-04 23:11:37 +040058 return 0;
59}
Paul Gortmakerabaf3782014-01-23 15:55:45 -080060fs_initcall(proc_devices_init);