dfs.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 <time.h>
  31. #include <rtthread.h>
  32. #include <rtdevice.h>
  33. #ifndef DFS_FILESYSTEMS_MAX
  34. #define DFS_FILESYSTEMS_MAX 2
  35. #endif
  36. #ifndef DFS_FD_MAX
  37. #define DFS_FD_MAX 4
  38. #endif
  39. /*
  40. * skip stdin/stdout/stderr normally
  41. */
  42. #ifndef DFS_FD_OFFSET
  43. #define DFS_FD_OFFSET 3
  44. #endif
  45. #ifndef DFS_PATH_MAX
  46. #define DFS_PATH_MAX 256
  47. #endif
  48. #ifndef SECTOR_SIZE
  49. #define SECTOR_SIZE 512
  50. #endif
  51. #ifndef DFS_FILESYSTEM_TYPES_MAX
  52. #define DFS_FILESYSTEM_TYPES_MAX 2
  53. #endif
  54. #define DFS_FS_FLAG_DEFAULT 0x00 /* default flag */
  55. #define DFS_FS_FLAG_FULLPATH 0x01 /* set full path to underlaying file system */
  56. /* File types */
  57. #define FT_REGULAR 0 /* regular file */
  58. #define FT_SOCKET 1 /* socket file */
  59. #define FT_DIRECTORY 2 /* directory */
  60. #define FT_USER 3 /* user defined */
  61. /* File flags */
  62. #define DFS_F_OPEN 0x01000000
  63. #define DFS_F_DIRECTORY 0x02000000
  64. #define DFS_F_EOF 0x04000000
  65. #define DFS_F_ERR 0x08000000
  66. #ifdef __cplusplus
  67. extern "C" {
  68. #endif
  69. struct statfs
  70. {
  71. size_t f_bsize; /* block size */
  72. size_t f_blocks; /* total data blocks in file system */
  73. size_t f_bfree; /* free blocks in file system */
  74. };
  75. struct dirent
  76. {
  77. uint8_t d_type; /* The type of the file */
  78. uint8_t d_namlen; /* The length of the not including the terminating null file name */
  79. uint16_t d_reclen; /* length of this record */
  80. char d_name[DFS_PATH_MAX]; /* The null-terminated file name */
  81. };
  82. /* Initialization of dfs */
  83. int dfs_init(void);
  84. char *dfs_normalize_path(const char *directory, const char *filename);
  85. const char *dfs_subdir(const char *directory, const char *filename);
  86. void dfs_lock(void);
  87. void dfs_unlock(void);
  88. /* FD APIs */
  89. int fd_new(void);
  90. struct dfs_fd *fd_get(int fd);
  91. void fd_put(struct dfs_fd *fd);
  92. int fd_is_open(const char *pathname);
  93. #ifdef __cplusplus
  94. }
  95. #endif
  96. #endif