Unit 5
Unit 5
system-wide process
open-file table open-file table file
file index
file pointer
file open count
one file disk location
access right
File Structure
Some systems support specific file types that
have special file structures.
For example, files that contain binary
executables.
An operating system becomes more complex
when more file types (i.e., file structures) are
supported.
In general, the number of supported file types
is kept to minimum.
File Access Methods
Access method: how a file be used.
There are three popular ones:
Sequential access method for sequential files
Direct access method for direct files
Indexed access method for indexed files.
Sequential Access Method
With the sequential access method, the file is
processed in order, one record after the other.
If p is the file pointer, the next record to be
accessed is either p+1 or p-1 (i.e., backspace).
current record
rewind
read/write
Direct Access Method
A file is made up of fixed-length logical records.
The direct access method uses record number to
identify each record. For example, read rec 0, write
rec 100, seek rec 75, etc.
Some systems may use a key field to access a record
(e.g., read rec “Age=24” or write rec “Name=Dow”).
This is usually achieved using hashing.
Since records can be accessed in random order,
direct access is also referred to as random access.
Direct access method can simulate sequential access.
Indexed Access Method
With the indexed access method, a file is sorted in
ascending order based on a number of keys.
Each disk block may contain a number of fixed-
length logical records.
An index table stores the keys of the first block in
each block.
We can search the index table to locate the block
that contains the desired record. Then, search the
block to find the desired record.
This is exactly a one-level B-, B+ or B* tree.
Multi-level index access method is also possible.
data file
index table
last name logical rec #
Adams Ashcroft, … Asher, … Atkins
Arthur
Ashcroft
Smith
/bin/mail/prog/spell
Acyclic-Graph Directory: 1/2
This type of directories
allows a file/directory to
be shared by multiple
directories.
This is different from
two copies of the same
file or directory.
An acyclic-graph
directory is more
flexible than a simple
file count is shared by directories tree structure.
dict and spell However, it is more
complex.
Acyclic-Graph Directory: 2/2
Since a file have multiple absolute path names, how do
we calculate file system statistics or do backup?
Would the same file be duplicated multiple times?
How do we delete a file?
If sharing is implemented with symbolic links, we
only delete the link if we have a list of links to the
file. The file is removed when the list is empty.
Or, we remove the file and keep the links. When the
file is accessed again, a message is given and the link
is removed.
Or, we can maintain a reference count for each
shared file. The file is removed when the count is
zero.