+ MOUNT_TARGET="${1:-$PND_MOUNT_DIR}"
+ if ! is_pnd_mounted;then
+ #check if pnd is already attached to loop
+ LOOP=$(/sbin/losetup -a | grep "$PND" | tail -n1 | awk -F: '{print $1}')
+ #check if the loop device is already mounted
+ if ! [ -z "$LOOP" ];then
+ echo "Found a loop ($LOOP), using it"
+ loopmountedon=$( mount | grep "$(mount | grep "$LOOP" | awk '{print $3}')" | grep utmp | awk '{print $3}' )
+ else
+ loopmountedon=""
+ fi
+ if [ ! "$loopmountedon" ]; then #check if the pnd is already attached to some loop device but not used
+ FREELOOP=$LOOP
+ #reuse existing loop
+ if [ ! "$LOOP" ]; then
+ FREELOOP=$(/sbin/losetup -f) #get first free loop device
+ if [ ! "$FREELOOP" ]; then # no free loop device, create a new one
+ #find a free loop device and use it
+ usedminor=$(/sbin/losetup -a | tail -n1|sed 's/.*loop\(.*\)\: .*/\1/')
+ #usedminor=${usedminor:9:1}
+ freeminor=$(($usedminor+1))
+ echo "Creating a new device : mknod -m777 /dev/loop$freeminor b 7 $freeminor"
+ mknod -m777 /dev/loop$freeminor b 7 $freeminor
+ FREELOOP=/dev/loop$freeminor
+ fi
+ fi
+
+ #detect fs
+ case $PND_FSTYPE in
+ ISO)
+ /sbin/losetup -r $FREELOOP "$PND" #attach the pnd to the loop device
+ mntline="mount -o ro" #setup the mountline for later
+ mntdev="${FREELOOP}"
+ ;;
+ directory)
+ #we bind the folder, now it can be treated in a unified way
+ #ATENTION: -o ro doesnt work for --bind at least on 25, on 26 its possible using remount, may have changed on 27
+ mntline="mount --bind -o ro"
+ mntdev="${PND}"
+ ;;
+ Squashfs)
+ /sbin/losetup -r $FREELOOP "$PND" #attach the pnd to the loop device
+ mntline="mount -t squashfs -o ro"
+ mntdev="${FREELOOP}"
+ ;;
+ *)
+ echo "ERROR Unknown filesystem type : $PND_FSTYPE"
+ exit 1;;
+ esac
+ echo "Mounting : $mntline \"$mntdev\" \"$MOUNT_TARGET/${PND_NAME}\""
+ $mntline "$mntdev" "$MOUNT_TARGET/${PND_NAME}" #mount the pnd/folder
+
+ if ! is_pnd_mounted ;then
+ sleep 1
+ echo "WARNING : mount faild, re-tring"
+ sleep 1
+ $mntline "$mntdev" "$MOUNT_TARGET/${PND_NAME}" #mount the pnd/folder
+ if ! is_pnd_mounted ;then
+ echo "ERROR The PND File-system is not mounted !"
+ show_mounted_info
+ return 2
+ fi
+ fi
+ else #the pnd is already mounted but a mount was requested with a different basename/uid, just link it there
+ echo WARNING $LOOP already mounted on $loopmountedon skipping losetup - putting link to old mount
+ #this is bullshit
+ rmdir "$UNION_MOUNT_DIR/$PND_NAME"
+ ln -s $loopmountedon "$UNION_MOUNT_DIR/$PND_NAME"
+ fi
+ fi
+
+ # For backward compatibility
+ if [[ "$MOUNT_TARGET" != "$PND_MOUNT_DIR" ]];then
+ if [ -d "$PND_MOUNT_DIR/$PND_NAME" ];then
+ rmdir "$PND_MOUNT_DIR/$PND_NAME"
+ else
+ rm "$PND_MOUNT_DIR/$PND_NAME"
+ fi
+ if [ ! -e "$PND_MOUNT_DIR/$PND_NAME" ];then
+ ln -s "$MOUNT_TARGET/$PND_NAME" "$PND_MOUNT_DIR/$PND_NAME"
+ fi
+ fi
+}
+
+mountUnion() {