txy-21 opened a new pull request, #21950:
URL: https://github.com/apache/nuttx/pull/21950

   ## Summary
   
     * Why: zipfs is read-only and reads only zip files, with minizip. This PR
       reads archives with libarchive (zip by default, other formats by option)
       and adds wzipfs, a write-only file system that streams a zip archive 
into a
       file, a FIFO, a socket or an open file descriptor.
     * What: fs/zipfs is rewritten on top of libarchive, wzipfs is new, and the
       sim:zipfs configuration and the zipfs document follow.
     * How:
       - zipfs reads the archive through libarchive callbacks on file_read() and
         file_seek(). Opening a file, and seeking backwards, start a new
         libarchive reader and scan the archive for the entry. Opening a
         directory starts a reader at the beginning of the archive, and 
readdir()
         returns every entry of the archive, whichever directory is opened.
       - wzipfs: open() writes the header of an entry, write() streams the data,
         mkdir() writes a directory entry, and unmount writes the central
         directory. The target is src=<path> or fd=<N>, and method=store|deflate
         selects the compression.
     * The 11 commits keep their original authors. They come from a downstream
       tree: archivefs is added, extended and renamed to zipfs, and then wzipfs 
is
       added. Commit 3 changes code that commit 5 replaces.
     * libarchive is not in this repository. fs/zipfs/libarchive is a symbolic
       link to ../../../apps/system/libarchive, which
       https://github.com/apache/nuttx-apps/pull/4076 adds.
     * Related: apache/nuttx#17882 and apache/nuttx-apps#3318 were closed. They
       proposed the same libarchive approach under the name archivefs.
     * BREAKING CHANGE: FS_ZIPFS now depends on UTILS_LIBARCHIVE, 
ZIPFS_SEEK_BUFSIZE
       is removed, and the fs/zipfs/zlib link is replaced by 
fs/zipfs/libarchive.
       Quick fix: enable UTILS_LIBARCHIVE (nuttx-apps), and set
       FS_ZIPFS_BUFFER_SIZE, the size of the read buffer of each open file.
   
   Depends-On: https://github.com/apache/nuttx-apps/pull/4076
   
   ## Impact
   
     * Is new feature added? Is existing feature changed? YES. wzipfs is new. 
The
       zipfs reader is a different implementation, and the formats are selected
       with FS_ZIPFS_FORMAT_*.
     * Impact on user (will user need to adapt to change)? YES. See the BREAKING
       CHANGE in the Summary. The file mode now comes from the archive:
       -rw-rw-r-- for the test archive below, which Linux zip made. Before, 
every
       file was -r-xr-xr-x, so the files no longer have the execute bit that
       "fs/zipfs: Report execute permission for files and the root" added. For 
an
       archive without a Unix mode, libarchive uses 0664 for files (read from 
its
       source, not tested).
     * Impact on build (will build process change)? YES. FS_ZIPFS needs
       system/libarchive of nuttx-apps, which downloads libarchive 3.7.7 at 
build
       time. The symbolic link is fixed to ../../../apps, so the apps directory
       must be named "apps".
     * Impact on hardware (will arch(s) / board(s) / driver(s) change)? NO. Only
       the sim:zipfs configuration changes.
     * Impact on documentation (is update required / provided)? YES. zipfs.rst 
is
       updated and has a new write mode section. file_permission.rst still lists
       zipfs among the file systems that report the execute permission for all
       files, which is no longer true. It is not changed here.
     * Impact on security (any sort of implications)? YES. libarchive is third
       party code that parses archives. Only the zip format is on by default, 
and
       the option for encrypted entries is off by default.
     * Impact on compatibility (backward/forward/interoperability)? YES. See the
       BREAKING CHANGE in the Summary. The mount command of zipfs is the same.
     * Anything else to consider or add? Each open file and each open directory 
of
       zipfs allocates a structure with a read buffer of FS_ZIPFS_BUFFER_SIZE
       bytes (32768 by default). This was not compared with the memory use of 
