dfs.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*****************************************************************************
  2. * Copyright (c) 2019, Nations Technologies Inc.
  3. *
  4. * All rights reserved.
  5. * ****************************************************************************
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. *
  10. * - Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the disclaimer below.
  12. *
  13. * Nations' name may not be used to endorse or promote products derived from
  14. * this software without specific prior written permission.
  15. *
  16. * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
  17. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  19. * DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  22. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  25. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. * ****************************************************************************/
  27. /**
  28. * @file dfs.h
  29. * @author Nations
  30. * @version v1.0.0
  31. *
  32. * @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
  33. */
  34. #ifndef __DFS_H__
  35. #define __DFS_H__
  36. #include <stdio.h>
  37. #include <stdint.h>
  38. #include <stdlib.h>
  39. #include <string.h>
  40. #include <time.h>
  41. #include <rtthread.h>
  42. #include <rtdevice.h>
  43. #ifndef DFS_FILESYSTEMS_MAX
  44. #define DFS_FILESYSTEMS_MAX 2
  45. #endif
  46. #ifndef DFS_FD_MAX
  47. #define DFS_FD_MAX 4
  48. #endif
  49. /*
  50. * skip stdin/stdout/stderr normally
  51. */
  52. #ifndef DFS_FD_OFFSET
  53. #define DFS_FD_OFFSET 3
  54. #endif
  55. #ifndef DFS_PATH_MAX
  56. #define DFS_PATH_MAX 256
  57. #endif
  58. #ifndef SECTOR_SIZE
  59. #define SECTOR_SIZE 512
  60. #endif
  61. #ifndef DFS_FILESYSTEM_TYPES_MAX
  62. #define DFS_FILESYSTEM_TYPES_MAX 2
  63. #endif
  64. #define DFS_FS_FLAG_DEFAULT 0x00 /* default flag */
  65. #define DFS_FS_FLAG_FULLPATH 0x01 /* set full path to underlaying file system */
  66. /* File types */
  67. #define FT_REGULAR 0 /* regular file */
  68. #define FT_SOCKET 1 /* socket file */
  69. #define FT_DIRECTORY 2 /* directory */
  70. #define FT_USER 3 /* user defined */
  71. /* File flags */
  72. #define DFS_F_OPEN 0x01000000
  73. #define DFS_F_DIRECTORY 0x02000000
  74. #define DFS_F_EOF 0x04000000
  75. #define DFS_F_ERR 0x08000000
  76. #ifdef __cplusplus
  77. extern "C" {
  78. #endif
  79. struct statfs
  80. {
  81. size_t f_bsize; /* block size */
  82. size_t f_blocks; /* total data blocks in file system */
  83. size_t f_bfree; /* free blocks in file system */
  84. };
  85. struct dirent
  86. {
  87. uint8_t d_type; /* The type of the file */
  88. uint8_t d_namlen; /* The length of the not including the terminating null file name */
  89. uint16_t d_reclen; /* length of this record */
  90. char d_name[DFS_PATH_MAX]; /* The null-terminated file name */
  91. };
  92. struct dfs_fdtable
  93. {
  94. uint32_t maxfd;
  95. struct dfs_fd **fds;
  96. };
  97. /* Initialization of dfs */
  98. int dfs_init(void);
  99. char *dfs_normalize_path(const char *directory, const char *filename);
  100. const char *dfs_subdir(const char *directory, const char *filename);
  101. void dfs_lock(void);
  102. void dfs_unlock(void);
  103. /* FD APIs */
  104. int fd_new(void);
  105. struct dfs_fd *fd_get(int fd);
  106. void fd_put(struct dfs_fd *fd);
  107. int fd_is_open(const char *pathname);
  108. struct dfs_fdtable *dfs_fdtable_get(void);
  109. #ifdef __cplusplus
  110. }
  111. #endif
  112. #endif