Occasionally one needs a directory (or a file system) somewhere else in the file system or maybe even at several different places in the file system. Instead of solving the problem with symbolic links, you can elegantly use the namefs file system.
In the following example /data/in is required elsewhere:
# ls -l /data/in total 16 -rw-r--r-- 1 root system 554 May 14 16:10 file1 -rw-r--r-- 1 root system 381 May 14 16:10 file2 # ls -l /other/place total 0 #
Mounting the directory to the desired location /other/place:
# mount -v namefs /data/in /other/place # ls -l /other/place total 16 -rw-r--r-- 1 root system 554 May 14 16:10 file1 -rw-r--r-- 1 root system 381 May 14 16:10 file2 #
The mount with the namefs file system additionally offers the possibility to specify mount options, which then only apply to the directory. One can do so to mount a directory with Direct-I/O, even though the original directory was not mounted with Direct-I/O:
# mount -v namefs -o dio /data/in /other/place # mount node mounted mounted over vfs date options -------- --------------- --------------- ------ ------------ --------------- /dev/hd4 / jfs2 May 02 11:30 rw,log=/dev/hd8 ... /data/in /other/place namefs May 14 16:14 rw,dio #
When accessing the files below /other/place, Direct-I / O will be used. When accessing via the “originals” under /data/in, no Direct-I / O will be used!
However, access to files is limited to the underlying physical file system, as with NFS. This can easily be demonstrated by the file system /. We mount / using namefs onto /mnt and look at /mnt/usr and /mnt/var:
# mount -v namefs / /mnt # ls -l /mnt/usr /mnt/var /mnt/usr: total 0 lrwxrwxrwx 1 root system 11 Apr 17 07:49 lib -> /../usr/lib /mnt/var: total 0 #
The directories are empty or contain a symbolic link, /usr and /var clearly look different!
Of course, this can also be exploited, e.g. in cases where interesting data has been over-mounted. We dropped a file below /home before /dev/hd1 was mounted onto /home. The root file system currently mounted on /mnt allows access to this over-mounted data:
# ls -l /mnt/home total 0 -rw-r--r-- 1 root system 0 May 14 17:48 overmounted_file #
Another application is to protect a directory against overwriting. We demonstrate this for the directory /data with 2 test files:
# ls -l /data total 16 -rw-r--r-- 1 root system 554 May 14 17:52 file1 -rw-r--r-- 1 root system 381 May 14 17:52 file2 # cp /etc/hosts /data # ls -l /data total 24 -rw-r--r-- 1 root system 554 May 14 17:52 file1 -rw-r--r-- 1 root system 381 May 14 17:52 file2 -rw-r--r-- 1 root system 2075 May 14 17:54 hosts #
Overwriting or changing data is currently still possible, as shown by the successful cp command. Now we protect the data by doing a mount with the namefs file system and the option ro (read-only):
# mount -v namefs -o ro /data /data # cp /etc/services /data cp: /data/services: Read-only file system #
The data obviously can not be changed anymore. Here we have over-mounted /data with a read-only version of itself!
Mounts with the namefs pseudo-file system can not only be done on jfs2 file systems, but also for NFS file systems or the procfs file system.
Finally we show the mounting of a file to some other place in the file system. We want to make the file /etc/hosts available via the name /hosts. To do this, we first create an empty file /hosts and then mount the file /etc/hosts onto this empty file:
# touch /hosts # ls -l /hosts -rw-r--r-- 1 root system 0 May 14 17:59 /hosts # mount -v namefs /etc/hosts /hosts # ls -l /hosts -rw-rw-r-- 1 root system 2075 Apr 26 10:47 /hosts #
Before the mount, /hosts was 0 bytes in size, after the mount 2075 bytes!
The namefs file system thus offers some interesting possibilities, that can be useful for some problems.