在 cifs 挂载上创建目录会返回错误,但目录确实已创建

在 cifs 挂载上创建目录会返回错误,但目录确实已创建

我安装了一个连接到华硕路由器的外部磁盘,该路由器实现了 Samba 服务器。除了一件烦人的事情外,一切都运行正常:使用 mkdir 创建目录会返回错误消息,即使目录确实已创建。

相关行/etc/fstab如下所示:

//192.168.1.1/data /media/external/data cifs username=data,password=data,vers=2.0,uid=1000,gid=1000 0 0

挂载磁盘时一切正常。(目录stackoverflow位于外部磁盘上。)

daniel@nuc:/media/external$ ll
total 12
drwxr-xr-x 5 root     root     4096 mar 23 21:05 ./
drwxr-xr-x 4 root     root     4096 mar 10 15:25 ../
drwxr-xr-x 2 daniel   daniel   4096 mar 24 10:50 data/
daniel@nuc:/media/external$ sudo mount -a
daniel@nuc:/media/external$ cd data
daniel@nuc:/media/external/data$ ll
total 4
drwxr-xr-x 2 daniel daniel    0 mar 24 10:54 ./
drwxr-xr-x 5 root   root   4096 mar 23 21:05 ../
drwxr-xr-x 2 daniel daniel    0 mar 14 23:07 stackoverflow/
daniel@nuc:/media/external/data$ 

创建目录时test,显示错误消息。

daniel@nuc:/media/external/data$ mkdir test
mkdir: cannot create directory ‘test’: Not a directory

但是,目录已经创建!

daniel@nuc:/media/external/data$ ll
total 4
drwxr-xr-x 2 daniel daniel    0 mar 24 11:01 ./
drwxr-xr-x 5 root   root   4096 mar 23 21:05 ../
drwxr-xr-x 2 daniel daniel    0 mar 14 23:07 stackoverflow/
drwxr-xr-x 2 daniel daniel    0 mar 24 11:01 test/

当删除目录并使用-p标志重新创建它时,错误消息不会显示。

daniel@nuc:/media/external/data$ rmdir test
daniel@nuc:/media/external/data$ ll
total 4
drwxr-xr-x 2 daniel daniel    0 mar 24 11:01 ./
drwxr-xr-x 5 root   root   4096 mar 23 21:05 ../
drwxr-xr-x 2 daniel daniel    0 mar 14 23:07 stackoverflow/
daniel@nuc:/media/external/data$ mkdir -p test
daniel@nuc:/media/external/data$ ll
total 4
drwxr-xr-x 2 daniel daniel    0 mar 24 11:01 ./
drwxr-xr-x 5 root   root   4096 mar 23 21:05 ../
drwxr-xr-x 2 daniel daniel    0 mar 14 23:07 stackoverflow/
drwxr-xr-x 2 daniel daniel    0 mar 24 11:01 test/
daniel@nuc:/media/external/data$ 

这让我怀疑问题是否是 mkdir 由于某种原因没有“看到”已挂载的目录并吐出一条错误消息,就像您尝试在一个不存在的目录中创建一个子目录一样。

但为什么会这样?我该怎么做才能解决这个问题?

(我要补充一点,当使用 安装时vers=1.0,mkdir 错误不会显示。但是,file_modedir_mode似乎被忽略了,我需要在另一个应用程序中将它们设置为0700。)

更新:当磁盘连接到计算机的 USB 端口并且安装 ntfs 时,一切正常。

更新:输出自strace mkdir test

