Check for multiple device mounts overridable by '-o force'.
authorshort <>
Tue, 28 Oct 2003 20:36:11 +0000 (20:36 +0000)
committershort <>
Tue, 28 Oct 2003 20:36:11 +0000 (20:36 +0000)
src/client/lufs/mount.captive.in
src/client/lufs/mount.captive.pod.pl.in

index b01ba33..1c4d1bc 100755 (executable)
@@ -38,7 +38,8 @@ $captive_sandbox_server_bin=~s#\$\Q{prefix}\E#'@prefix@';#ge;
 $captive_sandbox_server_bin="/usr/sbin/captive-sandbox-server" if $captive_sandbox_server_bin=~/^@/;
 
 
-my $fsname=($0=~m#([^/]*)$#)[0] or die "Cannot detetect my basename from: $0";
+my $ME=($0=~m#([^/]*)$#)[0] or die "Cannot detetect my basename from: $0";
+my $fsname=$ME;
 $fsname=~s/^mount[.]captive-// or die "Cannot detect captive filesystem module from my name: $fsname";
 my $image=shift @ARGV or die "Missing argv[1]: device or image pathname";
 -r $image or die "Image pathname not readable: $image";
@@ -87,11 +88,31 @@ if ($fsname eq "ntfs") {
 # to let the options be overridable by user (such as 'ro').
 my @opt_captive=();
 my @opt_lufs=();
+my $opt_force;
 for (split /,/,$oo) {
        $_="--$_" if $_ eq "ro" || $_ eq "rw";
+       $opt_force=1 if $_ eq "force";
        push @opt_captive,$_ if  /^--/;
        push @opt_lufs,$_    if !/^--/;
        }
+
+if (!$opt_force) {
+       local *MTAB;
+       if (!open MTAB,"/etc/mtab") {
+               warn "Cannot open /etc/mtab: $!";
+               }
+       else {
+               local $/=undef();
+               my $mtab=<MTAB>;
+               close MTAB;
+               die ""
+                                               ."$ME: $image already mounted\n"
+                                               ."$ME: according to mtab, $image is mounted on $1\n"
+                                               ."$ME: Use '-o force' to mount the image notwithstanding.\n"
+                               if $mtab=~/^\Q$image\E\s+(\S+)/m;
+               }
+       }
+
 $oo=""
                ."mntent.mnt_fsname=$image,mntent.mnt_type=captive-$fsname,"    # Double-dashes forbidden.
                ."dir_cache_entries=0,"
index 7c39880..be3676d 100644 (file)
@@ -94,6 +94,18 @@ B<lufsmount>(1). You may be interested in these unprefixed options:
 
 =over
 
+=item B<force>
+
+Force the mount of {B<image-file>|B<device>} despite it appears to be already
+mounted according to B<mtab>(5). You should never mount a device multiple
+times in read-write mode. It is safe to mount it multiple times in read-only
+mode. It is safe to mount it once in read-write mode and multiple times
+in read-only mode although you may encounter filesystem errors by the read-only
+filesystems in such case.
+
+This is the only option is interpreted by B<mount.@PACKAGE@> itself; it is not
+B<lufs-@PACKAGE@fs>(7) nor B<lufsmount>(1) option.
+
 =item B<uid>=B<500>
 
 Supply the B<UID> to be the user identification number owning all the files.