2. Recap
In the last class, you have learnt:
• File and File operations
9CM 402.54 2
3. • HOME PREVIOUS TOPIC NEXT
• PREVIOUS QUESTION PAPERS FOR
OS
• CPP TUTORIALS
3
4. Objective(s)
On completion of this period, you would be able to:
• Understand the different file access methods
• Introduction to directory
9CM 402.54 4
5. Introduction
• Files store information
• This information must be accessed and read into
computer memory for use
• There are different access methods
• Some systems support only one access method
• Other systems support different access methods
9CM 402.54 5
6. Types of Access Methods
• Sequential Access
• Direct Access
• Other Access Methods
9CM 402.54 6
7. Sequential Access
• Simplest access method
• Information processed in order
• Most common
• Used by editors and compilers
• Based on a tape model of a file
• Works well on sequential access devices and
random access devices
9CM 402.54 7
8. Sequential Access
current position
beginning end
rewind
read or write
Fig : Sequential Access File
9CM 402.54 8
10. File Pointer
• Whenever a file is opened for read or write
operation a file pointer is maintained to keep
track of the current position in the file
9CM 402.54 10
11. Read operation
• Reads the next portion of the file
• Automatically advances file pointer
9CM 402.54 11
12. Write operation
• Appends data to the end of the file
• Advances pointer to the new end of file
9CM 402.54 12
16. Direct Access
• Also known as Relative Access
• Fixed length logical records
• No particular order for read and write
• Based on disk model of a file
• File viewed as a numbered sequence of blocks or
records
• Arbitrary block read or written
9CM 402.54 16
17. Direct Access
• Useful for immediate access to large volumes of
data
• Most suitable for database applications
• Easy to read, write and delete a record
9CM 402.54 17
18. Direct Access
•Address of arbitrary record N
Let length of logical record = L
Address of record N = L*(N-1)
9CM 402.54 18
19. Simulate Sequential Access
• Easy to simulate sequential access on direct
access file
• Keep a variable cp i.e. Current position
9CM 402.54 19
20. Simulate Sequential Access
Sequential Access Implementation for
direct access
reset cp := 0
read next read cp
cp := cp + 1
write next write cp
cp := cp + 1
Fig : Simulation of sequential access on a direct access file
9CM 402.54 20
21. Applications for Direct access
• Airline reservation system
• Customer account processing in a bank
9CM 402.54 21
22. Other Access Methods
• Built on top of direct access method
• Require the construction of an index for the file
• Index is a small table stored in memory
• The index contains pointers to various blocks
9CM 402.54 22
23. To find an entry in the file…
• Search the index
• Use the pointer to access the file directly
for the desired entry
9CM 402.54 23
24. To find an entry in the file
logical record
last name
number
Adams
Arthur
Asher Smith, John SSN
Age
.
.
.
Smith relative file
index file
9CM 402.54 24
25. Primary index and Secondary index
• With large files index file itself too large to
be in memory
• Solution is create index for the index file
• Primary index points to secondary index
• Secondary index points to actual data
9CM 402.54 25