33 lines
2.1 KiB
Plaintext
33 lines
2.1 KiB
Plaintext
devpubd(8) and media change -- what the tree says (t0083)
|
|
Source: src/sbin/devpubd/devpubd.8, devpubd.c, hooks/02-wedgenames;
|
|
src/sys/dev/scsipi/cd.c. Read 2026-11-14.
|
|
|
|
1. What devpubd does (devpubd.8): "listens on drvctl(4) for new devices and
|
|
creates their device nodes using MAKEDEV(8) if they are missing." It runs
|
|
/libexec/devpubd-run-hooks, which "runs each script found in
|
|
/libexec/devpubd-hooks in a lexical order with two arguments: device-attach
|
|
or device-detach and the device file name." "Additional scripts may be added
|
|
for other dynamic device actions." The events are named in devpubd.c:67-68
|
|
(DEVPUBD_ATTACH_EVENT "device-attach", DEVPUBD_DETACH_EVENT "device-detach").
|
|
2. So a hook sees a DEVICE appear or go: a USB stick (sd0 attaches, then its
|
|
wedges dk0.. through 02-wedgenames, which keeps symlinks in /dev/wedges).
|
|
That is the event for "a stick was plugged in".
|
|
3. A MEDIUM put into a drive that stays is not a device event: cd.c has no
|
|
event for it -- the only media-change code in src/sys/dev/scsipi/cd.c is the
|
|
flag XS_CTL_IGNORE_MEDIA_CHANGE on its own commands (lines 411, 433, 469,
|
|
1380). An optical disc in cd0 therefore has to be found by asking the
|
|
drive. The frugal rule (ext/src/mcde/AGENTS.md; Konrad: no polling in the
|
|
second range) gives: one small probe of the drive every few seconds, only
|
|
for drives that exist, and none while a medium is known to be in.
|
|
Candidate probe: reading one block of /dev/rcd0d (fails with "not ready"
|
|
without a medium); to be measured in a VM (the VM is gone since 2026-11-14,
|
|
tools/devvm.sh makes one again).
|
|
4. What the design needs, in this order (t0083):
|
|
- a hook script in /libexec/devpubd-hooks for sticks (attach -> look at the
|
|
wedge, mount read-only below /media/<label>, tell the desktop);
|
|
- a small program for optical drives (poll as above), the same code path
|
|
after the medium is seen;
|
|
- type of the medium: the volume label of ISO 9660 (sysinst get_iso9660_
|
|
volname), VIDEO_TS for a video DVD, the file system for the rest;
|
|
- McdeSys media backend (lib/McdeSys/media.c), NetBSD first.
|