5 File Management

Operating Systems · Unit 5 · 6 hrs

File Management

Exam-focused notes for File Management (Operating Systems, CSC264): what the TU syllabus asks and how it has actually been tested, with 9 solved past questions from this unit.

File Management in short

This chapter covers file management: how the operating system names, structures and stores files, organizes them into directories, and keeps track of which disk blocks are still free.

File Management: notes

File Overview: File Naming, File Structure, File Types, File Access, File Attributes, File Operations, Single Level, two Level and Hierarchical Directory Systems, File System Layout

A file is a named collection of related information, typically records, held on a secondary storage device such as a disk; a file may hold a program or data, and data files may be numeric, alphanumeric or binary. Files are logical units of information created by a process; once the creating process terminates, the file continues to exist and can be accessed by other processes using its name.

File naming conventions vary between operating systems, but most allow names of at least 8 characters, and many modern file systems allow names up to 255 characters, often including a range of special characters. Windows systems commonly use NTFS, a more advanced native file system, alongside the newer ReFS (Resilient File System) aimed at server workloads.

File structure describes how the bytes inside a file are organized.

  • Unstructured files are simply an unstructured sequence of bytes; the operating system imposes no meaning on the contents, leaving interpretation entirely to user programs. Both UNIX and Windows take this approach, which gives maximum flexibility to the programs that use the file.
  • Record structured files are a sequence of fixed length records, each with its own internal structure; a read returns one record and a write appends or overwrites one record. This was common on older mainframe systems.
  • Tree structured files hold a tree of records, not all necessarily the same length, each containing a key field in a fixed position, sorted on that key so a specific record can be searched for and located quickly. This structure is used in large mainframe systems for commercial data processing.

File types include regular files (user data, ASCII or binary), directories (system files that maintain the structure of the file system), character special files (modelling serial I/O devices such as terminals), ASCII files (lines of text that can be viewed and edited directly with a text editor) and binary files (a sequence of bytes with an internal structure known only to the programs that use them, such as executables).

File access methods determine how a program locates data inside a file. Sequential access reads an ordered file from the beginning, scanning forward until the desired record is reached, natural for storage such as magnetic tape. Direct (random) access allows a program to read any byte or record in any order, based on the disk's ability to seek directly to any block, typically obtained through a hashing method that maps a key to a block position.

File attributes are metadata describing a file rather than its contents: name (the only attribute in human readable form), a unique identifier (tag) within the file system, type (for systems that distinguish file types), location (a pointer to where the file lives on the storage device), size, protection (read, write and execute permissions) and archive status (whether a backup utility should include the file).

File operations supported by the file system include create (announce the file and set its initial attributes with no data yet), delete (free the disk space once the file is no longer needed), open (fetch the file's attributes and disk addresses into memory for fast subsequent access), close (release that internal table space once all accesses are finished), read, write, append (add data only at the end of the file) and rename.

Files are organized into directories. A single-level directory system keeps every file in one shared directory (sometimes called the root directory, though with only one directory the name hardly matters); it is the simplest possible scheme but does not scale to multiple users. A two-level directory system gives each user a separate directory, suitable for a multi-user computer, though it makes it awkward for users who want to cooperate and access each other's files. A hierarchical directory system generalizes the two-level scheme into a tree of arbitrary height, letting users create their own subdirectories and organize their files however suits them, which is the structure used by virtually all modern general-purpose operating systems.

File-system layout places a boot block at the very start of the file system (occupying the first 4096 bytes, at byte offset 0), used to help start the operating system, followed by a superblock (also 4096 bytes, starting at byte offset 4096), which holds information describing the file system as a whole. Beyond the boot block and superblock, the file system contains bitmaps and one or more allocation groups, each containing disk nodes and fragments, with each complete file system occupying one logical volume.

What this unit covers

  • File Overview: File Naming, File Structure, File Types, File Access, File Attributes, File Operations, Single Level, two Level and Hierarchical Directory Systems, File System Layout
  • Implementing Files: Contiguous allocation, Linked List Allocation, Linked List Allocation using Table in Memory, Inodes
  • Directory Operations
  • Path Names
  • Directory Implementation
  • Shared Files
  • Free Space Management: Bitmaps, Linked List

File Overview

2081 · 5 marks

List different file structures and explain them. [5]

Show solved answer

File Structures

A file structure defines how data is organized and stored within a file. Different types of files have different internal structures depending on their purpose and the programs that use them.


Different File Structures

1. Regular Files (User Files)

Regular files contain user information. They are the most common type of file and are generally of two subtypes:

a) ASCII Files

  • Consist of lines of text.
  • Each line is terminated by a carriage return or newline character.
  • Can be displayed and printed directly.
  • Can be created and edited by any ordinary text editor.
  • Example: .txt files, source code files.

b) Binary Files

  • Consist of a sequence of bytes only.
  • They have some internal structure known only to the programs that use them.
  • Cannot be read directly as plain text.
  • Example: Executable files (compiled programs), object files.

2. Directory Files

  • These are system files used for maintaining the structure of the file system.
  • A directory file keeps track of the files contained within it, storing their names, identifiers, and locations.
  • They form the hierarchical tree structure of the file system.

3. Character Special Files

  • Related to Input/Output (I/O) operations of the computer.
  • Used to model serial I/O devices such as terminals, printers, and network interfaces.
  • They do not store data permanently; instead, they represent device streams.

Summary Table

