Ubuntu – Some files on Samba shares are displayed as folders

20.04directoryfilessamba

Ubuntu 20.04.1, Samba pkg 2:4.11.6+dfsg-0ubuntu1.2

Recently set a Samba share on my Ubuntu machine; nothing fancy just a share called "media" with three subdirectories – Movies, TV, & Photos.

This was fine for over a week, but as of yesterday, all of the files under the Photos directory are represented as directories. When accessing the Samba share from MacOS (smb://myserver/media), all the files are shown with the "folder" icon and when you cd into the folder through terminal, all the files are listed as drwx when running ls -al. The files cannot be used normally when they are in this state. Even if I copy that file to the MacOS machine, it remains as a directory. Accessing the files on the Ubuntu machine itself (i.e. locally) shows that the files are intact and everything appears normal.

Things I have tried to resolve the problem:

  • Restart the Ubuntu computer.
  • Restart the smbd service.
  • Added both min protocol = SMB2 and client min protocol = SMB2 to /etc/samba/smb.conf
  • Restart the MacOS machine.
  • Copied the affected files to a different directory on the share.
  • Made sure my Samba package is up to date.

It's weird because files in other directories on the share behave normally, and the files in the Photos directory behaved normally for over a week before this suddenly occurred.

Interestingly, this is similar behavior to an old bug, but I'm using the version of Samba which fixes this issue.

Any help would be much appreciated; since I didn't make any changes that resulted in this behavior, I'm not confident that a wipe-and-reload would (permanently) fix it. I was hoping to use this box as a NAS, but not being able to access files is a major showstopper.

Terminal

File GUI

*** EDIT: Similar behavior on Windows

Best Answer

I was experiencing the same issue, and the solution was worked for me was this:

All affected files/folders had the extended attribute user.DOSATTRIB. When performing getfattr #filename the result of a 'bad' file would be something like this:

getfattr Borat\ \(2006\).mp4
# file: Borat (2006).mp4
user.DOSATTRIB

To resolve this, I removed the extended attribute using the command setfattr -x user.DOSATTRIB #filename. So for the above example doing:

setfattr -x user.DOSATTRIB Borat\ \(2006\).mp4
getfattr Borat\ \(2006\).mp4

returned no extended attributes, and my network share file was able to be accessed again.

I'm currently figuring out how to run setfattr -x user.DOSATTRIB recursively on my folders. I'll edit this response when I've figured it out.

Update: Alright, so I did a kind of sloppy solution.

  1. First I used the command getfattr -R Movies > DOS-Movies.txt on the directory ABOVE my movies folder. The above command runs getfattr recursively on the movies folder and returns all files & folders that have extended attributes, then saves them in a text file.
  2. I opened that text file in Notepad++ in order to clean it up a bit, as other attributes which I did not want to remove were present, such as "user.encryptable".
  3. I used the regular expression (?-is)^.+\Ruser.encryptable\R to remove the line that included that attribute AND THE PREVIOUS LINE (the filename). I also removed all blank lines so I ended up with # file: Movies/Dune (1984)/Dune (1984).mp4 = just the files that had the DOSATTRIB extended attribute, one item per line. I also used Find/Replace to find \r\n and replace with "\r\n to add a " character at the end of each line.
  4. The command to remove the attribute is setfattr -x user.DOSATTRIB, so I did a basic Find/Replace and each line looked like this at the end: setfattr -x user.DOSATTRIB "Movies/Dune (1984)/Dune (1984).mp4"
  5. I then just pasted the commands which removed the DOSATTRIB on all files and folders, rendering them once again as readable from windows.

Hope this helps!

Related Question