Implement SD card autodetection, automount, and GUI/dmenu mounter

- Enable GPIO 38 active-low card detect (cd-gpios) with bias-pull-up on
  sdhci@7864000 across all MSM8905/MSM8909 device trees and DTBs
- Add sxmo_sdcard.sh and 88-bananarchy-sdcard.rules udev rules for
  automatic mounting at /media/sdcard on insertion and cleanup on
  removal
- Integrate SD card mount, unmount/eject, and navigation into the GUI
  File Manager (files.so) and built-in dmenu SD Card menu (@menu:sdcard)
This commit is contained in:
Luxferre committed 2026-10-29 21:02:51 +02:00
1 parent 370f8b085c
commit 32d5d2f2b4
26 files changed
+530 -24

No files matched your search

Binary file not shown.
@@ -945,6 +945,22 @@
phandle = <0x4f>;
};
sdc2-cd-on-state {
pins = "gpio38";
function = "gpio";
drive-strength = <0x02>;
bias-pull-up;
phandle = <0x90>;
};
sdc2-cd-off-state {
pins = "gpio38";
function = "gpio";
drive-strength = <0x02>;
bias-disable;
phandle = <0x91>;
};
wcnss-active-state {
pins = "gpio40", "gpio41", "gpio42", "gpio43", "gpio44";
function = "wcss_wlan";
@@ -1524,13 +1540,13 @@
clocks = <0x14 0x82 0x14 0x81 0x18>;
clock-names = "core", "iface", "xo";
pinctrl-names = "default", "sleep";
pinctrl-0 = <0x4a 0x4b 0x4c>;
pinctrl-1 = <0x4d 0x4e 0x4f>;
pinctrl-0 = <0x4a 0x4b 0x4c 0x90>;
pinctrl-1 = <0x4d 0x4e 0x4f 0x91>;
bus-width = <0x04>;
status = "okay";
vmmc-supply = <0x50>;
vqmmc-supply = <0x51>;
non-removable;
cd-gpios = <0x27 0x26 0x01>;
};
dma-controller@7884000 {
Binary file not shown.
@@ -945,6 +945,22 @@
phandle = <0x4f>;
};
sdc2-cd-on-state {
pins = "gpio38";
function = "gpio";
drive-strength = <0x02>;
bias-pull-up;
phandle = <0x90>;
};
sdc2-cd-off-state {
pins = "gpio38";
function = "gpio";
drive-strength = <0x02>;
bias-disable;
phandle = <0x91>;
};
wcnss-active-state {
pins = "gpio40", "gpio41", "gpio42", "gpio43", "gpio44";
function = "wcss_wlan";
@@ -1578,13 +1594,13 @@
clocks = <0x14 0x82 0x14 0x81 0x18>;
clock-names = "core", "iface", "xo";
pinctrl-names = "default", "sleep";
pinctrl-0 = <0x4a 0x4b 0x4c>;
pinctrl-1 = <0x4d 0x4e 0x4f>;
pinctrl-0 = <0x4a 0x4b 0x4c 0x90>;
pinctrl-1 = <0x4d 0x4e 0x4f 0x91>;
bus-width = <0x04>;
status = "okay";
vmmc-supply = <0x50>;
vqmmc-supply = <0x51>;
non-removable;
cd-gpios = <0x27 0x26 0x01>;
};
dma-controller@7884000 {
Binary file not shown.
@@ -949,6 +949,22 @@
phandle = <0x43>;
};
sdc2-cd-on-state {
pins = "gpio38";
function = "gpio";
drive-strength = <0x02>;
bias-pull-up;
phandle = <0x90>;
};
sdc2-cd-off-state {
pins = "gpio38";
function = "gpio";
drive-strength = <0x02>;
bias-disable;
phandle = <0x91>;
};
wcnss-active-state {
pins = "gpio40", "gpio41", "gpio42", "gpio43", "gpio44";
function = "wcss_wlan";
@@ -1250,13 +1266,13 @@
clocks = <0x14 0x82 0x14 0x81 0x18>;
clock-names = "core", "iface", "xo";
pinctrl-names = "default", "sleep";
pinctrl-0 = <0x3e 0x3f 0x40>;
pinctrl-1 = <0x41 0x42 0x43>;
pinctrl-0 = <0x3e 0x3f 0x40 0x90>;
pinctrl-1 = <0x41 0x42 0x43 0x91>;
bus-width = <0x04>;
status = "okay";
vmmc-supply = <0x44>;
vqmmc-supply = <0x45>;
non-removable;
cd-gpios = <0x27 0x26 0x01>;
};
dma-controller@7884000 {
@@ -949,6 +949,22 @@
phandle = <0x43>;
};
sdc2-cd-on-state {
pins = "gpio38";
function = "gpio";
drive-strength = <0x02>;
bias-pull-up;
phandle = <0x90>;
};
sdc2-cd-off-state {
pins = "gpio38";
function = "gpio";
drive-strength = <0x02>;
bias-disable;
phandle = <0x91>;
};
wcnss-active-state {
pins = "gpio40", "gpio41", "gpio42", "gpio43", "gpio44";
function = "wcss_wlan";
@@ -1250,13 +1266,13 @@
clocks = <0x14 0x82 0x14 0x81 0x18>;
clock-names = "core", "iface", "xo";
pinctrl-names = "default", "sleep";
pinctrl-0 = <0x3e 0x3f 0x40>;
pinctrl-1 = <0x41 0x42 0x43>;
pinctrl-0 = <0x3e 0x3f 0x40 0x90>;
pinctrl-1 = <0x41 0x42 0x43 0x91>;
bus-width = <0x04>;
status = "okay";
vmmc-supply = <0x44>;
vqmmc-supply = <0x45>;
non-removable;
cd-gpios = <0x27 0x26 0x01>;
};
dma-controller@7884000 {
Binary file not shown.
@@ -945,6 +945,22 @@
phandle = <0x4f>;
};
sdc2-cd-on-state {
pins = "gpio38";
function = "gpio";
drive-strength = <0x02>;
bias-pull-up;
phandle = <0x90>;
};
sdc2-cd-off-state {
pins = "gpio38";
function = "gpio";
drive-strength = <0x02>;
bias-disable;
phandle = <0x91>;
};
wcnss-active-state {
pins = "gpio40", "gpio41", "gpio42", "gpio43", "gpio44";
function = "wcss_wlan";
@@ -1578,13 +1594,13 @@
clocks = <0x14 0x82 0x14 0x81 0x18>;
clock-names = "core", "iface", "xo";
pinctrl-names = "default", "sleep";
pinctrl-0 = <0x4a 0x4b 0x4c>;
pinctrl-1 = <0x4d 0x4e 0x4f>;
pinctrl-0 = <0x4a 0x4b 0x4c 0x90>;
pinctrl-1 = <0x4d 0x4e 0x4f 0x91>;
bus-width = <0x04>;
status = "okay";
vmmc-supply = <0x50>;
vqmmc-supply = <0x51>;
non-removable;
cd-gpios = <0x27 0x26 0x01>;
};
dma-controller@7884000 {
+2
View File
@@ -35,6 +35,8 @@ permit nopass :wheel as root cmd tee args /sys/module/leds_msm8905_torch/paramet
permit nopass :wheel as root cmd /usr/bin/tee args /sys/module/leds_msm8905_torch/parameters/next_reboot_mode
permit nopass :wheel as root cmd /usr/bin/sxmo_power.sh
permit nopass :wheel as root cmd sxmo_power.sh
permit nopass :wheel as root cmd /usr/bin/sxmo_sdcard.sh
permit nopass :wheel as root cmd sxmo_sdcard.sh
permit nopass :wheel as root cmd /usr/bin/plymouth args quit
permit nopass :wheel as root cmd plymouth args quit
permit nopass :wheel as root cmd rc-service args hexagonrpcd-adsp-sensorspd stop
@@ -12,3 +12,8 @@ fi
{ echo 3000 > /proc/sys/vm/dirty_expire_centisecs; } 2>/dev/null || true
{ echo "1 4 1 4" > /proc/sys/kernel/printk; } 2>/dev/null || true
# Automount microSD card if present at boot
if [ -x /usr/bin/sxmo_sdcard.sh ]; then
/usr/bin/sxmo_sdcard.sh automount boot >/dev/null 2>&1 &
fi
@@ -0,0 +1,4 @@
# Automatically mount and unmount removable microSD cards (mmcblk1) at /media/sdcard
SUBSYSTEM=="block", KERNEL=="mmcblk1p[1-9]*", ACTION=="add", RUN+="/usr/bin/sxmo_sdcard.sh automount add %k"
SUBSYSTEM=="block", KERNEL=="mmcblk1", ATTR{partition}!="1", ENV{ID_FS_USAGE}=="filesystem", ACTION=="add", RUN+="/usr/bin/sxmo_sdcard.sh automount add %k"
SUBSYSTEM=="block", KERNEL=="mmcblk1*", ACTION=="remove", RUN+="/usr/bin/sxmo_sdcard.sh automount remove %k"
+322
View File
@@ -0,0 +1,322 @@
#!/bin/sh
# Bananarchy microSD card autodetection, automount, and GUI/dmenu mount manager
export PATH="/home/user/.config/sxmo/hooks:/usr/share/sxmo/default_hooks:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
MOUNT_POINT="/media/sdcard"
STATE_FILE="/tmp/sxmo_sdcard_mounted"
USER_UID="10000"
USER_GID="10000"
notify_user() {
title="$1"
body="$2"
if command -v notify-send >/dev/null 2>&1; then
if [ "$(id -u)" -eq 0 ]; then
su - user -c "DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/10000/bus notify-send '$title' '$body'" >/dev/null 2>&1 &
else
DISPLAY="${DISPLAY:-:0}" notify-send "$title" "$body" >/dev/null 2>&1 &
fi
fi
}
is_mounted() {
if command -v findmnt >/dev/null 2>&1; then
findmnt -rn "$MOUNT_POINT" >/dev/null 2>&1
return $?
fi
grep -qs " $MOUNT_POINT " /proc/mounts
}
find_sd_disk() {
if [ -b /dev/mmcblk1 ]; then
printf "/dev/mmcblk1\n"
return 0
fi
for sysblk in /sys/block/mmcblk*; do
[ -e "$sysblk" ] || continue
bname="$(basename "$sysblk")"
[ "$bname" = "mmcblk0" ] && continue
case "$bname" in
*boot*|*rpmb*) continue ;;
esac
link="$(readlink -f "$sysblk" 2>/dev/null || true)"
case "$link" in
*7864900.sdhci*|*7864000.sdhci*|*mmc1*)
if [ -b "/dev/$bname" ]; then
printf "/dev/%s\n" "$bname"
return 0
fi
;;
esac
done
return 1
}
find_sd_part() {
req_dev="${1:-}"
if [ -n "$req_dev" ]; then
case "$req_dev" in
/dev/*) [ -b "$req_dev" ] && { printf "%s\n" "$req_dev"; return 0; } ;;
*) [ -b "/dev/$req_dev" ] && { printf "/dev/%s\n" "$req_dev"; return 0; } ;;
esac
fi
disk="$(find_sd_disk || true)"
[ -n "$disk" ] || return 1
for p in "${disk}p1" "${disk}p2" "${disk}p3" "${disk}p4" "$disk"; do
if [ -b "$p" ]; then
if [ "$p" = "$disk" ] && [ -b "${disk}p1" ]; then
continue
fi
printf "%s\n" "$p"
return 0
fi
done
return 1
}
probe_controller() {
if [ -b /dev/mmcblk1 ]; then
return 0
fi
if [ -w /sys/bus/platform/drivers/sdhci_msm/unbind ]; then
if [ -e /sys/bus/platform/drivers/sdhci_msm/7864900.sdhci ]; then
printf "7864900.sdhci" > /sys/bus/platform/drivers/sdhci_msm/unbind 2>/dev/null || true
sleep 0.2
fi
printf "7864900.sdhci" > /sys/bus/platform/drivers/sdhci_msm/bind 2>/dev/null || true
i=0
while [ "$i" -lt 12 ]; do
[ -b /dev/mmcblk1 ] && return 0
sleep 0.1
i="$(( i + 1 ))"
done
fi
[ -b /dev/mmcblk1 ]
}
do_mount() {
if [ "$(id -u)" -ne 0 ]; then
exec doas /usr/bin/sxmo_sdcard.sh mount "$@"
fi
if is_mounted; then
printf "1\n" > "$STATE_FILE" 2>/dev/null || true
chmod 644 "$STATE_FILE" 2>/dev/null || true
printf "Already mounted at %s\n" "$MOUNT_POINT"
return 0
fi
part="$(find_sd_part "${1:-}" || true)"
if [ -z "$part" ]; then
probe_controller || true
part="$(find_sd_part "${1:-}" || true)"
fi
if [ -z "$part" ] || [ ! -b "$part" ]; then
rm -f "$STATE_FILE" 2>/dev/null || true
printf "No SD card detected\n" >&2
return 1
fi
mkdir -p "$MOUNT_POINT" 2>/dev/null || true
fstype="$(blkid -o value -s TYPE "$part" 2>/dev/null || true)"
mounted_ok=0
case "$fstype" in
vfat|fat|msdos)
if mount -t vfat -o "rw,nosuid,nodev,noatime,uid=${USER_UID},gid=${USER_GID},fmask=0022,dmask=0022,iocharset=utf8" "$part" "$MOUNT_POINT" 2>/dev/null || \
mount -t vfat -o "rw,nosuid,nodev,noatime,uid=${USER_UID},gid=${USER_GID},fmask=0022,dmask=0022" "$part" "$MOUNT_POINT" 2>/dev/null; then
mounted_ok=1
fi
;;
exfat)
if mount -t exfat -o "rw,nosuid,nodev,noatime,uid=${USER_UID},gid=${USER_GID},fmask=0022,dmask=0022" "$part" "$MOUNT_POINT" 2>/dev/null || \
mount -o "rw,nosuid,nodev,noatime,uid=${USER_UID},gid=${USER_GID}" "$part" "$MOUNT_POINT" 2>/dev/null; then
mounted_ok=1
fi
;;
ntfs|ntfs3)
if mount -t ntfs3 -o "rw,nosuid,nodev,noatime,uid=${USER_UID},gid=${USER_GID},umask=0022" "$part" "$MOUNT_POINT" 2>/dev/null || \
mount -o "rw,nosuid,nodev,noatime,uid=${USER_UID},gid=${USER_GID}" "$part" "$MOUNT_POINT" 2>/dev/null; then
mounted_ok=1
fi
;;
ext4|ext3|ext2|f2fs|btrfs|xfs)
if mount -o "rw,nosuid,nodev,noatime" "$part" "$MOUNT_POINT" 2>/dev/null; then
mounted_ok=1
chown "${USER_UID}:${USER_GID}" "$MOUNT_POINT" 2>/dev/null || true
fi
;;
*)
if mount -o "rw,nosuid,nodev,noatime,uid=${USER_UID},gid=${USER_GID}" "$part" "$MOUNT_POINT" 2>/dev/null || \
mount -o "rw,nosuid,nodev,noatime" "$part" "$MOUNT_POINT" 2>/dev/null; then
mounted_ok=1
fi
;;
esac
if [ "$mounted_ok" -eq 1 ] && is_mounted; then
printf "1\n" > "$STATE_FILE" 2>/dev/null || true
chmod 644 "$STATE_FILE" 2>/dev/null || true
if [ ! -e /home/user/sdcard ]; then
ln -s "$MOUNT_POINT" /home/user/sdcard 2>/dev/null || true
chown -h "${USER_UID}:${USER_GID}" /home/user/sdcard 2>/dev/null || true
fi
notify_user "SD Card" "Mounted $(basename "$part") at $MOUNT_POINT"
printf "Mounted %s at %s\n" "$part" "$MOUNT_POINT"
return 0
fi
rm -f "$STATE_FILE" 2>/dev/null || true
printf "Failed to mount %s\n" "$part" >&2
return 1
}
do_unmount() {
if [ "$(id -u)" -ne 0 ]; then
exec doas /usr/bin/sxmo_sdcard.sh unmount "$@"
fi
sync
if ! is_mounted; then
rm -f "$STATE_FILE" 2>/dev/null || true
printf "SD card is not mounted\n"
return 0
fi
if umount "$MOUNT_POINT" 2>/dev/null || umount -l "$MOUNT_POINT" 2>/dev/null; then
rm -f "$STATE_FILE" 2>/dev/null || true
notify_user "SD Card" "Safely unmounted $MOUNT_POINT"
printf "Unmounted %s\n" "$MOUNT_POINT"
return 0
fi
printf "Failed to unmount %s (device busy)\n" "$MOUNT_POINT" >&2
return 1
}
do_rescan() {
if [ "$(id -u)" -ne 0 ]; then
exec doas /usr/bin/sxmo_sdcard.sh rescan
fi
probe_controller || true
if find_sd_part >/dev/null 2>&1; then
do_mount
return $?
fi
rm -f "$STATE_FILE" 2>/dev/null || true
notify_user "SD Card" "No SD card detected in slot"
printf "No SD card detected\n" >&2
return 1
}
do_status() {
if is_mounted; then
printf "1\n" > "$STATE_FILE" 2>/dev/null || true
dev="$(findmnt -rn -o SOURCE "$MOUNT_POINT" 2>/dev/null || printf "/dev/mmcblk1p1")"
fstype="$(findmnt -rn -o FSTYPE "$MOUNT_POINT" 2>/dev/null || printf "auto")"
df_line="$(df -h "$MOUNT_POINT" 2>/dev/null | awk 'NR==2 {print $2, $3, $4, $5}')"
printf "mounted %s %s %s %s\n" "$MOUNT_POINT" "$dev" "$fstype" "$df_line"
return 0
fi
rm -f "$STATE_FILE" 2>/dev/null || true
part="$(find_sd_part 2>/dev/null || true)"
if [ -n "$part" ]; then
fstype="$(blkid -o value -s TYPE "$part" 2>/dev/null || printf "unknown")"
size="$(lsblk -dn -o SIZE "$part" 2>/dev/null | tr -d ' ' || printf "?")"
printf "unmounted %s %s %s\n" "$part" "$fstype" "$size"
return 0
fi
printf "absent\n"
return 0
}
do_menu() {
. sxmo_hook_icons.sh
. sxmo_common.sh
while : ; do
st="$(do_status)"
state_word="$(printf "%s" "$st" | awk '{print $1}')"
case "$state_word" in
mounted)
dev="$(printf "%s" "$st" | awk '{print $3}')"
free_sp="$(printf "%s" "$st" | awk '{print $7}')"
tot_sp="$(printf "%s" "$st" | awk '{print $5}')"
hdr="${icon_ton} Mounted: $(basename "$dev") (${free_sp:-?} free / ${tot_sp:-?})"
;;
unmounted)
dev="$(printf "%s" "$st" | awk '{print $2}')"
sz="$(printf "%s" "$st" | awk '{print $4}')"
hdr="${icon_tof} Unmounted: $(basename "$dev") (${sz:-?})"
;;
*)
hdr="${icon_tof} Status: No SD card detected"
;;
esac
CHOICES="$(cat <<EOF
$icon_cls Close Menu ^ exit 0
$hdr ^ :
$icon_dir Open /media/sdcard in Files ^ xfiles "$MOUNT_POINT" & exit 0
$icon_dsk Mount SD Card ^ sxmo_sdcard.sh mount
$icon_out Unmount / Eject SD Card ^ sxmo_sdcard.sh unmount
$icon_rld Rescan SD Card Slot ^ sxmo_sdcard.sh rescan
EOF
)"
PICKED="$(printf "%s\n" "$CHOICES" | cut -d'^' -f1 | sxmo_dmenu.sh -i -p "SD Card")" || exit 0
[ -n "$PICKED" ] || exit 0
CMD="$(printf "%s\n" "$CHOICES" | grep -m1 -F "$PICKED" | cut -d'^' -f2-)"
eval "$CMD"
done
}
cmd="${1:-menu}"
shift 2>/dev/null || true
case "$cmd" in
status)
do_status
;;
is_mounted|ismounted)
is_mounted
;;
is_present|ispresent)
find_sd_part >/dev/null 2>&1
;;
mount)
do_mount "$@"
;;
unmount|umount|eject)
do_unmount "$@"
;;
rescan|detect|probe)
do_rescan
;;
automount)
act="${1:-add}"
kname="${2:-}"
case "$act" in
add|boot)
if [ -n "$kname" ]; then
do_mount "/dev/$kname" >/dev/null 2>&1 || true
else
if find_sd_part >/dev/null 2>&1; then
do_mount >/dev/null 2>&1 || true
fi
fi
;;
remove)
if [ "$(id -u)" -eq 0 ]; then
umount -l "$MOUNT_POINT" 2>/dev/null || true
rm -f "$STATE_FILE" 2>/dev/null || true
notify_user "SD Card" "SD card removed"
fi
;;
esac
;;
menu|*)
do_menu
;;
esac
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+10 -9
View File
@@ -139,15 +139,16 @@ EOF
M=/bananarchy/src/leds-msm8905-torch clean
make ARCH=arm CROSS_COMPILE=armv7-alpine-linux-musleabihf- \
M=/bananarchy/src/msm8905-cam clean
cp -a arch/arm/boot/dts/qcom/qcom-msm8905-nokia-argon.dtb \
arch/arm/boot/dts/qcom/qcom-msm8909-nokia-sparkler.dtb \
arch/arm/boot/dts/qcom/qcom-msm8909-nokia-leo.dtb \
/bananarchy/prebuilt/kernel-6.12.1-msm8916/dtbs/
dtc -I dts -O dtb -o /bananarchy/prebuilt/kernel-6.12.1-msm8916/dtbs/qcom-msm8905-nokia-beatles.dtb \
/bananarchy/devices/nokia-beatles/qcom-msm8905-nokia-beatles.dts 2>/dev/null
dtc -I dts -O dtb -o /bananarchy/prebuilt/kernel-6.12.1-msm8916/dtbs/qcom-msm8905-nokia-coconut.dtb \
/bananarchy/devices/nokia-tough/qcom-msm8905-nokia-coconut.dts 2>/dev/null
for dts in \
/bananarchy/devices/nokia-argon/qcom-msm8905-nokia-argon.dts \
/bananarchy/devices/nokia-beatles/qcom-msm8905-nokia-beatles.dts \
/bananarchy/devices/nokia-tough/qcom-msm8905-nokia-coconut.dts \
/bananarchy/devices/nokia-sparkler/qcom-msm8909-nokia-sparkler.dts \
/bananarchy/devices/nokia-sparkler/qcom-msm8909-nokia-leo.dts; do
dtb="${dts%.dts}.dtb"
dtc -I dts -O dtb -o "$dtb" "$dts" 2>/dev/null
cp -a "$dtb" /bananarchy/prebuilt/kernel-6.12.1-msm8916/dtbs/
done
chown -R "$HOST_UID:$HOST_GID" /bananarchy/prebuilt/kernel-6.12.1-msm8916 \
/bananarchy/src/leds-msm8905-torch \
+48
View File
@@ -750,10 +750,22 @@ int runFilesApp(int argc, char** argv) {
statusBannerUntilMs = nowMs() + 2200;
};
auto isSdCardMounted = []() -> bool {
std::ifstream f("/proc/mounts");
std::string line;
while (std::getline(f, line)) {
if (line.find(" /media/sdcard ") != std::string::npos) {
return true;
}
}
return false;
};
auto buildActionsList = [&]() {
actionsList.clear();
bool hasSel = !filteredItems.empty();
bool isParent = hasSel && filteredItems[selected].isParent;
bool sdMounted = isSdCardMounted();
if (hasSel) {
if (!filteredItems[selected].isDir) {
@@ -807,6 +819,14 @@ int runFilesApp(int argc, char** argv) {
else if (sortMode == SortMode::Date) sortLbl += "Size (#)";
else sortLbl += "Name (#)";
actionsList.push_back({11, kIconSort, sortLbl});
if (sdMounted) {
if (currentDir != "/media/sdcard") {
actionsList.push_back({18, kIconFolderOpen, "Open SD Card (/media/sdcard)"});
}
actionsList.push_back({19, kIconOutCall, "Unmount / Eject SD Card"});
} else {
actionsList.push_back({20, kIconFolder, "Mount SD Card (/media/sdcard)"});
}
actionsList.push_back({12, kIconTerm, "Open Terminal Here"});
actionSelected = 0;
};
@@ -1667,6 +1687,34 @@ int runFilesApp(int argc, char** argv) {
filteredItems[selected].name);
} else if (actId == 17 && !filteredItems.empty()) {
openTextViewer(filteredItems[selected]);
} else if (actId == 18) {
loadDirectory("/media/sdcard");
mode = ViewMode::Browser;
} else if (actId == 19) {
if (currentDir.rfind("/media/sdcard", 0) == 0) {
loadDirectory(homeDir);
}
int rc = std::system("sxmo_sdcard.sh unmount >/dev/null 2>&1");
loadDirectory(currentDir);
statusBanner = (rc == 0 && !isSdCardMounted())
? "SD card unmounted"
: "Unmount failed (busy)";
statusBannerUntilMs = nowMs() + 2200;
mode = ViewMode::Browser;
} else if (actId == 20) {
mode = ViewMode::Browser;
statusBanner = "Scanning SD card slot...";
statusBannerUntilMs = nowMs() + 2500;
drawUI();
int rc = std::system("sxmo_sdcard.sh mount >/dev/null 2>&1");
if (rc == 0 && isSdCardMounted()) {
loadDirectory("/media/sdcard");
statusBanner = "SD card mounted";
} else {
loadDirectory(currentDir);
statusBanner = "No SD card detected";
}
statusBannerUntilMs = nowMs() + 2200;
}
};
+44
View File
@@ -966,6 +966,24 @@ write_str_file(const char *path, const char *val)
return n > 0;
}
static int
sdcard_is_mounted_fast(void)
{
FILE *fp = fopen("/proc/mounts", "r");
if (!fp)
return 0;
char line[512];
int mounted = 0;
while (fgets(line, sizeof(line), fp)) {
if (strstr(line, " /media/sdcard ") != NULL) {
mounted = 1;
break;
}
}
fclose(fp);
return mounted;
}
static int
dunst_window_visible(void)
{
@@ -2365,6 +2383,9 @@ open_builtin_menu(const char *menu_name, int keep_idx)
snprintf(label, sizeof(label), "%s Files", ICON_DIR);
add_menu_item(label, "@plugin:files", 0);
snprintf(label, sizeof(label), "%s SD Card %s", ICON_DIR, sdcard_is_mounted_fast() ? ICON_TON : ICON_TOF);
add_menu_item(label, "@menu:sdcard", 1);
snprintf(label, sizeof(label), "%s Dialer", ICON_PHN);
add_menu_item(label, "@plugin:dialer", 0);
@@ -2610,6 +2631,26 @@ open_builtin_menu(const char *menu_name, int keep_idx)
snprintf(label, sizeof(label), "%s Back to Config", ICON_CFG);
add_menu_item(label, "@menu:config", 1);
populate_timezone_menu();
} else if (strcmp(menu_name, "sdcard") == 0) {
reset_session_defaults(1, "SD Card");
append_active_call_entries();
int mounted = sdcard_is_mounted_fast();
snprintf(label, sizeof(label), "%s Status: %s %s", ICON_DIR,
mounted ? "Mounted (/media/sdcard)" : "Unmounted",
mounted ? ICON_TON : ICON_TOF);
add_menu_item(label, mounted ? "sxmo_sdcard.sh unmount >/dev/null 2>&1" : "sxmo_sdcard.sh mount >/dev/null 2>&1", 1);
snprintf(label, sizeof(label), "%s Open SD Card in Files", ICON_DIR);
add_menu_item(label, "@plugin:files:/media/sdcard", 0);
snprintf(label, sizeof(label), "%s Mount SD Card", ICON_DIR);
add_menu_item(label, "sxmo_sdcard.sh mount >/dev/null 2>&1", 1);
snprintf(label, sizeof(label), "%s Unmount / Eject SD Card", ICON_OUT);
add_menu_item(label, "sxmo_sdcard.sh unmount >/dev/null 2>&1", 1);
snprintf(label, sizeof(label), "%s Rescan SD Card Slot", ICON_RLD);
add_menu_item(label, "sxmo_sdcard.sh rescan >/dev/null 2>&1", 1);
snprintf(label, sizeof(label), "%s System Menu", ICON_MNU);
add_menu_item(label, "@menu:sys", 1);
snprintf(label, sizeof(label), "%s Close Menu", ICON_CLS);
add_menu_item(label, "@close", 0);
} else if (strcmp(menu_name, "config") == 0) {
reset_session_defaults(1, "Config");
append_active_call_entries();
@@ -2631,6 +2672,9 @@ open_builtin_menu(const char *menu_name, int keep_idx)
snprintf(label, sizeof(label), "%s Bluetooth %s", ICON_BTH, bt_is_unblocked_fast() ? ICON_TON : ICON_TOF);
add_menu_item(label, "@toggle:bluetooth", 1);
snprintf(label, sizeof(label), "%s SD Card %s", ICON_DIR, sdcard_is_mounted_fast() ? ICON_TON : ICON_TOF);
add_menu_item(label, "@menu:sdcard", 1);
snprintf(label, sizeof(label), "%s Change Timezone", ICON_CLK);
add_menu_item(label, "@menu:timezone", 1);