casaroli opened a new pull request, #3952:
URL: https://github.com/apache/nuttx-apps/pull/3952

   ## Summary
   
   The NXInit documentation lists `mount` and `umount` as built-in commands, 
but NXInit did not have them. A `mount` line ran the NSH command through `sh 
-c`, which needs NSH and has the NSH syntax.
   
   This PR adds the two commands with the syntax of the Android init language:
   
       mount <type> <device> <dir> [<flag>]* [<options>]
       umount <dir>
   
   The flags are `defaults`, `rw`, `ro`, `nosuid`, `nodev`, `noexec`, `sync`, 
`remount`, `dirsync` and `noatime`. A last argument that is not a flag is the 
option string of the file system (the `data` argument of `mount()`). For a file 
system without a device (tmpfs, procfs), `<device>` is any name that is not a 
device, for example `none`. As for the other commands, a failure sets the 
result that `&&` and `||` test. A `mount` line in another form, for example 
`mount -t tmpfs /tmp` in the sim `init.rc`, runs through `sh -c` as before. The 
PR also adds the unit test case `test_nxinit_action_builtin_mount`.
   
   
   ## Impact
   
   Two new built-in commands of NXInit (`system/nxinit/builtin.c`). With 
`CONFIG_DISABLE_MOUNTPOINT` they are not built. An `init.rc` without a `mount` 
or `umount` line in the new form does not change. `mount()` and `umount()` are 
system calls, so the commands are the same in flat, protected and kernel builds.
   
   ## Testing
   
   All tests with NuttX master 5c441693fa8 and nuttx-apps master d40132fba 
(2026-11-01), with this PR rebased on it.
   
   The NXInit unit tests (`CONFIG_SYSTEM_NXINIT_TEST`, cmocka) on 
qemu-armv8a:nsh (flat, QEMU with HVF). The new case mounts a tmpfs with 
`noexec`, checks `statfs()` and that a file made with mode 0755 has no execute 
permission, unmounts it, and expects `-EINVAL` for an unknown flag:
   
   | | apps master + the new test case | this PR |
   |---|---|---|
   | `test_nxinit_action_builtin_mount` | FAILED (`12 != 0`: the line went to 
`sh -c`) | OK |
   | all cases | 21 of 22 passed | 22 of 22 passed |
   
   Test program `nxinitmnt.c` on qemu-armv8a:knsh (kernel, QEMU with HVF), with 
NXInit as the program `nxinit` 
(`CONFIG_SYSTEM_NXINIT_RC_FILE_PATH=/system/hb-init.rc`) and `CONFIG_FS_TMPFS`. 
The program writes an `init.rc` with one `on boot` action, runs NXInit for 3 s, 
then checks each mount point with `statfs()`:
   
   | `init.rc` line | apps master | this PR |
   |---|---|---|
   | `mount tmpfs none /hbmnt1` | not mounted | tmpfs |
   | `mount tmpfs none /hbmnt2 ro nosuid`, `umount /hbmnt2` | not mounted | not 
mounted |
   | `mount tmpfs none /hbmnt4 bogus size=1` | not mounted | not mounted 
(`unknown flag 'bogus'`) |
   | `mount tmpfs none /hbmnt5 noexec` | not mounted | tmpfs, a 0755 file shows 
mode 0666 (0777 in /hbmnt1) |
   | `mount tmpfs none /hbmnt6 nosuid size=1` | not mounted | tmpfs |
   | `mount -t tmpfs /hbmnt3` (NSH form) | tmpfs | tmpfs |
   | result | FAIL (3 of 6 cases) | PASS |
   
   qemu-armv8a:nsh (flat), where NXInit is the init, with a test `init.rc` that 
has `mount tmpfs none /hbmnt1`, `mount tmpfs none /hbmnt2 nosuid`, `umount 
/hbmnt2` and `mount -t tmpfs /hbmnt3` under `on init`: on apps master NSH 
prints `mount: too many arguments` twice and `umount failed: 2`, and only 
/hbmnt3 is mounted. With this PR /hbmnt1 and /hbmnt3 are mounted, /hbmnt2 is 
not, and there is no error.
   
   ostest exits with status 0 on qemu-armv8a:knsh and qemu-armv8a:nsh, before 
and after.
   
   Build with `CONFIG_SYSTEM_NXINIT`, each OK and with no new warning: 
qemu-armv8a:knsh (kernel, arm64), rv-virt:knsh64 (kernel, rv64), 
mps2-an500:knsh (protected, armv7-m), rv-virt:pnsh64 (protected, rv64), 
qemu-armv8a:nsh (flat, arm64; also with `CONFIG_DISABLE_MOUNTPOINT`), and 
qemu-armv8a:nsh with CMake and `CONFIG_SYSTEM_NXINIT_TEST`.
   
   `tools/checkpatch.sh -c -u -m -g` passes.
   


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