fix(linux): O_DIRECT fallback for dd on incompatible SD card readers

Some USB SD card readers don't support O_DIRECT, causing dd to fail
immediately with EINVAL. Now tries O_DIRECT first and falls back to
normal write if dd exits within 1 second.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Douglas Teles
2026-03-02 11:44:28 -03:00
parent 14e704bfab
commit 3f1e03b7be
3 changed files with 11 additions and 4 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "archr-flasher"
version = "0.1.4"
version = "0.1.5"
description = "Arch R SD Card Flasher"
authors = ["Arch R Linux"]
edition = "2021"
+9 -2
View File
@@ -261,9 +261,16 @@ for part in "${DEVICE}"*; do
|| true
done
# Write raw image with O_DIRECT (bypasses page cache, like RPi Imager)
dd if="$IMAGE" of="$DEVICE" bs=4M oflag=direct conv=fsync status=none &
# Write raw image — try O_DIRECT first (bypasses page cache, like RPi Imager),
# fall back to normal write if device doesn't support it (EINVAL on some readers)
dd if="$IMAGE" of="$DEVICE" bs=4M oflag=direct conv=fsync status=none 2>/dev/null &
DD_PID=$!
sleep 1
if ! kill -0 $DD_PID 2>/dev/null; then
# dd with O_DIRECT exited immediately — retry without it
dd if="$IMAGE" of="$DEVICE" bs=4M conv=fsync status=none &
DD_PID=$!
fi
# Monitor dd progress via /proc/fdinfo
while kill -0 $DD_PID 2>/dev/null; do
+1 -1
View File
@@ -1,7 +1,7 @@
{
"$schema": "https://raw.githubusercontent.com/tauri-apps/tauri/dev/crates/tauri-config-schema/schema.json",
"productName": "Arch R Flasher",
"version": "0.1.4",
"version": "0.1.5",
"identifier": "com.archr.flasher",
"build": {
"frontendDist": "../src",