dfs.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * File : dfs.h
  3. * This file is part of Device File System in RT-Thread RTOS
  4. * COPYRIGHT (C) 2004-2012, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2005-02-22 Bernard The first version.
  23. */
  24. #ifndef __DFS_H__
  25. #define __DFS_H__
  26. #include <stdio.h>
  27. #include <stdint.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30. #include <sys/types.h>
  31. #include <time.h>
  32. #include <rtthread.h>
  33. #include <rtdevice.h>
  34. #ifndef DFS_FILESYSTEMS_MAX
  35. #define DFS_FILESYSTEMS_MAX 2
  36. #endif
  37. #ifndef DFS_FD_MAX
  38. #define DFS_FD_MAX 4
  39. #endif
  40. /*
  41. * skip stdin/stdout/stderr normally
  42. */
  43. #ifndef DFS_FD_OFFSET
  44. #define DFS_FD_OFFSET 3
  45. #endif
  46. #ifndef DFS_PATH_MAX
  47. #define DFS_PATH_MAX 256
  48. #endif
  49. #ifndef SECTOR_SIZE
  50. #define SECTOR_SIZE 512
  51. #endif
  52. #ifndef DFS_FILESYSTEM_TYPES_MAX
  53. #define DFS_FILESYSTEM_TYPES_MAX 2
  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 types */
  58. #define FT_REGULAR 0 /* regular file */
  59. #define FT_SOCKET 1 /* socket file */
  60. #define FT_DIRECTORY 2 /* directory */
  61. #define FT_USER 3 /* user defined */
  62. /* File flags */
  63. #define DFS_F_OPEN 0x01000000
  64. #define DFS_F_DIRECTORY 0x02000000
  65. #define DFS_F_EOF 0x04000000
  66. #define DFS_F_ERR 0x08000000
  67. #ifdef __cplusplus
  68. extern "C" {
  69. #endif
  70. struct stat
  71. {
  72. struct rt_device* st_dev;
  73. uint16_t st_mode;
  74. uint32_t st_size;
  75. time_t st_mtime;
  76. uint32_t st_blksize;
  77. };
  78. struct statfs
  79. {
  80. size_t f_bsize; /* block size */
  81. size_t f_blocks; /* total data blocks in file system */
  82. size_t f_bfree; /* free blocks in file system */
  83. };
  84. struct dirent
  85. {
  86. uint8_t d_type; /* The type of the file */
  87. uint8_t d_namlen; /* The length of the not including the terminating null file name */
  88. uint16_t d_reclen; /* length of this record */
  89. char d_name[DFS_PATH_MAX]; /* The null-terminated file name */
  90. };
  91. /* Initialization of dfs */
  92. int dfs_init(void);
  93. char *dfs_normalize_path(const char *directory, const char *filename);
  94. const char *dfs_subdir(const char *directory, const char *filename);
  95. void dfs_lock(void);
  96. void dfs_unlock(void);
  97. /* FD APIs */
  98. int fd_new(void);
  99. struct dfs_fd *fd_get(int fd);
  100. void fd_put(struct dfs_fd *fd);
  101. int fd_is_open(const char *pathname);
  102. #ifdef __cplusplus
  103. }
  104. #endif
  105. #endif