perl prog that writes a windows .bat file that recreates mounts

James Ganong jeg@bigseal.ucsc.edu
Fri Nov 26 19:58:00 GMT 1999


i was inspired by Phil Edwards entry in the todo list 
at http://sourceware.cygnus.com/cgi-bin/cygwin-todo.cgi?19991124.133151
"Some kind of 'fstab'"

to write a simple perl prog that dumps out the current mount
configuration into a .bat file that can run from windows
that will recreate the current mount setup.

here it is:

(i wrote this using cygwin v1.0 i don't
know if mount works the same on other versions)

#!/contrib/bin/perl
@fstab=`mount`;
$mount_path = &which_windows_style_path("mount");
$umount_path = &which_windows_style_path("umount");
print "$umount_path --remove-all-mounts \n";
for (@fstab) {
    next if /^Device/;
    chomp;
    ($device,$dir,$type,$flags)= split;
    $device =~ s/\\/\//g;
    $options="-f ";  # i force them all, it seems to work better!
    $options .= "-s "  if $type  =~  /system/;
    $options .= "-b "  if $flags  =~  /binmode/;
    $options .= "-x "  if $flags =~  /exec/;
    print "$mount_path $options $device $dir \n";
}

sub which_windows_style_path {
    $command =shift;
    for (split ':', $ENV{PATH}) {
        for ("$_/$command") {
            if (-x $_){
                if ($_ eq "./$command") {
                    $pwd = `pwd`;
                    chomp $pwd;
                    $_ = "$pwd/$command";
                }
                $_ = `cygpath -w $_`;
                chomp;
                return $_;
            }
        }
    }   die "could not find path to $command";
}

--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com



More information about the Cygwin mailing list