This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 825e093e07ca7d3aa72016c5fca55d3cebd15616 Author: anjiahao <[email protected]> AuthorDate: Fri Nov 8 09:19:42 2024 +0800 archivefs:add option to select archive format Add the FS_ARCHIVEFS_FORMAT_* options to select the archive formats that are compiled in, and register the selected formats when an archive is opened. ZIP is the default, and FS_ARCHIVEFS_FORMAT_ALL enables all the formats at the cost of binary size. The empty format option is spelled EMPTY, as the code tests it. Assisted-by: Claude Code:claude-sonnet-5.5 Signed-off-by: anjiahao <[email protected]> Signed-off-by: tengshuangshuang <[email protected]> --- fs/archivefs/Kconfig | 68 +++++++++++++++++++++++ fs/archivefs/archivefs.c | 138 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 206 insertions(+) diff --git a/fs/archivefs/Kconfig b/fs/archivefs/Kconfig index ebd402ebc54..62168914a18 100644 --- a/fs/archivefs/Kconfig +++ b/fs/archivefs/Kconfig @@ -15,4 +15,72 @@ config FS_ARCHIVEFS_BUFFER_SIZE ---help--- libarchive requires a buffer to read and write data. +config FS_ARCHIVEFS_FORMAT_ALL + bool "support archive all format" + default n + ---help--- + All format support will increase binary size. +if !FS_ARCHIVEFS_FORMAT_ALL +config FS_ARCHIVEFS_FORMAT_ZIP + bool "support archive xar format" + default y + +config FS_ARCHIVEFS_FORMAT_7ZIP + bool "support archive 7zip format" + default n + +config FS_ARCHIVEFS_FORMAT_AR + bool "support archive ar format" + default n + +config FS_ARCHIVEFS_FORMAT_CAB + bool "support archive cab format" + default n + +config FS_ARCHIVEFS_FORMAT_CPIO + bool "support archive cpio format" + default n + +config FS_ARCHIVEFS_FORMAT_EMPTY + bool "support archive empty format" + default n + +config FS_ARCHIVEFS_FORMAT_ISO9660 + bool "support archive iso9660 format" + default n + +config FS_ARCHIVEFS_FORMAT_LHA + bool "support archive lha format" + default n + +config FS_ARCHIVEFS_FORMAT_MTREE + bool "support archive mtree format" + default n + +config FS_ARCHIVEFS_FORMAT_RAR + bool "support archive rar format" + default n + +config FS_ARCHIVEFS_FORMAT_RAR_V5 + bool "support archive rar_v5 format" + default n + +config FS_ARCHIVEFS_FORMAT_RAW + bool "support archive raw format" + default n + +config FS_ARCHIVEFS_FORMAT_TAR + bool "support archive raw format" + default n + +config FS_ARCHIVEFS_FORMAT_WARC + bool "support archive warc format" + default n + +config FS_ARCHIVEFS_FORMAT_XAR + bool "support archive xar format" + default n + +endif + endif diff --git a/fs/archivefs/archivefs.c b/fs/archivefs/archivefs.c index 613362596cd..acef047197a 100644 --- a/fs/archivefs/archivefs.c +++ b/fs/archivefs/archivefs.c @@ -253,12 +253,150 @@ int archivefs_new(FAR const char *abspath, FAR const char *relpath, } nxmutex_init(&newp->lock); +#ifdef CONFIG_FS_ARCHIVEFS_FORMAT_ALL ret = archivefs_convert_result(archive_read_support_format_all(newp->a)); if (ret < 0) { ferr("ERROR: archive_read_support_format_all() failed\n"); goto err_with_lock; } +#else +# ifdef CONFIG_FS_ARCHIVEFS_FORMAT_ZIP + ret = archivefs_convert_result(archive_read_support_format_zip(newp->a)); + if (ret < 0) + { + ferr("ERROR: archive_read_support_format_zip() failed\n"); + goto err_with_lock; + } +# endif + +# ifdef CONFIG_FS_ARCHIVEFS_FORMAT_7ZIP + ret = archivefs_convert_result(archive_read_support_format_7zip(newp->a)); + if (ret < 0) + { + ferr("ERROR: archive_read_support_format_7zip() failed\n"); + goto err_with_lock; + } +# endif + +# ifdef CONFIG_FS_ARCHIVEFS_FORMAT_AR + ret = archivefs_convert_result(archive_read_support_format_ar(newp->a)); + if (ret < 0) + { + ferr("ERROR: archive_read_support_format_ar() failed\n"); + goto err_with_lock; + } +# endif + +# ifdef CONFIG_FS_ARCHIVEFS_FORMAT_CAB + ret = archivefs_convert_result(archive_read_support_format_cab(newp->a)); + if (ret < 0) + { + ferr("ERROR: archive_read_support_format_cab() failed\n"); + goto err_with_lock; + } +# endif + +# ifdef CONFIG_FS_ARCHIVEFS_FORMAT_CPIO + ret = archivefs_convert_result(archive_read_support_format_cpio(newp->a)); + if (ret < 0) + { + ferr("ERROR: archive_read_support_format_cpio() failed\n"); + goto err_with_lock; + } +# endif + +# ifdef CONFIG_FS_ARCHIVEFS_FORMAT_EMPTY + ret = archivefs_convert_result(archive_read_support_format_empty(newp->a)); + if (ret < 0) + { + ferr("ERROR: archive_read_support_format_empty() failed\n"); + goto err_with_lock; + } +# endif + +# ifdef CONFIG_FS_ARCHIVEFS_FORMAT_ISO9660 + ret = archive_read_support_format_iso9660(newp->a); + ret = archivefs_convert_result(ret); + if (ret < 0) + { + ferr("ERROR: archive_read_support_format_iso9660() failed\n"); + goto err_with_lock; + } +# endif + +# ifdef CONFIG_FS_ARCHIVEFS_FORMAT_LHA + ret = archivefs_convert_result(archive_read_support_format_lha(newp->a)); + if (ret < 0) + { + ferr("ERROR: archive_read_support_format_lha() failed\n"); + goto err_with_lock; + } +# endif + +# ifdef CONFIG_FS_ARCHIVEFS_FORMAT_MTREE + ret = archivefs_convert_result(archive_read_support_format_mtree(newp->a)); + if (ret < 0) + { + ferr("ERROR: archive_read_support_format_mtree() failed\n"); + goto err_with_lock; + } +# endif + +# ifdef CONFIG_FS_ARCHIVEFS_FORMAT_RAR + ret = archivefs_convert_result(archive_read_support_format_rar(newp->a)); + if (ret < 0) + { + ferr("ERROR: archive_read_support_format_rar() failed\n"); + goto err_with_lock; + } +# endif + +# ifdef CONFIG_FS_ARCHIVEFS_FORMAT_RAR_V5 + ret = archivefs_convert_result(archive_read_support_format_rar5(newp->a)); + if (ret < 0) + { + ferr("ERROR: archive_read_support_format_rar5() failed\n"); + goto err_with_lock; + } +# endif + +# ifdef CONFIG_FS_ARCHIVEFS_FORMAT_RAW + ret = archivefs_convert_result(archive_read_support_format_raw(newp->a)); + if (ret < 0) + { + ferr("ERROR: archive_read_support_format_raw() failed\n"); + goto err_with_lock; + } +# endif + +# ifdef CONFIG_FS_ARCHIVEFS_FORMAT_TAR + ret = archivefs_convert_result(archive_read_support_format_tar(newp->a)); + if (ret < 0) + { + ferr("ERROR: archive_read_support_format_tar() failed\n"); + goto err_with_lock; + } +# endif + +# ifdef CONFIG_FS_ARCHIVEFS_FORMAT_WARC + ret = archivefs_convert_result(archive_read_support_format_warc(newp->a)); + if (ret < 0) + { + ferr("ERROR: archive_read_support_format_warc() failed\n"); + goto err_with_lock; + } +# endif + +# ifdef CONFIG_FS_ARCHIVEFS_FORMAT_XAR + ret = archivefs_convert_result(archive_read_support_format_xar(newp->a)); + if (ret < 0) + { + ferr("ERROR: archive_read_support_format_xar() failed\n"); + goto err_with_lock; + } +# endif +#endif ret = file_open(&newp->file, abspath, O_RDONLY); if (ret < 0)
