A medium that is pulled while it is still mounted now gets the reference's
one-button "Disk Not Ejected" warning: Motif's error dialog, the device and
its stale mountpoint in the text, the Warning sound. The desktop (dtwm,
WmMcdeDesktop.c) owns the event descriptor already; it reads each event,
asks what it says, and checks the mount table before it shows anything.
McdeSys:
- mcde_sys_disk_event_info() parses both shapes the read gives: Linux's
uevent with its NULs turned into spaces ("remove@/... ACTION=remove
DEVNAME=sdb1 ...") and NetBSD's "device-detach sd0"; 1 when the device
went away, 0 for add/change/attach, -1 on bad arguments.
- mcde_sys_disk_detached(name, mountpoint, len): looks in the mount table
for a partition of NAME (sdb takes sdb1, sd0 takes sd0a), copies the
mountpoint and unmounts it the forced way -- "umount -l" on Linux,
"umount -f" on NetBSD (disk_linux.c, disk_netbsd.c) -- but never what the
computer runs from. 0 when nothing of NAME was mounted.
- test_disk_events.c: the uevent and drvctl shapes, add/change/attach,
missing DEVNAME, the bad arguments. make check: 8/8 PASS (the seven
before and this one).
Measured under Xvfb :79 with a real ext4 loop mount at /tmp/opencode/mnt:
- start of dtwm with MCDE_DESK_TEST_DEVICE="remove@/... DEVNAME=loop0":
log "desktop: loop0 (remove)", "umount: /tmp/opencode/mnt: must be
superuser to unmount.", "desktop: loop0 was mounted at
/tmp/opencode/mnt"; the dialog is 354x167 at (335,300), OK as the only
button (docs/screenshots/leopard/Device-Removal-mcde.png).
- sudo umount /tmp/opencode/mnt, the same event again: log "desktop: loop0
(remove)" and no "was mounted"; zero dialog windows -- a device that was
put away stays quiet.
- make mcde-linux MCDE_DIRS="install lib/McdeSys programs/dtwm" exit=0;
MCDE_DIRS=plist "mcde-plist-check: ok".
MCDE_DESK_TEST_DEVICE is the test hook: one event line through the same
handler a real event takes, without a kernel. The NetBSD drvctl branch is
unchanged (t0272); the force unmount there is written for it but was not
run. Still open in t0093: the Eject item in dtfile (Selected menu,
Command+E) and the qemu device_del test in a VM.
83 lines
2.8 KiB
C
83 lines
2.8 KiB
C
/*
|
|
* test_disk_events.c -- McdeSys: the device event line (make check)
|
|
*
|
|
* License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
|
|
*
|
|
* mcde_sys_disk_event_info() is what the desktop asks about an event that
|
|
* mcde_sys_disk_event_read() returned: Linux's uevent text with its NULs
|
|
* turned into spaces ("remove@/... ACTION=remove ... DEVNAME=sdb1 ...") and
|
|
* NetBSD's "device-detach sd0". The parser is what decides whether the
|
|
* removal warning (t0093) is looked at, so the cases here are the real
|
|
* shapes of both systems and the ones a wrong answer would hurt: an add is
|
|
* no removal, a change is none either, a missing DEVNAME leaves it empty,
|
|
* and bad arguments are refused.
|
|
*/
|
|
|
|
#define _POSIX_C_SOURCE 200809L
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include <Mcde/McdeSys.h>
|
|
|
|
static int failures;
|
|
|
|
#define CHECK(cond) do { \
|
|
if (!(cond)) { \
|
|
printf("FAIL %s:%d: %s\n", __FILE__, __LINE__, #cond); \
|
|
failures++; \
|
|
} \
|
|
} while (0)
|
|
|
|
static void
|
|
one(const char *event, int want, const char *wantAction,
|
|
const char *wantDevice)
|
|
{
|
|
char action[32] = "?", device[64] = "?";
|
|
int r = mcde_sys_disk_event_info(event, action, sizeof action, device,
|
|
sizeof device);
|
|
|
|
CHECK(r == want);
|
|
CHECK(strcmp(action, wantAction) == 0);
|
|
CHECK(strcmp(device, wantDevice) == 0);
|
|
if (r != want || strcmp(action, wantAction) != 0 ||
|
|
strcmp(device, wantDevice) != 0)
|
|
printf(" event [%s]: got %d [%s] [%s]\n", event, r, action,
|
|
device);
|
|
}
|
|
|
|
int
|
|
main(void)
|
|
{
|
|
one("remove@/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0/"
|
|
"host8/target8:0:0/8:0:0:0/block/sdb/sdb1 ACTION=remove "
|
|
"DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0/"
|
|
"host8/target8:0:0/8:0:0:0/block/sdb/sdb1 SUBSYSTEM=block "
|
|
"DEVNAME=sdb1 DEVTYPE=partition SEQNUM=4711",
|
|
1, "remove", "sdb1");
|
|
one("add@/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0/host8/"
|
|
"target8:0:0/8:0:0:0/block/sdb/sdb1 ACTION=add "
|
|
"DEVNAME=sdb1 DEVTYPE=partition", 0, "add", "sdb1");
|
|
one("change@/devices/virtual/block/dm-0 ACTION=change "
|
|
"DEVPATH=/devices/virtual/block/dm-0 SUBSYSTEM=block",
|
|
0, "change", "");
|
|
one("device-detach sd0", 1, "detach", "sd0");
|
|
one("device-attach sd0", 0, "attach", "sd0");
|
|
one("device-detach", 1, "detach", "");
|
|
one("", 0, "", "");
|
|
CHECK(mcde_sys_disk_event_info(NULL, NULL, 0, NULL, 0) == -1);
|
|
CHECK(mcde_sys_disk_event_info("ACTION=remove", NULL, 0, NULL, 0) ==
|
|
-1);
|
|
{
|
|
char action[8], device[8];
|
|
|
|
CHECK(mcde_sys_disk_event_info("ACTION=remove DEVNAME=sdb1",
|
|
action, 0, device, sizeof device) == -1);
|
|
CHECK(mcde_sys_disk_event_info("ACTION=remove DEVNAME=sdb1",
|
|
action, sizeof action, device, 0) == -1);
|
|
}
|
|
if (failures == 0)
|
|
printf("test_disk_events: all passed\n");
|
|
return failures != 0;
|
|
}
|