Linux上的强制性文件锁定 [英] Mandatory file lock on linux

查看:270
本文介绍了Linux上的强制性文件锁定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linux上,我可以dd硬盘上的文件,并在dd仍在运行时在Nautilus中将其删除.

On Linux I can dd a file on my hard drive and delete it in Nautilus while the dd is still going on.

Linux可以强制执行强制性文件锁定以保护R/W吗?

Can Linux enforce a mandatory file lock to protect R/W?

推荐答案

要在Linux上进行强制锁定,必须使用-o mand选项挂载文件系统,并且必须在文件上设置g-x,g+s权限.也就是说,您必须禁用组执行并启用setgid.一旦执行了此操作,根据文件描述符上O_NONBLOCK的值,所有访问都会因EAGAIN而阻塞或出错.但要注意:在所有已知版本的Linux中实施强制锁定都会受到竞争条件的影响,这使其变得不可靠...因此,不建议依靠强制锁定."参见fcntl(2).

To do mandatory locking on Linux, the filesystem must be mounted with the -o mand option, and you must set g-x,g+s permissions on the file. That is, you must disable group execute, and enable setgid. Once this is performed, all access will either block or error with EAGAIN based on the value of O_NONBLOCK on the file descriptor. But beware: "The implementation of mandatory locking in all known versions of Linux is subject to race conditions which render it unreliable... It is therefore inadvisable to rely on mandatory locking." See fcntl(2).

这篇关于Linux上的强制性文件锁定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