CS 111 section 2Scribe notes for 5/15/2007by Keith Stevens and Collinn NielsenMore on File SystemsHard LinksHard links occure when two or more directory-entries map to the same inode number Example code regarding Hard Links
this example will create a directory entry in the directory "b". It's inode number wil be the same as the the number found in "/a/d/" for the entry named "n". Possible issues with hard links, and their answers
Now suppose we have a directory "/usr/bin/" which contains a large amount of files and we want to have the contents of "/bin/" to contain all the same files. We could do this by create a hard link for each of the files in "/usr/bin/" but this would take up a large number of directory entries, so we need to have a better solution. This is where Symbolic Links come in. Symbolic LinksA symbolic link is a third type of file, which allows for linking more files together. Instead of being a directory with directory entries that just reference an already existing inode number, a Symbolic Link is a file whose contents are just the path we wish to link. When a symbolic link is read, its contens are read and placed into the pathname to find the actual files. For our example the "/" would have a directory entry for "/bin/" and the corresponding inode would be marked as a symbolic link. So now if we request "/bin/ls", the contents of "/bin/" will be read and and included to the requested path name so that we now have a pathname of "/usr/bin/ls" and read that file. Issues with Symbolic Links
Multiple File SystemsSuppose we have two hard disks each with their own file systems which we want to access at the same time. A simple solution would be to number each disk and include the disk number a file is located on when we want a file. Unfortunately this simple approach is not very flexible and makes it difficult when the two file systems are not of the same type. More Elegant ApproachA more Elegant way to use multiple hard disks is to mount one of them onto the other. One hard disk must be specified as the main disk, and any others will be mounted to a particular directory on the main disk. So for example we could say mount(disk2, "/home"), so when a user views the "/home" folder, they see the root of disk2. Some more details about mounting
But what about dealing with two hard disks that have differnt file system types, such as FAT and ext3. Our more elegant solution of mounting doesn't fully solve our problem. Instead we need to apply Object Oriented techniques to file accesses. This is where Virtual File Systems come in. Virtual Fle SystemsA virtual file system requires each file system to conform to a generic interface so that a another layer in the kernel will be able to call the common read and write requests with with the same parameters for each file system. The Virtual file system will determine which of the file systems that are registered should recieve a particular request. Aside from conforming to a standard interface the implementation of each file system can do what they need to, such as having inodes or not having inodes. Prior to any file system being available to the virtual file system, they must register themselves with the VFS layer example: rename ("a","b")
File operations that might cause trouble (continued)rename("d/a", "e/b");one possible solution:
Power failure between steps 3 and 4 causes file to disappear right before step 5. On disk there is an inode that is unreferenced. Description of a function that runs after reboot:
fsck (file system check)
As one can see, after power failure and reboot (and running of fsck) problems are caused with this first implementation: Here is a better way of doing it:
Worst case, if power failure happens, we won't have the problem of losing data; rather, an unreferenced block might be marked as used (if the link count is too high). Having too high of a link count is less severe than having a link count decremented too much and freeing data you weren't supposed to. File System Correctness Invariants
Penalties for Violating the above 4 invariants (respectively):
Disk Performance IssuesOptimize disk access since it's the real bottleneck; CPU is doing fine in comparison. Worry about disk scheduling. To read a sector on disk:
Some sample specs of a disk (Western Digital Caviar SE16):7200 rpm (120Hz), 16 MB buffer, 4.20 ms avg. rotational latency, 8.33 ms rotation time
|