File System in OS — Allocation, inode, FAT | Tutorials Logic
File Attributes and Operations
A file is a named collection of related information stored on secondary storage. File attributes include:
- Name: Human-readable identifier
- Type: File extension or magic number (text, binary, executable)
- Size: Current file size in bytes
- Location: Pointer to file location on disk
- Permissions: Read, write, execute for owner, group, others
- Timestamps: Creation time, last modified, last accessed
- Owner: User/group that owns the file
File Operations: Create, Read, Write, Seek (reposition), Delete, Truncate, Open, Close, Rename, Copy
Directory Structures
- Single-Level Directory: All files in one directory. Simple but no organization. Name conflicts for multiple users.
- Two-Level Directory: Separate directory for each user. Solves name conflicts but no grouping within user's files.
- Tree-Structured Directory: Hierarchical structure with subdirectories. Most common (Unix/Windows). Supports absolute and relative paths.
- Acyclic Graph Directory: Allows sharing of files/directories (hard links, symbolic links). No cycles allowed.
- General Graph Directory: Allows cycles. Requires garbage collection to handle cycles.
File Allocation Methods
How files are stored on disk affects performance and space utilization:
| Method | Description | Pros | Cons |
|---|---|---|---|
| Contiguous | File occupies consecutive disk blocks | Fast sequential and random access, simple | External fragmentation, file size must be known in advance |
| Linked | Each block contains a pointer to the next block | No external fragmentation, easy to grow | Slow random access, pointer overhead, reliability (lost pointer) |
| Indexed | Index block contains pointers to all file blocks | Fast random access, no external fragmentation | Index block overhead, small files waste space |
FAT and inode
FAT (File Allocation Table): Used by Windows (FAT12, FAT16, FAT32, exFAT). A table stored at the beginning of the disk where each entry corresponds to a disk cluster. Each entry contains the number of the next cluster in the file chain, or a special value for end-of-file or free cluster.
inode (Index Node): Used by Unix/Linux file systems (ext2, ext3, ext4). Each file has an inode that stores all metadata (permissions, owner, timestamps, size) and pointers to data blocks. The inode does NOT store the filename - that's stored in the directory entry.
- Direct pointers: Point directly to data blocks (fast for small files)
- Single indirect: Points to a block of pointers
- Double indirect: Points to a block of pointers to blocks of pointers
- Triple indirect: Three levels of indirection (for very large files)
Free Space Management
- Bitmap (Bit Vector): One bit per disk block. 0 = free, 1 = allocated. Easy to find contiguous free blocks. Requires extra space.
- Linked List: Free blocks are linked together. No wasted space but slow to find contiguous blocks.
- Grouping: First free block stores addresses of n free blocks. Last of those stores addresses of next n free blocks.
- Counting: Store address of first free block and count of consecutive free blocks following it.
Level Up Your Operating system Skills
Master Operating system with these hand-picked resources