Ch05
Ch05
Chapter 5
File Systems
Storing/Retrieving Information
• All computer applications need to store and retrieve information.
• Regular files are the ones that contain user information. They are either
ASCII files: can be edited with text editors. They consist of lines of text.
Lines need not all be of the same length.
or binary files: which just means that they are not ASCII files. Usually, they
have some internal structure known to programs that use them
• Directories are system files for maintaining the structure of the file system.
• Character special files are related to input/output and used to model serial I/O
devices such as terminals, printers, and networks.
1. Create 7. Append
2. Delete 8. Seek (for random access)
3. Open 9. Get attributes
4. Close 10. Set Attributes
5. Read 11. Rename
6. Write 12. Lock
Directories
• But another problem is that users with many files may want to
group them in smaller subgroups, for instance a professor might
want to separate handouts for a class from drafts of chapters of a
new textbook.
•What is needed is a general hierarchy (i.e., a tree of directories).
With this approach, each user can have as many directories as are
needed so that files can be grouped together in natural ways. This
approach is shown in (c).
Hierarchical Directory Systems
1. Create
2. Delete
3. Opendir (directory can be read)
4. Closedir
5. Readdir (this call returns the next entry in an open directory)
6. Rename
7. Link (a technique that allows a file to appear in more than one
directory)
8. Unlink (A directory entry is removed)
File System Implementation:
File System Layout
• Implementers are interested in how files and directories are stored, how
disk space is managed, and how to make everything work efficiently and
reliably.
• File systems usually are stored on disks. To review this material briefly,
most disks can be divided up into partitions, with independent file systems
on each partition.
• Sector 0 of the disk is called the MBR (Master Boot Record) and is used
to boot the computer.
• The end of the MBR contains the partition table. This table gives the
starting and ending addresses of each partition. One of the partitions in the
table may be marked as active.
File System Implementation: File System Layout
• When the computer is booted, the BIOS reads in and executes the code in
the MBR. The first thing the MBR program does is locate the active
partition, read in its first block, called the boot block, and execute it.
•The program in the boot block loads the OS contained in that partition.
•The first one is the superblock. It contains all the key parameters about
the file system and is read into memory when the computer is booted or the
file system is first touched.
•Next might come information about free blocks in the file system. This
might be followed by the i-nodes, an array of data structures, one per file,
telling all about the file and where its blocks are located.
• After that might come the root directory, which contains the top of the
file system tree. Finally, the remainder of the disk typically contains all the
other directories and files.
Implementing Files: Linked List Allocation
•The one of the used method for storing files is to keep each one as a
linked list of disk blocks.
• The first word of each block is used as a pointer to the next one.
The rest of the block is for data.
•Also, it is sufficient for the directory entry to store the disk address
of the first block. The rest can be found starting there.
•Figure 5-10 shows what the table looks like for the example of Figure 5-9.
•Using the table of Figure 5-10, we can start with block 4 and follow the
chain all the way to the end.
• The same can be done starting with block 6. Both chains are terminated
with a special marker (e.g., -1) that is not a valid block number.
Figure 5-10. Linked list allocation using a file allocation table in main memory.
I-nodes
• An i-node (index-node) is a data structure which lists the attributes and
disk addresses of the file's blocks.
• The big advantage of this scheme over linked files using an in-memory
table is that the i-node need only be in memory when the corresponding file
is open.
• If each i-node occupies n bytes and a maximum of k files may be open at
once, the total memory occupied by the array holding the i-nodes for the
open files is only k x n bytes.
• One problem with i-nodes is that if each one has room for a fixed number
of disk addresses, what happens when a file grows beyond this limit?
• One solution is to reserve the last disk address not for a data block, but for
the address of an indirect block containing more disk block addresses. This
idea can be extended to use double indirect blocks and triple indirect
blocks
I-nodes
• Storing a file as a contiguous sequence of bytes has the obvious problem that if a
file grows, it will probably have to be moved on the disk.
• The same problem holds for segments in memory, except that moving a segment
in memory is a relatively fast operation compared to moving a file from one disk
position to another.
Disk Space Management: Block Size
•For this reason, nearly all file systems chop files up into fixed-size
blocks that need not be adjacent.
Figure 5-17. The solid curve (left-hand scale) gives the data rate of a disk.
The dashed curve gives the disk space efficiency.
All files are 2 KB.
Keeping Track of Free Blocks
Figure 5-18. (a) Storing the free list on a linked list. (b) A bitmap.
Keeping Track of Free Blocks
•Once a block size has been chosen, the next issue is how to keep
track of free blocks.
The first one consists of using a linked list of disk blocks, with
each block holding as many free disk block numbers as will fit.
With a 1-KB block and a 32-bit disk block number, each block
on the free list holds the numbers of 255 free blocks.
•Security has many facets. Three of the more important ones are
The nature of the threats
The nature of intruders
Accidental data loss.
The Security Environment
2. Snooping by insiders.
2. Try illegal system calls, or legal system calls with illegal parameters,
or even legal system calls with legal but unreasonable parameters.
3. Start logging in and then hit DEL, or BREAK halfway through the
login sequence. (in some systems, the password checking program
will be killed and the login considered successful)
6. Look for manuals that say ‘‘Do not do X.’’ Try as many variations of
X as possible.
8. All else failing, the penetrator might find the computer center
director’s secretary and offer a large bribe.
Design Principles for Security
1. The system design should be public.
• Two methods that are practical, are storing the matrix by rows or by
columns, and then storing only the nonempty elements.
Figure 5-29. When capabilities are used, each process has a capability list.
Capabilities
• The other way of slicing up the matrix is by rows.
• associated with each process is a list of objects that may be
accessed, along with an indication of which operations are permitted
on each (its domain).
•This list is called a capability list or C-list and the individual items
on it are called capabilities.
• Usually, a capability consists of a file identifier and a bitmap for the
various rights. In a UNIX-like system, the file identifier would
probably be the i-node number.
• Capability lists are themselves objects and may be pointed to from
other capability lists, thus facilitating sharing of sub-domains.
Examples of Generic Rights
1. Copy capability: create a new capability for the same object.
The first process is the client, which wants some work performed by the
second one, the server. The client and the server do not entirely trust each
other. The third process is the collaborator, which is conspiring with the
server to indeed steal the client's confidential data.
The collaborator and server are typically owned by the same person.
Covert Channels
Figure 5-34. Disk layout for a floppy disk or small hard disk partition, with 64
i-nodes and a 1-KB block size
(i.e., two consecutive 512-byte sectors are treated as a single block).
The Block Cache
Figure 5-38. (a) Root file system. (b) An unmounted file system.
(c) The result of mounting the file system of (b) on /usr/.
File Descriptors
Figure 5-45. Three examples of how the first chunk size is determined for a 10-
byte file.
The block size is 8 bytes, and the number of bytes requested is 6. The chunk is
shown shaded.
Reading
a File