CS124 Lec 23
CS124 Lec 23
Persistent Storage
• All programs require some form of persistent storage that
lasts beyond the lifetime of an individual process
• Most obvious reason: need a way to specify the program!
• Other examples: configuration, input data files, output data files,
documents, files shared among programs, etc.
• Also frequently want storage to last through a process or
system crash
• e.g. banking information, reservation systems, document editors
• Or, just for backing up system information
• Computers often include some form of persistent storage
• Very common: hard disks (HDDs), solid-state drives (SSDs), USB
flash drives, flash memory cards, other flash storage
• Less common, but still widely used: tape drives, optical drives
3
Large Data-Sets
• Sometimes programs must manipulate data-sets that are
much larger than the system memory size
• i.e. the size of physical memory, or system’s virtual address space
• Frequently want to allow multiple processes to access and
manipulate the same large data-set concurrently
• Allow multiple processes to read the same data concurrently
• Allow multiple processes to write different parts of the same data
concurrently
• Typically, the devices used to store these large data-sets
are much slower than the computer’s main memory
• Reading many bytes is roughly as costly as reading one byte…
• Divide storage device into fixed-size blocks; allow system software
to read/write individual blocks of data
4
File Contents
• General-purpose operating systems usually don’t
constrain file contents to follow any particular format
• A process can interpret the file’s contents however it wants to
• The OS may distinguish between text and binary files, but usually
applications impose this distinction
• Some files may be constrained to follow a specific format,
e.g. executable program binaries or shared libraries
• Older systems would have constraints on file formats, due
to the characteristics of their storage devices!
• e.g. card readers could only store 80-character-wide text files, and
output was written to 132-character printers
• Purpose-built operating systems may also constrain files
to follow a specific format (files of records, etc.)
6
Referring to Files
• Files are referred to by a text name (a.k.a. “filename”)
• Often, files also specify an extension indicating the kind
of file, i.e. how to interpret the file’s contents
• The extension is usually the portion of the filename following the
last period “.” in the filename
• The portion before the extension is often called the base name
• Term “filename” may refer to base name, or name and extension
• The specific constraints on filenames vary from OS to OS
• e.g. MS-DOS only allows 8 characters for the filename and 3
characters for the extension
• Some OSes respect the capitalization of a filename; e.g. most
UNIXes treat FOO.txt and foo.txt as different files
• Others treat these as referring to the same file (e.g. MS-DOS, and
MacOS X by default)
7
Organizing Files
• Once a system has more than a few files, becomes very
helpful to be able to organize them
• OSes provide directories or folders that contain files
• Within a specific directory, every file must have a unique name
• Two different directories can contain files with the same name
• File systems usually have at least one directory: the root
directory
• The starting point for finding any file in the file system
• If the file system doesn’t have a root directory, programs must know
how to find files on the storage device by themselves
• Depending on the complexity of the file system, OSes will
support varying levels of complexity for directory structure
8
Directory Structures
• Simple operating systems frequently support a very
simple directory structure
• e.g. simple phones, digital cameras, … root
A B C C D
9
File Storage
• Files are presented as an unstructured sequence of bytes
• Programs are free to read and write sequences of varying sizes
• Programs are free to impose whatever meaning on a file’s contents
• The file system exposes various operations on files, e.g.
• Create a file at a specific path (can specify permissions, etc.)
• Delete a file at a specific path
• Rename a file
• The OS maintains a “current position” for open files
• When bytes are read or written, the current position is used
• The position is updated by the read or write operation
• Programs can also seek to a specific position within a file
• If multiple processes have a given file open, each process
has its own “current position” in the file
14
A 3 11
A 3 11
Directory Entry: A 3 11
File Allocation 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Table: 4 10 13 -1 14 15 11
21
File Allocation 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Table: 4 10 13 -1 14 15 11
index
3
A 2 4
10
Location of
Index Block 13
14
15
11
-1
Contents of -1
Index Block …
25
…
31
Next Time
• More details on file systems!