1

I mounted a SMB share folder under /mnt/smb/ and I can access the files. When I unmount this shared folder using command:

umount /mnt/smb/

naturally I cannot list shared folder contents using command:

ls /mnt/smb/

But the problem is when I run the ls command from a PHP file on the same machine, the contents of shared SMB folder can be listed! The contents of PHP file is:

<?php
  $command = 'ls /mnt/smb/';
  $result = shell_exec($command);
  echo $result;
?>

What is my mistake. Is there any other commanf needed for completely unmount the SMB share? I also used command below but there was no luck:

fusermount -u /mnt/smb/
  • Please also post the output of mount | grep /mnt/smb after umounting (when ls from the shell does not work), then also check whether the command gives the same result (hopefully, an empty line) after accessing from php. If there is a difference maybe the share is auto-mounted again. NB: If the output of the mount command contains a username or password, I suggest you remove it before posting. – Ned64 Feb 17 '18 at 9:45
  • The output is: //172.16.50.207/SoftBank on /mnt/smb type cifs (rw,relatime,vers=1.0,cache=strict,username=teknik,domain=OFIS-NAS,uid=0,noforceuid,gid=0,noforcegid,addr=172.16.50.207,file_mode=0755,dir_mode=0755,nounix,serverino,mapposix,rsize=61440,wsize=65536,echo_interval=60,actimeo=1) – Hamid Reza Feb 17 '18 at 12:16
  • If that it the output after umounting then the drive has NOT been umounted in the first place! ls /mnt/smb/ should work (at least as root!). Oh, and please move the output into your question so that it can be formatted correctly. – Ned64 Feb 17 '18 at 12:27
  • Sorry, my wrong. The output of mount | grep /mnt/smb after UMOUNT is empty line. My previous comment was output after MOUNT. – Hamid Reza Feb 17 '18 at 12:55
  • Very good. Now, after the empty line, (a) can you list the files by php?, and (b) if you can, then please test the mount command again and let us know. – Ned64 Feb 17 '18 at 12:58
1

Please repeat the umount command as needed, until the /mnt/smb folder is u(n)mounted according to ls in the shell. Then it should also be according to the mount command:

mount | grep /mnt/smb

so that the share really is not mounted any more. If some process still lists remote contents, it must be cached (unlikely in this php system call situation, though).

Any command can still see the mount point, of course, because it is a directory. Any local files that the directory contains will be listed, by php or from a shell.

In order to fix this last issue you could first move/remove the files from the local directory (while the share is not mounted), then do chmod 0 /mnt/smb as root to indicate the non-mountedness and create ls-errors while not mounted.

  • Thanks, any way for removing cahce? – Hamid Reza Feb 17 '18 at 12:12
  • @HamidReza Let's check whether the umount was successful, first. – Ned64 Feb 17 '18 at 12:33

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.