1. Gyanastra
  2. Operating Systems
  3. File System Structure
  4. File Attributes
Free lesson, no account needed 8 min read 1 practice questions after it
Asked in past papers1 time
  • UGC NET2008

Operating Systems · File System Structure

File Attributes

Overview

A file is an abstract data type, and its properties are called attributes. These attributes are the metadata about the file: once the complete attribute information is known, everything required to open, read, write, or otherwise operate on the file is known, so attributes are the first thing needed before any file operation.

Key concepts

  • File attributes: the properties of a file, i.e. the metadata about the file. The six attributes are name (and optionally an extension), type, location, size, protection, and time and date (creation and last modification).
  • Name: every file must have a name, otherwise it is difficult to retrieve the file when required. The name is generally human readable.
    An extension may be provided along with the name; it is not compulsory — some systems use it, some do not. The extension helps the operating system choose the application to use for the file.
  • Type: specifies what information is present inside the file. Files can be executable, video, audio, text, a collection of records, or a sequence of bytes.
    Some operating systems ask for the type when a file is saved; providing it is better, because the OS can then search for and open the related application when the file is opened.
  • Location: a hint to the operating system about where the file is located — a pointer which points to the physical location in which the file is present.
    It matters because a computer may have more than one storage device connected (for example an external hard disk and an internal hard disk), with some files on the internal disk and some on the external disk.
  • Size: the total size of the file in bytes. It is important because it is used in problems such as: given a file size and the block size of the hard disk, how many blocks are needed and what is the internal fragmentation.
  • Protection: specifies the class of users or group of users who can perform particular actions on the file.
    Not everyone should be able to run all files on a computer; for example, ordinary non-admin users may not be allowed to run a program that removes every directory or removes a file from a directory.
    Some users may be allowed only to read a file but not delete it; some may be allowed only to write a file but not execute it. Protection protects files that should not be given access to everyone.
  • Time and date: the time and date on which the file was created, and the time and date of its last modification. It is useful, for example, for a source file together with its compiled version (.exe).

How it works

  1. Name and extension: the name identifies the file for retrieval. The extension is optional; if provided, it helps the OS choose the application.
    If no extension is added and the type cannot be detected, the OS leaves the file as it is, and when the file is later opened the application must be specified.
  2. Type: records what kind of content the file holds, so the OS can find and open the related application.
  3. Location: stores a pointer to the physical location of the file, which the OS uses to find it across storage devices.
  4. Size: stores the total size in bytes, from which the number of blocks and the internal fragmentation are computed.
  5. Protection: records which classes or groups of users may read, write, execute, or delete the file.
  6. Time and date: records creation and last modification, which are compared to decide whether a compiled file is out of date.

Formulas

  • Number of blocks=⌈file size/block size⌉\text{Number of blocks} = \lceil \text{file size} / \text{block size} \rceil
    • file size = total size of the file in bytes
    • block size = size of one disk block in bytes
    • ⌈⋅⌉\lceil \cdot \rceil = round up to the next whole block, because the last partially filled block is also allocated
  • Internal fragmentation=(number of blocks×block size)−file size\text{Internal fragmentation} = (\text{number of blocks} \times \text{block size}) - \text{file size}
    • the wasted bytes in the last, partially filled block

Worked examples

Example 1 — Time and date used to decide recompilation. A source file and its compiled version (.exe) exist. The application is designed so that whenever someone clicks on the .exe, it searches for the related source file.
If the source file was modified after the .exe was created, the application recompiles the source into a new .exe, replaces the old .exe with the new one, and then runs it.

  1. The .exe file is created / last modified on May 5.
  2. The source file is modified on May 10.
  3. Today (when execution is attempted) is May 15.
  4. Compare: the source modification date (May 10) is later than the .exe creation date (May 5), so the .exe is out of date.
  5. Therefore it is better to compile the source again, get the latest copy of the .exe, and then execute it.

This is exactly why creation time and last-modified time are stored as file attributes.

Example 2 — Extensions as hints to the OS.

  • File saved as .exe: when the file is clicked, the OS tries to execute it because .exe means executable.
  • File saved as .doc: the OS opens MS Office to open the file.
  • File saved as .mov: a video player opens it when it is clicked.

In all these cases the extension is only a hint to the operating system for choosing the application.

Comparison

AttributeWhat it storesWhy it is needed
NameHuman-readable name of the file; optional extensionTo identify and retrieve the file; extension hints which application to use
TypeKind of information inside the file (executable, video, audio, text, collection of records, sequence of bytes)Helps the OS search for and open the related application
LocationPointer to the physical location where the file is presentNeeded when the computer has more than one storage device (internal / external hard disk)
SizeTotal size of the file in bytesUsed to compute number of blocks occupied and internal fragmentation
ProtectionClasses/groups of users and the access allowed (read, write, execute, delete)Prevents unauthorized users from reading, writing, executing or deleting the file
Time and dateCreation time/date and last-modified time/dateDeciding, e.g., whether a source file must be recompiled before running the .exe

Revision summary

  • Every file has a name, generally human readable; the extension is optional.
    Some systems once made it mandatory, but all recent operating systems keep it optional and auto-add it when the type is detected.
  • If no extension is added and the type cannot be detected, the file is left as it is, and the application must be specified when opening it.
  • The type describes the content: executable, video, audio, text, collection of records, or a sequence of bytes.
  • The location is a pointer to the physical location of the file — important because files may be spread over an internal and an external hard disk.
  • Size (in bytes) and block size (in bytes) are the two values needed for block-count and internal-fragmentation problems.
  • Protection restricts access per class/group of users: read-only, write-only, no execute, no delete, etc.
  • Time and date records creation and last modification; it is used to decide recompilation when the .exe is older than the source file.
  • All attributes together are the metadata of the file — what is needed before performing any file operation.

Previous-year exam insights

  • The standard attribute set also includes an owner (user) identifier and an access-rights/permission bitmask (read, write, execute, append, delete, list) stored per file; protection is implemented by comparing the requesting user's identity with the owner and permission bits.
  • In UNIX/Linux the file attributes are held in the inode (mode, owner, group, size, timestamps, link count, block pointers), and the directory entry maps only the file name to the inode number — name is not stored in the inode.
  • The three standard timestamps are last access (atime), last modification of contents (mtime) and last change of inode/metadata (ctime); creation time (birth time) is not available on all file systems.
  • File type is distinguished from file extension: the OS may determine type by extension (Windows), by a magic number stored in the file header (UNIX), or by an explicit type attribute; the extension is only a naming convention and can be wrong.
  • Number of blocks and internal fragmentation must use the file system block (cluster) size, not the disk sector size; the last block is partially wasted, so internal fragmentation is always less than one block.
  • A file's logical structure (unstructured byte sequence vs. fixed/variable-length records vs. indexed/tree) and its access methods (sequential, direct/random, indexed) are separate attributes that determine how the file can be read.
Pages 1–2 of 2