0% found this document useful (0 votes)
17 views19 pages

Os Unit-5 Part-1

The document provides detailed notes on file concepts in operating systems, explaining the structure and attributes of files, as well as various file operations such as creating, reading, writing, and deleting files. It discusses different file types, access methods, and directory structures, including single-level, two-level, tree-structured, and graph directories. Additionally, it covers the implementation of file systems, including the roles of logical and basic file systems, and the management of file control blocks.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views19 pages

Os Unit-5 Part-1

The document provides detailed notes on file concepts in operating systems, explaining the structure and attributes of files, as well as various file operations such as creating, reading, writing, and deleting files. It discusses different file types, access methods, and directory structures, including single-level, two-level, tree-structured, and graph directories. Additionally, it covers the implementation of file systems, including the roles of logical and basic file systems, and the management of file control blocks.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

OPERATING SYSTEMS NOTES II YEAR/I SEM

System

File Concept:

Computers can store information on various storage media such as, magnetic disks,
magnetic tapes, optical disks. The physical storage is converted into a logical storage
unit by operating system. The logical storage unit is called FILE. A file is a collection of
similar records. A record is a collection of related fields that can be treated as a unit by
some application program. A field is some basic element of data. Any individual field
contains a single value. A data base is collection of related data.

Student Marks Marks Fail/Pas


KUMA 85 86 P
LAKSH 93 92 P
DATA FILE

Student name, Marks in sub1, sub2, Fail/Pass is fields. The collection of fields is
called a RECORD. RECORD:
LAKSH 93 92 P
Collection of these records is called a data file.

FILE ATTRIBUTES :

1. Name : A file is named for the convenience of the user and is referred by its
name. A name is usually a string of characters.
2. Identifier : This unique tag, usually a number ,identifies the file within the file system.
3. Type : Files are of so many types. The type depends on the extension of the file.

Example:
.exe Executable file
.obj Object file
.src Source file
4. Location : This information is a pointer to a device and to the location of
the file on that device.

1
OPERATING SYSTEMS NOTES II YEAR/I SEM

5. Size : The current size of the file (in bytes, words,blocks).


6. Protection : Access control information determines who can do reading,
writing, executing and so on.
7. Time, Date, User identification : This information may be kept for
creation, last modification,last use.

FILE OPERATIONS

1. Creating a file : Two steps are needed to create a file. They are:
 Check whether the space is available ornot.
 If the space is available then made an entry for the new file in the
directory. The entry includes name of the file, path of the file,etc…
2. Writing a file : To write a file, we have to know 2 things. One is name of the
file and second is the information or data to be written on the file, the system searches
the entired given location for the file. If the file is found, the system must keep a write
pointer to the location in the file where the next write is to take place.
3. Reading a file : To read a file, first of all we search the directories for the file,
if the file is found, the system needs to keep a read pointer to the location in the file
where the next read is to take place. Once the read has taken place, the read pointer is
updated.
4. Repositioning within a file : The directory is searched for the appropriate
entry and the current file position pointer is repositioned to a given value. This
operation is also called file seek.
5. Deleting a file : To delete a file, first of all search the directory for named
file, then released the file space and erase the directoryentry.
6. Truncating a file : To truncate a file, remove the file contents only but, the
attributes are as itis.

FILE TYPES:The name of the file split into 2 parts. One is name and second is
Extension. The file type is depending on extension of the file.

File Type Extension Purpose


Executable .exe Ready to run
.com (or) ready
.bin to run
machine
Source code .c Source code in
.cpp various
.asm languages.
Object .obj Compiled,
.o machine

2
OPERATING SYSTEMS NOTES II YEAR/I SEM
Batch .bat Commands to
.sh the command

3
OPERATING SYSTEMS NOTES II YEAR/I SEM

Text .txt Textual


.doc data,
docume
nts
Word processor .doc Various word
.wp proc
.rtf essor
form
ats
Library .lib Libraries of
.dll routines for
Print or View .pdf Binary file in a
.jpg format for
Archive .arc Related files
.zip grouped into a
Multimedia .mpeg Binary file
.mp3 containing
.avi audio
or audio/video

FILE STRUCTURE

