Re: SMBFS: Question...

Brion Vibber (brion@pobox.com)
Tue, 04 Aug 1998 17:58:08 -0700


This is a multi-part message in MIME format.
--------------0CF7E27B40E605CB0B81755B
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Michael H. Warfield wrote:
>
> A way to hook this out of the "mount" command would definitly be
> sweet, let's just not loose sight of the compatibility issues this time.

I'm surprised no one else has done this yet... Here's a perl script that
will call either regular mount or (classic) smbmount (or new with the
wrapper). It seems to work for me, but I provide no warranty for it
working for anyone else in any circumstances! Feel free to tune to your
preferences.

Note that this will almost certainly _not_ work for smbfs partitions
listed in /etc/fstab, you'll need to specify at least service name
(//server/service) and mount point on the command line.

Enjoy!

-- brion vibber (brion@pobox.com)
--------------0CF7E27B40E605CB0B81755B
Content-Type: application/x-perl;
name="newmount.pl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="newmount.pl"

#!/usr/bin/perl
# Takes the place of mount to provide either regular or SMB mounts.
# Copyright (c) 1998 by Brion Vibber (brion@pobox.com)
# No warranty! Use at your own risk! License is GPL 2.0 - see http://www.fsf.org

# The real mount should be at the location specified here:
$mount = "/bin/mount.real";

# And smbmount should be here:
$smbmount = "/usr/sbin/smbmount";

# Check if we have -t smbfs or //foo/bar in the params
foreach $param (@ARGV) {
if($foundt) {
exit dosmbmount(@ARGV) if $param eq "smbfs";
$foundt = 0;
}

if($param eq "-t") {
$foundt = 1;
next;
} elsif($param =~ /^\/\/.+\/.+/) {
exit dosmbmount(@ARGV);
}
}

# Not a SMB share - run mount
unshift @ARGV, $mount;
exit system @ARGV;

# A SMB share - munge parameters and run smbmount
sub dosmbmount {
@mountargs = @_;
@args = ();

# Munge them args
foreach $arg (@ARGV) {
if($skip) {
# Skip this argument
$skip = 0;
next;
} elsif($isoptions) {
# Translate some logical options into smbmount args
# Based on the msdos & nfs options somewhat
@opts = split /,/, $arg;
foreach $option (@opts) {
($opt, $val) = split /=/, $option;
# These are based on the fat mount options
if($opt eq "uid") {
push @args, "-u";
push @args, $val;
} elsif($opt eq "gid") {
push @args, "-g";
push @args, $val;
} elsif($opt eq "umask") {
# Set the file mode to the umask
push @args, "-f";
push @args, $val;
# And the dir mode to the umask + execute
push @args, "-d";
push @args, sprintf "%lo", ((oct $val) | 0111);
} # These are specifically for smbfs
elsif($opt eq "user") {
# User name
push @args, "-U";
push @args, $val;
} elsif($opt eq "domain") {
# Domain name
push @args, "-D";
push @args, $val;
} elsif($opt eq "max") {
# Maximum packet size
push @args, "-m";
push @args, $val;
} elsif($opt eq "port") {
# TCP port - normallf 138
push @args, "-p";
push @args, $val;
} elsif($opt eq "ip") {
# IP address of server
push @args, "-I";
push @args, $val;
} elsif($opt eq "server") {
# Server's netbios name
push @args, "-s";
push @args, $val;
} elsif($opt eq "nopwd") {
# Don't prompt for password
push @args, "-n";
} elsif($opt eq "lcasepwd") {
# Don't capitalize password
push @args, "-C";
}
}
$isoptions = 0;
} elsif($arg eq "-a") {
# Mount all filesystems
# NYI
} elsif($arg eq "-F") {
# Fork
# NYI
} elsif($arg eq "-f") {
# Fake - don't actually go
# This will just print the command line to be used
$isfake = 1;
} elsif($arg eq "-n") {
# Don't write in fstab
# NYI
} elsif($arg eq "-s") {
# Tolerate sloppy mount options
# Implemented for errors _here_ but not in smbmount
$sloppy = 1;
} elsif($arg eq "-r") {
# Read-only
# Adjust to your preference
push @args, "-f";
push @args, "444";
push @args, "-f";
push @args, "555";
} elsif($arg eq "-w") {
# Read-write
# Adjust to your preference
push @args, "-f";
push @args, "664";
push @args, "-f";
push @args, "775";
} elsif($arg eq "-t") {
# Filesystem type
# We already know it's smbfs
$skip = 1;
next;
} elsif($arg eq "-o") {
# Options
$isoptions = 1;
next;
} elsif(not ($arg =~ /^\-/)) {
# Not an option - fill in service or mount point
if(not $service) {
$service = $arg;
} elsif(not $mountpoint) {
$mountpoint = $arg;
} else {
print STDERR "Unknown option $arg\n";
return 1 unless $sloppy;
}
} else {
print STDERR "Unknown option $arg\n";
return 1 unless $sloppy;
}
}

# Prepend mount program, service name, and mount point
unshift @args, ($smbmount, $service, $mountpoint);

# Go!
if($isfake) {
print "Command line: ", (join " ",@args), "\n";
} else {
return system @args;
}
}

--------------0CF7E27B40E605CB0B81755B--

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html