dfs_lwip.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. if (_dfs_fd->type != FT_SOCKET) return -1;
  34. return (int)_dfs_fd->data;
  35. }
  36. int dfs_lwip_ioctl(struct dfs_fd* file, int cmd, void* args)
  37. {
  38. return -DFS_STATUS_EIO;
  39. }
  40. int dfs_lwip_read(struct dfs_fd* file, void *buf, rt_size_t count)
  41. {
  42. int sock;
  43. sock = (int)file->data;
  44. count = lwip_read(sock, buf, count);
  45. return count;
  46. }
  47. int dfs_lwip_write(struct dfs_fd *file, const void *buf, rt_size_t count)
  48. {
  49. int sock;
  50. sock = (int)file->data;
  51. count = lwip_write(sock, buf, count);
  52. return count;
  53. }
  54. int dfs_lwip_close(struct dfs_fd* file)
  55. {
  56. int sock;
  57. int result;
  58. sock = (int)file->data;
  59. result = lwip_close(sock);
  60. if (result == 0) return DFS_STATUS_OK;
  61. return -result;
  62. }
  63. static const struct dfs_filesystem_operation _lwip_fs_ops =
  64. {
  65. "lwip",
  66. DFS_FS_FLAG_DEFAULT,
  67. RT_NULL, /* mount */
  68. RT_NULL, /* unmont */
  69. RT_NULL, /* mkfs */
  70. RT_NULL, /* statfs */
  71. RT_NULL, /* open */
  72. dfs_lwip_close,
  73. dfs_lwip_ioctl,
  74. dfs_lwip_read,
  75. dfs_lwip_write,
  76. RT_NULL,
  77. RT_NULL, /* lseek */
  78. RT_NULL, /* getdents */
  79. RT_NULL, /* unlink */
  80. RT_NULL, /* stat */
  81. RT_NULL, /* rename */
  82. };
  83. static struct dfs_filesystem _lwip_fs =
  84. {
  85. 0, /* dev_id */
  86. RT_NULL, /* path */
  87. &_lwip_fs_ops,
  88. RT_NULL /* data */
  89. };
  90. struct dfs_filesystem* dfs_lwip_get_fs(void)
  91. {
  92. return &_lwip_fs;
  93. }
  94. /*
  95. NOTE: Beause we don't need to mount lwIP file system, the filesystem_ops is not
  96. registered to the system.
  97. int dfs_lwip_system_init(void)
  98. {
  99. dfs_register(&_lwip_fs_ops);
  100. return 0;
  101. }
  102. INIT_FS_EXPORT(dfs_lwip_system_init);
  103. */