dfs_mnt.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. * 2023-05-05 Bernard Implement dentry in dfs v2.0
  9. */
  10. #ifndef DFS_MNT_H__
  11. #define DFS_MNT_H__
  12. #include <rtservice.h>
  13. #include <rtthread.h>
  14. #ifdef __cplusplus
  15. extern "C"
  16. {
  17. #endif
  18. struct dfs_mnt;
  19. struct dfs_dentry;
  20. struct dfs_filesystem_ops;
  21. struct dfs_mnt
  22. {
  23. struct dfs_mnt *parent; /* the parent mounted file system */
  24. rt_list_t sibling; /* the sibling node for mounted list */
  25. rt_list_t child; /* the child node for mounted list */
  26. char *fullpath; /* the fullpath of this mounted file system */
  27. int flags; /* the falgs of this mounted file system */
  28. #define MNT_IS_ALLOCED 0x1 /* the mnt struct is allocated */
  29. #define MNT_IS_ADDLIST 0x2 /* the mnt struct is added into list */
  30. #define MNT_IS_MOUNTED 0x4 /* the mnt struct is mounted */
  31. #define MNT_IS_UMOUNT 0x8 /* the mnt is unmount */
  32. #define MNT_IS_LOCKED 0x10 /* the mnt is locked */
  33. #define MNT_FORCE 0x20 /* the mnt force unmount */
  34. #define MNT_LAZY_UMNT 0x40 /* the mnt has pending umount */
  35. #define MNT_RDONLY 0x80 /* the mnt is read only */
  36. rt_atomic_t ref_count; /* reference count */
  37. rt_device_t dev_id; /* the mounted device id */
  38. const struct dfs_filesystem_ops *fs_ops;
  39. void *data;
  40. };
  41. struct dfs_mnt *dfs_mnt_create(const char *path);
  42. int dfs_mnt_destroy(struct dfs_mnt* mnt);
  43. int dfs_mnt_list(struct dfs_mnt* mnt);
  44. int dfs_mnt_insert(struct dfs_mnt* mnt, struct dfs_mnt* child);
  45. struct dfs_mnt *dfs_mnt_dev_lookup(rt_device_t dev_id);
  46. struct dfs_mnt *dfs_mnt_lookup(const char *path);
  47. const char *dfs_mnt_get_mounted_path(struct rt_device *device);
  48. struct dfs_mnt* dfs_mnt_ref(struct dfs_mnt* mnt);
  49. int dfs_mnt_unref(struct dfs_mnt* mnt);
  50. int dfs_mnt_umount(struct dfs_mnt *mnt, int flags);
  51. int dfs_mnt_setflags(struct dfs_mnt *mnt, int flags);
  52. rt_bool_t dfs_mnt_has_child_mnt(struct dfs_mnt *mnt, const char* fullpath);
  53. int dfs_mnt_foreach(struct dfs_mnt* (*func)(struct dfs_mnt *mnt, void *parameter), void *parameter);
  54. int dfs_mnt_umount_iter(rt_bool_t (*filter)(struct dfs_mnt *mnt, void *parameter), void *parameter);
  55. typedef void (*dfs_mnt_umnt_cb_t)(struct dfs_mnt *mnt);
  56. RT_OBJECT_HOOKLIST_DECLARE(dfs_mnt_umnt_cb_t, dfs_mnt_umnt);
  57. #ifdef __cplusplus
  58. }
  59. #endif
  60. #endif