Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an issue where a directory is shown as a file when accessing a samba share ( on Ubuntu 12.10 ) from a Windows machine.

The output from ls -ll in the folder on the linuxbox is as follows:

chubby@chubby:/media/blackhole/_Arkiv$ ls -ll
total 0
drwxrwxrwx 0 jv users 0 Jun 18  2012 _20
drwxrwxrwx 0 jv users 0 Apr 17  2012 _2006
drwxrwxrwx 0 jv users 0 Apr 17  2012 _2007
drwxrwxrwx 0 jv users 0 May 12  2011 _2008
drwxrwxrwx 0 jv users 0 Feb 19 09:53 _2009
drwxrwxrwx 0 jv users 0 Dec 20  2011 _2010
drwxrwxrwx 0 jv users 0 May  8  2012 _2011
drwxrwxrwx 0 jv users 0 Mar  5 11:37 _2012
drwxrwxrwx 0 jv users 0 Feb 28 10:09 _2013
drwxrwxrwx 0 jv users 0 Feb 28 11:18 _Mailarkiv
drwxrwxrwx 0 jv users 0 Jan  3  2011 _Praktikanter

The entry in /etc/fstab is:

# Mounting blackhole
// /media/blackhole cifs uid=jv,gid=users,credentials=/home/chubby/.smbcredentials,iocharset=utf8,file_mode=0777,dir_mode=0777 0 0

When I access the share directly from the NAS on my Windows box, there are no issues.

The version of Samba is 3.6.6, but I couldn't find anything in the changelogs that seem relevant.

I've tried mounting it in different locations with different permissions, users and groups but I have not made any progress

Due to my low reputation on serverfault ( mostly stackoverflow user ) I'm unable to post a screenshot that shows that the directories are shown as files.

If I type the full path in explorer, the directory listing works excellently, except for any subdirectories that are then shown as files.

Any attack vector for this issue would be greatly appreciated.

Please let me know if I have provided insufficient details.

Edit: The same share when accessed from a OS X, works perfectly listing the directories as directories. Best Regards!

share|improve this question
up vote 7 down vote accepted

I have finally solved the problem.

I'll try to write this answer out more when I have the time.

The issue is connected to resharing a cifs filesystem, and then accessing this from a Windows7 computer.

The samba bug is here:

This apparently stems from the way information is set on the inode in cifs.

See bug here:

So the way Samba tells determines ( for its Windows clients ) is by counting the number of hardlinks, rather than testing for the attribute. As cifs ( for some obscure reason ) always sets this to zero, where a directory always will have at least two, the directory will appear as a file for Windows clients.

So to "fix" this I installed my current kernel-headers and the linux source code:

sudo apt-get install linux-headers-$(uname -r) linux-source

I then went to /usr/src/linux-source-3.5.0 and extracted the archive there.

Finding the folder /usr/src/linux-source-3.5.0/linux-source-3.5.0/fs/cifs I change the following in the file inode.c (line 135):

set_nlink(inode, fattr->cf_nlink);


if(fattr->cf_cifsattrs & ATTR_DIRECTORY)
          set_nlink(inode, 2);
          set_nlink(inode, fattr->cf_nlink);

I then created a makefile to ease compilation ( and avoid annoying insmod errors ): Makefile2:

obm-m := cifs.o
KDIR := /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
        $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules

This allows us to do ( in the same folder ): sudo make -f Makefile2

This gives us a file called cifs.ko.

So now we can stop Samba, unmount any shares we have, remove the current cifs, and install our recompiled one.

sudo service smbd stop
sudo umount /path/to/share
sudo rmmod cifs
sudo insmod cifs.ko
sudo mount -a
sudo service smbd start

For me this did the trick, if you restart the box though, this change will not persist. I'll add to this post when I've figured out a good way to do this.

Please throw any questions or clarifications you require my way, I'll probably learn from it :)

Also thanks to kukks in #samba on freenode, I learned a lot of stuff there, though I ended up moving in another direction.

share|improve this answer
Wow, that's the kind of bug that makes me wonder "what the heck were they thinking when they wrote that?" If you want to detect an attribute, query the attribute, don't look at a loose correlate. It's like writing a method: bool isPirate() {return pegLegs == 1;}. You'll be right most of the time, but there are some significant times when you won't. – Kennet Belenky Jan 27 '14 at 22:19
Thanks, the patch worked for me running Ubuntu 12.04 kernel 3.11 and samba 3.6.3. Just a couple of problems I found: 1) I had to run apt-get source linux-image-$(uname -r) to get the proper sources. 2) To be able to run make succesfully I copied the fs/cifs sources folder under de headers folder with the same subpath and compiled from the root of headers with make M=fs/cifs, as explained here:‌​ule – drodsou Apr 23 '14 at 17:04

protected by HopelessN00b Jul 11 '14 at 13:25

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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