File StructureDescriptionExample
ASCII FileText lines, human-readable.txt, source code
Binary FileByte sequences, internal structureExecutable, .exe
Directory FileMaintains file system structureFolders/directories
Character Special FileModels serial I/O devicesTerminals, printers

Conclusion

Different file structures serve different purposes in an operating system. Regular files (ASCII and binary) store user data, directory files organize the file system hierarchy, and character special files provide an interface to hardware I/O devices. Understanding these structures is essential for effective file system management.

Open this answer on its own page →

2078 · 5 marks

What is ment by file attributes? Discuss any one technique of implementing directories in detail. [5]

Every file has a name and the data it contains. In addition, a file system stores extra information associated with each file, known as file attributes (also called metadata). These attributes describe the properties of the file and help the operating system manage it. Common file attributes incl...

Open this answer on its own page →

2080.1 · 5 marks

Why do we need hierarchical directory system? Explain structure of disk. [5]

--- A hierarchical directory system is the generalization of the two-level directory structure into a tree of arbitrary height. It allows users to create their own sub-directories and to organize their files accordingly. Directory Type Limitation ------ Single-level All files in one directory; na...

Open this answer on its own page →

Implementing Files

2080 · 5 marks

Differentiate between contiguous and linked list file allocation technique. [5]

As stated in the notes, "the simplest allocation scheme is to store each file as a contiguous run of disk blocks." Each file occupies a set of consecutive blocks on the disk. The directory entry stores only the starting block address and the length of the file. Example: A 50-KB file on a disk wit...

Open this answer on its own page →

2079 · 5 marks

Discuss the advantages disadvantages of implementing file system using Linked List. [5]

In a linked list allocation of a file system, each file is stored as a linked list of disk blocks. Each block contains a pointer to the next block of the file. The directory entry holds the address of the first block, and each block points to the next until the end of the file is reached. Note: A...

Open this answer on its own page →

2080.1 · 5 marks

Discuss about contiguous and linked list file allocation technique. [5]

Show solved answer

File Allocation Techniques: Contiguous and Linked List

1. Contiguous Allocation

In contiguous allocation, each file is stored as a contiguous run of disk blocks on the disk. The directory entry for each file records the starting block address and the length of the file.

Example:

  • On a disk with 1-KB blocks, a 50-KB file is allocated 50 consecutive blocks.
  • On a disk with 4-KB blocks, the same file would need 25 consecutive blocks.
  • Each file begins at the start of a new block; any wasted space occurs only at the end of the last block.

Advantages

  • Simple to implement -- the directory only needs to store the start address and length.
  • Excellent read performance -- since blocks are consecutive, sequential and random access are both fast (minimal disk seeks).

Disadvantages

  • External fragmentation -- over time, free space becomes scattered in small pieces, making it difficult to find a large contiguous area for new files.
  • Difficult to extend files -- if a file needs to grow, there may be no free space immediately after its last block.
  • Difficult to find space for new files when free blocks are fragmented.

2. Linked List Allocation

In linked list allocation, each file is stored as a linked list of disk blocks. The first word of each block is used as a pointer to the next block, and the remaining space in the block holds actual data.

Block 4        Block 7        Block 2        Block 9
[ptr=7|data]-->[ptr=2|data]-->[ptr=9|data]-->[EOF|data]

The directory entry stores only the address of the first block of the file; the chain of pointers leads to all subsequent blocks.

Variant: FAT (File Allocation Table)

  • The pointers are moved out of the data blocks and stored in a separate table called the FAT.
  • The entire block becomes available for data.
  • The FAT is used as a linked list; the directory entry contains the block number of the first block, and the FAT is looked up to find the next block until a special end-of-file (EOF) value is reached.

Advantages

  • Solves all problems of contiguous allocation -- no external fragmentation, files can grow easily by linking new blocks anywhere on disk.
  • No need for compaction of free space.

Disadvantages

  • Only efficient for sequential access -- random access is excessively slow because to reach block n, all n-1 preceding blocks must be traversed.
  • Space overhead for pointers -- each block loses some bytes to store the next-block pointer.
  • Each block access may require a disk seek, increasing access time.

Comparison Summary

FeatureContiguousLinked List
ImplementationSimpleModerate
Sequential AccessFastModerate
Random AccessFastVery Slow
FragmentationExternal fragmentationNo fragmentation
File ExtensionDifficultEasy
Space OverheadNonePointer per block
Open this answer on its own page →

2080.1 · 5 marks

Write short notes on : a. Inode b. RAID [5]

--- An inode (index node) is a fundamental data structure used in Unix/Linux file systems to store metadata about a file or directory. Every file in the file system has exactly one inode associated with it. - An inode stores all information about a file except its name and actual data content. - ...

Open this answer on its own page →

Free Space Management

2078 · 5 marks

What approaches are using for managing free disk spaces? Explain linked list approaches with example. [5]

The system maintains a free space list to keep track of disk blocks not allocated to any file or directory. The two main approaches are: 1. Bitmap (Bit Vector) 2. Linked List --- In the linked list approach, all free disk blocks are linked together. Each free block contains a pointer to the next ...

Open this answer on its own page →

2076 · 5 marks

How can you manage free disk space? Explain the linked list approach of managing free disk space with example. [5]

The operating system maintains a free space list to keep track of disk blocks that are not allocated to any file or directory. This list is used to allocate space when new files are created and to reclaim space when files are deleted. The free space list can be implemented using: - Bitmap / Bit V...

Open this answer on its own page →