This document discusses file systems and file operations in an operating systems course. It covers key concepts like file attributes, types of file access including sequential, direct, and indexed access. File operations like create, write, read, delete and open/close files are explained. Details are provided on open file tables, file pointers, locks and how different file structures can be implemented.
1. B.Tech – CS 2nd Year Operating System (KCS- 401) Dr. Pankaj Kumar
Operating System
KCS – 401
File System Interface
Dr. Pankaj Kumar
Associate Professor – CSE
SRMGPC Lucknow
2. File Concept
B.Tech – CS 2nd Year Operating System (KCS- 401) Dr. Pankaj Kumar
A file is a collection of related information that is recorded on secondary storage. Or file is a
collection of logically related entities. From user’s perspective a file is the smallest allotment of
logical secondary storage.
Contiguous logical address space
Types:
Data
numeric
character
binary
Program
Contents defined by file’s creator
Many types
Consider text file, source file, executable file
3. File Attributes
B.Tech – CS 2nd Year Operating System (KCS- 401) Dr. Pankaj Kumar
Name – only information kept in human-readable form
Identifier – unique tag (number) identifies file within file system
Type – needed for systems that support different types
Location – pointer to file location on device
Size – current file size
Protection – controls who can do reading, writing, executing
Time, date, and user identification – data for protection, security, and usage monitoring
Information about files are kept in the directory structure, which is maintained on the disk
Many variations, including extended file attributes such as file checksum
Information kept in the directory structure
4. File Operations
B.Tech – CS 2nd Year Operating System (KCS- 401) Dr. Pankaj Kumar
File is an abstract data type
Create
Write – at write pointer location
Read – at read pointer location
Reposition within file - seek
Delete
Truncate
Open(Fi) – search the directory structure on disk for entry Fi, and move the content of
entry to memory
Close (Fi) – move the content of entry Fi in memory to directory structure on disk
5. Open Files
B.Tech – CS 2nd Year Operating System (KCS- 401) Dr. Pankaj Kumar
Several pieces of data are needed to manage open files:
Open-file table: tracks open files
File pointer: pointer to last read/write location, per process that has the file open
File-open count: counter of number of times a file is open – to allow removal of
data from open-file table when last processes closes it
Disk location of the file: cache of data access information
Access rights: per-process access mode information
6. Open File Locking
B.Tech – CS 2nd Year Operating System (KCS- 401) Dr. Pankaj Kumar
Provided by some operating systems and file systems
Similar to reader-writer locks
Shared lock similar to reader lock – several processes can acquire concurrently
Exclusive lock similar to writer lock
Mediates access to a file
Mandatory or advisory:
Mandatory – access is denied depending on locks held and requested
Advisory – processes can find status of locks and decide what to do
7. File Type : Name & Extension
B.Tech – CS 2nd Year Operating System (KCS- 401) Dr. Pankaj Kumar
8. File Structure
B.Tech – CS 2nd Year Operating System (KCS- 401) Dr. Pankaj Kumar
None - sequence of words, bytes
Simple record structure
Lines
Fixed length
Variable length
Complex Structures
Formatted document
Relocatable load file
Can simulate last two with first method by inserting appropriate control characters
Who decides:
Operating system
Program
9. File Access
B.Tech – CS 2nd Year Operating System (KCS- 401) Dr. Pankaj Kumar
Sequential Access
read next
write next
reset
no read after last write
(rewrite)
Direct Access – file is fixed length logical records
read n
write n
position to n
read next
write next
rewrite n
n = relative block number
10. File Access
B.Tech – CS 2nd Year Operating System (KCS- 401) Dr. Pankaj Kumar
Other Method
Can be built on top of base methods
General involve creation of an index for the file
Keep index in memory for fast determination of location of data to be operated on (consider UPC
code plus record of data about that item)
If too large, index (in memory) of the index (on disk)
IBM indexed sequential-access method (ISAM)
Small master index, points to disk blocks of secondary index
File kept sorted on a defined key
All done by the OS
VMS operating system provides index and relative files as another example (see next slide)
11. File Access
B.Tech – CS 2nd Year Operating System (KCS- 401) Dr. Pankaj Kumar
Sequential Access
read next
write next
reset
no read after last write
(rewrite)
Direct Access – file is fixed length logical records
read n
write n
position to n
read next
write next
rewrite n
n = relative block number