#!/bin/sh # Copyright (C) 2005 Krzysztof Kozlowski # License: GNU General Public License version 2 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # version 2 as published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # # Homepage: http://www.kozik.net.pl # # Ostatnia zmiana: 28.09.2006 # # Mount cloop/loop file # # usage () { echo "Usage: $(basename $0) [--rw] [--cloop] file mount_point" echo " --cloop - use cloop" exit 127 } if [ $# -lt 2 ]; then usage fi if [ $# -eq 3 ] && [ $1 == "--cloop" ]; then USE_CLOOP=1 DEV="/dev/cloop" else USE_CLOOP=0 DEV="/dev/loop" fi find_free_loop_dev () { for i in 0 1 2 3 4 5 6 7 ; do is_used=`mount | grep loop${i} | cut -f 1 -d ' '` if [ "$is_used" == "" ]; then echo ${DEV}${i} return fi done echo "" return } if [ $USE_CLOOP -eq 1 ]; then modprobe cloop fi LOOP_DEV=`find_free_loop_dev` if [ "$LOOP_DEV" != "" ]; then echo "Using loop device: $LOOP_DEV" losetup $LOOP_DEV "$1" mount -o rw $LOOP_DEV "$2" exit 0 else echo "Could not find any free loop device!" exit 2 fi