I'm reading The Design of the Unix Operating System by Maurice J Bach, and have two questions regarding file system mounting:
-
Why does the file system mount fail when the reference count of the mount point inode is greater than 1 in the file table?
-
Why does Unix disallow mounting a file system at multiple points? (What bad things could happen if this were allowed?)
Best Answer
The HP (HP-UX) man page for
mount(2)
says:[EACCES]
A component of the path prefix denies search permission.[EBUSY]
path is currently mounted on, is someone's current working directory, or is otherwise busy.[EBUSY]
The file system associated with fs is currently mounted.You get the first EBUSY when your question (1) applies because:
/some/where
) is some process's current directory, you have a process with a different view of the contents of/some/where
; newcomers see what's on the mounted file system, but the old processes see what was in the mounted-upon directory.You get the second EBUSY to answer your question (2) when the file system is already mounted - in other words, you can't mount it twice. This is a good thing - there would be a dreadful danger of confusion if two separate mount points both went around assuming they had exclusive access to the superblock etc when it was in fact shared. It would also be confusing if creating a file
/some/where/newfile
also simultaneously created/opt/other/newfile
because the same device was mounted on both/some/where
and/opt/other
.I haven't checked the AIX, Solaris, Linux, MacOS X, BSD man pages for
mount(2)
, but I expect the behaviour to be the same.