proc_filesystems.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. */
  9. #include "proc.h"
  10. #include "procfs.h"
  11. #include <rthw.h>
  12. #include <rtdbg.h>
  13. #include <fcntl.h>
  14. #include <errno.h>
  15. #include <dfs_dentry.h>
  16. #include <dfs_fs.h>
  17. static void *seq_start(struct dfs_seq_file *seq, off_t *index)
  18. {
  19. off_t i = *index; // seq->index
  20. struct dfs_filesystem_type *fs = dfs_filesystems();
  21. if (fs)
  22. {
  23. while (i--)
  24. {
  25. fs = fs->next;
  26. if (!fs)
  27. {
  28. break;
  29. }
  30. }
  31. }
  32. return fs;
  33. }
  34. static void seq_stop(struct dfs_seq_file *seq, void *data)
  35. {
  36. }
  37. static void *seq_next(struct dfs_seq_file *seq, void *data, off_t *index)
  38. {
  39. /* data: The return value of the start or next*/
  40. off_t i = *index + 1; // seq->index
  41. struct dfs_filesystem_type *fs = (struct dfs_filesystem_type *)data;
  42. *index = i;
  43. return fs->next;
  44. }
  45. static int seq_show(struct dfs_seq_file *seq, void *data)
  46. {
  47. /* data: The return value of the start or next*/
  48. struct dfs_filesystem_type *fs = (struct dfs_filesystem_type *)data;
  49. dfs_seq_printf(seq, "%-9s%s\n", (fs->fs_ops->flags == FS_NEED_DEVICE) ? "" : "nodev", fs->fs_ops->name);
  50. return 0;
  51. }
  52. static const struct dfs_seq_ops seq_ops = {
  53. .start = seq_start,
  54. .stop = seq_stop,
  55. .next = seq_next,
  56. .show = seq_show,
  57. };
  58. int proc_filesystems_init(void)
  59. {
  60. struct proc_dentry *dentry = proc_create_data("filesystems", 0, NULL, NULL, NULL);
  61. if (dentry)
  62. {
  63. dentry->seq_ops = &seq_ops;
  64. }
  65. proc_release(dentry);
  66. return 0;
  67. }
  68. INIT_ENV_EXPORT(proc_filesystems_init);