From aad97f52107af5ee3e3fb41844da70d48e0af3fd Mon Sep 17 00:00:00 2001 From: V10lator Date: Tue, 23 Jun 2015 12:20:21 +0200 Subject: [PATCH 1/8] Wait for the tracker after we mounted, not before. We trigger indexing anyway on line 63, so no need to delay the mounting and annoy users. --- scripts/mount-sd.sh | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/scripts/mount-sd.sh b/scripts/mount-sd.sh index 59841ce..bcadcfa 100755 --- a/scripts/mount-sd.sh +++ b/scripts/mount-sd.sh @@ -31,19 +31,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} @@ -60,7 +47,21 @@ if [ "$ACTION" = "add" ]; then mount ${DEVNAME} $MNT/${UUID} -o $MOUNT_OPTS || /bin/rmdir $MNT/${UUID} ;; esac + + # This hack is here to delay indexing till the tracker has started. + 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} && touch $MNT/${UUID} + systemd-cat -t mount-sd /bin/echo "Finished ${ACTION}ing ${DEVNAME} of type ${TYPE} at $MNT/${UUID}" else From 6e066feb01c7d0e84b33b986c7ec57a4a82aac8f Mon Sep 17 00:00:00 2001 From: V10lator Date: Tue, 23 Jun 2015 12:23:39 +0200 Subject: [PATCH 2/8] Correctly unmount This tells the tracker to re-index, so it knows about the removed files. Also it removes the temporary mount directory as it's no longer needed (in fact line 63 checks that the directory hasn't been deleted, so this is just right). --- scripts/mount-sd.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/mount-sd.sh b/scripts/mount-sd.sh index bcadcfa..4a69ecd 100755 --- a/scripts/mount-sd.sh +++ b/scripts/mount-sd.sh @@ -72,6 +72,8 @@ else exit 0 fi umount $DIR || umount -l $DIR + touch ${DIR} # Tell the tracker to reindex. + rmdir ${DIR} # Remove the temporary mount directory. systemd-cat -t mount-sd /bin/echo "Finished ${ACTION}ing ${DEVNAME} at ${DIR}" fi fi From 2811de0fdf63a94fe8268e3ee1d0d5d1239b9c83 Mon Sep 17 00:00:00 2001 From: V10lator Date: Tue, 23 Jun 2015 12:26:11 +0200 Subject: [PATCH 3/8] Remove duplicated code This is needed for the next commit to be golden. --- scripts/mount-sd.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/scripts/mount-sd.sh b/scripts/mount-sd.sh index 4a69ecd..fae0314 100755 --- a/scripts/mount-sd.sh +++ b/scripts/mount-sd.sh @@ -37,16 +37,14 @@ 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} + MOUNT_OPTS+=",uid=$DEF_UID,gid=$DEF_GID,utf8,flush,discard" ;; # NTFS support has not been tested but it's being left to please the ego of an engineer! ntfs) - mount ${DEVNAME} $MNT/${UUID} -o uid=$DEF_UID,gid=$DEF_GID,$MOUNT_OPTS,utf8 || /bin/rmdir $MNT/${UUID} - ;; - *) - mount ${DEVNAME} $MNT/${UUID} -o $MOUNT_OPTS || /bin/rmdir $MNT/${UUID} + MOUNT_OPTS+=",uid=$DEF_UID,gid=$DEF_GID,utf8" ;; esac + mount ${DEVNAME} $MNT/${UUID} -o $MOUNT_OPTS || /bin/rmdir $MNT/${UUID} # This hack is here to delay indexing till the tracker has started. export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$DEF_UID/dbus/user_bus_socket From e361899dd344b7a6db70f31e65373f689b965d2e Mon Sep 17 00:00:00 2001 From: V10lator Date: Tue, 23 Jun 2015 12:27:21 +0200 Subject: [PATCH 4/8] Enable TRIM on ext4 and btrfs --- scripts/mount-sd.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/mount-sd.sh b/scripts/mount-sd.sh index fae0314..a391d67 100755 --- a/scripts/mount-sd.sh +++ b/scripts/mount-sd.sh @@ -43,6 +43,10 @@ if [ "$ACTION" = "add" ]; then ntfs) MOUNT_OPTS+=",uid=$DEF_UID,gid=$DEF_GID,utf8" ;; + # ext and btrfs are both able to handly TRIM. Add more to the list if needed. + ext4|btrfs) + MOUNT_OPTS+=",discard" + ;; esac mount ${DEVNAME} $MNT/${UUID} -o $MOUNT_OPTS || /bin/rmdir $MNT/${UUID} From e332cbc8b0b681209b0fab932217dc763efe3382 Mon Sep 17 00:00:00 2001 From: V10lator Date: Tue, 23 Jun 2015 12:29:53 +0200 Subject: [PATCH 5/8] Remove useless indexing No need to trigger indexing on line 36: At that time there won't be any new files to track. --- scripts/mount-sd.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/mount-sd.sh b/scripts/mount-sd.sh index a391d67..55ddb0a 100755 --- a/scripts/mount-sd.sh +++ b/scripts/mount-sd.sh @@ -33,7 +33,6 @@ if [ "$ACTION" = "add" ]; then test -d $MNT/${UUID} || mkdir -p $MNT/${UUID} chown $DEF_UID:$DEF_GID $MNT $MNT/${UUID} - touch $MNT/${UUID} case "${TYPE}" in vfat|exfat) From a945e2842b247c04af178ec87efafb81b2e979cf Mon Sep 17 00:00:00 2001 From: V10lator Date: Sat, 4 Jul 2015 12:31:04 +0200 Subject: [PATCH 6/8] Add TRIM support for f2fs. While officially not supported there's community support: https://openrepos.net/content/v10lator/f2fs Also exfat and ntfs aren't officially supported but handled here, so I can't see anything wrong with adding f2fs. --- scripts/mount-sd.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/mount-sd.sh b/scripts/mount-sd.sh index 55ddb0a..1148215 100755 --- a/scripts/mount-sd.sh +++ b/scripts/mount-sd.sh @@ -43,7 +43,7 @@ if [ "$ACTION" = "add" ]; then MOUNT_OPTS+=",uid=$DEF_UID,gid=$DEF_GID,utf8" ;; # ext and btrfs are both able to handly TRIM. Add more to the list if needed. - ext4|btrfs) + ext4|btrfs|f2fs) MOUNT_OPTS+=",discard" ;; esac From 8dc08031f2cd1b8c19229cc1e4dcac65103f8c95 Mon Sep 17 00:00:00 2001 From: V10lator Date: Wed, 8 Jul 2015 18:14:57 +0200 Subject: [PATCH 7/8] fschk before mounting. To detect and fix corruption. --- scripts/mount-sd.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/scripts/mount-sd.sh b/scripts/mount-sd.sh index 1148215..7792101 100755 --- a/scripts/mount-sd.sh +++ b/scripts/mount-sd.sh @@ -31,6 +31,16 @@ if [ "$ACTION" = "add" ]; then exit 0 fi + case "${TYPE}" in + f2fs) + FSCK_OPTS="-a" + ;; + *) + FSCK_OPTS="-p" + ;; + esac + fsck $FSCK_OPTS ${DEVNAME} + test -d $MNT/${UUID} || mkdir -p $MNT/${UUID} chown $DEF_UID:$DEF_GID $MNT $MNT/${UUID} From 1219ccf41896885e13287f7b9d12c8a9e3bea6c6 Mon Sep 17 00:00:00 2001 From: V10lator Date: Mon, 31 Aug 2015 09:32:36 +0200 Subject: [PATCH 8/8] Fix indentation. --- scripts/mount-sd.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/mount-sd.sh b/scripts/mount-sd.sh index 7792101..3d6e8af 100755 --- a/scripts/mount-sd.sh +++ b/scripts/mount-sd.sh @@ -32,7 +32,7 @@ if [ "$ACTION" = "add" ]; then fi case "${TYPE}" in - f2fs) + f2fs) FSCK_OPTS="-a" ;; *) @@ -45,14 +45,14 @@ if [ "$ACTION" = "add" ]; then chown $DEF_UID:$DEF_GID $MNT $MNT/${UUID} case "${TYPE}" in - vfat|exfat) - MOUNT_OPTS+=",uid=$DEF_UID,gid=$DEF_GID,utf8,flush,discard" - ;; - # NTFS support has not been tested but it's being left to please the ego of an engineer! - ntfs) - MOUNT_OPTS+=",uid=$DEF_UID,gid=$DEF_GID,utf8" - ;; - # ext and btrfs are both able to handly TRIM. Add more to the list if needed. + vfat|exfat) + MOUNT_OPTS+=",uid=$DEF_UID,gid=$DEF_GID,utf8,flush,discard" + ;; + # NTFS support has not been tested but it's being left to please the ego of an engineer! + ntfs) + MOUNT_OPTS+=",uid=$DEF_UID,gid=$DEF_GID,utf8" + ;; + # ext and btrfs are both able to handly TRIM. Add more to the list if needed. ext4|btrfs|f2fs) MOUNT_OPTS+=",discard" ;;