dfs_lwip.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * File : dfs_lwip.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2015, 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. * 2015-02-17 Bernard First version
  23. */
  24. #include <rtthread.h>
  25. #include <dfs.h>
  26. #include <dfs_fs.h>
  27. #include "dfs_lwip.h"
  28. int dfs_lwip_getsocket(int fd)
  29. {
  30. struct dfs_fd *_dfs_fd;
  31. _dfs_fd = fd_get(fd);
  32. if (_dfs_fd == RT_NULL) return -1;
  33. return 0;
  34. }
  35. int dfs_lwip_ioctl(struct dfs_fd* file, int cmd, void* args)
  36. {
  37. return -DFS_STATUS_EIO;
  38. }
  39. int dfs_lwip_read(struct dfs_fd* file, void *buf, rt_size_t count)
  40. {
  41. int sock;
  42. sock = (int)file->data;
  43. count = lwip_read(sock, buf, count);
  44. return count;
  45. }
  46. int dfs_lwip_write(struct dfs_fd *file, const void *buf, rt_size_t count)
  47. {
  48. int sock;
  49. sock = (int)file->data;
  50. count = lwip_write(sock, buf, count);
  51. return count;
  52. }
  53. int dfs_lwip_close(struct dfs_fd* file)
  54. {
  55. int sock;
  56. int result;
  57. sock = (int)file->data;
  58. result = lwip_close(sock);
  59. if (result == 0) return DFS_STATUS_OK;
  60. return -result;
  61. }
  62. static const struct dfs_filesystem_operation _lwip_fs_ops =
  63. {
  64. "lwip",
  65. DFS_FS_FLAG_DEFAULT,
  66. RT_NULL, /* mount */
  67. RT_NULL, /* unmont */
  68. RT_NULL, /* mkfs */
  69. RT_NULL, /* statfs */
  70. RT_NULL, /* open */
  71. dfs_lwip_close,
  72. dfs_lwip_ioctl,
  73. dfs_lwip_read,
  74. dfs_lwip_write,
  75. RT_NULL,
  76. RT_NULL, /* lseek */
  77. RT_NULL, /* getdents */
  78. RT_NULL, /* unlink */
  79. RT_NULL, /* stat */
  80. RT_NULL, /* rename */
  81. };
  82. static struct dfs_filesystem _lwip_fs =
  83. {
  84. 0, /* dev_id */
  85. RT_NULL, /* path */
  86. &_lwip_fs_ops,
  87. RT_NULL /* data */
  88. };
  89. struct dfs_filesystem* dfs_lwip_get_fs(void)
  90. {
  91. return &_lwip_fs;
  92. }
  93. /*
  94. NOTE: Beause we don't need to mount lwIP file system, the filesystem_ops is not
  95. registered to the system.
  96. int dfs_lwip_system_init(void)
  97. {
  98. dfs_register(&_lwip_fs_ops);
  99. return 0;
  100. }
  101. INIT_FS_EXPORT(dfs_lwip_system_init);
  102. */