Mac SMB共享常见问题

Mac OS X 10.11 开始连接 SMB 共享很慢的问题

Mac OS X 默认需要验证 SMB 共享签名,导致连接速度很慢,因此需要禁用签名:

iPhilBendeck:~ philbendeck$ cat /etc/nsmb.conf
[default]
signing_required=no

检查当前的 SMB 共享连接是否启用了签名:

iPhilBendeck:~ philbendeck$ smbutil statshares -a 
==================================================================================================
SHARE                         ATTRIBUTE TYPE                VALUE
==================================================================================================
SD01                     
                              SERVER_NAME                   10.0.0.140
                              USER_ID                       501
                              SMB_NEGOTIATE                 AUTO_NEGOTIATE
                              SMB_VERSION                   SMB_3.0
                              SMB_SHARE_TYPE                DISK
                              SIGNING_SUPPORTED             TRUE
                              EXTENDED_SECURITY_SUPPORTED   TRUE
                              LARGE_FILE_SUPPORTED          TRUE
                              CLIENT_REQUIRES_SIGNING       TRUE
                              FILE_IDS_SUPPORTED            TRUE
                              DFS_SUPPORTED                 TRUE
                              MULTI_CREDIT_SUPPORTED        TRUE
                              ENCRYPTION_SUPPORTED          TRUE

输出中的 SMB_VERSION 为使用的 SMB 协议版本,SIGNING_ON 表示是否启用了签名。

锁定文件的问题

苹果 Finder 中锁定的文件将无法修改和删除,可以在 Terminal 中先确认哪些文件被锁定:

iPhilBendeck:~ philbendeck$ find ./ -flags uchg

如果锁定的文件较多,需要批量解除锁定,可以通过 find 命令操作:

iPhilBendeck:~ philbendeck$ find ./ -flags uchg -exec chflags nouchg {} \;

也可以直接用 chflags 解除整个目录锁定:

iPhilBendeck:~ philbendeck$ chflags -R nouchg ./

.smbdelete 隐藏文件的问题

参考苹果 smbfs 代码。

We have an open file that they want to delete. Use the NFS silly rename trick, but try to do better than NFS. The picking of the name came from the NFS code. So we first open the file for deletion. Now come up with a new name and rename the file. Make the file hidden if we can. Now lets mark it for deletion and close the file. If the rename fails then the whole call should fail. If the mark for deletion call fails just set a flag on the vnode and delete it when we close.