File System Basics
File Concept
- File System: A collection of files used to store data.
- Directory Structure: Organizes information about files.
- Files: A sequence of bits, bytes, lines, or records defined by its creator and user.
- Data cannot be stored on secondary storage unless within a file.
- Types of information: source programs, executables, text, images, sound recordings, etc.
File Attributes
File Attributes:
- Name: Human-readable information.
- Identifier: Unique tag that identifies a file.
- Type: File classification; tells the system what to do with the file (e.g., JPG).
- Location: Pointer to the file's location in the file system.
- Size: Current file size (e.g., 826 KB).
- Protection: Access control over file permissions (read, write, execute).
- Time, date, and user info: Usage monitoring (e.g., last modified time).
- Created: Tuesday, July 14, 2009, 06:32:38
- Modified: Tuesday, July 14, 2009, 06:32:31
- Accessed: Tuesday, July 14, 2009, 06:32:31
EXIF Meta-Data (Exchangeable image file format):
- Contains date, time, physical/logical location, software version, owner, etc.
- Examples:
- Catching criminals using image meta-data.
- Catching hackers using image meta-data.
- Criminals exploiting vulnerabilities based on software versions.
- Phishing attacks based on owner information.
File Operations
- Basic Operations:
- Create a file: Allocate space on disk and link to directory.
- Deleting a file: Deallocate space and unlink from directory (in Windows, space may not be immediately deallocated).
- Write and Read a file: Use a pointer to the current file position.
- Reposition within a file: Change the current file position pointer.
- Truncating a file: Erase file content but keep attributes.
- Other Operations:
- Rename file, append info, copy file, get/set attributes.
Opening Files
- Open-file table: Tracks all opened files.
- File pointer: Unique per process, points to last read/write location.
- File-open count: Tracks number of open and close operations per file; when the counter is zero, the file entry is removed from the open-file table.
- Disk location of file: Pointer to the disk location.
- Access rights: Access mode per process.
File Locking
- File lock: Processes can block access to a file or section of a file, useful when multiple processes access the same file.
- Read/Write locks:
- Shared lock: Multiple processes can acquire concurrently (reader lock).
- Exclusive lock: Only one process can acquire (writer lock).
- Other lock types:
- Mandatory: Prevents access until the exclusive lock is released.
- Advisory: Returns the lock status of a file, letting software developers decide.
Access Methods
- Sequential Access:
- Process information in order.
- Operations: read next, write next, reset to file beginning.
- Current pointer.
- Direct Access:
- File is split into blocks.
- Operations: read i, write i.
- Can link to sequential access: position to i, read next, write next.
- Other Methods:
- Extend direct access with an index to blocks.
- Order blocks based on some method and use an index (e.g., books ordered by author's last name).
- Similarity to non-contiguous memory allocation.
Directory and Disk Structure
- Disks are split into partitions, and each partition has a directory.
- Directory: Listing of files and their attributes.
- Metadata
- Index to File 1
- Data for File 1
Directory Overview
- Directory Structure: Collection of nodes containing information about all files.
- Located on disk.
- Operations: Create, delete, search, rename, list files.
- Organized logically for efficiency, naming, grouping.
Directory Structure Types
- Single-Leveled Directory:
- All files in the same directory.
- Advantage: simple and efficient.
- Disadvantage: requires unique file names, can become very large.
- Two-level Directory:
- Separate directory per user.
- Users cannot access other user spaces.
- No grouping allowed.
- Tree-Structured Directory:
- Generalization of two-level, allowing grouping.
- Root directory with groupings.
- Permissions for each file and directory: read (r), write (w), execute (x).
- Permissions per user: owner, group, others.
- Caution: No Sharing
- Acyclic Graph Directories:
- Tree-structured with sharing allowed.
- Multiple links to files: symbolic (logical) and hard links (physical).
- General Graph Directory:
- Tree-structured with sharing and cycles.
- Cycles are a problem; cycle detection is needed on each new link.
- Garbage Collection: Cycles lead to self-referencing
Key Concepts
- The current directory may be included in the search path.
- A relative path name defines a path from the current directory.
- If the current directory is
/home/user/jane, then the correct relative path to the file/home/user/mike/prog.cis../mike/prog.c.