2. 1. File Concept
• A file is a named collection of related information that is
recorded on secondary storage
• User's perspective, a tile is the smallest allotment of
logical secondary storage i.e., data cannot be written to
secondary storage unless they are within a file
• Types of information may be stored in a file
– Data – numeric , character, binary
– Program – Source, Object, Executable
• A file has a defined structure depends on its type
– A Source file is a sequence of subroutines and functions
– An Object file is a sequence of bytes
– An Executable file is a series of code sections
Loganathan R, CSE, HKBKCE 2
3. 1. File Concept
1.1 File Attributes
Vary from one OS to another, but consists:
• Name – only information kept in human-readable form
• Identifier – unique tag (number) identifies file within
file system (non-human-readable name)
• 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
Loganathan R, CSE, HKBKCE 3
4. 1. File Concept Cntd…
1.2 File Operations
File is an abstract data type OS System calls for operations
• Creating a file – 2 steps: Find space in the file system for the file and an
entry in the directory
• Writing a file - name of the file and the information to be written to the file
• Read - name of the file and where (in memory)the next block of the file,
read pointer to the location of next read, per-process current file- position
pointer
• Reposition within file - current-file-position pointer is repositioned to a
given value, also known as a file seek
• Deleting a file - release all file space and erase the directory entry
• Truncating a file - all attributes to remain unchanged—except for file length
• appending new information to the end of an existing file
• renaming an existing file
• copy of a file
• 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
Loganathan R, CSE, HKBKCE 4
5. 1. File Concept Cntd…
Open file table
• Contains information about all 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
File locks
• Allow one process to lock a file and prevent other processes from gaining access to
it.
• Useful for files that are shared by several processes(eg. System log file)
• A shared lock is similar to a reader lock , several processes can acquire the lock
concurrently
• An exclusive lock behaves like a writer lock only one process at a time can acquire
• A Mandatory lock– once a process acquires an exclusive lock, the OS will prevent
any other process from accessing the locked file
• An Advisory lock– processes can find status of locks and decide what to do
Loganathan R, CSE, HKBKCE 5
6. 1. File Concept Cntd…
1.3 File Types
• OS should recognize and
support file types, so that
it can then operate on the
file in reasonable ways
• Common technique for
implementing file types is
to include the type as
part of the file name
• The name is split into two
parts—a name and an
extension, separated by a
period character
Loganathan R, CSE, HKBKCE 6
7. 2. Access Methods
2.1 Sequential Access
• Information in the file is processed in order, one record after the other
• read next—reads the next portion of the file and automatically advances
a file pointer
• write next—appends to the end of the file
• reset - to the beginning
• forward or backward n records
Loganathan R, CSE, HKBKCE 7
8. 2. Access Methods Contd…
2.2 Direct Access / relative access
• A file is made up of fixed length logical records that allow programs to read
and write records rapidly in no particular order
• File operations modified to include the block number as a parameter
• Block number provided by the user to the OS is a relative block number
• A relative block number is an index relative to the beginning of the file
Loganathan R, CSE, HKBKCE 8
9. 2. Access Methods Contd…
2.3 Other Access Methods
• Built on top of a direct-access method
• Example of Index and Relative Files
Loganathan R, CSE, HKBKCE 9
10. 3. Directory Structure
A collection of nodes containing information about all file
3.1 Storage Structure
• Both the directory structure and the files reside on disk
• Parts of a disk(partitions, slices, or minidisks) is used for a file system and other
parts for other things
• The parts can also be combined to form larger structures known as volumes
• A device directory or volume table of contents commonly
• Known as a directory records information—such as name, location, size, and type—
for all files on that volume
Loganathan R, CSE, HKBKCE 10
A typical file-system organization
11. 3. Directory Structure Cntd…
3.2 Operations Performed on Directory
• Search for a file - able to search a directory structure to find the entry for a
particular file
• Create a file - New files to be created and added to the directory
• Delete a file – remove it from the directory
• List a directory - able to list the files in a directory and the contents of the
directory entry for each file
• Rename a file - change the name when the contents or use of the file
changes
• Traverse the file system - access every directory and every file within a
directory structure
3.3 Single-Level Directory
Naming and Grouping problem Since all files are in the same directory
Loganathan R, CSE, HKBKCE 11
12. 3. Directory Structure Cntd…
3.4 Two-Level Directory
• Separate directory for each user user file directory (UFD)
• Master file directory (MFD) – All UFD entries
Path name
Can have the same file name for different user
Efficient searching
No grouping capability
Loganathan R, CSE, HKBKCE 12
13. 3. Directory Structure Cntd…
3.5 Tree-Structured Directories
Efficient searching , Grouping Capability
Current directory (working directory)
cd /spell/mail/prog
type list
Loganathan R, CSE, HKBKCE 13
14. 3. Directory Structure Cntd…
• Efficient searching and Grouping Capability
• Current directory (working directory)
cd /spell/mail/prog
type list
• Absolute path begins at the root and follows a path down to the specified file
• Relative path defines path from the current directory
• Creating a new file is done in current directory
• Delete a file
rm <file-name>
• Creating a new subdirectory is done in current directory
mkdir <dir-name>
Example: if in current directory /mail
mkdir count
mail
prog copy prt exp count
Deleting “mail” deleting the entire subtree rooted by “mail”
Loganathan R, CSE, HKBKCE 14
15. 3. Directory Structure Cntd…
3.6 Acyclic-Graph Directories
• Have shared subdirectories and files i.e. changes made by one is immediately
visible to the other
• New directory entry type
Link – another name (pointer)
to an existing file
Resolve the link – follow
pointer to locate the file
• Deletion of a link need
not affect the original file
• File entry is deleted, the
space for the file is
deallocated, leaving the
links dangling
• Preserve the file until all
references to it are
deleted.
Loganathan R, CSE, HKBKCE 15
16. 3. Directory Structure Cntd…
3.7 General Graph Directory
How do we guarantee no cycles?
Allow only links to file not subdirectories
Garbage collection
Every time a new link is added use a cycle detection algorithm to determine
whether it is OK
16
Loganathan R, CSE, HKBKCE
17. 4.File System Mounting
• A file system must be mounted before it can be accessed
• A unmounted file system (b) is mounted at a mount point
Mount point.
Existing system Unmounted volume
Loganathan R, CSE, HKBKCE 17
18. 5. File Sharing
• Sharing of files on multi-user systems is desirable
• Sharing may be done through a protection scheme
• On distributed systems, files may be shared across a
network
• Network File System (NFS) is a common distributed
file-sharing method
5.1 Multiple Users
• User IDs (Owner)identify users, allowing permissions
and protections to be per-user
• Group IDs allow users to be in groups, permitting
group access rights
Loganathan R, CSE, HKBKCE 18
19. 5. File Sharing
5.2 Remote File Systems
• Uses networking to allow file system access between systems
– Manually via programs like FTP
– Automatically, seamlessly using distributed file systems
– Semi automatically via the world wide web
• Client-server model allows clients to mount remote file systems from servers
– Server can serve multiple clients
– Client and user-on-client identification is insecure or complicated
• NFS is standard UNIX client-server file sharing protocol allow many-to-many
relationships.
• Distributed Information Systems (distributed naming services) such as LDAP(Light-
weight Directory Access Protocol), DNS(Domain Name System), NIS(Network
Information Service), Active Directory implement unified access to information
needed for remote computing
• Failure Modes
– Remote file systems add new failure modes, due to network failure, server failure
– Recovery from failure can involve state information about status of each remote
request
– Stateless protocols such as NFS include all information in each request, allowing easy
recovery but less security
Loganathan R, CSE, HKBKCE 19
20. File Sharing – Consistency Semantics
• Consistency semantics specify how multiple users are
to access a shared file simultaneously
– Similar to process synchronization algorithms
• Tend to be less complex due to disk I/O and network latency (for
remote file systems
– Andrew File System (AFS) implemented complex remote file
sharing semantics
– Unix file system (UFS) implements:
• Writes to an open file visible immediately to other users of the same
open file
• Sharing file pointer to allow multiple users to read and write
concurrently
– AFS has session semantics
• Writes only visible to sessions starting after the file is closed
Loganathan R, CSE, HKBKCE 20
21. Protection
• File owner/creator should be able to control:
– what can be done
– by whom
• Types of access
– Read
– Write
– Execute
– Append
– Delete
– List
Loganathan R, CSE, HKBKCE 21
22. Access Lists and Groups
• Mode of access: read, write, execute
• Three classes of users
RWX
a) owner access 7 111
RWX
b) group access 6 110
RWX
c) public access 1 001
• Ask manager to create a group (unique name), say G, and add some
users to the group.
• For a particular file (say game) or subdirectory, define an appropriate
access.
owner group public
chmod 761 game
Loganathan R, CSE, HKBKCE 22