CHROOT()

Correo Fernando-ruiz (E-mail) correo at fernando-ruiz.com
Fri Jan 19 00:13:25 UTC 2001


 
This is the capture from my Multiterminals environment
------------------------------------------------------

I have several terminals running like LINUX terminal session.

The prompt shows the ttyname() and pwd().

The shell has implemented several commands like LINUX.

At the stating point with the reset of the RTEMS...
I have a rtc. Once rtc is inited the system_clock is set.
The date file are used. We can see it.


/dev/pty0 [/] # ls
drwxrwx--x   1 rtems  rtems         4556 Jan 01 00:00 dev/
1 files 4556 bytes occupied
/dev/pty0 [/] # ls dev
-rwxrwx--x   1 rtems  rtems            0 Jan 01 00:00 sci0 
-rwxrwx--x   2 rtems  rtems            0 Jan 01 00:00 sci1 
-rwxrwx--x   2 rtems  rtems            0 Jan 01 00:00 console 
-rwxrwx--x   1 rtems  rtems            0 Jan 01 00:00 lcd 
-rwxrwx--x   1 rtems  rtems            0 Jan 01 00:00 fla 
-rwxrwx--x   1 rtems  rtems            0 Jan 01 00:00 kbd 
-rwxrwx--x   2 rtems  rtems            0 Jan 01 00:00 x24c16 
-rwxrwx--x   2 rtems  rtems            0 Jan 01 00:00 e2p 
-rwxrwx--x   1 rtems  rtems            0 Jan 19 00:09 ramrtc 
-rwxrwx--x   1 rtems  rtems            0 Jan 19 00:09 rtc 
-rwxrwx--x   1 rtems  rtems            0 Jan 19 00:09 alarm 
-rwxrwx--x   1 rtems  rtems            0 Jan 19 00:09 pty0 
-rwxrwx--x   1 rtems  rtems            0 Jan 19 00:09 pty1 
17 files 0 bytes occupied
/dev/pty0 [/] # mkdir ftp
/dev/pty0 [/] # mkdir ftp pub
mkdir 'ftp' failed:File exists
/dev/pty0 [/] # mkdir ftp/pub
/dev/pty0 [/] # mkdir ftp/incoming
/dev/pty0 [/] # mkdir ftp/bin
/dev/pty0 [/] # mkdir ftp/dev
/dev/pty0 [/] # chdir ftp
/dev/pty0 [/ftp] # ls
drwxrwx--x   1 rtems  rtems            0 Jan 19 00:09 pub/
drwxrwx--x   1 rtems  rtems            0 Jan 19 00:10 incoming/
drwxrwx--x   1 rtems  rtems            0 Jan 19 00:10 bin/
drwxrwx--x   1 rtems  rtems            0 Jan 19 00:10 dev/
4 files 0 bytes occupied
/dev/pty0 [/ftp] # ls
drwxrwx--x   1 rtems  rtems            0 Jan 19 00:09 pub/
drwxrwx--x   1 rtems  rtems            0 Jan 19 00:10 incoming/
drwxrwx--x   1 rtems  rtems            0 Jan 19 00:10 bin/
drwxrwx--x   1 rtems  rtems            0 Jan 19 00:10 dev/
4 files 0 bytes occupied
/dev/pty0 [/ftp] # chdir pub
/dev/pty0 [/ftp/pub] # ls
0 files 0 bytes occupied
/dev/pty0 [/ftp/pub] # mkdir rtems
/dev/pty0 [/ftp/pub] # mkdir contribs
/dev/pty0 [/ftp/pub] # ls
drwxrwx--x   1 rtems  rtems            0 Jan 19 00:10 rtems/
drwxrwx--x   1 rtems  rtems            0 Jan 19 00:11 contribs/
2 files 0 bytes occupied

*****************************************

Now the STAR COMMAND.  CHROOT()

*****************************************


/dev/pty0 [/ftp/pub] # chroot /ftp
/dev/pty0 [/] # ls
drwxrwx--x   1 rtems  rtems          536 Jan 19 00:09 pub/
drwxrwx--x   1 rtems  rtems            0 Jan 19 00:10 incoming/
drwxrwx--x   1 rtems  rtems            0 Jan 19 00:10 bin/
drwxrwx--x   1 rtems  rtems            0 Jan 19 00:10 dev/
4 files 536 bytes occupied
/dev/pty0 [/] # chdir /
/dev/pty0 [/] # ls
drwxrwx--x   1 rtems  rtems          536 Jan 19 00:09 pub/
drwxrwx--x   1 rtems  rtems            0 Jan 19 00:10 incoming/
drwxrwx--x   1 rtems  rtems            0 Jan 19 00:10 bin/
drwxrwx--x   1 rtems  rtems            0 Jan 19 00:10 dev/
4 files 536 bytes occupied
/dev/pty0 [/] # chdir pub
/dev/pty0 [/pub] # ls
drwxrwx--x   1 rtems  rtems            0 Jan 19 00:10 rtems/
drwxrwx--x   1 rtems  rtems            0 Jan 19 00:11 contribs/
2 files 0 bytes occupied
/dev/pty0 [/pub] # 

