From 0ab57e5d2f5e9a9a4b1d48187074ed67ccdc9172 Mon Sep 17 00:00:00 2001 From: Ivan Blagoev Topolsky Date: Fri, 26 Jun 2015 10:48:23 +0200 Subject: [PATCH 1/3] Adding support for swap space on SD card + NOTE: 'discard=once' currently not supported by Jolla, using 'discard' instead + priority set to 10 (i.e.: lower than zram) --- scripts/mount-sd.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/scripts/mount-sd.sh b/scripts/mount-sd.sh index 59841ce..7055a05 100755 --- a/scripts/mount-sd.sh +++ b/scripts/mount-sd.sh @@ -8,6 +8,8 @@ DEF_GID=$(grep "^GID_MIN" /etc/login.defs | tr -s " " | cut -d " " -f2) DEVICEUSER=$(getent passwd $DEF_UID | sed 's/:.*//') MNT=/media/sdcard MOUNT_OPTS="dirsync,noatime,users" +# options: --discard=once --priority 10 +SWAP_OPTS="--discard --priority 10" ACTION=$1 DEVNAME=$2 @@ -21,6 +23,22 @@ if [ "$ACTION" = "add" ]; then eval "$(/sbin/blkid -c /dev/null -o export /dev/$2)" + if [ -z "${TYPE}" ]; then + exit 1 + fi + + if [ "${TYPE}" = "swap" ]; then + SWAP=$(grep -w ${DEVNAME} /proc/swaps | cut -d \ -f 1) + if [ -n "$SWAP" ]; then + systemd-cat -t mount-sd /bin/echo "${DEVNAME} already used as swap space, ignoring" + exit 0 + fi + systemd-cat -t mount-sd /bin/echo "${DEVNAME} seems to be swap space" + swapon $SWAP_OPTS ${DEVNAME} + systemd-cat -t mount-sd /bin/echo "Finished ${ACTION}ing ${DEVNAME} of type ${TYPE} as swap space" + exit 0 + fi + if [ -z "${UUID}" ] || [ -z "${TYPE}" ]; then exit 1 fi @@ -72,6 +90,14 @@ else fi umount $DIR || umount -l $DIR systemd-cat -t mount-sd /bin/echo "Finished ${ACTION}ing ${DEVNAME} at ${DIR}" + else + SWAP=$(grep -w ${DEVNAME} /proc/swaps | cut -d \ -f 1) + if [ -z "$SWAP" ]; then + systemd-cat -t mount-sd /bin/echo "${DEVNAME} in not currently used as swap space, ignoring" + exit 0 + fi + swapoff "${SWAP}" + systemd-cat -t mount-sd /bin/echo "Finished ${ACTION}ing ${DEVNAME} as swap space" fi fi From b2d25cc9a40b24377bd0ad5ada100528379b1f37 Mon Sep 17 00:00:00 2001 From: Matti Kosola Date: Fri, 17 Jun 2016 11:57:11 +0300 Subject: [PATCH 2/3] [sd] Add mount script to support aliendalvik. Fixes JB#35533 Signed-off-by: Matti Kosola --- scripts/mount-sd.sh | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/scripts/mount-sd.sh b/scripts/mount-sd.sh index 59841ce..c0fca0c 100755 --- a/scripts/mount-sd.sh +++ b/scripts/mount-sd.sh @@ -11,7 +11,13 @@ MOUNT_OPTS="dirsync,noatime,users" ACTION=$1 DEVNAME=$2 -if [ -z "${ACTION}" ] || [ -z "${DEVNAME}" ]; then +if [ -z "${ACTION}" ]; then + systemd-cat -t mount-sd /bin/echo "ERROR: Action needs to be defined." + exit 1 +fi + +if [ -z "${DEVNAME}" ]; then + systemd-cat -t mount-sd /bin/echo "ERROR: Device name needs to be defined." exit 1 fi @@ -21,10 +27,32 @@ if [ "$ACTION" = "add" ]; then eval "$(/sbin/blkid -c /dev/null -o export /dev/$2)" - if [ -z "${UUID}" ] || [ -z "${TYPE}" ]; then + if [ -z "${TYPE}" ]; then + systemd-cat -t mount-sd /bin/echo "ERROR: Filesystem type missing for ${DEVNAME}." exit 1 fi + if [ -z "${UUID}" ]; then + # In case device does not have UUID lets create one for it based on + # the card identification. + PKNAME=$(lsblk -n -o PKNAME ${DEVNAME}) + if [ -e "/sys/block/${PKNAME}/device/cid" ]; then + CID=$(cat /sys/block/${PKNAME}/device/cid) + if [ -n "${CID}" ]; then + IDNAME=$(lsblk -n -o NAME ${DEVNAME}) + UUID="${CID}-${IDNAME}" + fi + fi + + if [ -z "${UUID}" ]; then + # Exit here as in the future there might be things like USB OTG disks or + # sdcards attached via adapter that might behave differently and needs special case + # in case such happens fail so we don't break anything. + systemd-cat -t mount-sd /bin/echo "ERROR: Could not find or generate UUID for device ${DEVNAME}." + exit 1 + fi + fi + DIR=$(grep -w ${DEVNAME} /proc/mounts | cut -d \ -f 2) if [ -n "$DIR" ]; then systemd-cat -t mount-sd /bin/echo "${DEVNAME} already mounted on ${DIR}, ignoring" @@ -50,7 +78,9 @@ if [ "$ACTION" = "add" ]; then case "${TYPE}" in vfat|exfat) - mount ${DEVNAME} $MNT/${UUID} -o uid=$DEF_UID,gid=$DEF_GID,$MOUNT_OPTS,utf8,flush,discard || /bin/rmdir $MNT/${UUID} + mkdir -p /opt/alien/storage/sdcard1/ + #mount ${DEVNAME} $MNT/${UUID} -o uid=$DEF_UID,gid=$DEF_GID,$MOUNT_OPTS,utf8,flush,discard || /bin/rmdir $MNT/${UUID} + mount ${DEVNAME} /opt/alien/storage/sdcard1/ -o uid=1015,gid=1015,fmask=002,dmask=002,$MOUNT_OPTS,utf8,flush,discard || /bin/rmdir $MNT/${UUID} ;; # NTFS support has not been tested but it's being left to please the ego of an engineer! ntfs) From 481a3990771095602448ad5751ba36f17d9d0829 Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Mon, 19 Sep 2016 11:07:06 +0200 Subject: [PATCH 3/3] [tracker] Remove blocks waiting for tracker to initialize. Contributes JB#36317 Conflicts: rpm/sdcard-utils.spec --- rpm/sdcard-utils.spec | 5 +++-- rules/90-mount-sd.rules | 2 +- scripts/mount-sd.sh | 13 ------------- 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/rpm/sdcard-utils.spec b/rpm/sdcard-utils.spec index c107e84..5b2cda5 100755 --- a/rpm/sdcard-utils.spec +++ b/rpm/sdcard-utils.spec @@ -1,6 +1,6 @@ Name: sd-utils Summary: SailfishOS scripts to mount/umount external sdcard. -Version: 0.3 +Version: 0.4 Release: 1 Group: System/Base License: MIT @@ -9,7 +9,8 @@ URL: https://github.com/nemomobile/sd-utils/ Source0: %{name}-%{version}.tar.gz BuildRequires: systemd Requires: systemd -Requires: tracker +# Required for lsblk +Requires: util-linux %description %{summary} diff --git a/rules/90-mount-sd.rules b/rules/90-mount-sd.rules index b06cd27..eb63611 100644 --- a/rules/90-mount-sd.rules +++ b/rules/90-mount-sd.rules @@ -1 +1 @@ -SUBSYSTEM=="block", KERNEL=="mmcblk1*", ACTION=="add", MODE="0660", TAG+="systemd", ENV{SYSTEMD_WANTS}="mount-sd@%k.service", ENV{SYSTEMD_USER_WANTS}="tracker-miner-fs.service tracker-store.service" +SUBSYSTEM=="block", KERNEL=="mmcblk1*", ACTION=="add", MODE="0660", TAG+="systemd", ENV{SYSTEMD_WANTS}="mount-sd@%k.service" diff --git a/scripts/mount-sd.sh b/scripts/mount-sd.sh index c0fca0c..4e9b3ce 100755 --- a/scripts/mount-sd.sh +++ b/scripts/mount-sd.sh @@ -59,19 +59,6 @@ if [ "$ACTION" = "add" ]; then exit 0 fi - # This hack is here to delay mounting the sdcard until tracker is ready - export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$DEF_UID/dbus/user_bus_socket - count=1 - while true; do - test $count -ge 64 && break - MINER_STATUS="$(dbus-send --type=method_call --print-reply --session --dest=org.freedesktop.Tracker1.Miner.Files /org/freedesktop/Tracker1/Miner/Files org.freedesktop.Tracker1.Miner.GetStatus | grep -o 'Idle')" - STORE_STATUS="$(dbus-send --type=method_call --print-reply --session --dest=org.freedesktop.Tracker1 /org/freedesktop/Tracker1/Status org.freedesktop.Tracker1.Status.GetStatus | grep -o 'Idle')" - test "$MINER_STATUS" = "Idle" -a "$STORE_STATUS" = "Idle" && break - systemd-cat -t mount-sd /bin/echo "Waiting $count seconds for tracker" - sleep $count ; - count=$(( count + count )) - done - test -d $MNT/${UUID} || mkdir -p $MNT/${UUID} chown $DEF_UID:$DEF_GID $MNT $MNT/${UUID} touch $MNT/${UUID}