File types also can be used to indicate the internal structure of the file. The operating
system requires that an executable file have a specific structure so that it can determine
where in memory to load the file and what the location of the first instruction is. If OS
supports multiple file structures, the resulting size of OS is large. If the OS defines 5
different file structures, it needs to contain the code to support these file structures. All
OS must support at least one structure that of an executable file so that the system is able
to load and run programs.

INTERNAL FILE STRUCTURE

In UNIX OS, defines all files to be simply stream of bytes. Each byte is individually
addressable by its offset from the beginning or end of the file. In this case, the logical
record size is 1 byte. The file system automatically packs and unpacks bytes into
physical disk blocks, say 512 bytes per block.

The logical record size, physical block size, packing determines how many logical
records are in each physical block. The packing can be done by the user’s application
program or OS. A file may be considered a sequence of blocks. If each block were 512
bytes, a file of 1949 bytes would be allocated 4 blocks (2048 bytes). The last 99 bytes
4
OPERATING SYSTEMS NOTES II YEAR/I SEM

would be wasted. It is called internal fragmentation all file systems suffer from internal
fragmentation, the larger the block size, the greater the internal fragmentation.
FILE ACCESS METHODS

Files stores information, this information must be accessed and read into computer
memory. There are so many ways that the information in the file can be accessed.

1. Sequential file access:

Information in the file is processed in order i.e. one record after the other.
Magnetic tapes are supporting this type of file accessing.
Eg : A file consisting of 100 records, the current position of read/write head is 45th
record, suppose we want to read the 75th record then, it access sequentially from 45,
46, 47
…….. 74, 75. So the read/write head traverse all the records between 45 to 75.

2. Direct access:

Direct access is also called relative access. Here records can read/write randomly
without any order. The direct access method is based on a disk model of a file, because
disks allow random access to any file block.
Eg : A disk containing of 256 blocks, the position of read/write head is at 95th block. The
block is to be read or write is 250th block. Then we can access the 250th block directly
without any restrictions.

Eg : CD consists of 10 songs, at present we are listening song 3, If we want to listen


song 10, we can shift to 10.

3. Indexed Sequential File access

The main disadvantage in the sequential file is, it takes more time to access a Record
.Records are organized in sequence based on a key field.
Eg :
A file consisting of 60000 records,the master index divide the total records into 6 blocks,
each block consisiting of a pointer to secondary index.The secondary index divide the
10,000 records into 10 indexes.Each index consisting of a pointer to its orginal
5
OPERATING SYSTEMS NOTES II YEAR/I SEM

location.Each record in the index file consisting of 2 field, A key field and a pointer field.

DIRECTORY STRUCTURE
Sometimes the file system consisting of millions of files,at that situation it is very hard
to manage the files. To manage these files grouped these files and load one group into
one partition.

Each partition is called a directory .a directory structure provides a mechanism for


organizing many files in the file system.

OPERATION ON THE DIRECTORIES :


1. Search for a file : Search a directory structure for requiredfile.

2. createafile : New files need to be created, added to thedirectory.

3. Deleteafile : When a file is no longer needed,we want to remove it fromthe

directory.

4. List adirectory : We can know the list of files in thedirectory.

5. Renameafile :
When ever we need to change the name of the
file,wecanchange thename.
6. Traverse the file system : We need to access every directory and every file
with in a directory structure we can traverse the file system

6
OPERATING SYSTEMS NOTES II YEAR/I SEM

The various directory structures

1. Single level directory:

The directory system having only one directory,it consisting of


all files some times it is said to be root directory.

E.g :- Here directory containing 4 files (A,B.C,D).the advantage of the scheme


is its simplicity and the ability to locate files quickly.The problem is different
users may accidentally use the same names for their files.

E.g :- If user 1 creates a files caled sample and then later user 2 to creates a file
called sample,then user2’s file will overwrite user 1 file.Thats why it is not used
in the multi user system.

2. Two level directory:

The problem in single level directory is different user may be accidentally use
7
OPERATING SYSTEMS NOTES II YEAR/I SEM

the same name for their files. To avoid this problem each user need a private
directory,

Names chosen by one user don't interfere with names chosen by a different
user.

Root directory is the first level directory.user 1,user2,user3 are user level of
directory A,B,C are files.

3. Tree structured directory:

Two level directory eliminates name conflicts among users but it is not
satisfactory for users with a large number of files.To avoid this create the sub-
directory and load the same type of files into the sub-directory.so, here each can
have as many directories are needed.

