op_power: try to handle mounted-cards-on-suspend mess
[openpandora.oe.git] / recipes / pandora-system / pandora-scripts / op_power.sh
index 5cee08c..bdfe27c 100644 (file)
@@ -91,6 +91,8 @@ lowPowerOn(){ #switch from normal to lowpower mode
        done
 
        suspend_net
+
+       cat /proc/pandora/cpu_mhz_max > /tmp/oldspeed
        /usr/pandora/scripts/op_cpuspeed.sh 125
 }
 
@@ -109,6 +111,13 @@ lowPowerOff(){ # switch from lowpower to normal mode
        echo 255 > /sys/class/leds/pandora\:\:power/brightness #power LED bright
 }
 
+show_message() {
+       # TODO: check if desktop is visible; maybe use layer3?
+       xfceuser=$(ps u -C xfce4-session | tail -n1 | awk '{print $1}')
+       cmd="DISPLAY=:0.0 zenity --info --text \"$1\""
+       su -c "$cmd" $xfceuser
+}
+
 suspend_real() {
        delay=0
 
@@ -127,6 +136,31 @@ suspend_real() {
        # - cards don't unmount (running PNDs will break)
        # - while charging too, since it stops on suspend?
 
+       if ! grep -q 'mmc_core.removable=0' /proc/cmdline; then
+               # must unmount cards because they will be "ejected" on suspend
+               # (some filesystems may even deadlock if we don't do this due to bugs)
+               mounts="$(grep "/dev/mmcblk" /proc/mounts | awk '{print $1}' | xargs echo)"
+               for mnt in $mounts; do
+                       if ! umount $mnt; then
+                               show_message "Could not unmount $mnt, using partial suspend only"
+                               return 1
+                       fi
+               done
+               swaps="$(grep "/dev/mmcblk" /proc/swaps | awk '{print $1}' | xargs echo)"
+               for swp in $swaps; do
+                       if ! swapoff $swp; then
+                               show_message "Could not unmount $swp, using partial suspend only"
+                               return 1
+                       fi
+               done
+       else
+               if [ ! -e /etc/pandora/suspend-warned ]; then
+                       show_message "Pandora will now suspend.\n\n\
+Please do not remove SD cards while pandora is suspended, doing so will corrupt them."
+                       touch /etc/pandora/suspend-warned
+               fi
+       fi
+
        # FIXME: fix the kernel and get rid of this
        suspend_net
 
@@ -143,11 +177,8 @@ suspend_real() {
                fi
        done
 
-       # must unmount cards because they will be "ejected" on suspend
-       # (some filesystems may even deadlock if we don't do this due to bugs)
-       grep "/dev/mmcblk" /proc/mounts | awk '{print $1}' | xargs umount -r
-
        sleep $delay
+       sync
        echo mem > /sys/power/state
 
        # if we are here, either we already resumed or the suspend failed