Skip to content

Commit

Permalink
pkg/spiffs: hook up .stat()
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed May 16, 2022
1 parent 7bad517 commit 9970630
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions pkg/spiffs/fs/spiffs_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,27 @@ static int _fsync(vfs_file_t *filp)
return spiffs_err_to_errno(ret);
}

static void spiffs_stat_to_stat(const spiffs_stat *in, struct stat *out)
{
/* ignored: in->name,pix,type;*/
out->st_ino = in->obj_id;
out->st_size = in->size;
out->st_mode = S_IFREG;
}

static int _stat(vfs_mount_t *mountp, const char *path, struct stat *buf)
{
spiffs_desc_t *fs_desc = mountp->private_data;
spiffs_stat stat;
s32_t ret;

ret = SPIFFS_stat(&fs_desc->fs, path, &stat);

spiffs_stat_to_stat(&stat, buf);

return spiffs_err_to_errno(ret);
}

static int _fstat(vfs_file_t *filp, struct stat *buf)
{
spiffs_desc_t *fs_desc = filp->mp->private_data;
Expand All @@ -348,15 +369,7 @@ static int _fstat(vfs_file_t *filp, struct stat *buf)

ret = SPIFFS_fstat(&fs_desc->fs, filp->private_data.value, &stat);

if (ret < 0) {
return ret;
}
/* stat.name; */
buf->st_ino = stat.obj_id;
/* stat.pix; */
buf->st_size = stat.size;
/* stat.type;*/
buf->st_mode = S_IFREG;
spiffs_stat_to_stat(&stat, buf);

return spiffs_err_to_errno(ret);
}
Expand Down Expand Up @@ -511,6 +524,7 @@ static const vfs_file_system_ops_t spiffs_fs_ops = {
.unlink = _unlink,
.rename = _rename,
.statvfs = _statvfs,
.stat = _stat,
};

static const vfs_file_ops_t spiffs_file_ops = {
Expand Down

0 comments on commit 9970630

Please sign in to comment.