0% found this document useful (0 votes)
2 views

Chapt-6 File Management

Uploaded by

savitasahane25
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Chapt-6 File Management

Uploaded by

savitasahane25
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 56

File management

10 marks

OPS -P. B. SHINDE( IT DEPT) chapt-5 1


Introduction
• File- File is a collection of related data.
• The data stored in the computer is in the form of
file. Data could be numbers, characters, Image,
audio, Video etc.
• OS plays a role of management of file system and
memory.
• File is physical memory area for an OS but for user
it is a logical place which has got some name due
to which it becomes easy for them to access that
file.
OPS -P. B. SHINDE( IT DEPT) chapt-5 2
• Directories- are logical compartment which only
stores files or sub directories.
• File is divided into two types-
a)Data b)Program
a) Data- Data file is a sequence of bits, bytes , lines or
records the meaning of which is defined by
creators or user.
b) Program- are the set of instructions given to m/c
to work.
• File naming is given for the easy human interaction
• File name has got two parts i.e. name and
extension
OPS -P. B. SHINDE( IT DEPT) chapt-5 3
Extension
• Extension is used to identify the application
from which file is created.
ex. Amrut.ppt
Here amrut is a file name and .ppt is an
extension of power point Presentation file.

OPS -P. B. SHINDE( IT DEPT) chapt-5 4


File extensions and meaning
File Type extension Function

Executable Exe,com,bin Machine language


program
Object Obj, o Compiled machine lang.,
not linked
Source code c, C++, java, asm… Source code in various
languages
Batch Bat, sh Commands to command
interpreter
text Txt, doc Textual data, documents

Print, view ps, dvi, gif ASCII or binary file

archive Arc, zip, tar Group of files, sometimes


compressed
Library Lib, a Libraries of routines

video mpeg video files

Image gif, jpeg Image files

OPS -P. B. SHINDE( IT DEPT) chapt-5 5


Attributes of Files
• It is a property of files which stores the file
related data like date, time, size, location,
extension.
• Attributes except name are given or
generated by system.
• Attributes are useful to get the information
about a particular file or directory.

OPS -P. B. SHINDE( IT DEPT) chapt-5 6


File Attributes
– Name
– It Is specified by user
– Identifier
– Unique tag that identifies file within file system; is used to refer files internally.
– Type -
– Type of file specifies that exactly what kind of data it is.
– Location -
– It indicate where exactly file is stored.
– Size -
– Useful to know the size of files in bytes or kb.
– Protection -
– controls who can read, write, execute
– Time, Date and user identification
– Attributes like created, modified, accessed etc.
– Password- Protection of file
– Creator/ Owner- User who has created that file
– Maximum size- no of bytes to which file can max grow.

OPS -P. B. SHINDE( IT DEPT) chapt-5 7


File Operations
– A file is an abstract data type. It can be defined by operations:
• Create a file
• Write a file
• Read a file
• Reposition within file - file seek
• Delete a file
• Close file
• Truncate a file
• Append a file
• Get Attributes
• Set Attributes
• Rename

OPS -P. B. SHINDE( IT DEPT) chapt-5 8


File Types
• File is a collection of related data or
information or may be records.
• Information about a file is stored in the
directory, such as the size of the file when
created and so on.
1. Simple files(Regular)-user information
2. Basic file system(Directories)-system files
3. Logical(Character special files)-i/o
4. Physical (Block special files)
OPS -P. B. SHINDE( IT DEPT) chapt-5 9
File Structure
1. Stream of Bytes
2. Records
3. Tree of Records

OPS -P. B. SHINDE( IT DEPT) chapt-5 10


 Stream of Bytes-
• The File contents are stored in the form of bits/ bytes
i.e. sequence of o and 1.
• The data does not have any structure.
 Records-
• Data is stored in the form of records.
• Records are collection of related data. means details of
one employee data like emp_code, name, address,
Salary etc. could form one record.
 Tree of Record-
• Records can be of variable length
• Each record has an associated key. The record retrieval
is based on key.
OPS -P. B. SHINDE( IT DEPT) chapt-5 11
File access method
• The different file access methods are-
1. Sequential access method
2. Direct Access Method

OPS -P. B. SHINDE( IT DEPT) chapt-5 12


Sequential access method

OPS -P. B. SHINDE( IT DEPT) chapt-5 13


Sequential access method
• It is based on tape based system.
• In sequential access method it reads all bytes or
records from the beginning of file.
• In sequential access only two operations are
provided i.e. a)move forward b)move backward
or rewind.
• The process is very time consuming and
accessing speed is very slow.
• E.x magnetic Tape
OPS -P. B. SHINDE( IT DEPT) chapt-5 14
Direct Access Method

