Re: [PATCH 12/18] shared mount handling: bind and rbind

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




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
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux