This question is not about me having any kind of technical problem. It is about understanding a design decision.
To me, the question "Why do mount points in Linux need to be existing directories?" splits into two parts:
- Why do mount points need to be directories?
- Why do mount points need to be existing files?
Neither of these circumstances make sense to me.
If we for now assume that mount points need to exist for some reason, clearly the VFS does something with them that the FS itself doesn't support. So why even bother checking whether a mount point is a directory? The only counter argument to this I can come up with myself is "Yeah, but what if an application has already determined that a certain path points to a directory?", to which I'd reply: "Well, if it only has the path then anything can happen with it anyway. Even without mounting, the next time it checks, that path might point to a directory. Or it might not exist anymore. If it has a file handle of it already, then no matter the mount, it will still have access to it."
The second part of the question makes even less sense to me. Again, the VFS is doing something the FS doesn't support. So why care what the FS says is there? Or if we decide to care, then why enforce that there is something rather than enforce that there is nothing? Sure, if there is nothing, then you have to tackle the question of what happens if someone tries to create something in this path. But this seems like a very simple thing to deal with. On the other hand, if we enforce that there is something, then always when there is a mount, a subtree of the FS one level higher up is hidden. This seems like it causes many other problems, including the inverse of the one problem we had before: What if someone tries to delete that something? But it also causes problems like "What if some process currently is navigating that subtree or its pwd is in that subtree?" and "What if space of the FS higher up needs to be freed and the files to be deleted are in that subtree?".
I'm not necessarily looking for the point where this design decision was made (though that would be interesting to know as I think it will go quite far back in time). I'm looking for the reasons why this design decision was made.
mount
has been finalized. I'm asking why the virtual file system requires those directories to exist. This is about the corresponding design decision of the virtual file system. It's not aboutmount
, about file systems, about anything magical slapped onto the whole thing. – UTF-8 Jun 28 '19 at 10:44mount
prevent typos without checking mount point exist? – alecxs Jan 04 '21 at 08:18