import { motion } from 'motion/react'; export default function FileSystemDiagram() { return (
FILE SYSTEMS
File System: The OS's method of organizing, storing, naming, and retrieving data on storage devices. Examples: ext4 (Linux), NTFS (Windows), APFS (macOS), FAT32, ZFS, Btrfs {/* Directory Tree */} DIRECTORY STRUCTURE Hierarchical tree. Every file has a full path from root. {/* Tree viz */} / (root) 📁 home 📁 etc 📁 user1 📁 user2 📄 notes.txt 📁 docs 📄 resume.pdf Path types: Absolute: /home/user1/docs/resume.pdf Relative: ../docs/resume.pdf (from user2) Special entries: . = current directory | .. = parent directory Hard link: same inode, different directory entry Soft link (symlink): pointer to another file path {/* Inode */} INODE STRUCTURE (Linux ext4) Every file has an inode containing metadata. Directory entry maps filename → inode number. {/* Inode box */} INODE #{'\u00A0'}1234 {[ {field:'File type',val:'Regular file / dir / link'}, {field:'Permissions',val:'rwxr-xr-- (owner/grp/other)'}, {field:'Owner UID/GID',val:'1000 / 1000'}, {field:'File size',val:'4,096 bytes'}, {field:'Link count',val:'2 (hard links)'}, {field:'atime',val:'Last accessed'}, {field:'mtime',val:'Last modified'}, {field:'ctime',val:'Last changed (inode)'}, {field:'Data block ptrs',val:'12 direct + indirect'}, ].map(({field,val},i)=>( {field} {val} ))} {/* Data block layout */} Data Block Addressing: 12 direct pointers → data blocks 1 single indirect → block of pointers 1 double indirect → 2 levels of ptrs 1 triple indirect → 3 levels of ptrs {/* Block diagram */} Inode {[0,1,2].map(i=>( Data{i+1} ))} Indirect Block Key insight: Filename NOT stored in inode. Directory entry maps name → inode#. Multiple names → same inode = hard links. Deleting file = unlink (decrement count). Data freed when link count hits 0. ls -i shows inode numbers. {/* Allocation methods + FS types */} FILE ALLOCATION METHODS {[ {m:'Contiguous',d:'File blocks stored consecutively. Fast sequential access. Suffers external fragmentation. Used in CD-ROM.',c:'#fbbf24',pros:'Fast reads',cons:'External frag'}, {m:'Linked List',d:'Each block has pointer to next block. No fragmentation. Slow random access (must traverse links).',c:'#60a5fa',pros:'No ext frag',cons:'Slow random access'}, {m:'Indexed (FAT/Inode)',d:'Index block holds all data block pointers. Supports direct + indirect addressing. Used in ext4.',c:'#4ade80',pros:'Fast random access',cons:'Index block overhead'}, ].map(({m,d,c,pros,cons},i)=>( {m} {d.slice(0,60)} {d.slice(60)} ✓ {pros} ✗ {cons} ))} FILE SYSTEM TYPES COMPARISON {['FS','OS','Max File','Journal','Features'].map((h,i)=>{h})} {[ {fs:'ext4',os:'Linux',max:'16TB',j:'Yes',feat:'Most common Linux FS',c:'#4ade80'}, {fs:'NTFS',os:'Windows',max:'16EB',j:'Yes',feat:'ACLs, encryption, compression',c:'#60a5fa'}, {fs:'APFS',os:'macOS',max:'8EB',j:'CoW',feat:'Snapshots, clones, SSD-opt',c:'#94a3b8'}, {fs:'FAT32',os:'Universal',max:'4GB',j:'No',feat:'Wide compatibility, USB drives',c:'#fbbf24'}, {fs:'ZFS',os:'Linux/BSD',max:'256ZB',j:'CoW',feat:'Snapshots, RAID, self-healing',c:'#c084fc'}, {fs:'Btrfs',os:'Linux',max:'16EB',j:'CoW',feat:'Snapshots, compression, RAID',c:'#f97316'}, ].map(({fs,os,max,j,feat,c},i)=>( {fs} {os} {max} {j} {feat} ))} Journaling: logs changes before writing → fast crash recovery. CoW (Copy-on-Write): safer, enables snapshots. Virtual FS (VFS): Linux abstraction layer — same API for all FS types (ext4, NTFS, NFS, procfs, etc.)
); }