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

fs/littlefs: stop applying local patches for unknown versions of littlefs #14956

Merged
merged 6 commits into from
Nov 26, 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
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ CONFIG_DEFAULT_TASK_STACKSIZE=4096
CONFIG_EXAMPLES_ALARM=y
CONFIG_EXAMPLES_ALARM_STACKSIZE=2048
CONFIG_FS_LITTLEFS=y
CONFIG_FS_LITTLEFS_MULTI_VERSION=y
CONFIG_FS_LITTLEFS_VERSION="v2.9.3"
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_INTELHEX_BINARY=y
CONFIG_LIBM=y
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ CONFIG_ESP32S3_WIFI=y
CONFIG_EXAMPLES_RANDOM=y
CONFIG_FS_LARGEFILE=y
CONFIG_FS_LITTLEFS=y
CONFIG_FS_LITTLEFS_MULTI_VERSION=y
CONFIG_FS_LITTLEFS_VERSION="v2.9.3"
CONFIG_FS_PROCFS=y
CONFIG_HOST_MACOS=y
CONFIG_IDLETHREAD_STACKSIZE=3072
Expand Down
45 changes: 30 additions & 15 deletions fs/littlefs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,30 @@

if(CONFIG_FS_LITTLEFS)
if(NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/littlefs)

FetchContent_Declare(
littlefs
URL https://github.com/ARMmbed/littlefs/archive/${CONFIG_FS_LITTLEFS_VERSION}.tar.gz
SOURCE_DIR
${CMAKE_CURRENT_LIST_DIR}/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 && 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)
if(CONFIG_FS_LITTLEFS_LOCAL_PATCHES)
FetchContent_Declare(
littlefs
URL https://github.com/ARMmbed/littlefs/archive/${CONFIG_FS_LITTLEFS_VERSION}.tar.gz
SOURCE_DIR
${CMAKE_CURRENT_LIST_DIR}/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 && 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)
else()
FetchContent_Declare(
littlefs
URL https://github.com/ARMmbed/littlefs/archive/${CONFIG_FS_LITTLEFS_VERSION}.tar.gz
SOURCE_DIR
${CMAKE_CURRENT_LIST_DIR}/littlefs
BINARY_DIR
${CMAKE_BINARY_DIR}/fs/littlefs/littlefs)
endif()
FetchContent_MakeAvailable(littlefs)
endif()

Expand All @@ -49,7 +59,12 @@ if(CONFIG_FS_LITTLEFS)
-DLFS_CONFIG=${CMAKE_CURRENT_LIST_DIR}/lfs_vfs.h
-DLFS_NAME_MAX=${CONFIG_FS_LITTLEFS_NAME_MAX}
-DLFS_FILE_MAX=${CONFIG_FS_LITTLEFS_FILE_MAX}
-DLFS_ATTR_MAX=${CONFIG_FS_LITTLEFS_ATTR_MAX})
-DLFS_ATTR_MAX=${CONFIG_FS_LITTLEFS_ATTR_MAX}
$<$<BOOL:${CONFIG_FS_LITTLEFS_MULTI_VERSION}>:-DLFS_MULTIVERSION>)

# Note: the littlefs upstream doesn't seems to care -Wshadow cf.
# https://github.com/littlefs-project/littlefs/pull/873
target_compile_options(fs PRIVATE -Wno-shadow)

target_sources(fs PRIVATE lfs_vfs.c ${CMAKE_CURRENT_LIST_DIR}/littlefs/lfs.c
${CMAKE_CURRENT_LIST_DIR}/littlefs/lfs_util.c)
Expand Down
42 changes: 42 additions & 0 deletions fs/littlefs/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,59 @@ config FS_LITTLEFS_ATTR_MAX
Note: Many of tools to generate LITTLEFS images use 1022
for this by default.

config FS_LITTLEFS_LOCAL_PATCHES
bool
depends on FS_LITTLEFS_VERSION = "v2.5.1"
default y
---help---
For the internal use to control the application of NuttX local
patches for LITTLEFS.
This is NOT expected to be tweaked directly by users.

config FS_LITTLEFS_ATTR_UPDATE
bool "LITTLEFS update attributes"
depends on FS_LITTLEFS_ATTR_MAX > 0
depends on FS_LITTLEFS_LOCAL_PATCHES
default y
---help---
Enable support for attributes when create a file.

CAVEAT: This feature is implemented with NuttX specific
modifications to LITTLEFS v2.5.1. The modifications might
not be compatible with other versions of LITTLEFS.

config FS_LITTLEFS_GETPATH
bool "LITTLEFS FIOC_FILEPATH ioctl support"
depends on FS_LITTLEFS_LOCAL_PATCHES
default y
---help---
FIOC_FILEPATH ioctl support for LITTLEFS file system.

CAVEAT: This feature is implemented with NuttX specific
modifications to LITTLEFS v2.5.1. The modifications might
not be compatible with other versions of LITTLEFS.

config FS_LITTLEFS_VERSION
string "LITTLEFS version to use"
default "v2.5.1"
---help---
The LITTLEFS version to use.

config FS_LITTLEFS_MULTI_VERSION
bool "Support multiple on-disk versions"
default n
---help---
Enable LFS_MULTIVERSION for LITTLEFS file system

