Chapter 5 File Mgmt (Updated)
Chapter 5 File Mgmt (Updated)
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
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.
• Within file
• Records must have same format
• Record length may vary
• 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
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
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
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
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
Disadvantage
Disadvantage
• Cannot get contiguously space easily.
0 1 2 6 3
4 5 6 (1) 7
8 9 10 11
12 13 14 14 (5) 15
16 17 18 19
,
,
,
,