I use sdcard extension cable, so when I physically unplug sdcard, linux thinks, that card still plugged. Dir still mounted, fdisk show mmcblk2 device, I can read files from mount dir.
After several minutes, linux write errors to dmesg and remove sdcard.
But I want immediately know, when sdcard unplugged. Maybe, I can force rescan available sdcards?
Hi, what kind of cable are you using? System detects the card by a mechanical signal CARD_DETECT. Does the cable support that?
What about other normal SD card plug-in? same as this or not?
After some tries and googling, I solve this problem by script:
#!/bin/sh
MOUNT_DIR="/home/ubuntu/sdcard/"
TEST_FILE=".sdcard_test"
TEST_FILE_PATH=$MOUNT_DIR$TEST_FILE
try_mount_sdcard () {
mkdir $MOUNT_DIR
mount -o sync /dev/mmcblk2p1 $MOUNT_DIR
result=$?
if [ "$result" -eq "0" ]
then
echo "SDCard mounted succesfully"
else
rmdir $MOUNT_DIR
fi
}
try_umount_sdcard () {
umount -l $MOUNT_DIR
umount -f $MOUNT_DIR
rmdir $MOUNT_DIR
}
rebind_mmc () {
echo 3400000.sdhci > /sys/bus/platform/drivers/sdhci-tegra/unbind
sleep 1
echo 3400000.sdhci > /sys/bus/platform/drivers/sdhci-tegra/bind
sleep 1
}
sdcard_available () {
mountpoint $MOUNT_DIR
if [ "$?" -eq "1" ]
then
echo $MOUNT_DIR is not mount point, remove...
rmdir $MOUNT_DIR
fi
rm $TEST_FILE_PATH
touch $TEST_FILE_PATH
if [ "$?" -eq "0" ]
then
rm $TEST_FILE_PATH
echo "SDCard available"
return 1
else
echo "SDCard unavailable"
return 0
fi
}
sdcard_available
if [ "$?" -eq "0" ]; then
try_umount_sdcard
rebind_mmc
try_mount_sdcard
fi
Good to hear this, so it is driver problem not hardware issue.