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

Chapter 5 File Mgmt (Updated)

Uploaded by

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

Chapter 5 File Mgmt (Updated)

Uploaded by

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

Chapter

File 5
Management
Chapter 5 Overview
• The file manager
• Interacting with file manager
• File organisation
• Physical storage allocation: contiguous,
non-contiguous and indexed
• Access methods: sequential access and
indexed access
5.1 File
Manager
• Controls every file in the system which is a complex job.
• Efficiency depends on:
– how system’s files are organized (Sequential, direct, and
indexed sequential file organization).
– how they’re stored (Contiguous, noncontiguous, & indexed
file storage allocation).
– how each file’s records are structured (fixed-length or
variable-length).
– how access to these files is controlled .(File permission)
5.1 File
Manager
Responsibilities of File Manager
• Track where each file is stored.
• Determine where and how files will be stored.
– Efficiently use available storage space.
– Provide efficient access to files.
• Allocate each file when a user has been cleared for
access to it, then record its use.
• Deallocate file when file is returned to storage.
– Communicate file availability to others waiting for
it.
File
Structure

Field Record File Database

Program
Data files
files
File Manager treats all files
exactly same way as far as
Directories storage in concerned.
Important Definitions
• Field: a group of related bytes that can be
identified by user with name, type, and size.
• Record: a group of related fields.
• File (flat file): a group of related records that
contains info used by specific application
programs to generate reports.
• Database: Groups of related files that are
interconnected at various levels to give flexible
access to users. Appears to File Manager to be
a type of file.
Important Definitions
• Program files contain instructions.
• Data files contain data.
• Directories have listings of file names and their
attributes.
• Every program and data file accessed by
computer system, and every piece of computer
software, is treated as a file.
• File Manager treats all files exactly same way as
far as storage is concerned.
5.2 Interacting with File
Manager

Embedded
commands
(program)
Interacting With
File Manager

Interactive
Commands (user)

Device Independent
INTERACTING WITH FILE MANAGER
• Users communicates with File Manager via
specific commands that may be either
embedded in user’s program or submitted
interactively by user.

Embedded commands:
• OPEN & CLOSE pertain to availability of file for
program invoking it.
• READ & WRITE are I/O commands.
• MODIFY – specialized WRITE command for
existing data files that allows for
appending/rewriting records.
INTERACTING WITH FILE MANAGER
Interactive Commands:
• CREATE & DELETE -- deal with system’s knowledge
of file.
• SAVE -- first time used, a file is actually created.
• OPEN NEW -- within a program indicates file must
be created.
• OPEN…FOR OUTPUT -- creates file by making
entry for it in directory & finding space for it in
secondary storage.
• RENAME -- allows users to change name of existing
file.
• COPY – allows user to make duplicate copies of
existing files.
Commands Are Device-Independent
• Interface commands designed to be as simple as
possible to use.
– Device independent.
• Physical location knowledge not needed
– Cylinder, surface, sector
• Device medium knowledge not needed
– Tape, magnetic disk, optical disc, flash storage
• Network knowledge not needed
• Each logical command broken down into sequence of
low-level signals that
– Trigger step-by-step actions performed by device.
– Supervise progress of operation by testing device’s
status
• Example: READ
– Move read/write heads to record cylinder
– Wait for rotational delay (sector containing
record passes under read/write head)
– Activate appropriate read/write head and read
record
– Transfer record to main memory
– Send flag indicating free device for another
request
5.3 Physical File
Organization
• Concerned with how records are arranged & characteristics of
medium used to store it.
• On magnetic disks, files can be organized as:
⮚ Sequential
⮚ Direct
⮚ Indexed sequential.

• Characteristics to considered when selecting file organization


⮚ Volatility of data—frequency with which additions &
deletions made.
⮚ Activity of file—% records processed during a given run.
⮚ Size of file.
⮚ Response time—amount of time user is willing to wait
before requested operation is completed.
Sequential Record
Organization
• Easiest to implement because records are stored &
retrieved serially, one after other.
• File search: beginning until record found
• To speed process some optimization features may be
built into system.
– Select key field from record and
sort before storage
– use original order must be
preserved every time records
added or deleted. (rewritten)
• Typically used in batch applications
Direct Record
Organization
• Uses direct access files which can be
implemented only on direct access storage
devices.
• Give users flexibility of accessing any record in
any order without having to begin search from
beginning of file.
Direct Record
Organization
• Records are identified by their relative addresses.
Logical addresses are computed when records are
stored & again when records are retrieved.
• User identifies a field to be used as the key field. The
program used to store the data follows a set of
instructions called a hashing algorithm.
• The hashing algorithm transforms each key into a
number: the record’s logical address.
• This logical address is then given to the File Manager,
which takes the necessary steps to translate the logical
address into a physical address (cylinder, surface, and
record numbers), preserving the file organization.
Logical Vs Physical Address Space

• Physical Address – It identifies a physical location of


required data in a memory. Address seen by the memory
unit (RAM). It is used to fetch and stored data in
memory.

• Logical Address – Generated by the CPU; also referred


to as virtual address because it does not exist physically.
It is used as a reference to access the physical memory
location by CPU.

• Note: The physical address is computed by Memory


Management Unit (MMU) and logical address is
generated by CPU while a program is running
• Memory-Management Unit (MMU), which is a hardware device,
maps logical address to physical address
Contains the smallest
physical address value.
limit register contains range MMU
of logical addresses
Logical address ≤ limit reg
*Relocation
register
Logical Physical
14000
address address Memory
CPU
346
+ 14346

