diff --git a/fs/littlefs/CMakeLists.txt b/fs/littlefs/CMakeLists.txt index fcc269c991012..1a0e1d1c2954d 100644 --- a/fs/littlefs/CMakeLists.txt +++ b/fs/littlefs/CMakeLists.txt @@ -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() diff --git a/fs/littlefs/Make.defs b/fs/littlefs/Make.defs index 70b6a79bcbdea..8eb7f2be3eecc 100644 --- a/fs/littlefs/Make.defs +++ b/fs/littlefs/Make.defs @@ -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 diff --git a/fs/littlefs/lfs_getsetattr.patch b/fs/littlefs/lfs_getsetattr.patch deleted file mode 100644 index 60d77412bea10..0000000000000 --- a/fs/littlefs/lfs_getsetattr.patch +++ /dev/null @@ -1,80 +0,0 @@ ---- ./littlefs/littlefs/lfs.c -+++ ./littlefs/littlefs/lfs.c -@@ -5717,6 +5717,41 @@ int lfs_file_path(lfs_t *lfs, lfs_file_t *file, char *path, lfs_size_t size) { - return err < 0 ? err : 0; - } - -+lfs_ssize_t lfs_file_getattr(lfs_t *lfs, lfs_file_t *file, -+ uint8_t type, void *buffer, lfs_size_t size) -+{ -+ int err = LFS_LOCK(lfs->cfg); -+ if (err) { -+ return err; -+ } -+ LFS_TRACE("lfs_file_setattr(%p, %p)", (void*)lfs, (void*)file); -+ LFS_TRACE("lfs_file_setattr(%"PRIu8", %p, %"PRIu32")", -+ type, buffer, size); -+ LFS_ASSERT(lfs_mlist_isopen(lfs->mlist, (struct lfs_mlist*)file)); -+ -+ return lfs_dir_get(lfs, &file->m, LFS_MKTAG(0x7ff, 0x3ff, 0), -+ LFS_MKTAG(LFS_TYPE_USERATTR + type, -+ file->id, lfs_min(size, lfs->attr_max)), buffer); -+} -+ -+#ifndef LFS_READONLY -+int lfs_file_setattr(lfs_t *lfs, lfs_file_t *file, -+ uint8_t type, const void *buffer, lfs_size_t size) -+{ -+ int err = LFS_LOCK(lfs->cfg); -+ if (err) { -+ return err; -+ } -+ LFS_TRACE("lfs_file_getattr(%p, %p)", (void*)lfs, (void*)file); -+ LFS_TRACE("lfs_file_getattr(%"PRIu8", %p, %"PRIu32")", -+ type, buffer, size); -+ LFS_ASSERT(lfs_mlist_isopen(lfs->mlist, (struct lfs_mlist*)file)); -+ -+ return lfs_dir_commit(lfs, &file->m, LFS_MKATTRS( -+ {LFS_MKTAG(LFS_TYPE_USERATTR + type, file->id, size), buffer})); -+} -+#endif -+ - #ifndef LFS_READONLY - int lfs_mkdir(lfs_t *lfs, const char *path) { - int err = LFS_LOCK(lfs->cfg); ---- ./littlefs/littlefs/lfs.h -+++ ./littlefs/littlefs/lfs.h -@@ -611,6 +611,33 @@ lfs_soff_t lfs_file_size(lfs_t *lfs, lfs_file_t *file); - // Returns a negative error code on failure. - int lfs_file_path(lfs_t *lfs, lfs_file_t *file, char *path, lfs_size_t size); - -+// Get a custom attribute of file -+// -+// Custom attributes are uniquely identified by an 8-bit type and limited -+// to LFS_ATTR_MAX bytes. When read, if the stored attribute is smaller than -+// the buffer, it will be padded with zeros. If the stored attribute is larger, -+// then it will be silently truncated. If no attribute is found, the error -+// LFS_ERR_NOATTR is returned and the buffer is filled with zeros. -+// -+// Returns the size of the attribute, or a negative error code on failure. -+// Note, the returned size is the size of the attribute on disk, irrespective -+// of the size of the buffer. This can be used to dynamically allocate a buffer -+// or check for existance. -+lfs_ssize_t lfs_file_getattr(lfs_t *lfs, lfs_file_t *file, -+ uint8_t type, void *buffer, lfs_size_t size); -+ -+// Set custom attributes of file -+// -+// Custom attributes are uniquely identified by an 8-bit type and limited -+// to LFS_ATTR_MAX bytes. If an attribute is not found, it will be -+// implicitly created. -+// -+// Returns a negative error code on failure. -+#ifndef LFS_READONLY -+int lfs_file_setattr(lfs_t *lfs, lfs_file_t *file, -+ uint8_t type, const void *buffer, lfs_size_t size); -+#endif -+ - /// Directory operations /// - - #ifndef LFS_READONLY diff --git a/fs/littlefs/lfs_vfs.c b/fs/littlefs/lfs_vfs.c index d2d6782e9dd5d..ea46a2e7ef836 100644 --- a/fs/littlefs/lfs_vfs.c +++ b/fs/littlefs/lfs_vfs.c @@ -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)); @@ -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; } @@ -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) @@ -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; } @@ -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 */ @@ -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, + 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) @@ -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; }