NameFS Follow up, Sun Studio 11 — Pt. 4
I learned something cool about NameFS today..
You can mount a file descriptor to a folder and that entire folder’s contents are irretrievable. The folder becomes what I like to think as a symbolic link to the file descriptor. Isn’t that cool :D Furthermore the NameFS mounts can be done “invisibly” to the mntab, which is the automatic behaviour of fattach. Although, fattach does check that the file descriptor is a STREAM or door, I already showed in a previous part how that can be circumvented easily, by writing my own fattach() without the checks.
OK Here’s an example of the NameFS behaviour I was talking about..
bazz@life[pts/5][/tmp] mkdir /tmp/namefs bazz@life[pts/5][/tmp] cd namefs /tmp/namefs bazz@life[pts/5][/tmp/namefs] touch 1 2 files bazz@life[pts/5][/tmp/namefs] mkdir dir bazz@life[pts/5][/tmp/namefs] touch dir/morefiles bazz@life[pts/5][/tmp/namefs] ls 1 2 dir files bazz@life[pts/5][/tmp/namefs] ls -l total 8 -rw-r--r-- 1 bazz 0 Oct 29 19:56 1 -rw-r--r-- 1 bazz 0 Oct 29 19:56 2 drwxr-xr-x 2 bazz 183 Oct 29 19:56 dir -rw-r--r-- 1 bazz 0 Oct 29 19:56 files bazz@life[pts/5][/tmp/namefs] cd .. bazz@life[pts/5][/tmp] ls -l | grep namefs drwxr-xr-x 3 bazz 355 Oct 29 19:56 namefs bazz@life[pts/5][/tmp] ~/namefs/a.out & sizeof = 4 1st mount = 0 2nd mount = 0 [1] 7930 [1]+ Stopped ~/namefs/a.out bazz@life[pts/5][/tmp] ls -l | grep namefs -rwxr-xr-x 1 bazz 0 Oct 29 19:56 namefs bazz@life[pts/5][/tmp] cd /tmp/namefs -bash: cd: /tmp/namefs: Not a directory bazz@life[pts/5][/tmp] echo "DERP" > /tmp/namefs bazz@life[pts/5][/tmp] cd /tmp/namefs -bash: cd: /tmp/namefs: Not a directory bazz@life[pts/5][/tmp] fg ~/namefs/a.out bazz@life[pts/5][/tmp] ls -l | grep namefs drwxr-xr-x 3 bazz 355 Oct 29 19:56 namefs bazz@life[pts/5][/tmp] cd namefs /tmp/namefs bazz@life[pts/5][/tmp/namefs] ls -l total 16 -rw-r--r-- 1 bazz 0 Oct 29 19:56 1 -rw-r--r-- 1 bazz 5 Oct 29 19:57 2 drwxr-xr-x 2 bazz 183 Oct 29 19:56 dir -rw-r--r-- 1 bazz 0 Oct 29 19:56 files bazz@life[pts/5][/tmp/namefs] cat 2 DERP bazz@life[pts/5][/tmp/namefs]
and here’s the C code to a.out
/* By BAzz This code bypasses the "Only STREAMS and doors allowed to be mounted" as NameFS nodes thing. Kind of creates invisible symlinks :) */ #include <sys/types.h> #include <errno.h> #include <stdio.h> #include <stropts.h> #include <sys/vnode.h> #include <sys/door.h> #include <sys/fs/namenode.h> #include <sys/mount.h> #include <fcntl.h> int myfattach(int fildes, const char *path) { struct namefd namefdp; namefdp.fd = fildes; return (mount((char *)NULL, path,MS_OVERLAY|MS_DATA, (const char *)"namefs", (char *)&namefdp, 4)); } main() { int fd1, fd2,fd3; char buf[100],buf2[100]; char path1[] = "/tmp/namefs/1"; char path2[] = "/tmp/namefs/2"; char path3[] = "/tmp/namefs"; int fd[201]; int s; fd1 = open (path1, O_RDWR|O_CREAT ); fd2 = open (path2, O_RDWR|O_CREAT ); printf ("sizeof = %d\n", sizeof (struct namefd)); int r = myfattach(fd1, path2); printf ("1st mount = %d\n", r); if (r < 0) perror(""); r = myfattach(fd2,path3); printf ("2nd mount = %d\n", r); if (r < 0) perror(""); getchar(); umount(path3); umount(path2); close (fd1); close(fd2); }
Sun Studio 11
I hear this is the last version supported by Solaris 8.
Well this can be found at http://ftp.cc.uoc.gr/programming/compilers/Sun/. I wanted this to compile a dynamic kernel module. Installing this thing required a j2se update from oracle’s website. And maybe u can bypass that by modifying the installer script to do a -nodisplay argument… Anyways.
Leave a Reply