dfs_fs.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. * 2005-02-22 Bernard The first version.
  9. * 2023-05-05 Bernard Change to dfs v2.0
  10. */
  11. #ifndef __DFS_FS_H__
  12. #define __DFS_FS_H__
  13. #include <dfs.h>
  14. #include <dfs_file.h>
  15. #ifdef __cplusplus
  16. extern "C"
  17. {
  18. #endif
  19. /* file system partition table */
  20. struct dfs_partition
  21. {
  22. uint8_t type; /* file system type */
  23. off_t offset; /* partition start offset */
  24. size_t size; /* partition size */
  25. rt_sem_t lock;
  26. };
  27. struct dfs_attr
  28. {
  29. unsigned int ia_valid;
  30. mode_t st_mode;
  31. struct timespec ia_atime;
  32. struct timespec ia_mtime;
  33. };
  34. struct dfs_mnt;
  35. struct dfs_dentry;
  36. struct dfs_vnode;
  37. struct statfs;
  38. struct dfs_filesystem_ops
  39. {
  40. const char *name;
  41. uint32_t flags;
  42. #define FS_NEED_DEVICE 0x1
  43. const struct dfs_file_ops *default_fops;
  44. int (*mount)(struct dfs_mnt *mnt, unsigned long rwflag, const void *data);
  45. int (*umount)(struct dfs_mnt *mnt);
  46. int (*mkfs)(rt_device_t devid, const char *fs_name);
  47. int (*readlink)(struct dfs_dentry *dentry, char *buf, int len);
  48. int (*link)(struct dfs_dentry *src_dentry, struct dfs_dentry *dst_dentry); /*hard link interface */
  49. int (*unlink)(struct dfs_dentry *dentry);
  50. int (*symlink)(struct dfs_dentry *parent_dentry, const char *target, const char *newpath); /*soft link interface*/
  51. int (*rename)(struct dfs_dentry *old_dentry, struct dfs_dentry *new_dentry);
  52. int (*stat)(struct dfs_dentry *dentry, struct stat *buf);
  53. int (*statfs)(struct dfs_mnt *mnt, struct statfs *buf);
  54. int (*setattr) (struct dfs_dentry *dentry, struct dfs_attr *attr);
  55. struct dfs_vnode* (*lookup)(struct dfs_dentry *dentry);
  56. struct dfs_vnode* (*create_vnode)(struct dfs_dentry *dentry, int type, mode_t mode);
  57. int (*free_vnode)(struct dfs_vnode* vnode);
  58. };
  59. struct dfs_filesystem_type
  60. {
  61. const struct dfs_filesystem_ops *fs_ops;
  62. struct dfs_filesystem_type *next;
  63. };
  64. struct dfs_filesystem_type *dfs_filesystems(void);
  65. int dfs_unregister(struct dfs_filesystem_type *fs);
  66. int dfs_register(struct dfs_filesystem_type *fs);
  67. const char *dfs_filesystem_get_mounted_path(struct rt_device *device);
  68. int dfs_mount(const char *device_name,
  69. const char *path,
  70. const char *filesystemtype,
  71. unsigned long rwflag,
  72. const void *data);
  73. int dfs_umount(const char *specialfile, int flags);
  74. int dfs_unmount(const char *specialfile);
  75. int dfs_is_mounted(struct dfs_mnt *mnt);
  76. int dfs_mkfs(const char *fs_name, const char *device_name);
  77. int dfs_statfs(const char *path, struct statfs *buffer);
  78. int dfs_filesystem_get_partition(struct dfs_partition *part,
  79. uint8_t *buf,
  80. uint32_t pindex);
  81. #ifdef __cplusplus
  82. }
  83. #endif
  84. #endif