OS Unit IV File System_Part 1
OS Unit IV File System_Part 1
File Concept
Access Methods
Directory and Disk Structure
File Concept
Computers can store information on various storage media, such as magnetic
disks, magnetic tapes, and optical disks.
So that the computer system will be convenient to use, the operating system
provides a uniform logical view of information storage.
The operating system abstracts from the physical properties of its storage
devices to define a logical storage unit, the file.
These storage devices are usually nonvolatile, so the contents are persistent
through power failures and system reboots.
A file is a collection of related information that is recorded on
secondary storage.
From a user’s perspective, a file is the smallest allotment of logical
secondary storage; that is, data cannot be written to secondary storage
unless they are within a file.
Commonly, files represent programs (both source and object forms) and
data.
Data files may be numeric, alphabetic, alphanumeric, or binary.
Types of Files
Many different types of information may be stored in a file—source or executable
programs, numeric or text data, photos, music, video, and soon.
A file has a certain defined structure, which depends on its type.
Text file: is a sequence of characters organized into lines (and possibly pages).
Executable file : is a sequence of code section that the loader can bring into
memory and execute.
File Types – Name, Extension
File Attributes
A file is named, for the convenience of its human users, and is referred to by
its name.
A name is usually a string of characters, such as example.c.
Some systems differentiate between uppercase and lowercase characters
in names, whereas other systems do not.
When a file is named, it becomes independent of the process, the user, and
even the system that created it.
For instance, one user might create the file example.c, and another user
might edit that file by specifying its name.
File Attributes
Detailed information about the file stored in directory structure
Name – only information kept in human-readable form
Identifier – unique tag (number) identifies file within file system. it is the
non-human-readable name for the file.
Type – needed for systems that support different types
Location – pointer to file location on device
Size – current file size
Protection – Access-control information determines 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. This data useful for
protection, security, and usage monitoring
Some newer file systems also support extended file attributes, including
character encoding of the file and security features such as a file checksum.
File Operations
Create
Write
Read
Reposition within file
Delete
Truncate
These six basic operations comprise the minimal set of required file
operations.
Other common operations are
appending new information to the end of an existing file
renaming an existing file.
Open(Fi) – search the directory structure on disk for entry Fi, and move the
content of entry to memory
Close (Fi) – move the content of entry Fi in memory to directory structure
on disk
Access Methods
Files store information. When it is used, this information must be accessed and
read into computer memory.
The information in the file can be accessed in several ways.
Sequential Access:
This is the simplest access method. Information in the file is processed in order,
one record after the other.
This mode of access is by far the most common; for example, editors and
compilers usually access files in this fashion.
Reads and writes make up the bulk of the operations on a file.
read next
write next
reset (or) rewind
no read after last write
(rewrite)
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, the write operation- write next- appends to the end of the file and
advances to the end of the newly written material (the new end of file).
Such a file can be reset to the beginning;
• If the file contains 100 records
• Now we are at 50th record.
• We need to access 75th record.
• First 50,then 51,52… 75
• We cannot access it directly.
• Which takes more time.
Direct Access or Relative Access or Random Access:
read n
write n
position to n
read next
write next
rewrite n
n = relative block number
A File is made up of fixed length logical records that allow programs to read and
write records rapidly in no particular order.
The direct-access method is based on a disk model of a file, since disks allow
random access to any file block.
For direct access, the file is viewed as a numbered sequence of blocks or
records. Thus, we may read block 14, then read block 53, and then write block 7.
There are no restrictions on the order of reading or writing for a direct-access file.
Direct-access files are of great use for immediate access to large amounts of
information.
Databases are often of this type. When a query concerning a particular subject
arrives, we compute which block contains the answer and then read that block
directly to provide the desired information.
As a simple example, on an airline-reservation system
Simulation of Sequential Access on
Direct-access File
• These methods generally involve the construction of an index for the file.
• The index like an index in the back of a book contains pointers to the various blocks.
• To find a record in the file, we first search the index and then use the to access the file
directly and to find the desired record.
• For example, IBM's indexed sequential-access method (ISAM) uses a small master index
that points to disk blocks of a secondary index.
• The secondary index blocks point to the actual file blocks. The file is kept sorted on a
defined key.
• To find a particular item, we first make a binary search of the master index, which
provides the block number of the secondary index.
• This block is read in, and again a binary search is used to find the block containing the
desired record. Finally, this block is searched sequentially.
Example of Index and Relative Files
Directory and Disk Structure
Directory
Files
F1 F2 F4
F3
Fn
Rename a file
Traverse the file system
Efficiency – locating a file quickly
Organize the Directory (Logically) to Obtain
DisAdvantages:
Naming problem: Can’t create more than one file with same name
Grouping problem
Two-Level Directory
Separate directory for each user
Advantages
Can have the same file name for different users
Efficient searching
Dis Advantages
Path name
No grouping capability : Sub directories cannot be created
Tree-Structured Directories
Tree-Structured Directories (Cont.)
We can have directories at More than two levels (Multilevel)
Advantages:
Efficient searching
Dis Advantages:
We share the files via links .If we delete a link it creates a problem
Advantages
It allows cycles
It is more flexible than other directories structure.
Dis Advantages
It is most costlier than others
Garbage collection
Every time a new link is added use a cycle detection algorithm to
determine whether it is OK