Documente Academic
Documente Profesional
Documente Cultură
File Concept
Access Methods
Directory Structure
File-System Management
Allocation Methods
Free-Space Management
File Concept
Logically a file is sequence of logical records i.e
sequence of bits and bytes.
A file is named collection of related information that
is recorded on secondary storage
Contiguous logical address space
Types:
Data
numeric
character
binary
Program
File Attributes
Name only information kept in human-readable
form.
Type needed for systems that support different
types.
Location pointer to file location on device.
Protection controls who can do reading, writing,
executing.
Time, date, and user identification
Information about files are kept in the directory
structure, which is maintained on the disk.
Owner User who created the file
Size current file size in bytes, words or blocks
File Operations
Typical operations include the following:
Create: A new file is defined and positioned within the
structure of files. To create a file space must be found for
the file in storage and an entry for the file should be in
the directory structure
Delete: A files entry is removed from the directory
structure and space occupied by it are added to the free
space list
Open: An existing file is declared to be opened by a
process,
allowing
the
process
to
perform
read/write/lseek/close functions on the file
Close: The file is closed with respect to a process, so
that the process no longer may perform functions on the
file, until the process opens the file again
File Type
Usual extension
Function
File Table
Operating system keeps a small table containing information
about all open files.
When a file operation is requested, the file is specified via an
index into this table, so no searching is required.
When a file is closed by the process the OS remove the entry
from the File Table
The open file table also has an open count associated with each
file, indicating the # of processes that have the file open.
Several piece of information are associated with file table:
File pointer
File open count
Disk location of the file
Access rights
Access Methods
The information in file can be accessed in several ways
Early operating system supported only one type of file
access that is sequential
With the introduction of disk technology, random access
of files came into picture, which is essential for most of
the applications of modern days
Access Method
Sequential Access
In this method data records are retrieved in the same
order in which have been stored on the disk
This mode of access is most common, for example editors
and compilers usually access files in this fashion
A read operation read next reads the next portion of
the file and automatically advances a file pointer, which
tracks the I/O location
Similarly a write operation write next appends to the
end of the file and advances the end of the newly written
data (new end of file)
For example magnetic tapes store information in
sequential manner and retrieval is performed in the same
manner
Direct Access
A file is made up of fixed length logical records that allow
programs to read and write records rapidly in no particular
order
It is based on the disk model of the file and it allows random
access to any block
For direct access the file is treated as a numbered sequence
of blocks or records
Hence we may read a block 12, then block 57 and then
write block 6
There is no restriction on the order of reading or writing for
a direct access file
Direct access files are of great use for immediate access to
a large amount of information
Indexed file
Indexed file approach is helpful with multiple attribute fields
like in database files
In this every field is associated with an index key
While querying data, the index key is kept in the memory and
related records are fetched from the disk
These indexing keys help distinguishing one record from the
other
Indexes are managed in various ways like single level index
and multilevel index
These are also called dense and sparse index respectively
In single level, every record has an index key associated with it
These index values can get associated with primary or
secondary index key
2.
3.
4.
Direct hashing
Direct Hashing the key is the address
Access Methods
Sequential Access
read next
write next
reset
no read after last write
(rewrite)
Direct Access
read n
write n
position to n
read next
write next
rewrite n
n = relative block
number
Index method:
To find a record in the file,we first search the index, and then
use the pointer to access the file directly and to find the
desired record.(index file & relative file)
Directory Structure
A collection of nodes containing information about all files.
Directory
Files
F1
F2
F3
F4
Fn
Information in a Device
Directory
Name
Type
Address
Current length
Maximum length
Date last accessed
Date last updated
Owner ID Protection information
Operations Performed on
Directory
Search for a file
Create a file
Delete a file
List a directory
Rename a file
Traverse the file system
Single-Level Directory
A single directory for all users.
Naming problem
Grouping problem
Two-Level Directory
Separate directory for each user.
Path name
Can have the same file name for different user
Efficient searching
Tree-Structured Directories
Tree-Structured Directories
Efficient searching
Grouping Capability
Current directory (working
directory)
cd /spell/mail/prog
type list
Tree-Structured Directories
Absolute or relative path name
Creating a new file is done in current directory.
Delete a file
rm <file-name>
Creating a new subdirectory is done in current directory.
mkdir <dir-name>
mail
prog
copy
prt
exp
count
modify files
2. Each user may have controlled access to other users files
3. Each user may control what types of accesses are allowed to
form appropriate to
5. Each user should be able to move data between files.
6. Each user should be able to back up and recover the users
Allocation Methods
Main problem is how the space is allocated to these files,
so that the disk space is utilized effectively and file can
be accessed quickly
An allocation method refers to how disk blocks are
allocated for files:
Three major methods of allocating disk space are in wide use
Contiguous allocation
Linked allocation
Indexed allocation
Contiguous Allocation
Each file occupies a set of contiguous blocks on the disk
Disk addresses define a linear ordering on the disk
With this ordering, assuming that only one job is
accessing the disk, there is no head movement
required, even if required it is to the next track
Hence the disk seek time is minimal
Simple only starting location (block #) and length
(number of blocks) are required
Random access : both sequential as well as direct
access is efficient
Contiguous Allocation of
Disk Space
(Contd)
One main problem, is finding the space for a new file, which depends
on the logic implemented to manage free space
Wasteful of space (dynamic storage-allocation problem): how to satisfy
a request for size n from a list of free holes
First fit and best fit are the most common strategies used to select the
free hole from the set of available holes
They are efficient but not best in terms of storage utilization
All these algorithms suffer from the problem of external fragmentation
As files are created and deleted, the free disk space is broken into
small pieces
Files cannot grow in size or need to know the maximum size at the time of
creation; but leads to inefficient usage if disk space
Contiguous Allocation
Each file occupies a set of contiguous blocks on
the disk
Simple only starting location (block #) and
length (number of blocks) are required
Random access
Wasteful of space (dynamic storage-allocation
problem)
First fit/best fit
Mapping from logical to physical
Linked Allocation
Linked allocation each file is a linked list of blocks ;
block
pointer
Linked Allocation
Allocate as needed, link together; e.g., file starts at block 9
File-Allocation Table
Indexed Allocation
Indexed allocation
Each file has its own index block(s) of pointers to its
data blocks
Logical view
Need index table
Random access
INDEX TABLE
Example of Indexed
Allocation
Free-Space Management
To keep track of free disk space,
the system maintains a free-space
list.
The free space list records all free
disks blocks-those not allocated to
some file or directory.
Free-Space Management
Bit vector (n blocks)
bit[i] =
n-1
1 block[i] free
0 block[i] occupied
Advantage:
It is relatively simple and efficient in finding the first free blocks
or n consecutive free blocks on the disk.
Easy to get contiguous files
Disadvantage:
May require special hardware support.
Bit map requires extra space, if the disk size is large.
Free-Space Management
Linked list (free list)
This approach maintains a linked list of all the free disk blocks.
The first block contains a pointer to the next free disk block,
and so on
Cannot get contiguous space easily
No waste of space
Grouping
This store the address of n free blocks in the first free block.
The last block contain the addresses of another n free blocks
and so on
Counting
We can keep the address of the first free block and the
number n of free contiguous blocks that follow the first block.
Each entry in the free space list consist of a disk address and a
count.