XuNeo opened a new pull request, #20460:
URL: https://github.com/apache/nuttx/pull/20460

   ## Summary
   
   Procfs text readers currently need to handle `f_pos`, receive buffer length, 
and intermediate line buffers themselves. This duplicates the same offset and 
copy logic in each node and makes short reads easy to get wrong.
   
   For example
   [#20256](https://github.com/apache/nuttx/pull/20256)
   [#20326](https://github.com/apache/nuttx/pull/20326).
   
   Add `procfs_format_read()`, which lets a procfs node render its completetext 
through a generic output stream. The helper skips bytes before the current file 
position, copies the requested window, advances `f_pos` by the copied size, and 
handles EOF and deferred errors.
   
   Also add `procfs_format_done()` so renderers can stop once the current read 
window is complete.
   
   Migrate `/proc/uptime` as the first user. It keeps the existing behavior of 
sampling uptime on the first read and reusing that sample during subsequent 
partial reads, while removing the per-open line buffer and manual 
`procfs_snprintf()` / `procfs_memcpy()` accounting.
   
   The helper separates text formatting from read-window handling. It centrally 
manages offsets, copies, and EOF, and eliminates the need for additional 
buffer, while each node only renders its complete text.
   
   ## Impact
   
   Only `/proc/uptime` is migrated in this PR. Its output format and
   first-read snapshot behavior are unchanged.
   
   Follow up PRs are needed to migrate most of the procfs nodes once this one 
is accepted.
   
   ## Testing
   
   Host: Ubuntu 22.04.5 x86_64
   
   Board: `sim:nsh`
   Built with CMake and Ninja.
   
   
   Test log:
   ```
   cmake -B build -G Ninja -DBOARD_CONFIG=sim:nsh 
-DNUTTX_APPS_DIR=/home/neo/projects/nuttx/apps
   -- nuttx_add_subdirectory: Skipping cxx-oot-build
   n-- Initializing NuttX
     Select HOST_LINUX=y
     Select HOST_X86_64=y
   inja -C buildLoaded configuration 
'/home/neo/tmp/ws/procfs-format-helper-pr/build/.config.compressed'
   Minimal configuration saved to 
'/home/neo/tmp/ws/procfs-format-helper-pr/build/defconfig.tmp'
   --   CMake:  3.22.1
   --   Ninja:  1.10.1
   --   Board:  sim
   --   Config: nsh
   --   Appdir: /home/neo/projects/nuttx/apps
   -- The C compiler identification is GNU 13.4.0
   -- Detecting C compiler ABI info
   -- Detecting C compiler ABI info - done
   -- Check for working C compiler: /usr/bin/cc - skipped
   -- Detecting C compile features
   -- Detecting C compile features - done
   -- NuttX Host Tools
   -- CMake C compiler: GNU
   -- CMake system name: Linux
   -- CMake host system processor: x86_64
   -- Configuring done
      TOOLS_DIR path is "/home/neo/tmp/ws/procfs-format-helper-pr"
      HOST = Linux
   -- Generating done
   -- Build files have been written to: 
/home/neo/tmp/ws/procfs-format-helper-pr/build/bin_host
   -- The C compiler identification is GNU 13.4.0
   -- The CXX compiler identification is GNU 13.4.0
   -- The ASM compiler identification is GNU
   -- Found assembler: /usr/bin/cc
   -- Detecting C compiler ABI info
   -- Detecting C compiler ABI info - done
   -- Check for working C compiler: /usr/bin/cc - skipped
   -- Detecting C compile features
   -- Detecting C compile features - done
   -- Detecting CXX compiler ABI info
   -- Detecting CXX compiler ABI info - done
   -- Check for working CXX compiler: /usr/bin/c++ - skipped
   -- Detecting CXX compile features
   -- Detecting CXX compile features - done
   -- nuttx_add_subdirectory: Skipping cxx-oot-build
   -- Configuring done
   -- Generating done
   -- Build files have been written to: 
/home/neo/tmp/ws/procfs-format-helper-pr/build
   
   ~/tmp/ws/procfs-format-helper-pr git:(b73726ac01f) ninja -C build
   
   ninja: Entering directory `build'
   [1248/1248] Pac SIM with dynamic libs in nuttx.tgz
   '/lib/x86_64-linux-gnu/libz.so.1' -> 'sim-pac/libs/libz.so.1'
   '/lib/x86_64-linux-gnu/libc.so.6' -> 'sim-pac/libs/libc.so.6'
   '/lib64/ld-linux-x86-64.so.2' -> 'sim-pac/ld-linux-x86-64.so.2'
   
   ./build/nuttx
   nsh> cat /proc/uptime
         2.90
   nsh> poweroff
   ```
   


-- 
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