• R/O
  • SSH
  • HTTPS

chibios: Commit


Commit MetaInfo

Revision15131 (tree)
Time2021-11-23 23:53:10
Authorgdisirio

Log Message

(empty log message)

Change Summary

Incremental Difference

--- trunk/os/vfs/drivers/streams/drvstreams.c (revision 15130)
+++ trunk/os/vfs/drivers/streams/drvstreams.c (revision 15131)
@@ -121,11 +121,29 @@
121121 const char *path,
122122 vfs_file_node_t **vfnpp);
123123
124-static const struct vfs_streams_driver_vmt vmt = {
124+static const struct vfs_streams_driver_vmt driver_vmt = {
125125 .open_dir = drv_open_dir,
126126 .open_file = drv_open_file
127127 };
128128
129+static void node_release(void *instance);
130+static BaseSequentialStream *node_get_stream(void *instance);
131+static ssize_t node_file_read(void *instance, uint8_t *buf, size_t n);
132+static ssize_t node_file_write(void *instance, const uint8_t *buf, size_t n);
133+static msg_t node_file_setpos(void *instance, vfs_offset_t offset);
134+static vfs_offset_t node_file_getpos(void *instance);
135+static vfs_offset_t node_file_getsize(void *instance);
136+
137+static const struct vfs_stream_file_node_vmt node_vmt = {
138+ .release = node_release,
139+ .get_stream = node_get_stream,
140+ .file_read = node_file_read,
141+ .file_write = node_file_write,
142+ .file_setpos = node_file_setpos,
143+ .file_getpos = node_file_getpos,
144+ .file_getsize = node_file_getsize
145+};
146+
129147 static vfs_stream_file_node_t drv_file_nodes[DRV_NODES_NUM];
130148 static vfs_streams_driver_t drv_streams;
131149
@@ -172,7 +190,7 @@
172190 if (sfnp != NULL) {
173191
174192 /* Node object initialization.*/
175- sfnp->vmt = 0;
193+ sfnp->vmt = &node_vmt;
176194 sfnp->refs = 1U;
177195 sfnp->driver = (vfs_driver_t *)drvp;
178196 sfnp->stream = dsep->stream;
@@ -194,6 +212,67 @@
194212 return err;
195213 }
196214
215+static void node_release(void *instance) {
216+ vfs_stream_file_node_t *sfnp = (vfs_stream_file_node_t *)instance;
217+
218+ osalDbgAssert(sfnp->refs > 0U, "zero count");
219+
220+ if (--sfnp->refs == 0U) {
221+
222+ chPoolFree(&((vfs_streams_driver_t *)sfnp->driver)->nodes_pool,
223+ (void *)sfnp);
224+ }
225+}
226+
227+static BaseSequentialStream *node_get_stream(void *instance) {
228+ vfs_stream_file_node_t *sfnp = (vfs_stream_file_node_t *)instance;
229+
230+ osalDbgAssert(sfnp->refs > 0U, "zero count");
231+
232+ return sfnp->stream;
233+}
234+
235+static ssize_t node_file_read(void *instance, uint8_t *buf, size_t n) {
236+ vfs_stream_file_node_t *sfnp = (vfs_stream_file_node_t *)instance;
237+
238+ osalDbgAssert(sfnp->refs > 0U, "zero count");
239+
240+ return streamRead(sfnp->stream, buf, n);
241+}
242+
243+static ssize_t node_file_write(void *instance, const uint8_t *buf, size_t n) {
244+ vfs_stream_file_node_t *sfnp = (vfs_stream_file_node_t *)instance;
245+
246+ osalDbgAssert(sfnp->refs > 0U, "zero count");
247+
248+ return streamWrite(sfnp->stream, buf, n);
249+}
250+
251+static msg_t node_file_setpos(void *instance, vfs_offset_t offset) {
252+ vfs_stream_file_node_t *sfnp = (vfs_stream_file_node_t *)instance;
253+
254+ osalDbgAssert(sfnp->refs > 0U, "zero count");
255+
256+ (void)offset;
257+
258+ return VFS_RET_NOT_IMPLEMENTED;
259+}
260+
261+static vfs_offset_t node_file_getpos(void *instance) {
262+ vfs_stream_file_node_t *sfnp = (vfs_stream_file_node_t *)instance;
263+
264+ osalDbgAssert(sfnp->refs > 0U, "zero count");
265+
266+ return 0U;
267+}
268+
269+static vfs_offset_t node_file_getsize(void *instance) {
270+
271+ (void)instance;
272+
273+ return 0U;
274+}
275+
197276 /*===========================================================================*/
198277 /* Module exported functions. */
199278 /*===========================================================================*/
@@ -201,7 +280,7 @@
201280 vfs_driver_t *drvStreamsInit(const char *rootname,
202281 const drv_stream_element_t *streams) {
203282
204- drv_streams.vmt = &vmt;
283+ drv_streams.vmt = &driver_vmt;
205284 drv_streams.rootname = rootname;
206285 drv_streams.streams = streams;
207286 chPoolObjectInit(&drv_streams.nodes_pool,
--- trunk/os/vfs/include/vfserrors.h (revision 15130)
+++ trunk/os/vfs/include/vfserrors.h (revision 15131)
@@ -39,10 +39,11 @@
3939 #define VFS_RET_SUCCESS 0
4040 #define VFS_RET_TIMEOUT -1
4141 #define VFS_RET_EOF -2
42-#define VFS_RET_NO_RESOURCE -3
43-#define VFS_RET_NO_DRIVER -4
44-#define VFS_RET_INVALID_PATH -5
45-#define VFS_RET_NOT_FOUND -6
42+#define VFS_RET_NOT_IMPLEMENTED -3
43+#define VFS_RET_NO_RESOURCE -4
44+#define VFS_RET_NO_DRIVER -5
45+#define VFS_RET_INVALID_PATH -6
46+#define VFS_RET_NOT_FOUND -7
4647 /** @} */
4748
4849 /*===========================================================================*/
--- trunk/os/vfs/include/vfsnodes.h (revision 15130)
+++ trunk/os/vfs/include/vfsnodes.h (revision 15131)
@@ -175,7 +175,7 @@
175175 */
176176 #define __vfs_file_node_methods \
177177 __vfs_node_methods \
178- BaseSequentialStream (*get_stream)(void *instance); \
178+ BaseSequentialStream *(*get_stream)(void *instance); \
179179 ssize_t (*file_read)(void *instance, uint8_t *buf, size_t n); \
180180 ssize_t (*file_write)(void *instance, const uint8_t *buf, size_t n); \
181181 msg_t (*file_setpos)(void *instance, vfs_offset_t offset); \
Show on old repository browser