proc_mounts.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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_mnt.h>
  17. const char *mnt_flag(int flag)
  18. {
  19. /*if (flag & MNT_READONLY)
  20. {
  21. return "ro";
  22. }*/
  23. return "rw";
  24. }
  25. static struct dfs_mnt* mnt_show(struct dfs_mnt *mnt, void *parameter)
  26. {
  27. struct dfs_seq_file *seq = (struct dfs_seq_file *)parameter;
  28. if (mnt)
  29. {
  30. if (mnt->dev_id)
  31. {
  32. dfs_seq_printf(seq, "%s %s %s %s 0 0\n", mnt->dev_id->parent.name, mnt->fullpath,
  33. mnt->fs_ops->name, mnt_flag(mnt->flags));
  34. }
  35. else
  36. {
  37. dfs_seq_printf(seq, "%s %s %s %s 0 0\n", mnt->fs_ops->name, mnt->fullpath,
  38. mnt->fs_ops->name, mnt_flag(mnt->flags));
  39. }
  40. }
  41. return RT_NULL;
  42. }
  43. static void *seq_start(struct dfs_seq_file *seq, off_t *index)
  44. {
  45. off_t i = *index; // seq->index
  46. return NULL + (i == 0);
  47. }
  48. static void seq_stop(struct dfs_seq_file *seq, void *data)
  49. {
  50. }
  51. static void *seq_next(struct dfs_seq_file *seq, void *data, off_t *index)
  52. {
  53. /* data: The return value of the start or next*/
  54. off_t i = *index + 1; // seq->index
  55. *index = i;
  56. return NULL;
  57. }
  58. static int seq_show(struct dfs_seq_file *seq, void *data)
  59. {
  60. /* data: The return value of the start or next*/
  61. dfs_mnt_foreach(mnt_show, seq);
  62. return 0;
  63. }
  64. static const struct dfs_seq_ops seq_ops = {
  65. .start = seq_start,
  66. .stop = seq_stop,
  67. .next = seq_next,
  68. .show = seq_show,
  69. };
  70. int proc_mounts_init(void)
  71. {
  72. struct proc_dentry *dentry = proc_create_data("mounts", 0, NULL, NULL, NULL);
  73. if (dentry)
  74. {
  75. dentry->seq_ops = &seq_ops;
  76. }
  77. proc_release(dentry);
  78. return 0;
  79. }
  80. INIT_ENV_EXPORT(proc_mounts_init);