dfs_fs.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. uid_t st_uid;
  31. gid_t st_gid;
  32. mode_t st_mode;
  33. struct timespec ia_atime;
  34. struct timespec ia_mtime;
  35. };
  36. struct dfs_mnt;
  37. struct dfs_dentry;
  38. struct dfs_vnode;
  39. struct statfs;
  40. struct dfs_filesystem_ops
  41. {
  42. const char *name;
  43. uint32_t flags;
  44. #define FS_NEED_DEVICE 0x1
  45. const struct dfs_file_ops *default_fops;
  46. int (*mount)(struct dfs_mnt *mnt, unsigned long rwflag, const void *data);
  47. int (*umount)(struct dfs_mnt *mnt);
  48. int (*mkfs)(rt_device_t devid, const char *fs_name);
  49. int (*readlink)(struct dfs_dentry *dentry, char *buf, int len);
  50. int (*link)(struct dfs_dentry *src_dentry, struct dfs_dentry *dst_dentry); /*hard link interface */
  51. int (*unlink)(struct dfs_dentry *dentry);
  52. int (*symlink)(struct dfs_dentry *parent_dentry, const char *target, const char *newpath); /*soft link interface*/
  53. int (*rename)(struct dfs_dentry *old_dentry, struct dfs_dentry *new_dentry);
  54. int (*stat)(struct dfs_dentry *dentry, struct stat *buf);
  55. int (*statfs)(struct dfs_mnt *mnt, struct statfs *buf);
  56. int (*setattr) (struct dfs_dentry *dentry, struct dfs_attr *attr);
  57. struct dfs_vnode* (*lookup)(struct dfs_dentry *dentry);
  58. struct dfs_vnode* (*create_vnode)(struct dfs_dentry *dentry, int type, mode_t mode);
  59. int (*free_vnode)(struct dfs_vnode* vnode);
  60. };
  61. struct dfs_filesystem_type
  62. {
  63. const struct dfs_filesystem_ops *fs_ops;
  64. struct dfs_filesystem_type *next;
  65. };
  66. struct dfs_filesystem_type *dfs_filesystems(void);
  67. int dfs_unregister(struct dfs_filesystem_type *fs);
  68. int dfs_register(struct dfs_filesystem_type *fs);
  69. const char *dfs_filesystem_get_mounted_path(struct rt_device *device);
  70. int dfs_mount(const char *device_name,
  71. const char *path,
  72. const char *filesystemtype,
  73. unsigned long rwflag,
  74. const void *data);
  75. int dfs_umount(const char *specialfile, int flags);
  76. int dfs_unmount(const char *specialfile);
  77. int dfs_is_mounted(struct dfs_mnt *mnt);
  78. int dfs_mkfs(const char *fs_name, const char *device_name);
  79. int dfs_statfs(const char *path, struct statfs *buffer);
  80. int dfs_filesystem_get_partition(struct dfs_partition *part,
  81. uint8_t *buf,
  82. uint32_t pindex);
  83. #ifdef __cplusplus
  84. }
  85. #endif
  86. #endif