Ch13 Modified
Ch13 Modified
File-System Interface
Operating System Concepts – 10h Edition Silberschatz, Galvin and Gagne ©2018
Outline
▪ File Concept
▪ Access Methods
▪ Disk and Directory Structure
Operating System Concepts – 10th Edition 13.2 Silberschatz, Galvin and Gagne ©2018
Objectives
▪ To explain the function of file systems
▪ To describe the interfaces to file systems
▪ To discuss file-system design tradeoffs, including access
methods, file sharing, file locking, and directory structures
Operating System Concepts – 10th Edition 13.3 Silberschatz, Galvin and Gagne ©2018
File Concept
▪ Contiguous logical address space
▪ Types:
• Data
Numeric
Character
Binary
• Program
▪ Contents defined by file’s creator
• Many types
text file, A text file is a file without any formatting or fonts, and has a .txt extension in
Windows.You can create a text file on your computer with a text editor. An example of a
text editor is Notepad, which is included with Microsoft Windows.
source file, A .SOURCE file is a source code file that contains text written in one or more
programming languages.
executable filen executable file is a type of computer file that runs a program or performs a
specific operation on a computer. Unlike data files, executable files contain compiled code that the
computer's CPU can directly execute. Common examples of executable files include .EXE, .BAT,
.COM, and .BIN on IBM-compatible computers, and .DMG and .APP on Apple Mac computers.
Operating System Concepts – 10th Edition 13.4 Silberschatz, Galvin and Gagne ©2018
File Attributes
▪ 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
Operating System Concepts – 10th Edition 13.5 Silberschatz, Galvin and Gagne ©2018
File Operations
▪ 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
Operating System Concepts – 10th Edition 13.6 Silberschatz, Galvin and Gagne ©2018
Open Files
▪ 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
Operating System Concepts – 10th Edition 13.7 Silberschatz, Galvin and Gagne ©2018
File Types – Name, Extension
Operating System Concepts – 10th Edition 13.8 Silberschatz, Galvin and Gagne ©2018
File Structure
▪ None - sequence of words, bytes
▪ Simple record structure
• Lines
• Fixed length
• Variable length
▪ Complex Structures:
1- Formatted document: File formats that store data in
structured, semi-structured, or unstructured forms, such as JSON,
XML, SQL, images, and audio
2- Relocatable load file: holds code and data suitable for
linking with other object files to obtain executable file.
Operating System Concepts – 10th Edition 13.9 Silberschatz, Galvin and Gagne ©2018
File structure types are:
Operating System Concepts – 10th Edition 13.10 Silberschatz, Galvin and Gagne ©2018
Access Methods
▪ A file is fixed length logical records
▪ Sequential Access
▪ Direct Access
▪ Other Access Methods
▪ Sequential files store data in a linear order, suitable for batch processing.
▪ Indexed sequential files add indexes for faster access. Direct access files
allow immediate access to any data record.
▪ The choice of file structure depends on access patterns and data requirements,
balancing speed, storage space, and complexity
Operating System Concepts – 10th Edition 13.11 Silberschatz, Galvin and Gagne ©2018
Sequential Access
▪ Operations
• read next
• write next
• Reset
• no read after last write (rewrite)
▪ Figure
Operating System Concepts – 10th Edition 13.12 Silberschatz, Galvin and Gagne ©2018
Direct Access
▪ Operations
• read n
• write n
• position to n
read next
write next
rewrite n
n = relative block number
Operating System Concepts – 10th Edition 13.13 Silberschatz, Galvin and Gagne ©2018
Other Access Methods
▪ Can be other access methods 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 Universal Produce Code
(UPC code) plus record of data about that item)
▪ If the index is too large, create an in-memory index, which
an index of a disk index
▪ 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
Operating System Concepts – 10th Edition 13.14 Silberschatz, Galvin and Gagne ©2018
Disk Structure
▪ Disk can be subdivided into partitions
▪ Disks or partitions can be RAID protected against failure
▪ Disk or partition can be used raw – without a file system, or
formatted with a file system
▪ Partitions also known as minidisks, slices
▪ Entity containing file system is known as a volume
▪ Each volume containing a file system also tracks that file system’s
info in device directory or volume table of contents
▪ In addition to general-purpose file systems there are many
special-purpose file systems, frequently all within the same
operating system or computer
Operating System Concepts – 10th Edition 13.15 Silberschatz, Galvin and Gagne ©2018
Operations Performed on Directory
▪ Search for a file
▪ Create a file
▪ Delete a file
▪ List a directory
▪ Rename a file
Operating System Concepts – 10th Edition 13.16 Silberschatz, Galvin and Gagne ©2018
Directory Organization
The directory is organized logically to obtain
▪ Efficiency – locating a file quickly
▪ Naming – convenient to users
• Two users can have same name for different files
• The same file can have several different names
▪ Grouping – logical grouping of files by properties, (e.g., all
Java programs, all games, …)
Operating System Concepts – 10th Edition 13.17 Silberschatz, Galvin and Gagne ©2018
Figure Tree-Structured Directory
Operating System Concepts – 10th Edition 13.18 Silberschatz, Galvin and Gagne ©2018
Protection
▪ File owner/creator should be able to control:
• What can be done
• By whom
▪ Types of access
• Read
• None
• Knowledge
• Write
• Execute
• updating
• Append
• Change protection
• Delete
• List
Operating System Concepts – 10th Edition 13.19 Silberschatz, Galvin and Gagne ©2018
Access Rights
Access Rights
▪The following list is representative of access rights that can be assigned to a
particular user for a particular file:
• None: The user may not even learn of the existence of the file, much less access it.
To enforce this restriction, the user would not be allowed to read the user directory
that includes this file.
• Knowledge: The user can determine that the file exists and who its owner is. The
user is then able to petition the owner for additional access rights.
• Execution: The user can load and execute a program but cannot copy it.
Proprietary programs are often made accessible with this restriction.
• Reading: The user can read the file for any purpose, including copying and
execution. Some systems are able to enforce a distinction between viewing and
copying. In the former case, the contents of the file can be displayed to the user, but
the user has no means for making a copy.
Operating System Concepts – 10th Edition 13.20 Silberschatz, Galvin and Gagne ©2018
Access Rights
• Appending: The user can add data to the file, often only at the end, but
▪cannot modify or delete any of the file’s contents. This right is useful in collecting data from a
number of sources.
• Updating: The user can modify, delete, and add to the file’s data. This normally includes
writing the file initially, rewriting it completely or in part, and removing all or a portion of the
data. Some systems distinguish among different degrees of updating.
• Changing protection: The user can change the access rights granted to other users.
Typically, this right is held only by the owner of the file. In some systems, the owner can
extend this right to others. To prevent abuse of this mechanism, the file owner will typically
be able to specify which rights can be changed by the holder of this right.
• Deletion: The user can delete the file from the file system.
▪Access can be provided to different classes of users:
• Specific user: Individual users who are designated by user ID
• User groups: A set of users who are not individually defined. The system must
have some way of keeping track of the membership of user groups.
• All: All users who have access to this system. These are public files.
Operating System Concepts – 10th Edition 13.21 Silberschatz, Galvin and Gagne ©2018
Access Lists and Groups in Unix
▪ Mode of access: read, write, execute
▪ Three classes of users on Unix / Linux
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 file (say game) or subdirectory, define an appropriate access.
Operating System Concepts – 10th Edition 13.22 Silberschatz, Galvin and Gagne ©2018
file allocation
Operating System Concepts – 10th Edition 13.23 Silberschatz, Galvin and Gagne ©2018
part
Allocation
Frequency
Once Low to high High Low
Time to Allocate Medium Long Short Medium
Operating System Concepts – 10th Edition 13.24 Silberschatz, Galvin and Gagne ©2018
Figure 6 Contiguous File Allocation
Operating System Concepts – 10th Edition 13.25 Silberschatz, Galvin and Gagne ©2018
Figure 7 Contiguous File Allocation (After Compaction)
Operating System Concepts – 10th Edition 13.26 Silberschatz, Galvin and Gagne ©2018
allocation methods
Operating System Concepts – 10th Edition 13.27 Silberschatz, Galvin and Gagne ©2018
allocation methods
Operating System Concepts – 10th Edition 13.28 Silberschatz, Galvin and Gagne ©2018
allocation methods
▪ III Indexed allocation addresses many of the problems of contiguous and chained
allocation. In this case, the file allocation table contains a separate one-level index
for each file; the index has one entry for each portion allocated to the file.
Typically, the file indexes are not physically stored as part of the file allocation
table. Rather, the file index for a file is kept in a separate block, and the entry for
the file in the file allocation table points to that block. Allocation may be on the
basis of either fixed-size blocks (see Figure 10) or variable-size portions (see Figure
11).
▪ Allocation by blocks eliminates external fragmentation, whereas allocation by
variable-size portions improves locality. In either case, file consolidation may be
done from time to time. File consolidation reduces the size of the index in the case
of variable-size portions, but not in the case of block allocation. Indexed allocation
supports both sequential and direct access to the file and thus is the most popular
form of file allocation.
Operating System Concepts – 10th Edition 13.29 Silberschatz, Galvin and Gagne ©2018
allocation methods
Operating System Concepts – 10th Edition 13.30 Silberschatz, Galvin and Gagne ©2018
allocation methods
Operating System Concepts – 10th Edition 13.31 Silberschatz, Galvin and Gagne ©2018
widows NTFS example
Operating System Concepts – 10th Edition 13.32 Silberschatz, Galvin and Gagne ©2018
windows NTFS file system
Operating System Concepts – 10th Edition 13.33 Silberschatz, Galvin and Gagne ©2018
End of Chapter 13
Operating System Concepts – 10h Edition Silberschatz, Galvin and Gagne ©2018