Skip to content

Commit

Permalink
littlefs/Make.defs:Add get path temp patch
Browse files Browse the repository at this point in the history
VELAPLATFO-26732

Change-Id: I2651f16ec15038ee543f41b8967d40f06508404f
Signed-off-by: chenrun1 <[email protected]>
  • Loading branch information
crafcat7 committed Feb 21, 2024
1 parent 19cc7c2 commit 623b017
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 1 deletion.
4 changes: 3 additions & 1 deletion fs/littlefs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ if(CONFIG_FS_LITTLEFS)
BINARY_DIR
${CMAKE_BINARY_DIR}/fs/littlefs/littlefs
PATCH_COMMAND patch -p2 -d ${CMAKE_CURRENT_LIST_DIR} <
${CMAKE_CURRENT_LIST_DIR}/lfs_util.patch)
${CMAKE_CURRENT_LIST_DIR}/lfs_util.patch
PATCH_COMMAND patch -p2 -d ${CMAKE_CURRENT_LIST_DIR} <
${CMAKE_CURRENT_LIST_DIR}/lfs_getpath.patch)
FetchContent_MakeAvailable(littlefs)
endif()

Expand Down
2 changes: 2 additions & 0 deletions fs/littlefs/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ $(LITTLEFS_TARBALL):
$(Q) tar zxf littlefs/$(LITTLEFS_TARBALL) -C littlefs
$(Q) mv littlefs/littlefs-$(LITTLEFS_VERSION) littlefs/littlefs
$(Q) git apply littlefs/lfs_util.patch
$(Q) cp littlefs/lfs_getpath.patch littlefs/littlefs
$(Q) patch -p1 -d littlefs/littlefs < littlefs/littlefs/lfs_getpath.patch
$(Q) touch littlefs/.littlefsunpack

# Download and unpack tarball if no git repo found
Expand Down
151 changes: 151 additions & 0 deletions fs/littlefs/lfs_getpath.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
From 696dfa6ce29cb44d22e48bf66032e217383d8a2f Mon Sep 17 00:00:00 2001
From: zhouliang3 <[email protected]>
Date: Tue, 24 Aug 2021 12:48:22 +0800
Subject: [PATCH] fs/littlefs: Add the function of obtaining absolute path

Signed-off-by: zhouliang3 <[email protected]>
---
lfs.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
lfs.h | 8 ++++++
2 files changed, 87 insertions(+)

diff --git a/lfs.c b/lfs.c
index 38b825d..48dbff6 100644
--- a/lfs.c
+++ b/lfs.c
@@ -542,6 +542,8 @@ static uint16_t lfs_fs_disk_version_minor(lfs_t *lfs) {


/// Internal operations predeclared here ///
+static lfs_ssize_t lfs_dir_rawpath(lfs_t *lfs,
+ lfs_mdir_t *dir, uint16_t id, char *path, lfs_size_t size);
#ifndef LFS_READONLY
static int lfs_dir_commit(lfs_t *lfs, lfs_mdir_t *dir,
const struct lfs_mattr *attrs, int attrcount);
@@ -3790,6 +3792,53 @@ static lfs_soff_t lfs_file_rawsize(lfs_t *lfs, lfs_file_t *file) {
return file->ctz.size;
}

+static lfs_ssize_t lfs_dir_rawpath(lfs_t *lfs,
+ lfs_mdir_t *dir, uint16_t id, char *path, lfs_size_t size) {
+ struct lfs_info info;
+ char *next = path;
+ lfs_mdir_t parent;
+ lfs_ssize_t len;
+ lfs_stag_t tag;
+ int err;
+
+ if (lfs_pair_cmp(lfs->root, dir->pair) != 0) {
+ tag = lfs_fs_parent(lfs, dir->pair, &parent);
+ if (tag < 0) {
+ return tag;
+ }
+
+ len = lfs_dir_rawpath(lfs, &parent, lfs_tag_id(tag), next, size);
+ if (len < 0) {
+ return len;
+ }
+
+ next += len;
+ size -= len;
+ }
+
+ err = lfs_dir_getinfo(lfs, dir, id, &info);
+ if (err < 0) {
+ return err;
+ }
+
+ len = strlen(info.name);
+ if (len >= size) {
+ return LFS_ERR_INVAL;
+ }
+
+ memcpy(next, info.name, len + 1);
+ next += len;
+
+ if (info.type == LFS_TYPE_DIR) {
+ *next++ = '/';
+ if (++len >= size) {
+ return LFS_ERR_INVAL;
+ }
+ *next = '\0';
+ }
+
+ return next - path;
+}

/// General fs operations ///
static int lfs_rawstat(lfs_t *lfs, const char *path, struct lfs_info *info) {
@@ -6042,6 +6091,22 @@ lfs_soff_t lfs_file_size(lfs_t *lfs, lfs_file_t *file) {
return res;
}

+int lfs_file_path(lfs_t *lfs, lfs_file_t *file, char *path, lfs_size_t size) {
+ int err = LFS_LOCK(lfs->cfg);
+ if (err) {
+ return err;
+ }
+
+ LFS_TRACE("lfs_file_path(%p, %p)", (void*)lfs, (void*)file);
+ LFS_ASSERT(lfs_mlist_isopen(lfs->mlist, (struct lfs_mlist*)file));
+
+ err = lfs_dir_rawpath(lfs, &file->m, file->id, path, size);
+
+ LFS_TRACE("lfs_file_path -> %d", err);
+ LFS_UNLOCK(lfs->cfg);
+ return err < 0 ? err : 0;
+}
+
#ifndef LFS_READONLY
int lfs_mkdir(lfs_t *lfs, const char *path) {
int err = LFS_LOCK(lfs->cfg);
@@ -6173,6 +6238,20 @@ lfs_ssize_t lfs_fs_size(lfs_t *lfs) {
return res;
}

+int lfs_dir_path(lfs_t *lfs, lfs_dir_t *dir, char *path, lfs_size_t size) {
+ int err = LFS_LOCK(lfs->cfg);
+ if (err) {
+ return err;
+ }
+
+ LFS_TRACE("lfs_dir_path(%p, %p)", (void*)lfs, (void*)dir);
+ err = lfs_dir_rawpath(lfs, &dir->m, dir->id, path, size);
+
+ LFS_TRACE("lfs_dir_path -> %d", err);
+ LFS_UNLOCK(lfs->cfg);
+ return err < 0 ? err : 0;
+}
+
int lfs_fs_traverse(lfs_t *lfs, int (*cb)(void *, lfs_block_t), void *data) {
int err = LFS_LOCK(lfs->cfg);
if (err) {
diff --git a/lfs.h b/lfs.h
index 1081735..ccd10de 100644
--- a/lfs.h
+++ b/lfs.h
@@ -629,6 +629,10 @@ int lfs_file_rewind(lfs_t *lfs, lfs_file_t *file);
// Returns the size of the file, or a negative error code on failure.
lfs_soff_t lfs_file_size(lfs_t *lfs, lfs_file_t *file);

+// Get the absolute path of the open 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);

/// Directory operations ///

@@ -679,6 +683,10 @@ lfs_soff_t lfs_dir_tell(lfs_t *lfs, lfs_dir_t *dir);
// Returns a negative error code on failure.
int lfs_dir_rewind(lfs_t *lfs, lfs_dir_t *dir);

+// Get the absolute path of the directory
+//
+// Returns a negative error code on failure.
+int lfs_dir_path(lfs_t *lfs, lfs_dir_t *dir, char *path, lfs_size_t size);

/// Filesystem-level filesystem operations

--
2.25.1

0 comments on commit 623b017

Please sign in to comment.