dfs.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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_H__
  12. #define __DFS_H__
  13. #include <stdio.h>
  14. #include <stdint.h>
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include "../../libc/compilers/common/include/dirent.h"
  18. #include <fcntl.h>
  19. #include <sys/stat.h>
  20. #include <sys/statfs.h>
  21. #include <sys/time.h>
  22. #include <sys/errno.h>
  23. #include <rtatomic.h>
  24. #include <rtdevice.h>
  25. #ifndef DFS_FD_MAX
  26. #define DFS_FD_MAX 16
  27. #endif
  28. /*
  29. * skip stdin/stdout/stderr normally
  30. */
  31. #ifndef DFS_STDIO_OFFSET
  32. #define DFS_STDIO_OFFSET 3
  33. #endif
  34. #ifndef DFS_PATH_MAX
  35. #define DFS_PATH_MAX DIRENT_NAME_MAX
  36. #endif
  37. #ifndef SECTOR_SIZE
  38. #define SECTOR_SIZE 512
  39. #endif
  40. #define DFS_FS_FLAG_DEFAULT 0x00 /* default flag */
  41. #define DFS_FS_FLAG_FULLPATH 0x01 /* set full path to underlaying file system */
  42. /* File flags */
  43. #define DFS_F_FREAD 0x01
  44. #define DFS_F_FWRITE 0x02
  45. #ifdef __cplusplus
  46. extern "C" {
  47. #endif
  48. rt_inline int dfs_fflags(int oflags)
  49. {
  50. int rw = oflags & O_ACCMODE;
  51. oflags &= ~O_ACCMODE;
  52. return (rw + 1) | oflags;
  53. }
  54. rt_inline int dfs_oflags(int fflags)
  55. {
  56. int rw = fflags & (DFS_F_FREAD | DFS_F_FWRITE);
  57. fflags &= ~(DFS_F_FREAD | DFS_F_FWRITE);
  58. return (rw - 1) | fflags;
  59. }
  60. struct dfs_fdtable
  61. {
  62. uint32_t maxfd;
  63. struct dfs_file **fds;
  64. };
  65. /* Initialization of dfs */
  66. int dfs_init(void);
  67. char *dfs_normalize_path(const char *directory, const char *filename);
  68. const char *dfs_subdir(const char *directory, const char *filename);
  69. rt_err_t dfs_lock(void);
  70. void dfs_unlock(void);
  71. rt_err_t dfs_file_lock(void);
  72. void dfs_file_unlock(void);
  73. #ifdef DFS_USING_POSIX
  74. /* FD APIs */
  75. int fdt_fd_new(struct dfs_fdtable *fdt);
  76. struct dfs_file *fdt_fd_get(struct dfs_fdtable* fdt, int fd);
  77. void fdt_fd_release(struct dfs_fdtable* fdt, int fd);
  78. int fd_new(void);
  79. int fd_associate(struct dfs_fdtable *fdt, int fd, struct dfs_file *file);
  80. struct dfs_file *fd_get(int fd);
  81. int fd_get_fd_index(struct dfs_file *file);
  82. void fd_release(int fd);
  83. void fd_init(struct dfs_file *fd);
  84. struct dfs_fdtable *dfs_fdtable_get(void);
  85. struct dfs_fdtable *dfs_fdtable_get_global(void);
  86. int dfs_dup(int oldfd, int startfd);
  87. #endif /* DFS_USING_POSIX */
  88. #ifdef __cplusplus
  89. }
  90. #endif
  91. #endif