S025: own MTP/PTP client over nusb with replay transport

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
astar76 2026-11-18 14:49:52 -06:00
commit c26c890ac4

View file

@ -99,5 +99,14 @@ One entry per session, newest last, ≤ 15 lines: done, verified how, not done,
- Not done: mouse back/forward buttons not exercised (winit only; no live window). Tab and section motion not watched (software renderer ignores `transform-*`; screenshots are single frames). Completion list delivery needs the event loop (logic and list checked separately). A closed tab vanishes at once; the others slide over.
- Later: tab bar scrolling past the minimum width; drag-reorder bookmarks in the sidebar; per-place glyph on tabs (Music shows a plain folder); Backspace to go up.
## S025 — MTP protocol over nusb
- Done: `tunal_devices::mtp` (D-007, nusb 0.2, jiff for dates). `Transport` trait (`max_packet_size`, `send` one bulk-out transfer / empty = ZLP, `receive(max)` one bulk-in transfer, `event(timeout)`); `UsbTransport::open(&DeviceInfo)` (interface 6/1/1 or vendor 0xFF named "MTP", `detach_and_claim_interface`, clears halt on stall, 10 s per transfer), `devices()`, `mtp_interface()`. `Container`/`Header`/`Kind`, `Writer`/`Reader` (ints, arrays, PTP strings, dates, `Value` by data type), `parse_date` (local, `Z`, `±hhmm`) / `format_date` (local).
- `Session<T>`: `new`, `open(id) -> &DeviceInfo` (takes over SessionAlreadyOpen), `close`, `supports(op)`, `event`, `request`, `request_data`, `transaction(op, params, DataOut::{None, Bytes, Stream(reader, len)}, Option<sink>)` (tid 0 outside a session, 1.. inside; header travels with the first 256 KiB chunk; host ZLP after aligned data; skips empty transfers before a container; bytes past a data phase kept for the next container (devices without ZLP); >4 GiB `0xFFFFFFFF` length read to the short transfer; a failing sink drains the phase so the session stays in step).
- Ops: `device_info`, `storage_ids`, `storage_info`, `object_handles(storage, parent)`, `object_info`, `object(h)` (64-bit size via ObjectSize when needed), `list(storage, parent) -> Vec<Object { handle, storage_id, parent, format, name, size, modified }>` (one GetObjectPropList depth 1 for folders when supported, else ObjectInfo per handle; top of storage always ObjectInfo), `object_prop_list`, `prop_value`, `get_object(h, &mut Write)`, `get_partial_object(h, offset, len, &mut Write)` (0x95C1 if offered, else 32-bit), `send_object_info(storage, parent, &NewObject { name, size, modified, folder }) -> (storage, parent, handle)`, `send_object(&mut Read, len)`, `delete_object`, `move_object`, `copy_object`, `rename`. `code::*` constants, `Error::{NoInterface, Usb, Disconnected, Timeout, Protocol, Response(u16), Io}`, `code::response_name`. Parent `code::ROOT` = top of storage.
- `ReplayTransport::new(packet, Vec<Step::{Out(container), In { data, zlp }}>)` + `finished()`; example `mtp_replay <scratch dir>` (script bytes built by hand, not by the crate).
- Verified: workspace build; clippy -D warnings and fmt --check for `tunal-devices`; example: open, device/storage info, list root (ObjectInfo) and folder (prop list without ZLP, read-ahead path), 512 KiB download with its ZLP in a transfer of its own (bytes match), range read, packet-aligned 300 KB upload streamed from a file (host ZLP checked), rename, move, copy, error 0x2009 → `Response`, close, script finished; dates checked in local time (CST). `devices()` on this PC: 0.
- Not done: no real device (S036). Workspace-wide clippy/fmt currently fail only in S011's in-progress `crates/tunal/src/{smoke,actions,jobs_bridge}.rs`. Events only decoded, not acted on. I touched `crates/tunal-devices/src/lib.rs` (one `pub mod mtp;` line) and added `examples/`, outside `src/mtp/**`.
- Later: MTP class Cancel request (0x64) for aborting a running transfer; GetObjectPropsSupported checks; event-driven refresh (ObjectAdded/Removed) in S026.
## Later
-