在 Linux 上,我可以dd
我硬盘上的一个文件,然后在 Nautilus 中删除它,同时 dd 仍在继续。
Linux 可以强制执行文件锁定来保护 R/W 吗?
[编辑] 最初的问题不是关于 linux 文件锁定功能,而是关于 linux 中的一个假设错误,在下面重现它,其他人可能有同样的问题。
People keep telling me Linux/Unix is better OS. I am coding Java on Linux now and come across a problem, that I can easily reproduce: I can dd a file on my hard drive and delete it in Nautilus while the dd is still going on. How come linux cannot enforce a mandatory file lock to protect R/W??
最佳答案
要在 Linux 上执行强制锁定,必须使用 -o mand
选项挂载文件系统,并且必须对文件设置 g-x,g+s
权限。也就是说,您必须禁用组执行,并启用 setgid。执行此操作后,根据文件描述符上的 O_NONBLOCK
值,所有访问都将被阻止或出现 EAGAIN
错误。但要注意:“所有已知 Linux 版本中强制锁定的实现都受制于竞争条件,这使得它变得不可靠......因此依赖强制锁定是不可取的。”参见 fcntl(2)
。
关于linux - linux上的强制文件锁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12062466/