6

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?

Community
  • 1
  • 1
LairdPleng
  • 948
  • 3
  • 9
  • 28
  • I would use JCIFs (I've used it before, it works) and run a `Service`. – Ken Wolf Jun 09 '13 at 14:21
  • 1
    The real problem is that to mount the filesystem using `mount` you're going to need CIFS support in your kernel via the appropriate modules. – Brian Roach Jun 09 '13 at 14:29
  • Ken, running a service is not an option. I need the files to be transparently available to other applications which aren't aware of mine. Essentially, once the mount is complete, any file explorer in any android app should be able to access the remote files – LairdPleng Jun 10 '13 at 02:48
  • Well CifsManager manages it, though it requires root access. – LairdPleng Jun 15 '13 at 02:57
  • 3
    `mount` requires a) the filesystem to be registered with the kernel (or use FUSE) and b) root access (not strictly true, it's possible to restrict mounting in a way that normal users can use it but Android doesn't do that). Use `cat /proc/filesystems` to find what file systems are recognized by the kernel. You'll still need root, if go down that path. I suspect the way other apps work is either by copying to external storage and pointing other apps to that, or by using a streaming ContentProvider (very, very difficult to implement, especially with samba). – Delyan Jun 19 '13 at 10:53
  • No, CifsManager definitely doesn't copy data or use a streaming provider (I think apps like ES FileManger *do* use a streming provider). I can use CifsManager to mount a share on my sdcard and then I can browse it with standard file manager tools and open files with any application. I have checked /proc/filesystems and my devices don't have CIFS or SMBFS as standard, so I guess it must be using FUSE, so I'll have a look into that. (Requiring root access is not an issue for this app) – LairdPleng Jun 20 '13 at 00:59
  • Are you sure CifsManager works without the cifs.ko kernel module you can specify under settings? – devconsole Jun 21 '13 at 17:19
  • Hmm I've just tested it on a couple of other devices. Some it just works on, and others not at all. The ones it does work on don't require loading the cifs.ko module – LairdPleng Jun 22 '13 at 06:41
  • Hmm, maybe some Android builds have CIFS built in and others don't (custom ROMs maybe)?. You could check if `su -c mount -t cifs //[ip]/[share] [mountpoint]` works on the devices where cifs.ko is not required. For the other devices you probably have to load cifs.ko yourself (try `su -c modprobe ...` or maybe `su -c insmod ...`, I didn't investigate in more detail. You should also be able to find a few cifs.ko modules out there. – devconsole Jun 22 '13 at 18:52
  • Hi. As I said in the question. On the device where it's working I've tried mounting the devices with SU and I'm getting 'no such device' errors – LairdPleng Jun 23 '13 at 01:19

2 Answers2

6

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).

Community
  • 1
  • 1
EricLavault
  • 12,130
  • 3
  • 23
  • 45
  • I have explained in the question and reiterated in the comments that CifsManager works, without any additional configuration, on the devices where this functionality is needed, yet mounting via command line doesn't work. – LairdPleng Jun 28 '13 at 15:43
  • Is the option "Load via insmod" checked in the CifsManager settings? In this case try to run 'busybox insmod cifs' before running mount command. – EricLavault Jun 28 '13 at 18:52
1

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.

Dre
  • 1,985
  • 16
  • 13