• In MMU scheme, the value in the relocation register is added to


every address generated by a user process at the time it is sent to
memory.
• Used to protect processes from each other, and from changing
operating-system code and data
Direct Record
–Advantages
• FastOrganization
record access
• Sequential access if starting at first relative address
and incrementing to next record
• Updated more quickly than sequential files
• No preservation of records order, so adding, deleting
records is quick
– Disadvantages
• Hashing algorithm collision
– Two records (keys) attempt to insert into the same
position.
Collisions Are a Problem With Direct Access
Organization
• Several records with unique keys may generate
same logical address (collision).
• Program generates another logical address before
presenting it to File Manager for storage.
• Colliding records stored in overflow area via links.
• File Manager handles physical allocation of space.
• Maximum file size established when created &
eventually file is full or too many records are stored
in overflow area.
• Programmer must reorganize & rewrite file.
Indexed sequential record

orgn
Sequential + direct access
• Indexed Sequential Access Method (ISAM) software: creates,
maintains
– Advantage: no collisions (no hashing algorithm)
• Generates index file for record retrieval
• Divides ordered sequential file into blocks of equal size
• Each entry in index file contains the highest record key and
physical data block location
• Search index file
• Overflow areas
• to handle new records
• Each record in the main file
contains a hidden pointer to the
overflow file (used if needed)
Each record of a file has a key field which uniquely
identifies that record.
An index consists of keys and addresses.
5.4 Physical Storage
Allocation
• File manager works with files
• As whole units
• As logical units or records

• Within file
• Records must have same format
• Record length may vary

• Application programs manage record structure

• File storage
• Refers to record storage
Contiguous
Storage
Physical
Storage Noncontiguous
Allocation Storage

Indexed Storage
i. Contiguous Storage
• Records stored one after another
– Advantages
• Any record found once starting address, size
known
• Easy direct access
– Disadvantages
• Difficult file expansion, fragmentation

With contiguous file storage, File A can’t be expanded without being rewritten to a
larger storage area. File B can be expanded, by only one record replacing the free
space preceding File C.
Contiguous Storage
Contiguous Storage

• Difficult to find space for a new file


(Requires first-fit and best-fit strategies)
• Wasteful of space – External
fragmentation
• Difficult to determine the size of the
space needed for a file - If too little space,
files cannot grow, resulting in Internal
fragmentation
• Solution: Compaction
Compaction
External fragmentation

0 1 2 3 0 1 2 3
4 5 6 7 4 5 6 7

8 9 10 11 8 9 10 11

12 13 14 15 12 13 14 15

16 17 18 19 16 17 18 19

20 21 22 23 20 21 22 23
ii. Linked Allocation Storage
• Files use any available disk storage space
• File records stored in contiguous manner
– If enough empty space
• Remaining file records and additions
– Stored in other disk sections (extents)
– Extents
• Linked together with pointers
• Physical size determined by OS
Linked Allocation
Directory

File Start End


0 1 2 3 fileA 9 23
4 -1 5 6 7

8 9 10 11

12 13 14 15

16 17 18 19

20 21 22 23 -1
ii. Linked Allocation Storage

• Advantages
– Eliminates external storage fragmentation
– Eliminates need for compaction
• Disadvantage
– No direct access support
• Cannot determine specific record’s exact location
• File accessing method must be seqential
Linked Allocation Storage

• Eliminate external fragmentation


• Effective of sequential access
and problematic for direct
access
Indexed Storage
• Allows direct record access
– Brings pointers together
• Links every extent file into index block
• Every file has own index block
– Disk sector addresses for file
– Lists entry in order sectors linked
• Supports sequential and direct access
• Does not necessarily improve storage space use
• Larger files experience several index levels
• Every file has own index block
• Links every extent file into index block
• Larger files experience several index levels.

Linked scheme
Link blocks of index blocks (no limit on size)

12 34
17 55
8 9 23
7
15 32
1 42
7 -1

(highest level) (lower level)


5.5 Free-Space Management

a) Bit Vector

b) Linked List

c) Grouping

d) Counting
a) Bit Vector

0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
16 17 18 19

0 0 1 1 1 1 0 0 1 1 1 1 1 1 0 0 0 0 0 0
• Each block is represented by 1 bit.
• If the block is free – the bit is 1
• If the block is allocated, the bit is 0.
a) Bit Vector (Bit Map)

0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
16 17 18 19

0-3 0 0 1 1
4-7 1 1 0 0
8-11 1 1 1 1
12-15 1 1 0 0
16-19 0 0 0 0
a) Bit Vector / bitmap (n blocks)

Advantages

• Easy to retrieve contiguous blocks.


• Offers quicker file search.

Disadvantage

• Bit vector requires extra space.

Example: Block size = 212 bytes


Disk size = 230 bytes (1 GB)
n = 230 / 212
= 218 blocks
b) Linked
List
Advantages
• Easy to track the number of usable
space

Disadvantage
• Cannot get contiguously space easily.

• Not efficient - requires substantial I/O


time (traverse the list for reading each
of block)
c)
Grouping
• Store the addresses of n free blocks in first free
block
• nth block contains the address of another n free
blocks
• The addresses of a large number of free blocks
can therefore be found quickly.
d)
Counting
■ Keep the address of first free block and the
number n of free contiguous blocks that follow.
■ List then consists of a block number and a
count.

0 1 2 6 3
4 5 6 (1) 7
8 9 10 11
12 13 14 14 (5) 15
16 17 18 19
,
,
,
,

You might also like