Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/spiffs: hook up .stat() #17971

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
pkg/spiffs: hook up .stat()
  • Loading branch information
benpicco committed May 16, 2022
commit 99706304f06c148777da0adf9670b4c8cb0da99b
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;
benpicco marked this conversation as resolved.
Show resolved Hide resolved
}

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