+ mount -o bind "${old_mountp}" "${mountp}" || panic "Cannot bind-mount ${old_mountp} on ${mountp}"
+ else
+ if [ -z "${fstype}" ]
+ then
+ fstype=$(get_fstype "${dev}")
+ fi
+ mount -t "${fstype}" -o "${opts}" "${dev}" "${mountp}" || \
+ ( echo "SKIPPING: Cannot mount ${dev} on ${mountp}, fstype=${fstype}, options=${opts}" > live-boot.log && return 0 )
+ fi
+}
+
+find_cow_device ()
+{
+ # Returns a device containing a partition labeled "${pers_label}" or containing a file named the same way
+ # in the latter case the partition containing the file is left mounted
+ # if is not in black_listed_devices.
+ # Additionally, if the white_listed_devices list is non-empty, the
+ # parent block device of the returned device must be part of this list.
+ pers_label="${1}"
+ cow_backing="/${pers_label}-backing"
+ black_listed_devices="${2}"
+ white_listed_devices="${3}"
+
+ if [ -z "${PERSISTENT_PATH}" ]
+ then
+ pers_fpath=${cow_backing}/${pers_label}
+ else
+ pers_fpath=${cow_backing}/${PERSISTENT_PATH}/${pers_label}
+ fi
+
+ for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram | grep -v fd)
+ do
+ fulldevname=$(sys2dev "${sysblock}")
+
+ if echo "${black_listed_devices}" | grep -q -w "${fulldevname}"
+ then
+ # skip this device entirely
+ break
+ fi
+
+ if [ -n "${white_listed_devices}" ]
+ then
+ if echo "${white_listed_devices}" | grep -v -q -w "${fulldevname}"
+ then
+ # skip this device entirely
+ break
+ fi
+ fi
+
+ for dev in $(subdevices "${sysblock}")
+ do
+ devname=$(sys2dev "${dev}")
+
+ if echo "${black_listed_devices}" | grep -q -w "${devname}"
+ then
+ # skip this subdevice
+ continue
+ fi
+
+ # Checking for a luks device
+ if [ "${PERSISTENT_ENCRYPTION}" = "luks" ] && [ -e /sbin/cryptsetup ]
+ then
+ if ! /sbin/cryptsetup isLuks ${devname}
+ then
+ # we only look for encrypted subdevices
+ continue
+ fi
+
+ while true
+ do
+ load_keymap
+
+ /lib/cryptsetup/askpass "Enter passphrase for ${pers_label} on ${devname}: " | /sbin/cryptsetup -T 1 luksOpen ${devname} $(basename ${devname}) --key-file=-
+ error=${?}
+
+ devname="/dev/mapper/$(basename ${devname})"
+
+ if [ 0 -eq ${error} ]
+ then
+ unset error
+ break
+ fi
+
+ echo
+ echo -n "There was an error decrypting ${devname} ... Retry? [Y/n] " >&6
+ read answer
+
+ if [ "$(echo "${answer}" | cut -b1 | tr A-Z a-z)" = "n" ]
+ then
+ unset answer
+ break
+ fi
+ done
+ fi
+
+ if [ "$(/sbin/blkid -s LABEL -o value $devname 2>/dev/null)" = "${pers_label}" ]
+ then
+ echo "${devname}"
+ return 0
+ fi
+
+ if [ "${PERSISTENT}" = "nofiles" ]
+ then
+ # do not mount the device to find for image files
+ # just skip this
+ continue
+ fi
+
+ case "$(get_fstype ${devname})" in
+ vfat|ext2|ext3|ext4|jffs2)
+ mkdir -p "${cow_backing}"
+ if try_mount "${devname}" "${cow_backing}" "rw"
+ then
+ if [ -f "${pers_fpath}" ]
+ then
+ echo $(setup_loop "${pers_fpath}" "loop" "/sys/block/loop*")
+ return 0
+ else
+ umount ${cow_backing} > /dev/null 2>&1 || true
+ fi
+ fi
+ ;;
+ *)
+ ;;
+ esac
+ done
+ done
+ return 1
+}
+
+find_files ()
+{
+ # return the a string composed by device name, mountpoint an the first of ${filenames} found on a supported partition
+ # if is not in black_listed_devices.
+ # Additionally, if the white_listed_devices list is non-empty, the
+ # parent block device of the returned device must be part of this list.
+ # FIXME: merge with above function
+
+ filenames="${1}"
+ snap_backing="/snap-backing"
+ black_listed_devices="${2}"
+ white_listed_devices="${3}"
+
+ for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -v loop | grep -v ram | grep -v fd)
+ do
+ fulldevname=$(sys2dev "${sysblock}")
+
+ if echo "${black_listed_devices}" | grep -q -w "${fulldevname}"
+ then
+ # skip this device entirely
+ break
+ fi
+
+ if [ -n "${white_listed_devices}" ]
+ then
+ if echo "${white_listed_devices}" | grep -v -q -w "${fulldevname}"
+ then
+ # skip this device entirely
+ break
+ fi
+ fi
+
+ for dev in $(subdevices "${sysblock}")
+ do
+ devname=$(sys2dev "${dev}")
+ devfstype="$(get_fstype ${devname})"
+
+ if echo "${black_listed_devices}" | grep -q -w "${devname}"
+ then
+ # skip this subdevice
+ break
+ fi
+
+ if is_supported_fs ${devfstype}
+ then
+ mkdir -p "${snap_backing}"
+
+ if try_mount "${devname}" "${snap_backing}" "ro" "${devfstype}"
+ then
+ for filename in ${filenames}
+ do
+ if [ -f "${snap_backing}/${filename}" ]
+ then
+ echo "${devname} ${snap_backing} ${filename}"
+ umount ${snap_backing}
+ return 0
+ fi
+ done
+ fi
+
+ umount ${snap_backing}
+ fi
+ done
+ done
+}
+
+get_mac ()
+{
+ mac=""
+
+ for adaptor in /sys/class/net/*
+ do
+ status="$(cat ${adaptor}/iflink)"
+
+ if [ "${status}" -eq 2 ]
+ then
+ mac="$(cat ${adaptor}/address)"
+ mac="$(echo ${mac} | sed 's/:/-/g' | tr '[a-z]' '[A-Z]')"
+ fi
+ done
+
+ echo ${mac}
+}
+
+is_luks()
+{
+ devname="${1}"
+ if [ -x /sbin/cryptsetup ]
+ then
+ /sbin/cryptsetup isLuks "${devname}" 2>/dev/null || ret=${?}
+ return ${ret}