Theory
The Invisible Cabinet
When you save your C program as lab2.c on our shared college server, LabOne, you think of it as a single, neat document sitting in a directory folder. But if you looked at the actual magnetic platter or electronic chips inside the server room, your code is scattered as binary digits across random physical sectors. How does a massive collection of fragmented bits look like a single continuous notebook to your compiler?
Theory
The Library Catalog Card
Think of a file like a printed library book. To the student, it is a single continuous story with a title, author, and size. But to the physical building, that book is broken into individual pages stored across distant shelves. The operating system acts like the master librarian: it wraps all those scattered pages together, slaps a logical title tag on them, and says, 'Do not worry about the shelf numbers, just read the title.'
Theory
The File Concept Defined
Formally, a file is a named collection of related information that is recorded on secondary storage. From the operating system perspective, a file is the smallest logical storage unit: data cannot be written to secondary storage unless it is wrapped inside a file. It represents a continuous logical address space mapped by the system software onto physical storage tracks and blocks.
At a glance
Core attributes maintained by the file system for every logical file entry.
| File Attribute | Purpose | LabOne Server Example |
|---|---|---|
| Name | Human readable identifier for user convenience | lab2.c |
| Identifier | Unique system tag number tracking the data | Inode 45219 |
| Type | Specifies the internal format extension | .c or .out |
| Location | Pointer to the physical disk block addresses | Blocks 1024 to 1028 |
Follow along
The Six Core Lifecycle Operations
- Create The OS allocates empty disk space and adds a new name pointer entry into the directory structure.
- Write The system specifies the file name and data, keeping an active write pointer to track where the next byte goes.
- Read The system reads data from the current read pointer position and advances the tracking pointer head.
- Reposition Also known as a file seek, this changes the current position pointer without reading or writing data.
- Delete The OS searches the directory, releases all allocated disk blocks, and erases the directory entry.
- Truncate The system clears the contents of the file down to zero bytes but keeps its attributes and directory name intact.
Quiz
When multiple student sessions read a shared textbook file on LabOne simultaneously, what internal marker does the operating system maintain for each individual program to track its reading position?
- A physical hardware track address
- A current file position pointer
- A global disk sector index number
- A file format extension string
Show the answer
A current file position pointer
The operating system maintains an independent current file position pointer for each open process. This pointer tracks where the next read or write operation will take place, isolating one student's position from another.
Watch out
The Missing Close Trap
A classic mistake in university exams is forgetting the close operation when listing file lifecycles. Students think deleting or creating are the only major tasks. But if a program does not explicitly call close, the active file pointers and internal system table buffers remain locked in RAM. This wastes memory resources on LabOne and can cause permanent data corruption if the server restarts unexpectedly.
Think first
Deleting vs Truncating a File
Suppose a student wants to clear all log messages inside a temporary file but keep the filename intact for future automated scripts. Should they delete the file or truncate it? Analyze the logical difference mentally before tapping.
Show the answer
They must truncate the file. Deleting removes the file name, attributes, and entry pointer entirely from the directory structure, requiring a recreation step. Truncating keeps the file name, permissions, and ownership intact, but resets the file size to zero and releases its stored data blocks back to the free disk pool.
Theory
System Calls and Later Semesters
You will execute these exact operations using raw programming commands in Unit 4. Utilities like cat, rm, and touch are not magic tools: they are direct scripts around the fundamental operating system algorithms we studied today. In your fourth semester data structures course, you will build memory index maps that mirror exactly how these logical file pointers translate to physical storage sectors.
Summary
Key takeaways
- A file is the smallest named logical storage unit mapped onto physical secondary storage devices.
- The operating system completely hides physical tracks, sectors, and sector boundaries from applications.
- File attributes like name, identifier, type, and location are securely tracked inside directory records.
- The six basic system operations are create, write, read, reposition, delete, and truncate.
- System tables maintain current file pointers to track multi-user access states cleanly.
- Memory hook: Create it, open it, seek it, lock it, close it, and protect it!