Patchwork udev-extraconf: Unmount SD card after ejection

login
register
mail settings
Submitter Yasir Khan
Date Aug. 14, 2014, 2:56 p.m.
Message ID <1408028197-21536-1-git-send-email-yasir_khan@mentor.com>
Download mbox | patch
Permalink /patch/78239/
State Accepted
Commit 0cd5af027234735fe83d0681dbdddb197c02f262
Headers show

Comments

Yasir Khan - Aug. 14, 2014, 2:56 p.m.
From: Yasir-Khan <yasir_khan@mentor.com>

Adds udev rule to unmount SD card partitions in case of improper
ejection from card reader.

When SD card is ejected from card reader without being unmounted
first, kernel does not generate a REMOVE event, instead it
generates a CHANGE event(only if polling is enabled
/sys/module/block/parameters/events_dfl_poll_msecs) and we don't
have any udev rule in automount.rules to handle this event,so
partitions never get unmounted. Unmounting of partitions can be
done if udev rules handle this CHANGE event.

Signed-off-by: Abbas Raza <Abbas_Raza@mentor.com>
Signed-off-by: Yasir-Khan <yasir_khan@mentor.com>
---
 .../udev/udev-extraconf/automount.rules            |    2 +-
 meta/recipes-core/udev/udev-extraconf/mount.sh     |    3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)

Patch

diff --git a/meta/recipes-core/udev/udev-extraconf/automount.rules b/meta/recipes-core/udev/udev-extraconf/automount.rules
index 7e844c3..62578ea 100644
--- a/meta/recipes-core/udev/udev-extraconf/automount.rules
+++ b/meta/recipes-core/udev/udev-extraconf/automount.rules
@@ -16,4 +16,4 @@ 
 # Media automounting
 SUBSYSTEM=="block", ACTION=="add"    RUN+="/etc/udev/scripts/mount.sh"
 SUBSYSTEM=="block", ACTION=="remove" RUN+="/etc/udev/scripts/mount.sh"
-
+SUBSYSTEM=="block", ACTION=="change", ENV{DISK_MEDIA_CHANGE}=="1" RUN+="/etc/udev/scripts/mount.sh"
diff --git a/meta/recipes-core/udev/udev-extraconf/mount.sh b/meta/recipes-core/udev/udev-extraconf/mount.sh
index 7df1b6e..3eea910 100644
--- a/meta/recipes-core/udev/udev-extraconf/mount.sh
+++ b/meta/recipes-core/udev/udev-extraconf/mount.sh
@@ -78,8 +78,7 @@  if [ "$ACTION" = "add" ] && [ -n "$DEVNAME" ] && [ -n "$ID_FS_TYPE" -o "$media_t
 fi
 
 
-
-if [ "$ACTION" = "remove" ] && [ -x "$UMOUNT" ] && [ -n "$DEVNAME" ]; then
+if [ "$ACTION" = "remove" ] || [ "$ACTION" = "change" ] && [ -x "$UMOUNT" ] && [ -n "$DEVNAME" ]; then
 	for mnt in `cat /proc/mounts | grep "$DEVNAME" | cut -f 2 -d " " `
 	do
 		$UMOUNT $mnt