File Concept, Operations on File

A file is an abstract logical collection of related records mapped onto physical storage, hiding the complex hardware sectors from the programmer.

10 min read · 10 cards · 2 checks

Read in: English · हिन्दी · ગુજરાતી


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 AttributePurposeLabOne Server Example
NameHuman readable identifier for user conveniencelab2.c
IdentifierUnique system tag number tracking the dataInode 45219
TypeSpecifies the internal format extension.c or .out
LocationPointer to the physical disk block addressesBlocks 1024 to 1028

Follow along

The Six Core Lifecycle Operations

  1. Create The OS allocates empty disk space and adds a new name pointer entry into the directory structure.
  2. Write The system specifies the file name and data, keeping an active write pointer to track where the next byte goes.
  3. Read The system reads data from the current read pointer position and advances the tracking pointer head.
  4. Reposition Also known as a file seek, this changes the current position pointer without reading or writing data.
  5. Delete The OS searches the directory, releases all allocated disk blocks, and erases the directory entry.
  6. 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?

  1. A physical hardware track address
  2. A current file position pointer
  3. A global disk sector index number
  4. 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!

Study this properly

This page is the lesson to read. In Gri-Learn the same topic is a graded deck: the self-checks are scored and your weak topics are tracked. Free to start.

Start this topic

Already have an account? Sign in

More from File and Memory Management

Gri-Learn · syllabus-mapped B.C.A. lessons in English, Hindi and Gujarati

File Concept, Operations on File · Operating System · Gri-Learn