Tuesday, 26 September 2017

Showing Hidden Files as Hidden in Windows from Linux Samba Share of NTFS Drive


I have a Raspberry Pi which is using samba and ntfs-3g in order to share a USB external hard drive on my home network. On the hard drive, there are some files which are marked with the "Hidden" Windows file attribute. However, when I access the share on a Windows PC, the files do not show as hidden. As a result, I see many hidden files such as desktop.ini, thumbs.db, as well as directories like $RECYCLE.BIN and System Volume Information, even though my Windows setting in Folder Options is set to not show hidden files.


I know that samba is not correctly transferring the Hidden attribute because if I view the Properties of a file that should be hidden, the Hidden check-box is not selected:


Not hidden


These are the current contents of my smb.conf file:


#### GLOBAL CONFIG #####

workgroup = WORKGROUP
netbios name = raspberrypi
server string = %h
wins support = yes
dns proxy = no
security = share
null passwords = yes
guest account = nobody
interfaces = eth0 lo
bind interfaces only = yes

#### PUBLIC SHARE #####

[Mazda6]
comment = Media Drive
path = /media/HDD
browseable = yes
guest ok = yes
writeable = yes
public = yes
available = yes
create mask = 0666
directory mask = 0777

How can I have files that are marked with the Hidden file attribute on the NTFS drive to be shown as Hidden when viewed through the samba share on a Windows PC?



Answer



I believe -- but have not tested myself -- that you need only add map hidden = yes to the configuration for your share. Note that this may have the unintended/undesired behavior of making "other executable" files (per the Linux file permissions) rendered "hidden" in Windows as well; this is because Samba in effect repurposes that bit to be the "hidden" attribute for Windows, as it resides on top of Linux which has no such attributes.


Failing that, you should be able to use the hide files option to hide the files you specify; for example, you apply this to your share's config:


hide files = /$RECYCLE.BIN/System Volume Information/desktop.ini/thumbs.db/

The downside here, of course, is that you must hard-code the files you want hidden explicitly in your config, and unfortunately there's no way to distinguish between e.g. a desktop.ini that should be hidden, and a desktop.ini that should not be hidden -- both will be hidden with this setting. (NOTE: I'm unsure if this will work with directories; I believe it should, but cannot test it at the moment. There may also be issue with the $ character; again, I think it will work, but I'm not able to test it right now.)


As always, the documentation is your friend.


Update: Per the OP's testing as reported in the comments below, it seems all files on an NTFS partition may show up in Linux with 0777 permissions; since this means the "other execute" bit is set, Samba ends up interpreting every single file as "hidden" with the map hidden setting turned on, rendering that solution untenable without first moving all data to a different file system.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...