++++++++++++++++++++++++++++++++++++++++++++++
While in the second terminal(pty1). I browse the IMFS...
++++++++++++++++++++++++++++++++++++++++++++++


/dev/pty1 [/] # 
/dev/pty1 [/] # 
/dev/pty1 [/] # 
/dev/pty1 [/] # 
/dev/pty1 [/] # 
/dev/pty1 [/] # ls
drwxrwx--x   1 rtems  rtems         4556 Jan 01 00:00 dev/
drwxrwx--x   1 rtems  rtems         1072 Jan 19 00:09 ftp/
2 files 5628 bytes occupied
/dev/pty1 [/] # ls ftp
drwxrwx--x   1 rtems  rtems          536 Jan 19 00:09 pub/
drwxrwx--x   1 rtems  rtems            0 Jan 19 00:10 incoming/
drwxrwx--x   1 rtems  rtems            0 Jan 19 00:10 bin/
drwxrwx--x   1 rtems  rtems            0 Jan 19 00:10 dev/
4 files 536 bytes occupied
/dev/pty1 [/] # ls ftp/pub
drwxrwx--x   1 rtems  rtems            0 Jan 19 00:10 rtems/
drwxrwx--x   1 rtems  rtems            0 Jan 19 00:11 contribs/
2 files 0 bytes occupied
/dev/pty1 [/] # 

+++++++++++++++++++++++++++++++++++++++++++++++
All seems ok.... In the second terminal...
Returning...
+++++++++++++++++++++++++++++++++++++++++++++++

/dev/pty0 [/pub] # 
/dev/pty0 [/pub] # 
/dev/pty0 [/pub] # ls /dev
0 files 0 bytes occupied

*********************
None file is present. 
/dev is /ftp/dev in the real life and it is empty
Now we change the root directory
*********************

/dev/pty0 [/pub] # chroot /
/dev/pty0 [/] # ls /dev
-rwxrwx--x   1 rtems  rtems            0 Jan 01 00:00 sci0 
-rwxrwx--x   2 rtems  rtems            0 Jan 01 00:00 sci1 
-rwxrwx--x   2 rtems  rtems            0 Jan 01 00:00 console 
-rwxrwx--x   1 rtems  rtems            0 Jan 01 00:00 lcd 
-rwxrwx--x   1 rtems  rtems            0 Jan 01 00:00 fla 
-rwxrwx--x   1 rtems  rtems            0 Jan 01 00:00 kbd 
-rwxrwx--x   2 rtems  rtems            0 Jan 01 00:00 x24c16 
-rwxrwx--x   2 rtems  rtems            0 Jan 01 00:00 e2p 
-rwxrwx--x   1 rtems  rtems            0 Jan 19 00:09 ramrtc 
-rwxrwx--x   1 rtems  rtems            0 Jan 19 00:09 rtc 
-rwxrwx--x   1 rtems  rtems            0 Jan 19 00:09 alarm 
-rwxrwx--x   1 rtems  rtems            0 Jan 19 00:09 pty0 
-rwxrwx--x   1 rtems  rtems            0 Jan 19 00:09 pty1 
17 files 0 bytes occupied
/dev/pty0 [/] # ls
drwxrwx--x   1 rtems  rtems         4556 Jan 01 00:00 dev/
drwxrwx--x   1 rtems  rtems         1072 Jan 19 00:09 ftp/
2 files 5628 bytes occupied
/dev/pty0 [/] # 
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
That's all.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

In order to makes this story possible only a "chroot.c" has been
added into libc directory. (And Makefile.am touched and bootstraped)

The application source example:

rtems_task shell_task(rtems_task_arguments args) {
...
 rtems_libio_set_private_env();
 chroot("/ftp");
...
 for (;;) {
	 ...

 };
 rtems_task_delete(RTEMS_SELF);
};

If you want a new task but the same private environment then

   You can share the private enviromnet with

   rtems_libio_share_private_env(parent_task_id);

   The root_dir and current_dir are shared in two task only 
   (Or more if you want)

   Ahh! the process and the task tree......

Are you interested? 

After reading the Sergei's ftpd daemon patches (17-Jan-2001)
I think that this will be useful.
Don't worry with the current dir. 
You have a local copy. 
The same with the root directory.
Wonderful. To be continued...

(uid,gid, /etc/passwd...)

Enjoy it.

Fernando RUIZ CASAS
fernando.ruiz at ctv.es
correo at fernando-ruiz.com

P.S:
 Joel, Is it possible add "chroot()" 
 if __rtems__ defined in "unistd.h" from gcc
 of course if all of this is correct... and useful.	

Best Regards... 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: chroot.patch.tgz
Type: application/x-compressed
Size: 6357 bytes
Desc: not available
URL: <http://lists.rtems.org/pipermail/users/attachments/20010119/b23f5773/attachment.bin>


More information about the users mailing list