Some files on Samba shares are displayed as folders
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
andclient 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
Solution 1:
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.
- First I used the command
getfattr -R Movies > DOS-Movies.txt
on the directory ABOVE my movies folder. The above command runsgetfattr
recursively on the movies folder and returns all files & folders that have extended attributes, then saves them in a text file. - 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".
- 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. - 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"
- 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!
Solution 2:
As an alternative to removing the attributes, which does work for the currently shared files, but not necessarily for new files you add in the future, you can also disable the option, which is enabled by default since samba 4.9.0 and is causing this problem. (At least that is my experience)
Edit /etc/samba/smb.conf with your favorite file editor and disable the option to store the dos attributes.
[global]
...
# Make sure files are not shown as folders!
store dos attributes = no
Restart SMB afterwards via sudo systemctl restart smbd
.
Apparently it was enabled "[...] to allow better Windows fileserver compatibility in a default install."
Solution 3:
it's a bug, but there is a solution: https://bugs.launchpad.net/ubuntu/+source/samba/+bug/1872476