- # 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)
+ # Scans devices for overlays and snapshots, and returns a whitespace
+ # separated list of how to use them. Only overlays with a partition
+ # label or file name in ${overlays} are returned, and ditto for
+ # snapshots with labels in ${snapshots}.
+ #
+ # When scanning a LUKS device, the user will be asked to enter the
+ # passphrase; on failure to enter it, or if no persistent partitions
+ # or files were found, the LUKS device is closed.
+ #
+ # For a snapshot file the return value is ${label}=${snapdata}", where
+ # ${snapdata} is the parameter used for try_snap().
+ #
+ # For all other cases (overlay/snapshot partition and overlay file) the
+ # return value is "${label}=${device}", where ${device} a device that
+ # can mount the content. In the case of an overlay file, the device
+ # containing the file will remain mounted as a side-effect.
+ #
+ # No devices in ${black_listed_devices} will be scanned, and if
+ # ${white_list_devices} is non-empty, only devices in it will be
+ # scanned.
+
+ overlays="${1}"
+ snapshots="${2}"
+ black_listed_devices="${3}"
+ white_listed_devices="${4}"
+
+ for dev in $(storage_devices "${black_listed_devices}" "${white_listed_devices}")