8
OPERATING SYSTEMS NOTES II YEAR/I SEM

There are 2 types of path

1. Absoulte path
2. Relative path
Absoulte path : Begging with root and follows a path down to specified
files giving directory, directory name on the path.
Relative path : A path from current directory.

4. Acyclic graphdirectory

Multiple users are working on a project, the project files can be stored in a
comman sub-directory of the multiple users. This type of directory is called
acyclic graph directory .The common directory will be declared a shared
directory. The graph contain no cycles with shared files, changes made by one
user are made visible to other users.A file may now have multiple absolute paths.
when shared directory/file is deleted, all pointers to the directory/ files also to be
removed.

5. General graph directory:


When we add links to an existing tree structured directory, the tree
structure is destroyed, resulting is a simple graph structure.

Advantages :- Traversing is easy. Easy sharing is possible.

9
OPERATING SYSTEMS NOTES II YEAR/I SEM

File system structure:

FIELD, Record, File, DATABASE.


Each individual column in table called as field.
Collections of fields is nothing but record.
Collection similar records is file.
Collection of File database.
Disk provides the bulk of secondary storage on which a file system is maintained.
They have 2 characteristics that make them a convenient medium for storing
multiple files.
1. A disk can be rewritten in place. It is possible to read a block from
the disk, modify the block, and write it back into same place.
2. A disk can access directly any block of information it contains.

Application Programs

Logical File System

File Organisation Module

Basic File System

I/O Control

Devices

I/O Control: consists of device drivers and interrupt handlers to transfer


information between the main memory and the disk system. The device driver
writes specific bit patterns to special locations in the I/O controller’s memory to
tell the controller which device location to act on and what actions to take.
The Basic File System needs only to issue commands to the appropriate device
driver to read and write physical blocks on the disk. Each physical block is
identified by its numeric disk address (Eg. Drive 1, cylinder 73, track2, secto10).

The File Organization Module knows about files and their logical blocks and
physical blocks. By knowing the type of file allocation used and the location of
10
OPERATING SYSTEMS NOTES II YEAR/I SEM
the file, file organization module can translate logical block address to physical
addresses for the basic file system to transfer. Each file’s logical blocks are
numbered from 0 to n. so, physical blocks containing the data usually do not
match the logical numbers. A translation is needed to locate each block.

11
OPERATING SYSTEMS NOTES II YEAR/I SEM

The Logical File System manages all file system structure except the actual data
(contents of file). It maintains file structure via file control blocks. A file control
block (inode in Unix file systems) contains information about the file, ownership,
permissions, location of the file contents.

File System Implementation:

Overview:

A Boot Control Block (per volume) can contain information needed by the
system to boot an OS from that volume. If the disk does not contain an OS, this
block can be empty.

A Volume Control Block (per volume) contains volume (or partition) details,
such as number of blocks in the partition, size of the blocks, a free block, count
and free block pointers, free FCB count, FCB pointers.
A Typical File Control Block

A Directory Structure (per file system) is used to organize the files. A PER-
FILE FCB contains many details about the file.
A file has been created; it can be used for I/O. First, it must be opened. The open( )
call passes a file name to the logical file system. The open( ) system call First
searches the system wide open file table to see if the file is already in use by another
process. If it is ,a per process open file table entry is created pointing to the existing
system wide open file table. If the file is not already open, the directory structure is
searched for the given file name. Once the file is found, FCB is copied into a
12
OPERATING SYSTEMS NOTES II YEAR/I SEM
system

13
OPERATING SYSTEMS NOTES II YEAR/I SEM

wide open file table in memory. This table not only stores the FCB but also tracks
the number of processes that have the file open.
Next, an entry is made in the per – process open file table, with the pointer to the
entry in the system wide open file table and some other fields. These are the fields
include a pointer to the current location in the file (for the next read/write operation)
and the access mode in which the file is open. The open () call returns a pointer to
the appropriate entry in the per-process file system table. All file operations are
preformed via this pointer. When a process closes the file the per- process table
entry is removed. And the system wide entry open count is decremented. When all
users that have opened the file close it, any updated metadata is copied back to the
disk base directory structure. System wide open file table entry is removed.
System wide open file table contains a copy of the FCB of each open
file, other information. Per process open file table, contains a pointer
to the appropriate entry in the system wide open file
table, other information.

