8

I'm reading The Design of the Unix Operating System by Maurice J Bach, and have two questions regarding file system mounting:

  1. Why does the file system mount fail when the reference count of the mount point inode is greater than 1 in the file table?

  2. Why does Unix disallow mounting a file system at multiple points? (What bad things could happen if this were allowed?)

1
  • This is related to programming. I got these questions while reading the design of the unix operating sytem by maurice J bach. I dont know why people voted to close this topic!
    – user40559
    Jul 25, 2010 at 6:31

3 Answers 3

6

The HP (HP-UX) man page for mount(2) says:

If mount() fails, errno is set to one of the following values.

  • [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:

  • if the directory is already a mount point, you lose access to the previously mounted directory, which makes the prior mount irrelevant.
  • if the directory (say /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.

3
  • @Neil Smithline: Please justify your 'many' variants by citing at least one non-Linux variant that provides what you describe: '25 July 2012 Update: Many Unix/Linux variants now support the -o union option that allows two filesystems to share a mount point. The second mount shadows the first in that all file accesses take place first in the new mount and then in the original mount. Also, file creation happens in the new mount.' Wikipedia has a brief outline but little specificity about which o/s other than Plan 9 support them. Jul 26, 2012 at 4:08
  • FreeBSD supports that option: freebsd.org/cgi/…
    – jlliagre
    Jul 26, 2012 at 6:16
  • Two of about seven — an exaggerated version of many. I prefer that the addendum is a comment (or a separate answer) than a modification of my answer. Jul 26, 2012 at 6:34
5

This isn't a direct answer, but you can get behavior similar to mounting in two places by using mount --bind

0
1

Basically the possibility of mounting one filesystem at several places breaks the concept of a tree hierarchical filesystem, converting it in a directed acyclic graph (even you can try to mount a mounted filesystem into a subdirectory of itshelf, breaking more to a possible cyclic, nondirected general graph). Basically, the problem is that when you try to pass up to the parent directory using the .. entry in the mounted root directory, you have to select which of the now several parent directories to follow to get to the parent.

In linux, there's a --bind option to mount that allows you to mount a directory (not necessary for it to be a root directory on a filesystem) at some other place (not a mounted filesystem, but a plain directory) so you can mount things like the /proc or /sys filesystems on chroot(2)ed processes and let them access to this framework.

This kind of mount is different in the same sense as the diference between soft and hard links to files. It's treated differently by the kernel and it only allows a true mount point per root filesystem. The reason is basically the same as you cannot create loops with hard links and you can with soft. You cannot mount again a mounted filesystem, and you can mount --bind several times the same directory.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .