Directory - Files
π Files, Directories, and File Systems
Clean, GitHubβfriendly summary with structure, highlights, and visuals in mind.
ποΈ 1. Files β Logical Data Containers
A file is a structured collection of data stored on secondary storage.
π File Contents
- Program code
- User data
- Metadata (attributes)
π·οΈ File Attributes (Metadata)
| Attribute | Meaning | |βββ|βββ| | Type | Executable, source, media, library | | Size | Current & maximum size | | Permissions | Read / Write / Execute | | Created Time | File creation timestamp | | Last Access | Last opened | | Last Modified | Last edit | | Owner | File creator | | Disk Location | Physical storage pointer |
βοΈ File Operations (System Calls)
1
create(), delete(), open(), close(), read(), write(), seek(), rename()
π 2. Directories β File Organization Structure
Directories organize files in a tree hierarchy.
π³ Directory Structure
- Root directory:
/orC:\ - Subdirectories nested under root
π Path Types
| Path Type | Example | |βββ|βββ| | Absolute Path | /home/user/file.txt | | Relative Path | ../docs/file.txt |
π Directory Entry Stores
- File name
- File type
- Storage block pointer
- Metadata reference
π½ 3. File Systems β Disk Management Layer
A file system defines how files are stored, retrieved, and protected.
π§± Disk Preparation
| Step | Purpose | |ββ|βββ| | Partitioning | Divide disk into logical regions | | Formatting | Install file system structure |
π§© 4. File Allocation Methods
π Contiguous Allocation
- File stored in continuous disk blocks
- Fast access
- β Causes external fragmentation
π Linked Allocation
- Each block stores pointer to next
- No fragmentation
- β Slow random access
ποΈ Indexed Allocation
- Index block stores all file block addresses
- Fast random access
- Used in modern systems
π§ 5. FAT File System (File Allocation Table)
- Based on linked allocation
- FAT stores all block links centrally
- Faster lookup if FAT cached in RAM
π¦ Disk Layout
1
Reserved | FAT Table | Root Directory | Data Area
π Directory Entry Includes
- File name & extension
- Size
- Timestamps
- Starting block
π§ 6. UNIX File System β i-node Architecture
Uses indexed allocation.
π i-node Stores
- File metadata
- Up to 15 block pointers
π§± Block Pointer Levels
| Type | Purpose | |ββ|βββ| | Direct Blocks | Store file data | | Single Indirect | Pointer list | | Double Indirect | Pointerβtoβpointer | | Triple Indirect | Large file support |
Root directory location is always known.
πΎ 7. Popular File Systems Comparison
| File System | Platform | Features |
|---|---|---|
| FAT / exFAT | Portable | Simple, removable drives |
| NTFS | Windows | Security, journaling |
| EXT4 | Linux | Stable, scalable |
| APFS | Apple | Optimized for SSD |
π§ Developer Takeaways
β File allocation affects performance
β Indexed allocation improves random access
β Metadata enables security & ownership
β FAT = portable, NTFS = secure, EXT4 = scalable
β File systems manage fragmentation & disk efficiency