14
OPERATING SYSTEMS NOTES II YEAR/I SEM

Allocation Methods – Contiguous


An allocation method refers to how disk blocks are allocated for files:
Contiguous allocation – each file occupies set of contiguous blocks o Best
performance in most cases
o Simple – only starting location (block #) and length (number ofblocks) are required
o Problems include finding space for file, knowing file size, external
fragmentation, need for compaction off-line (downtime) or on-line

Linked
Linked allocation – each file a linked list
of blocks o File ends at nil pointer
o No external fragmentation
o Each block contains pointer to next block
o No compaction, external fragmentation
o Free space management system called when new block needed
o Improve efficiency by clustering blocks into groups but
increases internal fragmentation
o Reliability can be a problem
o Locating a block can take many I/Os
and disk seeks FAT (File Allocation
Table) variation
o Beginning of volume has table, indexed by block number
o Much like a linked list, but faster on disk and cacheable

15
OPERATING SYSTEMS NOTES II YEAR/I SEM

File-Allocation Table

Indexed allocation
o Each file has its own index block(s) of pointers to its data blocks

16
OPERATING SYSTEMS NOTES II YEAR/I SEM

Free-Space Management
File system maintains free-space list to track available
blocks/clusters Linked list (free list)
o Cannot get contiguous space easily
o No waste of space
o No need to traverse the entire list

1. Bitmap or Bit vector –


A Bitmap or Bit Vector is series or collection of bits where each bit corresponds to a disk block. The bit
can take two values: 0 and 1: 0 indicates that the block is allocated and 1 indicates a free block.
The given instance of disk blocks on the disk in Figure 1 (where green blocks are allocated) can be
represented by a bitmap of 16 bits as: 0000111000000110.
Advantages –
 Simple to understand.
 Finding the first free block is efficient. It requires scanning the words (a group of 8 bits) in a bitmap
for a non-zero word. (A 0-valued word has all bits 0). The first free block is then found by scanning for
the first 1 bit in the non-zero word.

Linked Free Space List on Disk

In this approach, the free disk blocks are linked together i.e. a free block contains a pointer to the next
free block. The block number of the very first disk block is stored at a separate location on disk and is
also cached in memory.
17
OPERATING SYSTEMS NOTES II YEAR/I SEM

Grouping
Modify linked list to store address of next n-1 free blocks in first free block, plus
a pointer to next block that contains free-block-pointers (like this one).
An advantage of this approach is that the addresses of a group of free disk blocks
can be found easily
Counting
Because space is frequently contiguously used and freed, with contiguous- allocation
allocation, extents, or clustering.
Keep address of first free block and count of following free blocks. Free space list
then has entries containing addresses and counts.

Directory Implementation
1. Linear List
In this algorithm, all the files in a directory are maintained as singly lined list. Each file contains the
pointers to the data blocks which are assigned to it and the next file in the directory.
Characteristics
1. When a new file is created, then the entire list is checked whether the new file name is matching to a
existing file name or not. In case, it doesn't exist, the file can be created at the beginning or at the end.
Therefore, searching for a unique name is a big concern because traversing the whole list takes time.
2. The list needs to be traversed in case of every operation (creation, deletion, updating, etc) on the
files therefore the systems become inefficient.

2. Hash Table
To overcome the drawbacks of singly linked list implementation of directories, there is an alternative
approach that is hash table. This approach suggests to use hash table along with the linked lists.
A key-value pair for each file in the directory gets generated and stored in the hash table. The key can
be determined by applying the hash function on the file name while the key points to the corresponding
file stored in the directory.
Now, searching becomes efficient due to the fact that now, entire list will not be searched on every
operating. Only hash table entries are checked using the key and if an entry found then the
corresponding file will be fetched using the value.

18
OPERATING SYSTEMS NOTES II YEAR/I SEM

Efficiency and Performance

Efficiency dependent on:


● Disk allocation and directory algorithms
● Disk cache – separate section of main memory for frequently used blocks
● free-behind and read-ahead – techniques to optimize sequential access
● improve PC performance by dedicating section of memory as virtual disk, or
RAM disk
● Types of data kept in file’s directory entry performance

19

You might also like