Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

File Concept and Operations

Lesson 27 of 31 in the free Operating System & Linux Programming notes on Siksha Sarovar, written by Rohit Jangra.

What is a File?

A file is a named collection of related information stored on secondary storage. From the user's view it is a logical, contiguous sequence of bytes; from the OS's view it is a set of disk blocks linked by metadata.

File Attributes

Every file has metadata that the OS keeps in a directory entry / inode:

  • Name — human-readable identifier.
  • Identifier — inode number, unique within the filesystem.
  • Type — regular, directory, symbolic link, device, FIFO, socket.
  • Location — pointer(s) to data blocks.
  • Size — current size in bytes.
  • Protection — owner, group, permission bits.
  • Time stamps — created, modified, accessed.

File Operations (System Calls)

OperationPurpose
createMake a new file.
openEstablish a file descriptor.
readBytes from current offset.
writeBytes at current offset.
lseekMove the offset.
closeRelease file descriptor.
renameChange name.
unlink/deleteRemove a directory entry; data freed when last link gone.
stat/fstatRead metadata.
truncateResize.

File Descriptor Table

When a process opens a file, the kernel assigns a small integer file descriptor (fd). Three are pre-opened: 0 stdin, 1 stdout, 2 stderr. The fd indexes a per-process table that points to system-wide open-file entries.

File Types in Linux (ls -l first character)

SymbolType
-Regular file
dDirectory
lSymbolic link
cCharacter device (/dev/tty)
bBlock device (/dev/sda)
pNamed pipe (FIFO)
sSocket

Internal File Structure

  • None (byte stream) — Unix philosophy; the program imposes structure (e.g., text lines).
  • Simple records — fixed/variable-length lines.
  • Complex — formatted documents, executables (ELF, PE).

File Sharing

Multiple processes can share a file. Issues:

  • Lockingflock/fcntl for exclusive ranges.
  • Open across fork — children inherit parent's fds.
  • Network sharing — NFS, SMB.

Summary

  • Files are named byte streams with metadata in inodes.
  • The file-descriptor + open-file + inode triple decouples per-process state from the on-disk data.
  • "Everything is a file" extends the abstraction to devices, pipes and sockets.