#!/bin/sh #---------------------------------------------------------------------------- # /etc/boot.d/volume.inc # Functions for finding/mounting/unmounting volumes. # # Last Update: $Id$ #---------------------------------------------------------------------------- # List all block-devices excluding the raw device if partitions exist on it scandevices() { lastdev='' for dev in `sed -n '/ 1 [a-z]/d;s/^[ 0-9]\+\([^ 0-9#]\+[0-9]\{0,1\}\)$/\1/p' /proc/partitions | sed '/sr[0-9]/d'` do basedev=`echo $dev | sed 's/[0-9]\+//'` if [ "$lastdev" != "$basedev" ] then if [ -n "$lastdev" ] then echo $lastdev fi fi lastdev=$dev done if [ -n "$lastdev" ] then echo $lastdev fi } # Checks an unmounted filesystem. # $1 = device # $2 = file system check_fs() { case $2 in vfat) if type -p fsck.fat >/dev/null then fsck.fat -c 850 -a "$1" fi ;; ext2|ext3|ext4) if type -p e2fsck >/dev/null then e2fsck -p -C 0 "$1" fi ;; *) return 0 ;; esac } # Mounts a volume. Checks its file system if possible before mounting. # $1 = device # $2 = mount path # $3 = file system (vfat, ext[234]) # $4 = mount options (rw, ro, ...) mount_volume() { local opt=$4 [ -n "$opt" ] && opt="-o $opt" check_fs $1 $3 local rc=$? if [ $rc -gt 1 ] then log_error "File system check failed for $1 (return code $rc)! Mount aborted!" return 1 elif ! mount -t $3 $opt $1 "$2" then log_error "Unable to mount volume $1 on $2!" return 2 else return 0 fi }