• R/O
  • SSH
  • HTTPS

chibios: Commit


Commit MetaInfo

Revision15134 (tree)
Time2021-11-25 18:25:59
Authorgdisirio

Log Message

(empty log message)

Change Summary

Incremental Difference

--- trunk/os/vfs/drivers/streams/drvstreams.c (revision 15133)
+++ trunk/os/vfs/drivers/streams/drvstreams.c (revision 15134)
@@ -35,11 +35,16 @@
3535 /*===========================================================================*/
3636
3737 /**
38- * @brief Number of nodes pre-allocated in the pool.
38+ * @brief Number of directory nodes pre-allocated in the pool.
3939 */
40-#define DRV_NODES_NUM 2
40+#define DRV_DIR_NODES_NUM 1
4141
4242 /**
43+ * @brief Number of file nodes pre-allocated in the pool.
44+ */
45+#define DRV_FILE_NODES_NUM 2
46+
47+/**
4348 * @brief @p vfs_streams_driver_t specific methods.
4449 */
4550 #define __vfs_streams_driver_methods \
@@ -51,9 +56,23 @@
5156 #define __vfs_streams_driver_data \
5257 __vfs_driver_data \
5358 const drv_stream_element_t *streams; \
54- memory_pool_t nodes_pool;
59+ memory_pool_t file_nodes_pool; \
60+ memory_pool_t dir_nodes_pool;
5561
5662 /**
63+ * @brief @p vfs_stream_dir_node_t specific methods.
64+ */
65+#define __vfs_stream_dir_node_methods \
66+ __vfs_directory_node_methods
67+
68+/**
69+ * @brief @p vfs_stream_dir_node_t specific data.
70+ */
71+#define __vfs_stream_dir_node_data \
72+ __vfs_directory_node_data \
73+ unsigned index;
74+
75+/**
5776 * @brief @p vfs_stream_file_node_t specific methods.
5877 */
5978 #define __vfs_stream_file_node_methods \
@@ -93,8 +112,26 @@
93112 } vfs_streams_driver_t;
94113
95114 /**
96- * @brief @p vfs_file_node_t virtual methods table.
115+ * @brief @p vfs_stream_dir_node_t virtual methods table.
97116 */
117+struct vfs_stream_dir_node_vmt {
118+ __vfs_stream_dir_node_methods
119+};
120+
121+/**
122+ * @brief Type of a structure representing a stream dir VFS node.
123+ */
124+typedef struct vfs_stream_dir_node {
125+ /**
126+ * @brief Virtual Methods Table.
127+ */
128+ const struct vfs_stream_dir_node_vmt *vmt;
129+ __vfs_stream_dir_node_data
130+} vfs_stream_dir_node_t;
131+
132+/**
133+ * @brief @p vfs_stream_file_node_t virtual methods table.
134+ */
98135 struct vfs_stream_file_node_vmt {
99136 __vfs_stream_file_node_methods
100137 };
@@ -127,7 +164,17 @@
127164 };
128165
129166 static void node_release(void *instance);
130-static BaseSequentialStream *node_get_stream(void *instance);
167+
168+static msg_t node_dir_first(void *instance, vfs_node_info_t *nip);
169+static msg_t node_dir_next(void *instance, vfs_node_info_t *nip);
170+
171+static const struct vfs_stream_dir_node_vmt dir_node_vmt = {
172+ .release = node_release,
173+ .dir_first = node_dir_first,
174+ .dir_next = node_dir_next
175+};
176+
177+static BaseSequentialStream *node_file_get_stream(void *instance);
131178 static ssize_t node_file_read(void *instance, uint8_t *buf, size_t n);
132179 static ssize_t node_file_write(void *instance, const uint8_t *buf, size_t n);
133180 static msg_t node_file_setpos(void *instance, vfs_offset_t offset);
@@ -134,9 +181,9 @@
134181 static vfs_offset_t node_file_getpos(void *instance);
135182 static vfs_offset_t node_file_getsize(void *instance);
136183
137-static const struct vfs_stream_file_node_vmt node_vmt = {
184+static const struct vfs_stream_file_node_vmt file_node_vmt = {
138185 .release = node_release,
139- .get_stream = node_get_stream,
186+ .get_stream = node_file_get_stream,
140187 .file_read = node_file_read,
141188 .file_write = node_file_write,
142189 .file_setpos = node_file_setpos,
@@ -144,7 +191,9 @@
144191 .file_getsize = node_file_getsize
145192 };
146193
147-static vfs_stream_file_node_t drv_file_nodes[DRV_NODES_NUM];
194+static vfs_stream_file_node_t drv_dir_nodes[DRV_DIR_NODES_NUM];
195+static vfs_stream_file_node_t drv_file_nodes[DRV_FILE_NODES_NUM];
196+
148197 static vfs_streams_driver_t drv_streams;
149198
150199 /*===========================================================================*/
@@ -154,12 +203,36 @@
154203 static msg_t drv_open_dir(void *instance,
155204 const char *path,
156205 vfs_directory_node_t **vdnpp) {
206+ vfs_streams_driver_t *drvp = (vfs_streams_driver_t *)instance;
207+ msg_t err;
157208
158- (void)instance;
159- (void)path;
160- (void)vdnpp;
209+ do {
210+ vfs_stream_dir_node_t *sdnp;
161211
162- return VFS_RET_NOT_FOUND;
212+ err = vfs_parse_match_separator(&path);
213+ VFS_BREAK_ON_ERROR(err);
214+
215+ err = vfs_parse_match_end(&path);
216+ VFS_BREAK_ON_ERROR(err);
217+
218+ sdnp = chPoolAlloc(&drv_streams.dir_nodes_pool);
219+ if (sdnp != NULL) {
220+
221+ /* Node object initialization.*/
222+ sdnp->vmt = &dir_node_vmt;
223+ sdnp->refs = 1U;
224+ sdnp->driver = (vfs_driver_t *)drvp;
225+ sdnp->index = 0U;
226+
227+ *vdnpp = (vfs_directory_node_t *)sdnp;
228+ return VFS_RET_SUCCESS;
229+ }
230+
231+ err = VFS_RET_NO_RESOURCE;
232+ }
233+ while (false);
234+
235+ return err;
163236 }
164237
165238 static msg_t drv_open_file(void *instance,
@@ -186,11 +259,11 @@
186259 if (strncmp(fname, dsep->name, VFS_CFG_MAX_NAMELEN) == 0) {
187260 vfs_stream_file_node_t *sfnp;
188261
189- sfnp = chPoolAlloc(&drv_streams.nodes_pool);
262+ sfnp = chPoolAlloc(&drv_streams.file_nodes_pool);
190263 if (sfnp != NULL) {
191264
192265 /* Node object initialization.*/
193- sfnp->vmt = &node_vmt;
266+ sfnp->vmt = &file_node_vmt;
194267 sfnp->refs = 1U;
195268 sfnp->driver = (vfs_driver_t *)drvp;
196269 sfnp->stream = dsep->stream;
@@ -219,12 +292,41 @@
219292
220293 if (--sfnp->refs == 0U) {
221294
222- chPoolFree(&((vfs_streams_driver_t *)sfnp->driver)->nodes_pool,
295+ chPoolFree(&((vfs_streams_driver_t *)sfnp->driver)->file_nodes_pool,
223296 (void *)sfnp);
224297 }
225298 }
226299
227-static BaseSequentialStream *node_get_stream(void *instance) {
300+static msg_t node_dir_first(void *instance, vfs_node_info_t *nip) {
301+ vfs_stream_dir_node_t *sdnp = (vfs_stream_dir_node_t *)instance;
302+
303+ osalDbgAssert(sdnp->refs > 0U, "zero count");
304+
305+ sdnp->index = 0U;
306+
307+ return node_dir_next(instance, nip);
308+}
309+
310+static msg_t node_dir_next(void *instance, vfs_node_info_t *nip) {
311+ vfs_stream_dir_node_t *sdnp = (vfs_stream_dir_node_t *)instance;
312+
313+ osalDbgAssert(sdnp->refs > 0U, "zero count");
314+
315+ if (drv_streams.streams[sdnp->index].name != NULL) {
316+
317+ nip->attr = VFS_NODE_ATTR_ISSTREAM;
318+ nip->size = (vfs_offset_t)0;
319+ strcpy(nip->name, drv_streams.streams[sdnp->index].name);
320+
321+ sdnp->index++;
322+
323+ return VFS_RET_SUCCESS;
324+ }
325+
326+ return VFS_RET_EOF;
327+}
328+
329+static BaseSequentialStream *node_file_get_stream(void *instance) {
228330 vfs_stream_file_node_t *sfnp = (vfs_stream_file_node_t *)instance;
229331
230332 osalDbgAssert(sfnp->refs > 0U, "zero count");
@@ -283,10 +385,18 @@
283385 drv_streams.vmt = &driver_vmt;
284386 drv_streams.rootname = rootname;
285387 drv_streams.streams = streams;
286- chPoolObjectInit(&drv_streams.nodes_pool,
388+ chPoolObjectInit(&drv_streams.dir_nodes_pool,
389+ sizeof (vfs_stream_dir_node_t),
390+ chCoreAllocAligned);
391+ chPoolLoadArray(&drv_streams.dir_nodes_pool,
392+ drv_dir_nodes,
393+ DRV_DIR_NODES_NUM);
394+ chPoolObjectInit(&drv_streams.file_nodes_pool,
287395 sizeof (vfs_stream_file_node_t),
288396 chCoreAllocAligned);
289- chPoolLoadArray(&drv_streams.nodes_pool, drv_file_nodes, DRV_NODES_NUM);
397+ chPoolLoadArray(&drv_streams.file_nodes_pool,
398+ drv_file_nodes,
399+ DRV_FILE_NODES_NUM);
290400
291401 return (vfs_driver_t *)&drv_streams;
292402 }
--- trunk/os/vfs/include/vfsnodes.h (revision 15133)
+++ trunk/os/vfs/include/vfsnodes.h (revision 15134)
@@ -41,6 +41,7 @@
4141 #define VFS_NODE_ATTR_SYSTEM 4U
4242 #define VFS_NODE_ATTR_RESERVED8 8U
4343 #define VFS_NODE_ATTR_ISDIR 16U
44+#define VFS_NODE_ATTR_ISSTREAM 256U
4445 /** @} */
4546
4647 /*===========================================================================*/
@@ -137,7 +138,9 @@
137138 * @brief @p vfs_directory_node_t specific methods.
138139 */
139140 #define __vfs_directory_node_methods \
140- __vfs_node_methods
141+ __vfs_node_methods \
142+ msg_t (*dir_first)(void *instance, vfs_node_info_t *nip); \
143+ msg_t (*dir_next)(void *instance, vfs_node_info_t *nip);
141144
142145 /**
143146 * @brief @p vfs_directory_node_t specific data.
@@ -149,9 +152,7 @@
149152 * @brief @p vfs_directory_node_t virtual methods table.
150153 */
151154 struct vfs_directory_node_vmt {
152- __vfs_directory_node_methods \
153- msg_t (*dir_first)(void *instance); \
154- msg_t (*dir_next)(void *instance);
155+ __vfs_directory_node_methods
155156 };
156157
157158 /**
@@ -175,7 +176,7 @@
175176 */
176177 #define __vfs_file_node_methods \
177178 __vfs_node_methods \
178- BaseSequentialStream *(*get_stream)(void *instance); \
179+ BaseSequentialStream *(*get_stream)(void *instance); \
179180 ssize_t (*file_read)(void *instance, uint8_t *buf, size_t n); \
180181 ssize_t (*file_write)(void *instance, const uint8_t *buf, size_t n); \
181182 msg_t (*file_setpos)(void *instance, vfs_offset_t offset); \
Show on old repository browser