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

Add support fchstat and chstat function for littlefs #13964

Merged
merged 7 commits into from
Oct 11, 2024
Merged
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
6 changes: 4 additions & 2 deletions fs/littlefs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ if(CONFIG_FS_LITTLEFS)
${CMAKE_BINARY_DIR}/fs/littlefs/littlefs
PATCH_COMMAND
patch -p2 -d ${CMAKE_CURRENT_LIST_DIR} <
${CMAKE_CURRENT_LIST_DIR}/lfs_util.patch COMMAND patch -p2 -d
${CMAKE_CURRENT_LIST_DIR} < ${CMAKE_CURRENT_LIST_DIR}/lfs_getpath.patch)
${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)
FetchContent_MakeAvailable(littlefs)
endif()

Expand Down
1 change: 1 addition & 0 deletions fs/littlefs/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ $(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: 80 additions & 0 deletions fs/littlefs/lfs_getsetattr.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
--- ./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
Loading
Loading