execve("/bin/mkdir", ["mkdir", "test"], 0x7ffdb3669768 /* 67 vars */) = 0
brk(NULL)                               = 0x561761838000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=158495, ...}) = 0
mmap(NULL, 158495, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f782b715000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libselinux.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\20b\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=154832, ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f782b713000
mmap(NULL, 2259152, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f782b2ed000
mprotect(0x7f782b312000, 2093056, PROT_NONE) = 0
mmap(0x7f782b511000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x24000) = 0x7f782b511000
mmap(0x7f782b513000, 6352, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f782b513000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260\34\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=2030544, ...}) = 0
mmap(NULL, 4131552, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f782aefc000
mprotect(0x7f782b0e3000, 2097152, PROT_NONE) = 0
mmap(0x7f782b2e3000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1e7000) = 0x7f782b2e3000
mmap(0x7f782b2e9000, 15072, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f782b2e9000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libpcre.so.3", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0 \25\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=464824, ...}) = 0
mmap(NULL, 2560264, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f782ac8a000
mprotect(0x7f782acfa000, 2097152, PROT_NONE) = 0
mmap(0x7f782aefa000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x70000) = 0x7f782aefa000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libdl.so.2", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P\16\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0644, st_size=14560, ...}) = 0
mmap(NULL, 2109712, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f782aa86000
mprotect(0x7f782aa89000, 2093056, PROT_NONE) = 0
mmap(0x7f782ac88000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x2000) = 0x7f782ac88000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0000b\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=144976, ...}) = 0
mmap(NULL, 2221184, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f782a867000
mprotect(0x7f782a881000, 2093056, PROT_NONE) = 0
mmap(0x7f782aa80000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x19000) = 0x7f782aa80000
mmap(0x7f782aa82000, 13440, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f782aa82000
close(3)                                = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f782b711000
arch_prctl(ARCH_SET_FS, 0x7f782b712040) = 0
mprotect(0x7f782b2e3000, 16384, PROT_READ) = 0
mprotect(0x7f782aa80000, 4096, PROT_READ) = 0
mprotect(0x7f782ac88000, 4096, PROT_READ) = 0
mprotect(0x7f782aefa000, 4096, PROT_READ) = 0
mprotect(0x7f782b511000, 4096, PROT_READ) = 0
mprotect(0x56175ffd9000, 4096, PROT_READ) = 0
mprotect(0x7f782b73c000, 4096, PROT_READ) = 0
munmap(0x7f782b715000, 158495)          = 0
set_tid_address(0x7f782b712310)         = 7736
set_robust_list(0x7f782b712320, 24)     = 0
rt_sigaction(SIGRTMIN, {sa_handler=0x7f782a86ccb0, sa_mask=[], sa_flags=SA_RESTORER|SA_SIGINFO, sa_restorer=0x7f782a879890}, NULL, 8) = 0
rt_sigaction(SIGRT_1, {sa_handler=0x7f782a86cd50, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART|SA_SIGINFO, sa_restorer=0x7f782a879890}, NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
statfs("/sys/fs/selinux", 0x7fff4f557960) = -1 ENOENT (No such file or directory)
statfs("/selinux", 0x7fff4f557960)      = -1 ENOENT (No such file or directory)
brk(NULL)                               = 0x561761838000
brk(0x561761859000)                     = 0x561761859000
openat(AT_FDCWD, "/proc/filesystems", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
read(3, "nodev\tsysfs\nnodev\trootfs\nnodev\tr"..., 1024) = 420
read(3, "", 1024)                       = 0
close(3)                                = 0
access("/etc/selinux/config", F_OK)     = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=11861168, ...}) = 0
mmap(NULL, 11861168, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f7829d17000
close(3)                                = 0
mkdir("test", 0777)                     = -1 ENOTDIR (Not a directory)
openat(AT_FDCWD, "/usr/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=2995, ...}) = 0
read(3, "# Locale name alias data base.\n#"..., 4096) = 2995
read(3, "", 4096)                       = 0
close(3)                                = 0
openat(AT_FDCWD, "/usr/share/locale/en_US.UTF-8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/en_US.utf8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/en_US/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/en.UTF-8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/en.utf8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/en/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale-langpack/en_US.UTF-8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale-langpack/en_US.utf8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale-langpack/en_US/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale-langpack/en.UTF-8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale-langpack/en.utf8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale-langpack/en/LC_MESSAGES/coreutils.mo", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=578, ...}) = 0
mmap(NULL, 578, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f782b73b000
close(3)                                = 0
openat(AT_FDCWD, "/usr/lib/x86_64-linux-gnu/charset.alias", O_RDONLY|O_NOFOLLOW) = -1 ENOENT (No such file or directory)
write(2, "mkdir: ", 7mkdir: )                  = 7
write(2, "cannot create directory \342\200\230test\342"..., 34cannot create directory ‘test’) = 34
openat(AT_FDCWD, "/usr/share/locale/en_US.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/en_US.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/en_US/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/en.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/en.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale/en/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale-langpack/en_US.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale-langpack/en_US.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale-langpack/en_US/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale-langpack/en.UTF-8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale-langpack/en.utf8/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/usr/share/locale-langpack/en/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
write(2, ": Not a directory", 17: Not a directory)       = 17
write(2, "\n", 1
)                       = 1
close(1)                                = 0
close(2)                                = 0
exit_group(1)                           = ?
+++ exited with 1 +++

根据要求更新,smb.conf来自华硕路由器的文件(有所整理,保留相关部分):

[global]
workgroup = WORKGROUP
netbios name = RT-AC68U-AC48
server string = RT-AC68U-AC48
unix charset = UTF8
display charset = UTF8
load printers = no
printing = bsd
printcap name = /dev/null
log file = /var/log.samba
log level = 0
max log size = 5
security = USER
guest ok = no
map to guest = Bad User
encrypt passwords = yes
pam password change = no
null passwords = yes
force directory mode = 0777
force create mode = 0777
max connections = 5
socket options = IPTOS_LOWDELAY TCP_NODELAY SO_KEEPALIVE
obey pam restrictions = no
disable spoolss = yes
host msdfs = no
strict allocate = no
wide links = no
bind interfaces only = yes
interfaces = lo br0 192.168.1.1/255.255.255.0 
use sendfile = yes
map archive = no
map hidden = no
map read only = no
map system = no
store dos attributes = yes
dos filemode = yes
oplocks = yes
level2 oplocks = yes
kernel oplocks = no
enable core files = no
deadtime = 30
load printers = no
printable = no
max protocol = SMB2
min protocol = SMB2
smb encrypt = disabled
min receivefile size = 16384
passdb backend = smbpasswd
smb passwd file = /etc/samba/smbpasswd
[data]
comment = Seagate_3TB's data in Seagate Backup+ Desk
path = /tmp/mnt/Seagate_3TB/data
dos filetimes = yes
fake directory create times = yes
valid users = data, backup
invalid users = backup
read list = data
write list = data

当通过 ssh 连接到路由器时创建目录的工作符合预期(也许并不奇怪):

daniel@RT-AC68U-AC48:/tmp/mnt/Seagate_3TB/data# ll
drwxrwxrwx    1 daniel root             0 Mar 15 00:07 stackoverflow/
daniel@RT-AC68U-AC48:/tmp/mnt/Seagate_3TB/data# mkdir test
daniel@RT-AC68U-AC48:/tmp/mnt/Seagate_3TB/data# ll
drwxrwxrwx    1 daniel root             0 Mar 15 00:07 stackoverflow/
drwxrwxrwx    1 daniel root             0 Apr  3 21:46 test/

答案1

这可能是硬盘/SSD 损坏,mkdir无法写入数据。

因为这是外部驱动器。它是否开启了读写锁?

它可以以只读方式安装,而不是读写方式。

使用:sudo mount -o remount,rw /partition/identifier /mount/point重新挂载为读写。来源:https://askubuntu.com/a/175742/886917

相关内容