Professional Documents
Culture Documents
Os Chapter 13
Os Chapter 13
• Intro
The implementation of file systems is a major aspect of operating system architecture. Designers have
to decide how to map file system information onto the physical storage device(s), and what methods to
provide for access and manipulation. File systems are often performance bottlenecks, and it is quite a
challenge to make them adequately efficient.
File systems consist of two parts, a collection of files and a directory structure. The purpose of the
directory structure is to provide information about, and organization of the files.
• 13.0 Objectives
◦ A file is a logical unit of storage - the smallest allotment of logical secondary storage, a named
collection of related information that is recorded on secondary storage, "a clinking, clanking,
clattering collection of caliginous junk," as it were.
1 of 12 16-09-2021, 18:00
10th ed. chapter 13 https://www.cs.csustan.edu/~john/Classes/CS3750/Notes/Chap13/13_Fil...
▪ Files are abstract data structures. They have associated file operations, which are
implemented with system calls:
▪ Creating a file (allocate space and make entry in a directory)
▪ Opening a file (cache info about the file in main memory and return a pointer to it)
▪ Writing a file (may involve updating a pointer to current file position)
▪ Reading a file (also may involve updating a pointer to current file position)
▪ Repositioning within a file (change the value of the file pointer)
▪ Deleting a file (remove entry from directory and deallocate space no longer used)
2 of 12 16-09-2021, 18:00
10th ed. chapter 13 https://www.cs.csustan.edu/~john/Classes/CS3750/Notes/Chap13/13_Fil...
▪ The operations above are a minimal set. Designers can implement other operations using
combinations. For example to copy a file we can create a new file, then read from the old
and write to the new.
▪ Many systems require that files be opened before use. The open operation places directory
information about the file into an open file table data structure in primary memory. That
way, processes will be able to make a lot of accesses to the file without needing to fetch
directory information from the disk each time.
▪ In systems that allow multiple processes to have a file open simultaneously, it is customary
to have two levels of open file tables - a single system-wide table, and multiple per-process
open file tables. Each per-process table holds information having to do with the particular
process' use of the file, such as the current read and write positions of the process in the
file. The entry for a file in the per-process table contains a pointer to the entry for the file
in the system-wide table. Process-independent things like location of the file on disk,
access dates, file size, and file open count are contained in the file's entry in the system-
wide file table.
▪ File-locking operations may be available, shared and/or exclusive locks, mandatory and/or
advisory locks.
3 of 12 16-09-2021, 18:00
10th ed. chapter 13 https://www.cs.csustan.edu/~john/Classes/CS3750/Notes/Chap13/13_Fil...
4 of 12 16-09-2021, 18:00
10th ed. chapter 13 https://www.cs.csustan.edu/~john/Classes/CS3750/Notes/Chap13/13_Fil...
5 of 12 16-09-2021, 18:00
10th ed. chapter 13 https://www.cs.csustan.edu/~john/Classes/CS3750/Notes/Chap13/13_Fil...
◦ The directory is basically a table for looking up information about files, using the name of the
file as the lookup key.
◦ The directory structure needs to support the following operations.
▪ Search for a file (by name)
▪ Create a file (add to directory)
▪ Delete a file (remove from directory)
▪ List a directory (list names and info for files in directory)
▪ Rename a file (change directory entry)
▪ Traverse the file system (access all directories and files, for example when performing a
backup)
6 of 12 16-09-2021, 18:00
10th ed. chapter 13 https://www.cs.csustan.edu/~john/Classes/CS3750/Notes/Chap13/13_Fil...
▪ In a two-level directory structure, there is a master file directory that has multiple sub-
directories.
▪ Each user on a computing system can be assigned his or her own 'home' directory. Users
can name files whatever they like without fear of collisions with the filenames of other
users.
▪ If a user name and file name within the user's directory are specified, this "pathname"
uniquely determines which file it is.
▪ The OS assumes that a filename without a user name refers to the user's own directory, or
to a special directory that contains the system files (e.g. programs that are user shell
commands)
▪ The sequence of directories searched when a file is named is called a search path.
7 of 12 16-09-2021, 18:00
10th ed. chapter 13 https://www.cs.csustan.edu/~john/Classes/CS3750/Notes/Chap13/13_Fil...
▪ The tree has a root, and every file or directory has a unique pathname that starts with the
root.
▪ Processes can typically "move around" in the tree, by using a system call to specify which
directory is their current working directory.
▪ The accounting file (e.g. passwd file) of a user typically designates which directory should
initially be made the current working directory when the user logs in.
▪ This structure allows directories to share a file or subdirectory. By definition, this is not
possible in a tree.
▪ Shared files and subdirectories may be implemented through the use of (symbolic) links
[aka soft links]. A symbolic link may be thought of as a file that contains a path name. The
directory entry of the symbolic link has a special bit value set that marks the file as a link
rather than an ordinary file. For example, if /x/y is a file that we wish to share, we can put
a symbolic link in /z containing the pathname "/x/y" and name the symbolic link (file) r.
Then all references to /z/r will access the same file as /x/y.
▪ Going on with the previous example, the original directory entry for /x/y is sometimes
referred to as a hard link. It is just an ordinary directory entry, typically consisting of the
name of the file (y, in this case) and the address on disk of the directory information for the
8 of 12 16-09-2021, 18:00
10th ed. chapter 13 https://www.cs.csustan.edu/~john/Classes/CS3750/Notes/Chap13/13_Fil...
file.
▪ Another way to implement the sharing of the file would be to use another hard link - an
entry in the /z directory that contains the other name (r, in this case), plus the same address
on disk of the directory information for the original file (known as /x/y). This gives us two
separate directory entries that point to the same file on disk.
▪ When there are multiple hard and/or soft links to files and/or directories, designers of the
system must take care when implementing the file and directory deletion operations.
Pointers can be left dangling and/or file space can be deallocated when the files are still in
use.
• 13.4 Protection
◦ When valuable information is stored on a computing system we want to keep it safe from
physical damage and improper access.
9 of 12 16-09-2021, 18:00
10th ed. chapter 13 https://www.cs.csustan.edu/~john/Classes/CS3750/Notes/Chap13/13_Fil...
▪ There are different kinds of protection mechanisms, suited to different sorts of computing
systems. The next few sections discuss a few aspects of protection. There's more detail in
Chapter 20.
▪ Many systems are designed with a condensed form of ACLs in which access rights are
stored just for three entities: the owner of the file (or directory), the group, and everybody
else.
▪ Owner (the owner is the user who created the file)
▪ Group (a designated 'work group')
▪ Other (everyone else who uses the system)
▪ Some systems, like Solaris, use the (owner, group, others) approach by default, but also
allow more detailed access controls to be added to specific file objects. (The term file
object is meant to include files, directories, and other special kinds of items that might
10 of 12 16-09-2021, 18:00
10th ed. chapter 13 https://www.cs.csustan.edu/~john/Classes/CS3750/Notes/Chap13/13_Fil...
▪ Read, write, and execute bits are commonly associated with each of the three classes:
owner (user), group, and other.
▪ For a plain file, a set read bit means a member of the class has permission to read the file.
Similarly the write bit gives permission to write, and the execute bit gives permission to
execute the file (presumably the file is a program, script, or the like).
▪ For directories, the read bit gives permission to list the directory. The write bit allows
creation of new files in the directory and, if it is empty, deletion of the directory. The
execute bit gives permission to cd to the directory, and to access the file objects in the
directory, subject to the permissions on the objects themselves.
▪ Users who lack either write or execute permission on a directory cannot delete a file object
in that directory.
◦ File I/O sometimes requires multiple time-consuming system calls and disk accesses. Designers
can make things more efficient with virtual-memory techniques.
▪ The OS can copy modified file blocks through to disk after the process closes the file, or
possibly as part of a periodic interrupt routine.
11 of 12 16-09-2021, 18:00
10th ed. chapter 13 https://www.cs.csustan.edu/~john/Classes/CS3750/Notes/Chap13/13_Fil...
• 13.6 Summary
12 of 12 16-09-2021, 18:00