Operating System Concepts - File System Interface Study Notes
Chapter 11: File-System Interface
File Concept
- Logical Address Space: A contiguous logical address space is associated with files.
- Types of Files:
- Data Files:
- Numeric: Store numerical data.
- Character: Store character data.
- Binary: Store data in binary format.
- Program Files:
- Contents: Defined by the creator of the file.
- Examples: Text files, source files, executable files.
File Attributes
- Name: Only information kept in a human-readable format.
- Identifier: A unique tag (number) that identifies the file within the file system.
- Type: Necessary for systems that support different file types.
- Location: Pointer to the file's location on the storage device.
- Size: Current file size.
- Protection: Controls user permissions for reading, writing, and executing.
- Time, Date, and User Identification: Data provides protection, security, and usage monitoring information.
- Directory Structure: Information about files is stored in this structure, which is maintained on the disk.
- Extended File Attributes: Variations of file attributes can include items like file checksums.
File Operations
- A file is treated as an abstract data type with several operations:
- Create: Initiate a new file.
- Write: Write data at the current write pointer location.
- Read: Read data from the current read pointer location.
- Reposition within File: Seek to a different location in the file.
- Delete: Remove the file from the file system.
- Truncate: Shorten the file.
- Open(Fi): Search the directory structure on disk for entry Fi and move the contents of entry to memory.
- Close(Fi): Move the contents of entry Fi back from memory to the directory structure on disk.
Open Files
- Managing open files requires several data points:
- Open-file Table: Tracks all open files.
- File Pointer: Pointer indicating the last read/write location per process that has the file open.
- File-open Count: Counts the number of times a file is open to ensure proper resource management in the open-file table.
- Disk Location of the File: Caches information about data access.
- Access Rights: Information on access modes for the process.
Open File Locking
- Provided by some operating systems and file systems to control access.
- Locking Types:
- Shared Lock: Similar to a reader lock, allowing concurrent access for multiple processes.
- Exclusive Lock: Similar to a writer lock, restricting access to one process.
- Locking Modes:
- Mandatory Locking: Denies access based on held and requested locks.
- Advisory Locking: Processes can check lock status and make decisions based on that information.
File Types and Names
- Executable: Usual extensions include
.exe, .com, .bin for machine-readable programs. - Object: Files can have no extension or be
.obj, .o, representing machine code not yet linked. - Source Code: Includes extensions like
.c, .java, .asm, containing human-readable code. - Batch Files: Extensions
.bat, .sh often used for scripting. - Text Files: Common extensions include
.txt, .doc, for storing plain text documents. - Library Files: Used in programming, with extensions like
.lib, .a, .so, that contain conventions for linking code. - Multimedia Files: Formats like
.mp3, .avi, for audio and video content, and .jpg, .pdf, for images and documents.
File Structure
- Types of Structures:
- None: Just a sequence of bytes or words.
- Simple Record Structure: Organizes as lines, either fixed-length or variable-length records.
- Complex Structures: Includes formatted documents or relocatable load files.
- Simulation of Complex Structures: Can be achieved using the simple record structure by inserting control characters.
- Responsibility for Structure: The operating system or the program determines the file structure.
Access Methods
- Sequential Access:
- Operations:
read next, write next, reset are available. - Limitations: Cannot read after the last write until the file is rewound.
- Direct Access:
- Files consist of fixed-length logical records.
- Allows for operations:
read, write, position to n, read next, write next, rewrite. - Here,
n represents the relative block number where the operation can occur.
Directory Structure
- Definition: A collection of nodes containing information about all files within the file system.
- Contains entries like
F1, F2, F3, …, F_n which correspond to various files.
Disk Structure
- Partitions: Disks can be divided into partitions.
- RAID Protection: Disks or partitions can be configured for redundancy to protect against failures.
- File System Usage: Disks may be used in two ways:
- Raw: Without any file system.
- Formatted: With a file system in place.
- Terminology:
- Partitions are also referred to as minidisks or slices.
- Each file system entity is known as a volume, and each volume tracks details in the device directory or volume table of contents.
Types of File Systems
- General-Purpose File Systems: Commonly used file systems, but systems often have multiple file systems, both general and special-purpose.
- Examples from Solaris:
- tmpfs: A memory-based volatile file system for fast temporary I/O.
- objfs: An interface for kernel memory to access kernel symbols for debugging.
- ctfs: A contract file system for managing daemons.
- lofs: A loopback file system allowing one file system to access another.
- procfs: A kernel interface for process structures.
- ufs, zfs: Both serve as general-purpose file systems.
Operations on Directory
- Common Operations:
- Searching for a file.
- Creating a new file.
- Deleting a file from the system.
- Listing files within a directory.
- Renaming a file.
- Traversing the file system.
Directory Organization
- Efficiency: Key objective is to locate files quickly.
- Naming: Users should have convenience in naming, allowing:
- Different files by same name for different users.
- The same file having multiple names.
- Grouping: Logical organization of files by properties, such as grouping all documents or programs of a similar type together.