问题原文
原帖链接 · angainor · CC BY-SA 3.0
I have the following scenario:
- users run software installed in /path/to/software
- I create a file-backed FS image with exactly the same contents as in /path/to/software
- I mount the image using loopback in read-only mode at /path/to/software
After step 3 the old contents of the directory are 'shadowed' by the newly mounted image with exactly same contents.
Can this in any way affect the users that have started the original software prior to the mount? I have made a few tests and it seems that the started programs are unaware of any change, i.e., they continue to run without any error. It is a bit surprising since the programs have previously opened some files (libraries) in the old file system, which is gone after step 3. I would expect that the file descriptors would change after the mount.
So how come there is no error? Are the old files visible somehow to the running programs despite the fact that the directory contents have been shadowed?
已采纳解答
原帖链接 · chicks · CC BY-SA 3.0
In POSIX-compliant file systems open files are not removed until no one has them open anymore. This same behavior is used in the standard library tmpfile which opens a temporary file and then deletes it. The open file handle is still usable by the process that has the file handle (or its children) but no other processes can open the file since there is no filename anymore. It seems reasonable to expect this would also work when mounting over some directory.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
