1
0

dfs.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 ATTR_ATIME_SET
  26. #define ATTR_ATIME_SET (1 << 7)
  27. #endif
  28. #ifndef ATTR_MTIME_SET
  29. #define ATTR_MTIME_SET (1 << 8)
  30. #endif
  31. #ifndef AT_SYMLINK_NOFOLLOW
  32. #define AT_SYMLINK_NOFOLLOW 0x100
  33. #endif
  34. #ifndef UTIME_NOW
  35. #define UTIME_NOW 0x3fffffff
  36. #endif
  37. #ifndef UTIME_OMIT
  38. #define UTIME_OMIT 0x3ffffffe
  39. #endif
  40. #ifndef DFS_FD_MAX
  41. #define DFS_FD_MAX 16
  42. #endif
  43. /*
  44. * skip stdin/stdout/stderr normally
  45. */
  46. #ifndef DFS_STDIO_OFFSET
  47. #define DFS_STDIO_OFFSET 3
  48. #endif
  49. #ifndef DFS_PATH_MAX
  50. #define DFS_PATH_MAX 4096
  51. #endif
  52. #ifndef SECTOR_SIZE
  53. #define SECTOR_SIZE 512
  54. #endif
  55. #define DFS_FS_FLAG_DEFAULT 0x00 /* default flag */
  56. #define DFS_FS_FLAG_FULLPATH 0x01 /* set full path to underlaying file system */
  57. /* File flags */
  58. #define DFS_F_FREAD 0x01
  59. #define DFS_F_FWRITE 0x02
  60. #ifdef __cplusplus
  61. extern "C" {
  62. #endif
  63. rt_inline int dfs_fflags(int oflags)
  64. {
  65. int rw = oflags & O_ACCMODE;
  66. oflags &= ~O_ACCMODE;
  67. return (rw + 1) | oflags;
  68. }
  69. rt_inline int dfs_oflags(int fflags)
  70. {
  71. int rw = fflags & (DFS_F_FREAD | DFS_F_FWRITE);
  72. fflags &= ~(DFS_F_FREAD | DFS_F_FWRITE);
  73. return (rw - 1) | fflags;
  74. }
  75. struct dfs_fdtable
  76. {
  77. uint32_t maxfd;
  78. struct dfs_file **fds;
  79. };
  80. /* Initialization of dfs */
  81. int dfs_init(void);
  82. char *dfs_normalize_path(const char *directory, const char *filename);
  83. const char *dfs_subdir(const char *directory, const char *filename);
  84. rt_err_t dfs_lock(void);
  85. void dfs_unlock(void);
  86. rt_err_t dfs_file_lock(void);
  87. void dfs_file_unlock(void);
  88. int dfs_fdtable_dup(struct dfs_fdtable *fdt_dst, struct dfs_fdtable *fdt_src, int fd_src);
  89. int dfs_fdtable_drop_fd(struct dfs_fdtable *fdtab, int fd);
  90. #ifdef DFS_USING_POSIX
  91. /* FD APIs */
  92. int fdt_fd_new(struct dfs_fdtable *fdt);
  93. struct dfs_file *fdt_get_file(struct dfs_fdtable* fdt, int fd);
  94. void fdt_fd_release(struct dfs_fdtable* fdt, int fd);
  95. int fd_new(void);
  96. int fdt_fd_associate_file(struct dfs_fdtable *fdt, int fd, struct dfs_file *file);
  97. struct dfs_file *fd_get(int fd);
  98. void fd_release(int fd);
  99. void fd_init(struct dfs_file *fd);
  100. struct dfs_fdtable *dfs_fdtable_get(void);
  101. struct dfs_fdtable *dfs_fdtable_get_global(void);
  102. int dfs_dup(int oldfd, int startfd);
  103. #endif /* DFS_USING_POSIX */
  104. #ifdef __cplusplus
  105. }
  106. #endif
  107. #endif