OPS -P. B. SHINDE( IT DEPT) chapt-5 15


Direct Access Method
• It is considered as a collection of blocks.
• Direct access file methods are great use for immediate
access to large amount of information.
• When a query concerning a particular subject arrives, we
compute which block contains the answer and then read
the block directly to provide the desired information.
• E.x in an airline reservation system, we might store all
the information about a particular flight.
• This method is necessary for database system.
• Accessing speed is very fast

OPS -P. B. SHINDE( IT DEPT) chapt-5 16


Memory Allocation Methods
• An allocation method refers to how disk blocks are
allocated for files:

• Contiguous allocation

• Linked allocation

• Indexed allocation

OPS -P. B. SHINDE( IT DEPT) chapt-5 17


Contiguous Allocation
• Each file occupies a set of contiguous blocks on the
disk

• Simple – only starting location and length (number of


blocks) are required

• Random access

• Wasteful of space (dynamic storage-allocation


problem)

OPS -P. B. SHINDE( IT DEPT) chapt-5 18


Contiguous Allocation of Disk Space

OPS -P. B. SHINDE( IT DEPT) chapt-5 19


Advantages
1. Quick and easy calculation of block holding data.
2. It supports both direct accessing and sequential access.
3. Contiguous allocation is the best allocation for
sequential files.
Disadvantages
4. It is very difficult to allocate space for new file.
5. Before allocation we have to predict the size of file.
6. It suffers from external fragmentation.
7. Compaction may be required and it can be very
expensive.
OPS -P. B. SHINDE( IT DEPT) chapt-5 20
Linked Allocation
(Dynamic Memory allocation)

• Each file is a linked list of disk blocks: blocks may be


scattered anywhere on the disk.
• Simple – need only starting address
• Free-space management system – no waste of space
• The directory contains a pointer to the first as well as
last block of the file.
• E.x file jeep consider a file of 5 block which occupy the
lock 91611025.
• Each block contain a pointers to the next block and the
last block contains a (-1) i.e. NIL pointer.

OPS -P. B. SHINDE( IT DEPT) chapt-5 21


Linked Allocation

OPS -P. B. SHINDE( IT DEPT) chapt-5 22


Advantages
• There is no external fragmentation with linked
allocation.
• There is no need to declare the size of the file
when it is created.
• Starting and ending of the file can be easily
found out by the linked list.
• File can grow to its required size.

OPS -P. B. SHINDE( IT DEPT) chapt-5 23


Disadvantages
1. Pointers are required which needs an
additional memory space.
2. It does not support direct access.
3. Linked allocation is not reliable as the blocks
are scattered on disk anywhere.
4. Every time searching has to be reliable as the
blocks are scattered on disk anywhere.

OPS -P. B. SHINDE( IT DEPT) chapt-5 24


Indexed Allocation
• Brings all pointers together into the index block.
• Linked allocation method solves the problem of
external fragmentation and size declaration.
• But it does not solve the problem of direct access,
because pointers are scattered anywhere on the disk.
• Indexed allocation method solve the problem of
direct access by bringing all the pointers together in
one location which is called as Index block.
• In indexed allocation each file has its own index block
which is an array of disk block address.

OPS -P. B. SHINDE( IT DEPT) chapt-5 25


Example of Indexed Allocation

OPS -P. B. SHINDE( IT DEPT) chapt-5 26


Advantages
1. This method is faster than contiguous and
linked allocation.
2. There is no external fragmentation.
3. There is no need to declare the size of file.
4. It support direct as well as sequential access.
5. Block creates the set of pointer at one
location.

OPS -P. B. SHINDE( IT DEPT) chapt-5 27


Disadvantages
1. Deciding index block size for each file is
complicated process.
2. If the files are very small requiring only one
or two blocks then one block will be wasted
for the index block o store only one or two
address.

OPS -P. B. SHINDE( IT DEPT) chapt-5 28


Fragmentation
• Fragmentation is a process of breaking down
the memory space into small pieces.
• fragmentation is a phenomenon in which
storage space is used inefficiently
• Types-
1. Internal fragmentation
2. External fragmentation

OPS -P. B. SHINDE( IT DEPT) chapt-5 29


Internal fragmentation
• Internal fragmentation happens when the memory is split into
mounted sized blocks. Whenever a method request for the
memory, the mounted sized block is allotted to the method.
just in case the memory allotted to the method is somewhat
larger than the memory requested, then the distinction
between allotted and requested memory is that the Internal
fragmentation.

OPS -P. B. SHINDE( IT DEPT) chapt-5 30


External fragmentation

