Skip to content

Support for writing files - #27

Closed
FadyAckad wants to merge 5 commits into
linux-msm:mainfrom
FadyAckad:sp11-sensors
Closed

FadyAckad wants to merge 5 commits into
linux-msm:mainfrom
FadyAckad:sp11-sensors

Conversation

@FadyAckad

Copy link
Copy Markdown

Implements the write side of apps_std/hexagonfs so the Snapdragon Sensor Core can
initialise its registry, which is what #19 is blocked on. Unlike the stubs in #21,
the writes actually reach the files, so what the framework persists — its parsed
registry, calibration — survives a restart.

The work is split as:

  • hexagonfs: create, write, truncate, unlink and rename for mapped directories.
    Virtual and read-only backends keep returning ENOSYS.
  • apps_std: serve fopen, fwrite, fsync, fremove, ftrunc and frename (ids per
    quic/fastrpc inc/apps_std.h; ids above 30 travel in the first primitive word).
  • listener: answer unsupported requests with an error and empty output buffers
    instead of ending the session, and fetch input buffers longer than the 256 bytes
    adsp_listener_next2 inlines, via adsp_listener_get_in_bufs2.
  • rpcd_builder: when DIR/sensors/persist/registry exists, back the whole of
    /persist/sensors/registry with it; otherwise the tree is unchanged.
  • A final commit fixing bugs found reviewing the above, including two that predate
    this branch and reproduce on main: fastrpc_apps_std_deinit freeing the root
    descriptor before its descendants, and outbufs_calculate_size padding
    zero-length buffers that outbufs_encode never writes.

Open question: how much of the tree should be writable

The write ops are on the shared mapped ops tables, so they reach every mapped
directory, not just the registry — including DIR/dsp/<dsp> and DIR/acdb. Nothing
can be written today because hexagonrpcd runs as fastrpc against a root-owned
/usr/share/qcom, but making the registry writable to that user is precisely what
this feature needs, and that exposes the rest of the tree at the same time.

This is the same concern raised in #21 about a mutable hexagonrpc. Options seem to be
a separate read-write ops table used only by the registry mapping, or the copy-to-
/var/lib/hexagonrpc idea from that thread. I'd rather settle it here than after it
ships — opinions welcome.

Testing

Developed against X1E80100, where refusing the first write made the firmware assert
in sns_registry_sensor.c and take the ADSP down. #19 is Milos (SM7635), which I
haven't tested — confirmation there would be valuable before merging.

Fixes are covered by the existing suite plus targeted checks; ninja test passes.

…directories

The Snapdragon Sensor Core's registry service does not only read its registry: while it initialises it removes and rewrites entries, writes a temporary file next to the registry directory and renames it into place. Give hexagonfs the write side of its API for physically mapped directories (create/open for writing with O_TRUNC or O_APPEND, write, ftruncate, unlink, rename across mapped directories) and report S_IWUSR in stat so the framework sees writable files. Virtual directories and the read-only backends keep returning ENOSYS, so a tree that maps read-only system files (/usr/share/qcom) stays untouched: the writable directory is whatever the daemon is pointed at with -R.

Link: linux-msm#19
Signed-off-by: Fady <me@fadyackad.dev>
Implement the apps_std methods the sensor framework's registry initialisation calls (ids as in quic/fastrpc inc/apps_std.h: fopen 0, fwrite 5, fsync 23, fremove 24, ftrunc 32, frename 33; ids above 30 travel in the first primitive word), open w/a/+ modes read-write, and let fopen_with_env open an absolute name whatever search variable the DSP names. Refusing the first write (fremove, then fopen of the DIR marker for writing) made the X1E80100 firmware assert in sns_registry_sensor.c and take the whole ADSP down. Unlike the stubs proposed in pull request 21, the writes reach the files, so what the framework persists (its parsed registry, calibration) is there at the next start.

Link: linux-msm#19
Link: linux-msm#21
Signed-off-by: Fady <me@fadyackad.dev>
…than 256 bytes

A request the server cannot serve is answered with AEE_EUNSUPPORTED/AEE_EBADPARM and empty output buffers instead of ending the session, so the DSP sees a failed call rather than a vanished listener. Requests whose input buffers exceed the 256 bytes adsp_listener_next2 inlines (the framework writing its secure database in one call) are completed with adsp_listener_get_in_bufs2 from offset 256, as Qualcomm's listener_android.c does; the method's definition follows quic/fastrpc inc/adsp_listener.h (index 5).

Link: linux-msm#19
Signed-off-by: Fady <me@fadyackad.dev>
…rsist exists

The framework writes /persist/sensors/registry/fstempfile and renames it into /persist/sensors/registry/registry, and it looks for sns_reg_version and parsed_file_list.csv next to the registry directory (it creates sns_reg_version through that temporary file when the file is missing). With DIR/sensors/persist/ present that directory backs the whole of /persist/sensors/registry, its registry/ subdirectory being the registry; without it the tree is as before.

Link: linux-msm#19
Link: linux-msm#21
Signed-off-by: Fady <me@fadyackad.dev>
…he registry

hexagonfs_openat hands out a second file number when a name's directory part resolves to an already-assigned descriptor (".", "..", "/"), so the close in create/unlink/rename freed one still held elsewhere; hexagonfs_close now destroys only on the last reference, and fastrpc_apps_std_deinit closes descendants before the root. mapped_or_empty pointed write and truncate at implementations that dereference a NULL context for an absent directory. outbufs_calculate_size padded zero-length buffers outbufs_encode never writes, and alloc_outbufs4 did not skip the method id extended methods carry in the first primitive word. A '+' mode no longer implies O_CREAT and falls back to a read-only open on an unwritable tree, stat reports the write bit only when the backing file has it, mapped writes loop until done, and the persist layout is probed at DIR/sensors/persist/registry rather than its parent.

Signed-off-by: Fady <me@fadyackad.dev>
@FadyAckad
FadyAckad marked this pull request as ready for review September 21, 2026 10:24
@FadyAckad FadyAckad closed this Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant