Post

Directory - Files

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: / or C:\
  • 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.


File SystemPlatformFeatures
FAT / exFATPortableSimple, removable drives
NTFSWindowsSecurity, journaling
EXT4LinuxStable, scalable
APFSAppleOptimized 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

This post is licensed under CC BY 4.0 by the author.