Operating Systems: Internals and Design Principles: File Management
Operating Systems: Internals and Design Principles: File Management
Operating Systems: Internals and Design Principles: File Management
Systems:
Internals
and Design
Principles Chapter 12
File Management
Eighth Edition
By William Stallings
Files
Data collections created by users
The File System is one of the most important parts of the OS to a user
Long-term existence
• files are stored on disk or other secondary storage and do not disappear when a user logs off
Structure
• files can be organized into hierarchical or more complex structure to reflect the relationships
among files
File Systems
Provide a means to store data organized as files as well as a
collection of functions that can be performed on files
• should be able to access his or her files by name rather than by numeric identifier
7
User Program
Indexed
Pile Sequential Indexed Hashed
Sequential
Logical I/O
Deals with blocks of data that are exchanged with disk or tape
systems
Control structures that deal with device I/O, scheduling, and file
status are maintained
Provides
general-
purpose
Enables users record I/O
and capability Maintains
applications to basic data
access records about file
Access Method
Level of the file system closest to the user
File
allocation
User access
control
Priority of criteria depends on the application that will use the file
File Organization Types
The pile
The
The direct, or sequential
hashed, file file
The indexed
The sequential file
indexed file
Variable-length records Fixed-length records
Variable set of fields Fixed set of fields in fixed order
Chronological order Sequential order based on key field
n
Index Main File
levels
Index
2
1
Overflow
File
Purpose is simply to
Variable-length records
accumulate the mass of
Variable set of fields
data and save it Chronological order
Record access is by
exhaustive search (a) Pile File
E
The Sequential
File
Most common form of file
structure
Typically
ble-length records used in batch Fixed-length records
ble set of applications
fields Fixed set of fields in fixed order
nological order Sequential order based on key field
Only organization that is
easily stored on tape as well
(a)
asPile
diskFile (b) Sequential File
Exhaustive Exhaustive Partial
(a) Pile File
Indexed
Sequential File
n
Index Main File
Adds an index to the file
to support random access
levels
Index
2
Adds an overflow file 1
Greatly reduces the time
required to access a single
record
Overflow
Multiple levels of
indexing can be used to
File
provide greater efficiency
in access
(c) Indexed Sequential File
(a) Pile File (b) Sequential File
Exhaustive Exhaustive Partial
n
Records are accessed only through
Indextheir indexes Main File
levels
Index
2Variable-length records can be
1 employed
Exhaustive index contains one
entry for every record in the main
file
Overflow
Partial index contains
Fileentries to
records where the field of interest
exists
(c) Indexed
Used mostly inSequential File
applications where Primary File
timeliness of information is (variable-length records)
critical
2 10 30 32 39 43 44 52 59 60 67 68 73 85 88 96
23 51 61 71
2 10 30 32 39 43 44 52 59 60 67 68 73 85 88 90 96
23 39 51 61 71
2 10 30 32 43 44 45 52 59 60 67 68 73 85 88 90 96
(c) Key = 45 inserted. This requires splitting a node into two parts and promoting one key to the root node.
51
23 39 61 71 88
2 10 30 32 43 44 45 52 59 60 67 68 73 84 85 90 96
(d) Key = 84 inserted. This requires splitting a node into two parts and promoting one key to the root node
This then requires the root node to be split and a new root created.
Table 12.1 File Name Name as chosen by creator (user or program). Must be unique within a specific
directory.
Address Information
Size Used
Starting physical address on secondary storage (e.g., cylinder, track, and block
number on disk)
Owner User who is assigned control of this file. The owner may be able to grant/deny
access to other users and to change these privileges.
File Directory Access Information A simple version of this element would include the user's name and password for
each authorized user.
Usage Information
Date Last Read Access Date of the last time a record was read
Date of Last Backup Date of the last time the file was backed up on another storage medium
Current Usage Information about current activity on the file, such as process or processes that
have the file open, whether it is locked by a process, and whether the file has been
(Table can be found on page 537 in textbook) updated in main memory but not yet on disk
Operations Performed
on a Directory
To understand the requirements for a file structure, it is helpful to
consider the types of operations that may be performed on the
directory:
Directory Directory
"User_C" Directory "User_B" "User_A"
Draw
Word
Unit_A ABC
Directory "Unit_A"
ABC File
"ABC"
management of
access rights simultaneous
access
Access Rights
None Appending
the user would not be allowed to
read the user directory that the user can add data to the file
includes the file but cannot modify or delete any
of the file’s contents
Knowledge
Updating
the user can determine that the
file exists and who its owner is the user can modify, delete, and
and can then petition the owner add to the file’s data
for additional access rights
Changing protection
Execution
the user can load and execute a the user can change the access
program but cannot copy it rights granted to other users
Reading Deletion
the user can read the file for any the user can delete the file from
purpose, including copying and the file system
execution
User Access Rights
Specific User
Owner All
Users Groups
usually the
initial creator all users who
of the file have access to
this system
individual a set of users
users who are who are not
has full rights
designated by individually
user ID defined
may grant these are
rights to public files
others
Record Blocking
1) Fixed-Length Blocking – fixed-
Blocks are the unit of I/O length records are used, and an
with secondary storage integral number of records are
for I/O to be stored in a block
performed records Internal fragmentation – unused
must be organized as space at the end of each block
blocks
2) Variable-Length Spanned Blocking
– variable-length records are used
and are packed into blocks with no
unused space
R5 R6 R7 R8 Track 2
Fixed Blocking
R1 R2 R3 R4 R4 R5 R6 Track 1
R1 R2 R3 R4 R5 Track 1
R6 R7 R8 R9 R10 Track 2
The approach taken for file allocation may influence the approach
taken for free space management
Items to be considered:
1) contiguity of space increases performance, especially for
Retrieve_Next operations, and greatly for transactions
running in a transaction-oriented operating system
2) having a large number of small portions increases the size of
tables needed to manage the allocation information
3) having fixed-size portions simplifies the reallocation of space
4) having variable-size or small fixed-size portions minimizes
waste of unused storage due to overallocation
Alternatives
Two major alternatives:
15 16 17 18 19
File C
20 21 22 23 24
File E
25 26 27 28 29
File D
30 31 32 33 34
20 21 22 23 24
25 26 27 28 29
30 31 32 33 34
10 11 12 13 14
15 16 17 18 19
20 21 22 23 24
25 26 27 28 29
30 31 32 33 34
10 11 12 13 14
15 16 17 18 19
20 21 22 23 24
25 26 27 28 29
30 31 32 33 34
10 11 12 13 14
15 16 17 18 19
1
20 21 22 23 24 8
3
25 26 27 28 29 14
28
30 31 32 33 34
10 11 12 13 14
15 16 17 18 19
Start Block Length
20 21 22 23 24 1 3
28 4
25 26 27 28 29 14 1
30 31 32 33 34
Advantages:
• works well with any file
allocation method
• it is as small as possible
Chained Free Portions
The free portions may be chained together by using a pointer and
length value in each free portion
Disadvantages:
• leads to fragmentation
• every time you allocate a block you need to read
the block first to recover the pointer to the new
first free block before writing data to that block
Indexing
Treats free space as a file and uses an index table as it would for file
allocation
This approach provides efficient support for all of the file allocation
methods
Free Block List
There are two effective
Depending on the size of
techniques for storing a
Each block is assigned a the disk, either 24 or 32
small part of the free
number sequentially bits will be needed to store
block list in main
a single block number
memory:
Directory
• contains a list of file names plus pointers to associated inodes
Special
• contains no data but provides a mechanism to map physical devices to file names
Named pipes
• an interprocess communications facility
Links
• an alternative file name for an existing file
Symbolic links
• a data file that contains the name of the file it is linked to
Inodes
All types of UNIX files are administered by the OS by means of
inodes
direct(0) Data
Pointers
Data Data
Pointers
direct(12)
triple indirect
Pointers
block count Data
reference count
Pointers Pointers
flags (2)
Data
Pointers
generation number
extended
attribute Pointers
blocks Data
Inode
Direct 12 48K
i1 Name1
i2 Name2
i3 Name3
i4 Name4
File
system Individual File Kernel
Systems space
Buffer cache
Device drivers
Files on secondary
storage maintained
by file system X
Each row describes a file on this volume, including the MFT itself,
which is treated as a file
Note: Colored rows refer to required file attributes; the other attributes are optional.
I/O Manager
Log the transaction
Log File NTFS Driver Read/write a
Service mirrored or
Read/write
Fault Tolerant striped volume
the file
Flush the Write the Driver
Read/write
log file cache the disk
Disk Driver
Virtual Memory
Manager
(ro)
/system bin
etc
lib
/data (rw)
usr
/cache (rw)