UNIX File System Go Climb a Tree Weiyu Zhang (96142) COSC513 Operating Systems Southeastern University
Introduction It is true. In UNIX, the thing we spend most of our time working with is files. Treating files consistently is one of the greatest strengths in UNIX. It is true.
What is “consistent”? UNIX use the same method to save all the files. For example, an executable script has the same format as a text file. Simplify the file system. The idea is widely used later. (In DOS, Win95/98, etc.)
Three types of UNIX Files Regular files Directory files Device files
Regular files Most common type Hold programs and data Example: Source code of a program Email received from friend Executable programs and applications (such as ls, cat, etc.)
Directory files Basic management tools in UNIX file system Like a cabinet in real life, the files that contain other files Save information of files (such as location, size, etc.)
Devices files Each hardware is treated like a file Example Terminals Printers Keyboards, etc.
More about device file Example: Convenient to handle Read the user input read from a keyboard device file. Print a text file Copy the file to the printer device file. Convenient to handle
File system organization A bottom-up tree with root on the top All the files must be put into directory files Root (/), a special directory file Exact one Can not been deleted
One sample “tree” Root (/) bin/ dev/ etc/ usr/ zhang/ li/ wang/ ... letter.txt Hello.c
Find a file in UNIX Start from the root Go down (or climb) the tree, record the path Each file has a name
An example Root (/) bin/ dev/ etc/ usr/ zhang/ li/ wang/ ... letter.txt Hello.c /usr/wang/letter.txt
File and directory permission Only need in a multi-user OS Keep your own secrets Three classes of users Three permissions
Three classes of users Owner: I created the file. Group: The owner and I are in the same working group. World (a.k.a. other): I just want to use the file.
Three permissions Read permission: read Write permission: modify, delete Execute permission: run No exact priority, normally write permission is the most important one
Nine bits (3 3)
Nine bits (continue) 1 for Y and 0 for N. So the permission of the file is (111 101 000)2
Why permission Keep your secrets. In the above example, world user can not read the file, group user can not modify or delete the file.
Why permission (cont) Keep your secrets. Show more information about a file. Since the files are saved consistently, only those which have the execute permission set can be run.
Why permission (cont) Keep your secrets. Show more information about a file. Avoid wrong operation Setting the owner write permission to be ‘N’ (or 0) can avoid the careless delete of very important files.
I have no permission but I can ...
Conclusions Everything is a file. Bottom-up tree organization Easy but safe
The End