Skip to content

Commit

Permalink
Several improvements. See TODO and FIXME. Tested with inserting a usb…
Browse files Browse the repository at this point in the history
… disk

with 4 partitions (ext2,ext3,ext4 and fat32) and a SD-card with 2 partitions
(ext4 and fat32) No problems with mounting yet.
  • Loading branch information
divx118 committed Aug 13, 2014
1 parent a6ebc6d commit de123c9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
12 changes: 6 additions & 6 deletions host-bin/mount-extfs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ mount_extfs() {
loopfile_path="/usr/local/"
if [ "${ID_FS_TYPE##ext*}" != "$ID_FS_TYPE" ];then
# Creating loop file
dd if=/dev/zero of=$loopfile_path$kernel_devname bs=1KB count=40
dd if=/dev/zero of=$loopfile_path$kernel_devname bs=1KB count=128
# Use UUID when we have no label.
if [ -z $ID_FS_LABEL ];then
ID_FS_LABEL=$ID_FS_UUID
Expand All @@ -34,11 +34,11 @@ mount_extfs() {
# Find unused loop device
# TODO: Using a sleep here, it somehow prevents devices getting
# the same loop device not working everytime.
sleep 1
loop=`losetup -f`
losetup $loop $loopfile_path$kernel_devname

# UPDATE: added different sleeptimer, depends on partition number
# This works well for now with the increased fat partition of 128KB.
# FIXME: No fan of sleep timers for this.
sleep $((${kernel_devname##???}/4))
loop=`losetup -f --show $loopfile_path$kernel_devname`
found=0
first=0
# start monitoring dbus crosdisks to receive the mountpoint.
Expand Down
17 changes: 14 additions & 3 deletions host-bin/unmount-loop
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#!/bin/sh
# script to cleanup leftover loopdevices from mountextfs.
# Script to cleanup leftover loopdevices from mountextfs.
# The script keeps running until there are no mounted loops
# with a mountpoint on /media/removable.

# Turn on/off verbose debugging by uncomment/comment
#set -x
#exec 2>/var/log/mountloop.log

# Start checking /proc/mounts
while [ "x`cat /proc/mounts|grep /dev/loop )`" != "x" -a \
"x`cat /proc/mounts|grep /media/removable )`" != "x" ];do
cat /proc/mounts|grep /dev/loop| \
Expand All @@ -10,9 +16,14 @@ while [ "x`cat /proc/mounts|grep /dev/loop )`" != "x" -a \
loopdevice=`echo "$line"|cut -d " " -f 1`
# check if our ext2/3/4 device is still mounted
device=`cat /proc/mounts|grep $mountpoint|grep -v $loopdevice`
# TODO: This should be done better, but works for now.
if [ "x$device" = "x" ];then
umount -d $loopdevice || umount $mountpoint && losetup -d $loopdevice

if ! umount $loopdevice;then
umount $mountpoint
losetup -d $loopdevice
else
losetup -d $loopdevice
fi
# Be sure the directory is empty before deleting.
if [ "x`ls -A $mountpoint`" = "x" ];then
rm -r $mountpoint
Expand Down

0 comments on commit de123c9

Please sign in to comment.