Extract enable_usb_storage() from mount-usb

enable_usb_storage() inserts usb-storage.ko if not already loaded, then
waits for USB storage devices to appear.

Signed-off-by: Jonathon Hall <jonathon.hall@puri.sm>
This commit is contained in:
Jonathon Hall 2022-11-09 14:02:03 -05:00
parent b365f1324a
commit 606c29f0ec
No known key found for this signature in database
GPG Key ID: 1E9C3CA91AE25114
2 changed files with 19 additions and 12 deletions

View File

@ -5,18 +5,7 @@
TRACE "Under /bin/mount-usb"
enable_usb
if ! lsmod | grep -q usb_storage; then
timeout=0
echo "Scanning for USB storage devices..."
insmod /lib/modules/usb-storage.ko >/dev/null 2>&1 \
|| die "usb_storage: module load failed"
while [[ $(list_usb_storage | wc -l) -eq 0 ]]; do
[[ $timeout -ge 8 ]] && break
sleep 1
timeout=$(($timeout+1))
done
fi
enable_usb_storage
if [ ! -d /media ]; then
mkdir /media

View File

@ -81,6 +81,24 @@ confirm_totp()
echo
}
# Enable USB storage (if not already enabled), and wait for storage devices to
# be detected. If USB storage was already enabled, no wait occurs, this would
# have happened already when USB storage was enabled.
enable_usb_storage()
{
if ! lsmod | grep -q usb_storage; then
timeout=0
echo "Scanning for USB storage devices..."
insmod /lib/modules/usb-storage.ko >/dev/null 2>&1 \
|| die "usb_storage: module load failed"
while [[ $(list_usb_storage | wc -l) -eq 0 ]]; do
[[ $timeout -ge 8 ]] && break
sleep 1
timeout=$(($timeout+1))
done
fi
}
list_usb_storage()
{
TRACE "Under /etc/functions:list_usb_storage"