2

I'm in a situation where I need to mount the UNC root, i.e. "\" or "smb://". I can open up nautilus and go to "smb://" but I need to actually do things with that, such as: readdir, mkdir, unlink, rmdir, open, read, write, etc. from the standard POSIX filesystem APIs. Is there existing software that lets me do that?

I've tried mount -t cifs "//" but it gives me

mount error: UNC name too short

I've also tried mount -t cifs "smb://" but that gives me a

Mounting cifs URL not implemented yet. Attempt to mount smb://

I've tried all those smb commands of old, but they're no longer present - I believe which have moved to cifs instead. I've also tried these fancy new gvfs / gio things, which I suppose is a gobject based userland mounting system, but gio mount smb:// gives me...

gio: smb:///: Location is already mounted

... Mounted where? I can go to it in nautilus, but again I can't do anything with that. I thought it might be mounted at /run/user/1000/gvfs but that program-fuse-folder-thing doesn't seem to do much on it's own unless I specifically mount things using the command.

I don't even really require to be able to list smb:// or even smb://server/, but I need ALL smb://server/shares/ to be available, which the same functionality as if I had mounted them using smb or gvfs (e.g. listing, making folders, deleting things, opening files, and also authentication).

To further clarify, any and all applications need to be able to basic perform filesystem API functions on any and all unc paths, at least to the extent provided by gvfs or cifs. For example, I should be able to:

cd /some/path/server1/share1/folder1
cat file1
mkdir newfolder2
cd ../existingfolder3
touch file2
cd /some/path/server2/share2
rmdir existingfolder4

... etc. Bonus points if I could ls /some/path/server1

There are plenty of fuse libraries out there, so I was considering writing a little script that automatically mounted the shares when requested, and then just passing through the commands to the mount points, but I certainly don't want to reinvent the wheel, and I'd also love for something much for portable than anything I would have the time to develop. But if this is the easiest way then I can start writing some code and either post it here or start a new question when I need help with it.

Thank you!

2

Just as a side note: Every time someone on earth creates a smb / samba share of the root directory of a machine a Network Administrator in heaven loses his wings.

I've tried mount -t cifs "//"

Your syntax is wrong, it's incomplete, and you can't designate a share on the server as "/".

[1] Go to the server and create a share of "/" if that is what you truly want to do but name the share ... I don't know ... how about "root"

[2] Create a mount point on the client to mount the share - let's say /home/agnes/servername

[3] Then mount with a command that looks something like this:

sudo mount -t cifs //servername/root /home/agnes/servername -o some-list-of-options

Will it do everything you want it to do in your original post? I have no idea.

You can also go old school I guess and use smbclient:

smbclient //servername/root

You will end up with the prompt:

smb: >

If you enter help you will see the list of commands at your disposal:

? allinfo altname archive backup
blocksize cancel case_sensitive cd chmod
chown close del deltree dir
du echo exit get getfacl
geteas hardlink help history iosize
lcd link lock lowercase ls
l mask md mget mkdir
more mput newer notify open
posix posix_encrypt posix_open posix_mkdir
posix_rmdir posix_unlink posix_whoami print prompt
put pwd q queue quit
readlink rd recurse reget rename
reput rm rmdir showacls setea
setmode scopy stat symlink tar
tarmode timeout translate unlock volume
vuid wdel logon listconnect
showconnect tcon tdis tid logoff
..

  • Fantastic reply, thank you. I like the remark at the beginning too, but I am working with a windows-related thing so that's to be expected of course xD But this still doesn't solve my problem unfortunately - I have something that expects the exact same api for browsing the UNC root as it does the files inside of a samba share. Modifying the thing is not an option for both the reasons that it's not the simplest and more direct thing to do, but also another reason which I will not list. I would prefer to use the same API everything else in Linux is using, because that seems most correct. – user165680 Aug 12 '18 at 21:08
  • And also, Your syntax is wrong, it's incomplete, and you can't designate a share on the server as "/" It is wrong and incomplete which is why I'm asking for help, but I'm not trying to designate a share on a server as "/", I'm asking for something that will automatically translate that for me. – user165680 Aug 12 '18 at 21:10
0

As far I can understand - the smbtree command will do what you want.

From its man smbtree-page:

NAME
smbtree - A text based smb network browser

DESCRIPTION

This tool is part of the samba(7) suite.

smbtree is a smb browser program in text mode. It is similar to the "Network Neighborhood" found on Windows computers. It prints a tree with all the known domains, the servers in those domains and the shares on the servers.

  • Hey, this is a spectacular tool, thank you! Especially for answering so quickly. But I should probably clarify in my question that I need to be able to: readdir, mkdir, unlink, rmdir, open, read, etc. from the standard POSIX filesystem API with the smb monts. – user165680 Aug 11 '18 at 14:54
  • I recommend to read Samba documentation and determine how they do all these things. From my experience we have two stages - share discovery and share mount. Discovery is done by smbtree and smbclient -L host. Then mounted share may be manipulated by cifs-utils, smbmount, GVFS and so on. Also see ArchLinux wiki for brief information about Samba. – N0rbert Aug 11 '18 at 15:03
  • So then I would need the share share discovery and share mount stages to happen without any interaction at all. I'll take a look through the documentation links and report back, thanks! – user165680 Aug 11 '18 at 15:18
0

I found it...

It's called smbnetfs.

It does everything I asked for in the question, although for listing and some other operations it's really slow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.