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