dfs.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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_H__
  11. #define __DFS_H__
  12. #include <stdio.h>
  13. #include <stdint.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <dirent.h>
  17. #include <fcntl.h>
  18. #include <sys/stat.h>
  19. #include <sys/time.h>
  20. #include <rtdevice.h>
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. #ifndef DFS_FILESYSTEMS_MAX
  25. #define DFS_FILESYSTEMS_MAX 4
  26. #endif
  27. #ifndef DFS_FD_MAX
  28. #define DFS_FD_MAX 16
  29. #endif
  30. /*
  31. * skip stdin/stdout/stderr normally
  32. */
  33. #ifndef DFS_FD_OFFSET
  34. #define DFS_FD_OFFSET 3
  35. #endif
  36. #ifndef DFS_PATH_MAX
  37. #define DFS_PATH_MAX DIRENT_NAME_MAX
  38. #endif
  39. #ifndef SECTOR_SIZE
  40. #define SECTOR_SIZE 512
  41. #endif
  42. #ifndef DFS_FILESYSTEM_TYPES_MAX
  43. #define DFS_FILESYSTEM_TYPES_MAX 2
  44. #endif
  45. #define DFS_FS_FLAG_DEFAULT 0x00 /* default flag */
  46. #define DFS_FS_FLAG_FULLPATH 0x01 /* set full path to underlaying file system */
  47. /* File types */
  48. #define FT_REGULAR 0 /* regular file */
  49. #define FT_SOCKET 1 /* socket file */
  50. #define FT_DIRECTORY 2 /* directory */
  51. #define FT_USER 3 /* user defined */
  52. #define FT_DEVICE 4 /* device */
  53. /* File flags */
  54. #define DFS_F_OPEN 0x01000000
  55. #define DFS_F_DIRECTORY 0x02000000
  56. #define DFS_F_EOF 0x04000000
  57. #define DFS_F_ERR 0x08000000
  58. struct statfs
  59. {
  60. size_t f_bsize; /* block size */
  61. size_t f_blocks; /* total data blocks in file system */
  62. size_t f_bfree; /* free blocks in file system */
  63. };
  64. struct dfs_fdtable
  65. {
  66. uint32_t maxfd;
  67. struct dfs_fd **fds;
  68. };
  69. /* Initialization of dfs */
  70. int dfs_init(void);
  71. char *dfs_normalize_path(const char *directory, const char *filename);
  72. const char *dfs_subdir(const char *directory, const char *filename);
  73. void dfs_lock(void);
  74. void dfs_unlock(void);
  75. /* FD APIs */
  76. int fd_new(void);
  77. struct dfs_fd *fd_get(int fd);
  78. void fd_put(struct dfs_fd *fd);
  79. int fd_is_open(const char *pathname);
  80. struct dfs_fdtable *dfs_fdtable_get(void);
  81. #ifdef __cplusplus
  82. }
  83. #endif
  84. #endif