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

lfs_vfs:Use provided lfs_getattr / lfs_setattr instead of lfs_file_getattr / lfs_ file_setattr #14901

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions fs/littlefs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ if(CONFIG_FS_LITTLEFS)
PATCH_COMMAND
patch -p2 -d ${CMAKE_CURRENT_LIST_DIR} <
${CMAKE_CURRENT_LIST_DIR}/lfs_util.patch && patch -p2 -d
${CMAKE_CURRENT_LIST_DIR} < ${CMAKE_CURRENT_LIST_DIR}/lfs_getpath.patch
&& patch -p2 -d ${CMAKE_CURRENT_LIST_DIR} <
${CMAKE_CURRENT_LIST_DIR}/lfs_getsetattr.patch)
${CMAKE_CURRENT_LIST_DIR} < ${CMAKE_CURRENT_LIST_DIR}/lfs_getpath.patch)
FetchContent_MakeAvailable(littlefs)
endif()

Expand Down
1 change: 0 additions & 1 deletion fs/littlefs/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ $(LITTLEFS_TARBALL):
$(Q) mv littlefs/littlefs-$(LITTLEFS_VERSION) littlefs/littlefs
$(Q) git apply littlefs/lfs_util.patch
$(Q) git apply littlefs/lfs_getpath.patch
$(Q) git apply littlefs/lfs_getsetattr.patch
$(Q) touch littlefs/.littlefsunpack

# Download and unpack tarball if no git repo found
Expand Down
80 changes: 0 additions & 80 deletions fs/littlefs/lfs_getsetattr.patch

This file was deleted.

50 changes: 42 additions & 8 deletions fs/littlefs/lfs_vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -741,8 +741,9 @@ static int littlefs_fstat(FAR const struct file *filep, FAR struct stat *buf)
{
FAR struct littlefs_mountpt_s *fs;
FAR struct littlefs_file_s *priv;
FAR struct inode *inode;
struct littlefs_attr_s attr;
FAR struct inode *inode;
FAR char *path;
int ret;

memset(buf, 0, sizeof(*buf));
Expand All @@ -755,9 +756,24 @@ static int littlefs_fstat(FAR const struct file *filep, FAR struct stat *buf)

/* Call LFS to get file size */

path = lib_get_pathbuffer();
if (path == NULL)
{
return -ENOMEM;
}

ret = littlefs_convert_result(lfs_file_path(&fs->lfs, &priv->file, path,
PATH_MAX));
if (ret < 0)
{
lib_put_pathbuffer(path);
return ret;
}

ret = nxmutex_lock(&fs->lock);
if (ret < 0)
{
lib_put_pathbuffer(path);
return ret;
}

Expand All @@ -768,8 +784,8 @@ static int littlefs_fstat(FAR const struct file *filep, FAR struct stat *buf)
goto errout;
}

ret = littlefs_convert_result(lfs_file_getattr(&fs->lfs, &priv->file, 0,
&attr, sizeof(attr)));
ret = littlefs_convert_result(lfs_getattr(&fs->lfs, path, 0, &attr,
sizeof(attr)));
if (ret < 0)
{
if (ret != -ENODATA && ret != -ENOENT)
Expand All @@ -796,6 +812,7 @@ static int littlefs_fstat(FAR const struct file *filep, FAR struct stat *buf)
buf->st_blksize;

errout:
lib_put_pathbuffer(path);
nxmutex_unlock(&fs->lock);
return ret;
}
Expand All @@ -806,8 +823,9 @@ static int littlefs_fchstat(FAR const struct file *filep,
{
FAR struct littlefs_mountpt_s *fs;
FAR struct littlefs_file_s *priv;
FAR struct inode *inode;
struct littlefs_attr_s attr;
FAR struct inode *inode;
FAR char *path;
int ret;

/* Recover our private data from the struct file instance */
Expand All @@ -816,16 +834,31 @@ static int littlefs_fchstat(FAR const struct file *filep,
inode = filep->f_inode;
fs = inode->i_private;

path = lib_get_pathbuffer();
if (path == NULL)
{
return -ENOMEM;
}

/* Call LFS to get file size */

ret = littlefs_convert_result(lfs_file_path(&fs->lfs, &priv->file, path,
crafcat7 marked this conversation as resolved.
Show resolved Hide resolved
PATH_MAX));
if (ret < 0)
{
lib_put_pathbuffer(path);
return ret;
}

ret = nxmutex_lock(&fs->lock);
if (ret < 0)
{
lib_put_pathbuffer(path);
return ret;
}

ret = littlefs_convert_result(lfs_file_getattr(&fs->lfs, &priv->file,
0, &attr, sizeof(attr)));
ret = littlefs_convert_result(lfs_getattr(&fs->lfs, path, 0, &attr,
sizeof(attr)));
if (ret < 0)
{
if (ret != -ENODATA)
Expand Down Expand Up @@ -867,14 +900,15 @@ static int littlefs_fchstat(FAR const struct file *filep,
buf->st_mtim.tv_nsec;
}

ret = littlefs_convert_result(lfs_file_setattr(&fs->lfs, &priv->file, 0,
&attr, sizeof(attr)));
ret = littlefs_convert_result(lfs_setattr(&fs->lfs, path, 0, &attr,
sizeof(attr)));
if (ret < 0)
{
goto errout;
}

errout:
lib_put_pathbuffer(path);
nxmutex_unlock(&fs->lock);
return ret;
}
Expand Down
Loading