Am 26.05.2010 schrieb Paul Slootman:
> On Wed 26 May 2010, Jens Lang wrote:
> > mount_check() checks for the presence of /lost+found in a mount point in
> > order to find out whether the mount succeeded. Instead, one should check
> > the return value of the mount command. If it is not equal to zero, the
> > mount failed.
> 
> Ah yes, but perhaps the filesystem was already mounted beforehand?
> The mount will fail, but the filesystem is mounted so the backup can
> proceed. Please suggest how to work around that.

Yes, of course it should be checked beforehand if the file system is already 
mounted. For some reason this does not occur on my system so I did not notice 
that insufficiency.

So, now I am doing a mount which lists all mount points. With grep, I am 
looking, if the desired mount point exists already. If not, I try to mount 
that device.

As http://git.debian.org/?p=users/lamont/util-
linux.git;a=blob;f=mount/mount.c;hb=HEAD#l261 indicates (packet util-linux, 
file mount/mount.c, line 266), the output of mount is not localised so that it 
should be safe parsing the output with the regular expression given to grep.

Best regards,

Jens

9,17c9,19
< 	mntout=`tempfile -p mount`
< 	mount $1 >$mntout 2>&1
< 	if [ ! -d $1/lost+found ]; then # only works for "real" filesystems :-)
< 					# (Yes, I know about reiserfs.)
< 		echo "'mount $1' failed?! Stopping."
< 		echo "mount output:"
< 		cat $mntout
< 		rm -f $mntout
< 		exit 2
---
> 	mount | grep '^.* on '$1' ' --silent # check if already mounted
> 	if [ $? -ne 0 ]; then # is not mounted
> 		mntout=`tempfile -p mount`
> 		mount $1 >$mntout 2>&1 # try mounting
> 		if [ $? -ne 0 ]; then  # mount failed
> 			echo "'mount $1' failed?! Stopping."
> 			echo "mount output:"
> 			cat $mntout
> 			rm -f $mntout
> 			exit 2
> 		fi

Reply via email to