dfs_fs.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright (c) 2006-2021, 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. */
  10. #ifndef __DFS_FS_H__
  11. #define __DFS_FS_H__
  12. #include <dfs.h>
  13. #ifdef RT_USING_LIBC
  14. #include <sys/types.h>
  15. #endif
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. /* Pre-declaration */
  20. struct dfs_filesystem;
  21. struct dfs_fd;
  22. /* File system operations */
  23. struct dfs_filesystem_ops
  24. {
  25. char *name;
  26. uint32_t flags; /* flags for file system operations */
  27. /* operations for file */
  28. const struct dfs_file_ops *fops;
  29. /* mount and unmount file system */
  30. int (*mount) (struct dfs_filesystem *fs, unsigned long rwflag, const void *data);
  31. int (*unmount) (struct dfs_filesystem *fs);
  32. /* make a file system */
  33. int (*mkfs) (rt_device_t devid);
  34. int (*statfs) (struct dfs_filesystem *fs, struct statfs *buf);
  35. int (*unlink) (struct dfs_filesystem *fs, const char *pathname);
  36. int (*stat) (struct dfs_filesystem *fs, const char *filename, struct stat *buf);
  37. int (*rename) (struct dfs_filesystem *fs, const char *oldpath, const char *newpath);
  38. };
  39. /* Mounted file system */
  40. struct dfs_filesystem
  41. {
  42. rt_device_t dev_id; /* Attached device */
  43. char *path; /* File system mount point */
  44. const struct dfs_filesystem_ops *ops; /* Operations for file system type */
  45. void *data; /* Specific file system data */
  46. };
  47. /* file system partition table */
  48. struct dfs_partition
  49. {
  50. uint8_t type; /* file system type */
  51. off_t offset; /* partition start offset */
  52. size_t size; /* partition size */
  53. rt_sem_t lock;
  54. };
  55. /* mount table */
  56. struct dfs_mount_tbl
  57. {
  58. const char *device_name;
  59. const char *path;
  60. const char *filesystemtype;
  61. unsigned long rwflag;
  62. const void *data;
  63. };
  64. int dfs_register(const struct dfs_filesystem_ops *ops);
  65. struct dfs_filesystem *dfs_filesystem_lookup(const char *path);
  66. const char *dfs_filesystem_get_mounted_path(struct rt_device *device);
  67. int dfs_filesystem_get_partition(struct dfs_partition *part,
  68. uint8_t *buf,
  69. uint32_t pindex);
  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_unmount(const char *specialfile);
  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_mount_device(rt_device_t dev);
  79. int dfs_unmount_device(rt_device_t dev);
  80. #ifdef __cplusplus
  81. }
  82. #endif
  83. #endif