>#!/usr/bin/bash >mkdir $2 >lofiadm -a $1 /dev/lofi/1 >mount -F hsfs -o ro /dev/lofi/1 $2 && echo -e "\n\t I have mounted $1 under >the folder $2\n\n"
You should realize that "lofiadm" actually outputs the device used, so the script can be written so as not to require only /dev/lofi/1 I've attached my scripts which I use for mounting/unmounting lofi volumes. It detects pcfs, ufs and hsfs filesystem and mounts them; it remembers the mount and a single "lofiumount" without arguments will unmount all you mounted. I've written these a long time ago, shortly after lofiadm was added, I think. Usage is simple: lofimount file.iso /mnt lofiumount /mnt lofimount file.ufs /mnt etc.
#!/usr/bin/sh # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # Author: [EMAIL PROTECTED] # PATH=/usr/sbin:$PATH export PATH if [ ! -x /usr/sbin/lofiadm ] then echo "$0: Only supported on systems with lofiadm (Solaris 8+)" 2>&1 exit 1 fi usage () { echo "Usage: $0 [-o options] file dir" 1>&2 exit 1 } options= while getopts o: c do case "$c" in o) if [ -n "$options" ] then usage fi options="$OPTARG," ;; *) usage;; esac done shift `expr $OPTIND - 1` state=/var/run/.lofi-$LOGNAME if [ "$#" = 0 ] then cat $state exit fi f=$1 dir=$2 if [ ! -f "$f" -o ! -d "$dir" ] then usage fi case "$f" in /*) ;; *) f=`pwd`/$f;; esac lofi=`lofiadm -a $f` if [ "$lofi" = "" ] then exit 1 # Lofi printed an error fi fstyp=`fstyp $lofi` # Sanity case "$fstyp" in ufs | udf) opt=nosuid; fsck -o p $lofi;; pcfs) opt=foldcase,hidden;; hsfs) opt=ro,nosuid;; *) echo "$0: unexpected filesystem type \"$fstyp\"" 2>&1 lofiadm -d $lofi exit 1;; esac opt="$options$opt" if [ ! -w $f ] then opt="$opt,ro" fi if mount -F $fstyp -o $opt $lofi $dir then echo $lofi $dir $f >> $state exit 0 else lofiadm -d $lofi exit 1 fi
#!/usr/bin/sh # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # # Copyright 2007 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # Author: [EMAIL PROTECTED] # PATH=/usr/sbin:$PATH export PATH p=`basename $0` if [ ! -x /usr/sbin/lofiadm ] then echo "$p: Only supported on systems with lofiadm (Solaris 8+)" 2>&1 exit 1 fi state=/var/run/.lofi-$LOGNAME # Nothing to do? [ -f $state ] || exit 0 if [ $# -gt 1 ] then echo "Usage: $p [file|dir]" 1>&2 exit 1 fi > $state.new while read lofi dir file do if [ -z "$1" -o "$1" = "$dir" -o "$1" = "$file" ] && umount $dir then lofiadm -d $lofi echo "$p: Unmounted $dir ($file)" else echo $lofi $dir $file >> $state.new fi done < $state mv $state.new $state if [ -s $state ] then exit 1 else rm -f $state exit 0 fi
_______________________________________________ opensolaris-discuss mailing list opensolaris-discuss@opensolaris.org