config FS_LITTLEFS_DISK_VERSION
hex "LITTLEFS on-disk version"
default 0x0
depends on FS_LITTLEFS_MULTI_VERSION
---help---
The LITTLEFS disk version to use.

0 means to leave it to the default from the LITTLEFS.
0x00020000 means 2.0.
0x00020001 means 2.1.

endif
9 changes: 9 additions & 0 deletions fs/littlefs/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ CSRCS += lfs.c lfs_util.c
DEPPATH += --dep-path littlefs/littlefs
VPATH += :littlefs/littlefs

# Note: the littlefs upstream doesn't seems to care -Wshadow
# cf. https://github.com/littlefs-project/littlefs/pull/873
CFLAGS += -Wno-shadow

CFLAGS += -DLFS_TRACE=finfo
CFLAGS += -DLFS_DEBUG=finfo
CFLAGS += -DLFS_WARN=fwarn
Expand All @@ -46,6 +50,9 @@ CFLAGS += -DLFS_CONFIG=../lfs_vfs.h
CFLAGS += -DLFS_NAME_MAX=$(CONFIG_FS_LITTLEFS_NAME_MAX)
CFLAGS += -DLFS_FILE_MAX=$(CONFIG_FS_LITTLEFS_FILE_MAX)
CFLAGS += -DLFS_ATTR_MAX=$(CONFIG_FS_LITTLEFS_ATTR_MAX)
ifeq ($(CONFIG_FS_LITTLEFS_MULTI_VERSION),y)
CFLAGS += -DLFS_MULTIVERSION
endif

LITTLEFS_TARBALL = $(CONFIG_FS_LITTLEFS_VERSION).tar.gz

Expand All @@ -55,9 +62,11 @@ $(LITTLEFS_TARBALL):
.littlefsunpack: $(LITTLEFS_TARBALL)
$(Q) tar zxf littlefs/$(LITTLEFS_TARBALL) -C littlefs
$(Q) mv littlefs/littlefs-* littlefs/littlefs
ifeq ($(CONFIG_FS_LITTLEFS_LOCAL_PATCHES),y)
$(Q) git apply littlefs/lfs_util.patch
$(Q) git apply littlefs/lfs_getpath.patch
$(Q) git apply littlefs/lfs_getsetattr.patch
endif
$(Q) touch littlefs/.littlefsunpack

# Download and unpack tarball if no git repo found
Expand Down
14 changes: 14 additions & 0 deletions fs/littlefs/lfs_vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,14 +598,18 @@ static off_t littlefs_seek(FAR struct file *filep, off_t offset, int whence)
static int littlefs_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
{
FAR struct littlefs_mountpt_s *fs;
#ifdef CONFIG_FS_LITTLEFS_GETPATH
FAR struct littlefs_file_s *priv;
#endif
FAR struct inode *inode;
FAR struct inode *drv;
int ret;

/* Recover our private data from the struct file instance */

#ifdef CONFIG_FS_LITTLEFS_GETPATH
priv = filep->f_priv;
#endif
inode = filep->f_inode;
fs = inode->i_private;
drv = fs->drv;
Expand All @@ -618,6 +622,7 @@ static int littlefs_ioctl(FAR struct file *filep, int cmd, unsigned long arg)

switch (cmd)
{
#ifdef CONFIG_FS_LITTLEFS_GETPATH
case FIOC_FILEPATH:
{
FAR char *path = (FAR char *)(uintptr_t)arg;
Expand All @@ -637,6 +642,7 @@ static int littlefs_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
}
}
break;
#endif

default:
{
Expand Down Expand Up @@ -742,7 +748,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;
#ifdef CONFIG_FS_LITTLEFS_ATTR_UPDATE
struct littlefs_attr_s attr;
#endif
int ret;

memset(buf, 0, sizeof(*buf));
Expand All @@ -768,6 +776,7 @@ static int littlefs_fstat(FAR const struct file *filep, FAR struct stat *buf)
goto errout;
}

#ifdef CONFIG_FS_LITTLEFS_ATTR_UPDATE
ret = littlefs_convert_result(lfs_file_getattr(&fs->lfs, &priv->file, 0,
&attr, sizeof(attr)));
if (ret < 0)
Expand All @@ -791,6 +800,7 @@ static int littlefs_fstat(FAR const struct file *filep, FAR struct stat *buf)
buf->st_mtim.tv_nsec = attr.at_mtim % 1000000000ull;
buf->st_ctim.tv_sec = attr.at_ctim / 1000000000ull;
buf->st_ctim.tv_nsec = attr.at_ctim % 1000000000ull;
#endif /* CONFIG_FS_LITTLEFS_ATTR_UPDATE */
buf->st_blksize = fs->cfg.block_size;
buf->st_blocks = (buf->st_size + buf->st_blksize - 1) /
buf->st_blksize;
Expand Down Expand Up @@ -1313,6 +1323,10 @@ static int littlefs_bind(FAR struct inode *driver, FAR const void *data,
fs->cfg.lookahead_size = CONFIG_FS_LITTLEFS_LOOKAHEAD_SIZE;
#endif

#ifdef CONFIG_FS_LITTLEFS_MULTI_VERSION
fs->cfg.disk_version = CONFIG_FS_LITTLEFS_DISK_VERSION;
#endif

/* Then get information about the littlefs filesystem on the devices
* managed by this driver.
*/
Expand Down
Loading