A file is a named collection of related information stored on secondary storage. File attributes include:
File Operations: Create, Read, Write, Seek (reposition), Delete, Truncate, Open, Close, Rename, Copy
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 (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.
Creating or replacing a file may update data blocks, metadata, directory entries, allocation maps, and journal records. A write call returning does not always mean every layer has persisted the data. Applications that require durable replacement write a temporary file, flush the required data, rename atomically within the file system, and account for directory durability according to the platform contract.
Hard links share one file object, while symbolic links store another path. Test deletion, rename, open handles, permission changes, and recovery after interruption so code does not confuse a directory name with the underlying file identity.
Event 1: a process requests a resource related to File
Event 2: the kernel checks permissions, availability, and current state
Event 3: the scheduler or manager decides whether to run, wait, block, or fail
Event 4: the process observes the result and continues or handles the error
Input: P1, P2, P3
Resource/state: limited
Rule: apply the File policy step by step
Output: show which process runs, waits, completes, or is denied
Always write the before-state and after-state for each step.
A file stores data; a directory maps names to files and other directories.
It affects sequential access, random access, fragmentation, and metadata overhead.
It is a process-local handle for an open file or I/O resource.
Explore 500+ free tutorials across 20+ languages and frameworks.