dfs_net.c 2.9 KB

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