Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Mount a Samba share in code

Tags:

android

mount

smb

I'm looking for a way to mount Samaba shares programatically.

I am aware of this question which, if it works, would allow browsing a Samba share within my app, but I want the shares to be available to other apps once mounted.

I know ES File Explorer can do this, so it must be possible to implement in code, but I'm trying to figure out how it's done. The only method I can think of is opening a Process with Runtime.getRuntime().exec(...) but then there's the issue of what commands to send. I've been playing about in a terminal emulator app and the standard mount command doesn't seem to be working. I've tried the following:

mount -t smbfs //[ipaddress] /mnt/sdcard/net/Share1

and

mount -t cifs //[ipaddress] /mnt/sdcard/net/Share1

but in both cases I'm getting the rather uninformative error message "mount: no such device"

Where could I be going wrong?

like image 600
LairdPleng Avatar asked Jun 09 '13 14:06

LairdPleng


2 Answers

Probably smbfs/cifs are currently not supported by your kernel. As Delyan said, ensure your kernel can mount these filesystem :

$ cat /proc/filesystems
nodev   sysfs
nodev   rootfs
nodev   bdev
nodev   proc
nodev   cgroup
nodev   tmpfs
nodev   debugfs
nodev   sockfs
nodev   usbfs
....

If they are not listed, you should try to do a modprobing (sometimes the module you want just have to be activated), get root access then :

# modprobe <modulename(without.ko)>

e.g. :

# modprobe cifs

If it doesn't work you will have to change or recompile your kernel (including appropriate modules).

like image 109
EricLavault Avatar answered Oct 31 '22 16:10

EricLavault


I ran into the exact same problem. Cifs manager was working, but the command from the terminal was not. For me anyway, it turned out that I just had to modify the command slightly and it worked. Try the following command:

mount -o username=guest,password=guest -t cifs //[ipaddress]/[share] /sdcard/cifs/nas

Make sure that the local folder /sdcard/cifs/nas (or your desired equivalent) exists before running the command or you might get a "file or directory doesn't exist" error.

like image 1
Dre Avatar answered Oct 31 '22 16:10

Dre