Computer Science 390 Project 2 - Sharing with Links in

Due: Thu. May 11, at 2:30 p.m. (the final exam time)

For this project, we will investigate the two different types of file sharing mechanisms available under Linux. Do all of your work for this project on sand. Perform the steps in this exercise, and answer all the questions that are in boldface. Then, up your answers using a word processor.

1. Log in to sand and a shell or terminal window. Use the mkdir command to create a sub- under your home directory titled cs390 project.

2. Use your favorite text editor to create a file named file0.txt. It should contain exactly 64 of the character ’0’. Make sure that the file does not contain any other characters such as newlines or tabs.

3. In Linux, a file control block is referred to as an inode (short for in- formation node.) Obtain the inode number of this file by typing the command

-l --inode file0.txt at the shell. Write down the output of the command, and circle the inode number. (You can type man ls to get the online manual page for the ls command.)

4. Linux provides two types of links: hard links (referred to as duplicate directory entries in the text) and symbolic links (referred to as links in the text). The command is used to create both types of links. By default, ln creates hard links. Look at the for ln to learn the syntax of the command. Use the ln command to create a hard between a new file named file1.txt and file0.txt. Give the output of the command

ls -l --inode file0.txt file1.txt

1 and circle the inode numbers of both files. What do you notice about the inode numbers? How did the information in the third column (the column immediately preceding the file owner’s name) change after you created a to file0.txt. What does the information in this column represent?

5. Open file1.txt and change the first ’0’ to a ’X’. Save the file and return to the shell. Now examine the contents of file0.txt. What do you notice about the file?

6. Use the command to remove file0.txt. Does file1.txt still exist? Has it changed?

7. The strace command is used in Linux for debugging. Strace will run a program as normally, but each time the program makes a system call, strace will print a line on the screen listing the system call and its parameters. Look at the manual pages for strace and rm if you are not familiar with them. Then, remove the file file1.txt using the rm command, but have the command executed by strace. Which system call is used to remove a file from a directory?

8. In Linux, a symbolic link (generically, a link) is a file that contains information about where to find another file. Symbolic links are created by passing the -s option to the ln command. Create a file called file2.txt. The file should contain exactly 64 of the character ’2’. Then, create a symbolic link to file2.txt called file3.txt. Use the ls command to obtain the inode numbers of file2.txt and file3.txt. Are they the same or different?

9. Look at the contents of file3.txt to verify that it contains the same information as file2.txt. Then, edit file2.txt to change the first ’2’ to the char ’X’. Look at file3.txt. What do you notice?

10. Remove file2.txt. Then, try to examine the contents of file3.txt. What message do you get?

2 11. Explain why you got an error message after deleting the target of the symbolic link.

12. Create a new file named file2.txt. Add some characters to the file. Now look at file3.txt again using the more command. How has the content of file3.txt changed since you looked at it in 9?

13. Use the ln command to make a hard link to the directory you are currently in. Call the hard link this dir. (Hint: In Linux, you can always refer to the current directory by its name, which is a period: . The parent of the current directory’s shortcut is two periods: ..) What error message do you get?

14. Many kernel algorithms that need to traverse a portion of the file system assume that the file system is a true tree. Why do you think Linux does not allow the creation of hard links to directories?

15. Try to make a symbolic link to the directory you are currently in. Where you successful? What do you think the Linux kernel does when it is traversing a portion of the file system and it encounters a symbolic link? Why can the kernel not use that technique when it encounters a hard link?

3