• External fragmentation happens when there’s a


sufficient quantity of area within the memory to
satisfy the memory request of a method. however
the process’s memory request cannot be fulfilled
because the memory offered is during a non-
contiguous manner.

OPS -P. B. SHINDE( IT DEPT) chapt-5 31


Directory Structure
• It is a collection of nodes containing
information about all files, which are present
in it.
• Types of directory:
1. Single Level Directory
2. Two Level directory
3. Tree Structure Directories

OPS -P. B. SHINDE( IT DEPT) chapt-5 32


Single-Level Directory
• A single directory for all users
Advantages
• Single level directory is very simple.
• Easy to understand, maintain and easy to
implement.
• The ability to locate files is very fast as there
is only one directory.
Disadvantages
• It is difficult to remember the names of the
files if the files are very large in quantity.
OPS -P. B. SHINDE( IT DEPT) chapt-5 34
Two-Level Directory
• Separate directory for each user

 Different users who have their own directories and their files are
stored in their own Directories.
 Can have the same file name for different user
 Efficient searching
Tree-Structured Directories
Tree-Structured Directories
• Two level directory system eliminates the
problem of common filename but it does not
support large number of files, so a tree of
directory is needed.
• It is very useful because it solves the problem
of grouping.

OPS -P. B. SHINDE( IT DEPT) chapt-5 37


File Protection
• File owner/creator should be able to control:
• File can be protected or secured using following method-
1. Naming
2. Password
3. Access Control

• Types of access
– Read
– Write
– Execute
– Append
– Delete
– List
Naming
• It is traditional method of providing protection
to a file.
• For naming files there are certain rules such
as-
 The starting letter should always be an
alphabets.
 A combination of numbers can be used.
 Special Characters are not allowed.

OPS -P. B. SHINDE( IT DEPT) chapt-5 39


Password
• In this the method every file is given a password and
is known only to the owner of that file.
• Rules for giving Password:
 Use a combination of alphabetic and numeric
characters for password.
 Do not write password on easily accessible document.
 Password should be given when you are alone in
computer lab.
 Change the password regularly

OPS -P. B. SHINDE( IT DEPT) chapt-5 40


Access Control
• An access list is associated to each file or
directory.
• The access list contains information on the
type of users and access permission.
• The 3-bits of user, group, and other user are
read(r), write(w),execute(x)
• E.x. drwxrwxrwx

OPS -P. B. SHINDE( IT DEPT) chapt-5 41


Windows XP Access-control List Management
Paging

• Dynamic memory partitioning suffers from external fragmentation.


• To overcome this problem either we can use compaction or paging.
• This paging method allows a program to be allocated physical
memory wherever it is available.
• Logical address space of a process can be non contiguous; process is
allocated physical memory whenever the latter is available
• In paging physical memory is broken into fixed size blocks called
frames.
• Divide logical memory into blocks of same size called pages
• Keep track of all free frames.
• The page number is used as an index into a page table. The page
table contains the base address of each page in physical memory.
Address Translation Scheme
• Address generated by CPU is divided into:

– Page number (p) – used as an index into a page table which

contains base address of each page in physical memory

– Page offset (d) – combined with base address to define the

physical memory address that is sent to the memory unit

– For given logical address space 2m and page size 2n

page number page offset


p d
Paging Hardware

Base
address
Paging Model of Logical and Physical
Memory
Paging Example

32-byte memory and 4-byte pages


Free Frames

Before allocation After allocation


Demand Paging

OPS -P. B. SHINDE( IT DEPT) chapt-5 49


Demand Paging
•It is similar to paging system with swapping
•Process resides on the back storage (i.e.
secondary memory disk.
•When we want to execute the process we
swap it into memory.
•A lazy swapper is used when swapping is
needed.
•Instead of swapping the whole process the
page is swapped strictly if it is needed

OPS -P. B. SHINDE( IT DEPT) chapt-5 50


Virtual Memory

OPS -P. B. SHINDE( IT DEPT) chapt-5 51


Virtual Memory
•Virtual memory is the memory generated from
the physical memory devices like disk when less
amount of main memory is available.
•VM is the separation of user logical memory from
physical memory and is commonly implemented
by demand paging.
•A very large virtual memory can be provided for
programmers on a smaller physical memory.
•The large amount of physical memory gets
available to the user.

OPS -P. B. SHINDE( IT DEPT) chapt-5 52


FIFO Page Replacement

FIFO Illustrating Belady’s Anomaly


Optimal Page Replacement

LRU Page Replacement


Use Of A Stack to Record The Most Recent Page
References
Second-Chance (clock) Page-Replacement Algorithm

You might also like