devices.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/fs.h>
  3. #include <linux/init.h>
  4. #include <linux/proc_fs.h>
  5. #include <linux/seq_file.h>
  6. #include <linux/blkdev.h>
  7. #include "internal.h"
  8. static int devinfo_show(struct seq_file *f, void *v)
  9. {
  10. int i = *(loff_t *) v;
  11. if (i < CHRDEV_MAJOR_MAX) {
  12. if (i == 0)
  13. seq_puts(f, "Character devices:\n");
  14. chrdev_show(f, i);
  15. }
  16. #ifdef CONFIG_BLOCK
  17. else {
  18. i -= CHRDEV_MAJOR_MAX;
  19. if (i == 0)
  20. seq_puts(f, "\nBlock devices:\n");
  21. blkdev_show(f, i);
  22. }
  23. #endif
  24. return 0;
  25. }
  26. static void *devinfo_start(struct seq_file *f, loff_t *pos)
  27. {
  28. if (*pos < (BLKDEV_MAJOR_MAX + CHRDEV_MAJOR_MAX))
  29. return pos;
  30. return NULL;
  31. }
  32. static void *devinfo_next(struct seq_file *f, void *v, loff_t *pos)
  33. {
  34. (*pos)++;
  35. if (*pos >= (BLKDEV_MAJOR_MAX + CHRDEV_MAJOR_MAX))
  36. return NULL;
  37. return pos;
  38. }
  39. static void devinfo_stop(struct seq_file *f, void *v)
  40. {
  41. /* Nothing to do */
  42. }
  43. static const struct seq_operations devinfo_ops = {
  44. .start = devinfo_start,
  45. .next = devinfo_next,
  46. .stop = devinfo_stop,
  47. .show = devinfo_show
  48. };
  49. static int __init proc_devices_init(void)
  50. {
  51. struct proc_dir_entry *pde;
  52. pde = proc_create_seq("devices", 0, NULL, &devinfo_ops);
  53. pde_make_permanent(pde);
  54. return 0;
  55. }
  56. fs_initcall(proc_devices_init);