Re: [PATCH 12/18] shared mount handling: bind and rbind
From: Linus Torvalds
Date: Tue Nov 15 2005 - 22:53:38 EST
On Tue, 15 Nov 2005, Rob Landley wrote:
> The || fallback in the third part won't work. chroot(".") will get you to the
> new filesystem, but chdir("/") still gets you to the old one, even though
> we've overmounted it. (I have no idea why. I assume it's because / is
'/' is special exactly the same way '.' is: one is shorthand for "current
process' root", and the other is shorthand for "current process' cwd".
So if you mount over '/', it won't actually do what you think it does:
because when you open "/", it will continue to open the _old_ "/". Exactly
the same way that mounting over somebody's cwd won't do what you think it
does - because the root and the cwd have been looked-up earlier and are
cached with the process.
This is why we have "pivot_root()" and "chroot()", which can both be used
to do what you want to do. You mount the new root somewhere else, and then
you chroot (or pivot-root) to it. And THEN you do 'chdir("/")' to move the
cwd into the new root too (and only at that point have you "lost" the old
root - although you can actually get it back if you have some file
descriptor open to it).
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/