Skip to content

Commit 8469eba

Browse files
author
Vincent Dupont
committed
spiffs: add dir ops support
1 parent e065f12 commit 8469eba

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

pkg/spiffs/fs/spiffs_fs.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,67 @@ static int _fstat(vfs_file_t *filp, struct stat *buf)
256256
return spiffs_err_to_errno(ret);
257257
}
258258

259+
static int _opendir(vfs_DIR *dirp, const char *dirname, const char *abs_path)
260+
{
261+
spiffs_desc_t *fs_desc = dirp->mp->private_data;
262+
spiffs_DIR d;
263+
(void) abs_path;
264+
265+
if (VFS_DIR_BUFFER_SIZE < sizeof(spiffs_DIR)) {
266+
return -EOVERFLOW;
267+
}
268+
269+
SPIFFS_opendir(&fs_desc->fs, dirname, &d);
270+
memcpy(dirp->private_data.buffer, &d, sizeof(d));
271+
272+
return 0;
273+
}
274+
275+
static int _readdir(vfs_DIR *dirp, vfs_dirent_t *entry)
276+
{
277+
spiffs_DIR d;
278+
struct spiffs_dirent e;
279+
struct spiffs_dirent *ret;
280+
281+
memcpy(&d, dirp->private_data.buffer, sizeof(d));
282+
283+
ret = SPIFFS_readdir(&d, &e);
284+
memcpy(dirp->private_data.buffer, &d, sizeof(d));
285+
if (ret == NULL) {
286+
s32_t err = SPIFFS_errno(d.fs);
287+
if (err != SPIFFS_OK && err > SPIFFS_ERR_INTERNAL) {
288+
DEBUG("spiffs: readdir: err=%d\n", err);
289+
return -EIO;
290+
}
291+
}
292+
293+
if (ret) {
294+
entry->d_ino = e.obj_id;
295+
strncpy(entry->d_name, (char*) e.name, VFS_NAME_MAX);
296+
return 1;
297+
}
298+
else {
299+
return 0;
300+
}
301+
}
302+
303+
static int _closedir(vfs_DIR *dirp)
304+
{
305+
spiffs_DIR d;
306+
307+
memcpy(&d, dirp->private_data.buffer, sizeof(d));
308+
309+
return spiffs_err_to_errno(SPIFFS_closedir(&d));
310+
}
311+
259312
static int spiffs_err_to_errno (s32_t err)
260313
{
261314
if (err >= 0) {
262315
return (int) err;
263316
}
264317

318+
DEBUG("spiffs: error=%d\n", err);
319+
265320
switch (err) {
266321
case SPIFFS_OK:
267322
return 0;
@@ -359,7 +414,14 @@ static const vfs_file_ops_t spiffs_file_ops = {
359414
.fstat = _fstat,
360415
};
361416

417+
static const vfs_dir_ops_t spiffs_dir_ops = {
418+
.opendir = _opendir,
419+
.readdir = _readdir,
420+
.closedir = _closedir,
421+
};
422+
362423
const vfs_file_system_t spiffs_file_system = {
363424
.fs_op = &spiffs_fs_ops,
364425
.f_op = &spiffs_file_ops,
426+
.d_op = &spiffs_dir_ops,
365427
};

sys/include/fs/spiffs_fs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extern "C" {
3030
#define SPIFFS_FS_WORK_SIZE (512)
3131
#endif
3232
#ifndef SPIFFS_FS_FD_SPACE_SIZE
33-
#define SPIFFS_FS_FD_SPACE_SIZE (50)
33+
#define SPIFFS_FS_FD_SPACE_SIZE (125)
3434
#endif
3535

3636
/**

0 commit comments

Comments
 (0)