the
       minizip version.
   
   ## Testing
   
     I confirm that changes are verified on local setup and works as intended:
     * Build Host(s): Linux 7.0.0-34-generic x86_64, Intel i7-14700,
       gcc (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0, GNU Make 4.3, CMake 3.28.3,
       Ninja 1.11.1.
     * Target(s): sim:zipfs (sim:nsh for the size comparison). Real hardware was
       not tested.
     * The series and the nuttx-apps pull request were replayed on nuttx
       e9eefaa0e9a and nuttx-apps 72937e7f86f. The archive is made on the host 
with
       "zip -r test.zip a top.txt <a file with a UTF-8 name>" and mounted from 
the
       host through hostfs.
   
     Testing logs before change (nuttx master), NSH session as printed:
   
   <details><summary>before</summary>
   
   ```
   nsh> mount -t hostfs -o fs=/tmp/zh.XsVmlD/host /host
   nsh> mount -t zipfs -o /host/test.zip /zip
   nsh> echo ---ls-zip
   ---ls-zip
   nsh> ls /zip
   /zip:
    a/
    a/1
    a/2
    top.txt
    文件.txt
   nsh> echo ---cat-top
   ---cat-top
   nsh> cat /zip/top.txt
   top level file
   nsh> echo ---cat-a1
   ---cat-a1
   nsh> cat /zip/a/1
   this is zipfs test 1
   nsh> echo ---cat-utf8
   ---cat-utf8
   nsh> cat /zip/文件.txt
   utf8 name file
   nsh> echo ---ls-l-top
   ---ls-l-top
   nsh> ls -l /zip/top.txt
    -r-xr-xr-x          15 /zip/top.txt
   nsh> echo ---ls-l-a1
   ---ls-l-a1
   nsh> ls -l /zip/a/1
    -r-xr-xr-x          21 /zip/a/1
   nsh> echo ---ls-l-dir
   ---ls-l-dir
   nsh> ls -l /zip/a
   nsh: ls: stat failed: 2
   nsh> umount /zip
   nsh> echo done
   done
   nsh> poweroff
   ```
   
   </details>
   
     Testing logs after change (nuttx master and this series), NSH session as
     printed:
   
   <details><summary>after</summary>
   
   ```
   nsh> mount -t hostfs -o fs=/tmp/zh.XsVmlD/host /host
   nsh> mount -t zipfs -o /host/test.zip /zip
   nsh> echo ---ls-zip
   ---ls-zip
   nsh> ls /zip
   /zip:
    a/
    a/1
    a/2
    top.txt
    文件.txt
   nsh> echo ---cat-top
   ---cat-top
   nsh> cat /zip/top.txt
   top level file
   nsh> echo ---cat-a1
   ---cat-a1
   nsh> cat /zip/a/1
   this is zipfs test 1
   nsh> echo ---cat-utf8
   ---cat-utf8
   nsh> cat /zip/文件.txt
   utf8 name file
   nsh> echo ---ls-l-top
   ---ls-l-top
   nsh> ls -l /zip/top.txt
    -rw-rw-r--          15 2026-11-17 12:14 /zip/top.txt
   nsh> echo ---ls-l-a1
   ---ls-l-a1
   nsh> ls -l /zip/a/1
    -rw-rw-r--          21 2026-11-17 12:14 /zip/a/1
   nsh> echo ---ls-l-dir
   ---ls-l-dir
   nsh> ls -l /zip/a
   nsh: ls: stat failed: 2
   nsh> umount /zip
   nsh> echo done
   done
   nsh> poweroff
   ```
   
   </details>
   
     wzipfs: CONFIG_FS_ZIPFS_WRITE=y and CONFIG_FS_ZIPFS_WRITE_DEFLATE=y added 
to
     sim:zipfs, mounted with the default method=store. NSH session as printed, 
and
     the check of out.zip on the host:
   
   <details><summary>wzipfs</summary>
   
   ```
   nsh> mount -t hostfs -o fs=/tmp/zh.XsVmlD/host /host
   nsh> mount -t zipfs -o /host/test.zip /zip
   nsh> echo ---ls-zip
   ---ls-zip
   nsh> ls /zip
   /zip:
    a/
    a/1
    a/2
    top.txt
    文件.txt
   nsh> echo ---cat-top
   ---cat-top
   nsh> cat /zip/top.txt
   top level file
   nsh> echo ---cat-a1
   ---cat-a1
   nsh> cat /zip/a/1
   this is zipfs test 1
   nsh> echo ---cat-utf8
   ---cat-utf8
   nsh> cat /zip/文件.txt
   utf8 name file
   nsh> echo ---ls-l-top
   ---ls-l-top
   nsh> ls -l /zip/top.txt
    -rw-rw-r--          15 2026-11-17 12:14 /zip/top.txt
   nsh> echo ---ls-l-a1
   ---ls-l-a1
   nsh> ls -l /zip/a/1
    -rw-rw-r--          21 2026-11-17 12:14 /zip/a/1
   nsh> echo ---ls-l-dir
   ---ls-l-dir
   nsh> ls -l /zip/a
   nsh: ls: stat failed: 2
   nsh> umount /zip
   nsh> echo ---wzipfs
   ---wzipfs
   nsh> mount -t wzipfs -o src=/host/out.zip /w
   nsh> echo hello > /w/hello.txt
   nsh> mkdir /w/dir
   nsh> echo nested > /w/dir/n.txt
   nsh> umount /w
   nsh> echo ---w-done
   ---w-done
   nsh> echo done
   done
   nsh> poweroff
   ```
   
   ```
   Archive:  /tmp/zh.XsVmlD/host/out.zip
     Length      Date    Time    Name
   ---------  ---------- -----   ----
           6  2008-06-01 08:00   hello.txt
           0  2008-06-01 08:00   dir/
           7  2008-06-01 08:00   dir/n.txt
   ---------                     -------
          13                     3 files
   No errors detected in compressed data of /tmp/zh.XsVmlD/host/out.zip.
   hello.txt => [hello]
   dir/n.txt => [nested]
   ```
   
   </details>
   
     size(1) of nuttx, text/data/bss: sim:zipfs before 671812/2680/9344, after
     746168/2644/9376, after with wzipfs 789980/2644/9376. sim:nsh does not 
enable
     zipfs: 1247954/279696/196800 before (two builds) and after. sim:zipfs is
     covered by tools/ci/testlist/sim-03.dat (glob /sim/*/*/*/[o-z]*).
   
     CMake with Ninja builds sim:zipfs with the same series, and its nuttx 
binary
     mounts and reads the archive the same way.
   
     Not tested: real hardware, ostest, the protected and kernel builds, other
     architectures, every commit of the series built on its own, the FIFO, 
socket
     and fd= targets of wzipfs, an encrypted archive, and DEFLATE at run time.
     No regression test is added in this PR. "ls -l" of a directory of the 
archive
     fails before and after the change.
   
   ## PR verification Self-Check
   
     * [ ] This PR introduces only one functional change.
     * [x] I have updated all required description fields above.
     * [ ] My PR adheres to Contributing 
[Guidelines](https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md) and 
[Documentation](https://nuttx.apache.org/docs/latest/contributing/index.html) 
(git commit title and message, coding standard, etc).
     * [x] My PR is still work in progress (not ready for review).
     * [ ] My PR is ready for review and can be safely merged into a codebase.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to