From mboxrd@z Thu Jan 1 00:00:00 1970 From: Linus Torvalds Subject: Re: [PATCH 12/18] shared mount handling: bind and rbind Date: Tue, 15 Nov 2005 19:53:36 -0800 (PST) Message-ID: References: <1131561849.5400.384.camel@localhost> <200511152129.04079.rob@landley.net> Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Cc: Ram Pai , Miklos Szeredi , Al Viro , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Return-path: To: Rob Landley In-Reply-To: <200511152129.04079.rob@landley.net> Sender: linux-kernel-owner@vger.kernel.org List-Id: linux-fsdevel.vger.kernel.org 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 > special.) '/' 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). Linus