Skip to main content

File and attributes; allocation methods

Short answer

File attributes: name, ID, type, location, size, permissions, timestamps. Allocation methods: contiguous (fast, external fragmentation), linked list (no fragmentation, slow random), FAT (pointers in memory table), indexed/i-node (fast random, indirect blocks).

What is file and their attributes? Briefly explain the file allocation methods.

File and its attributes

A file is a named collection of related information stored on secondary storage; it is the logical unit of storage seen by the user (programs, documents, data). Files have an internal structure (byte stream, records, tree) and a type (regular, directory, special).

File attributes (metadata) maintained for each file:

AttributeMeaning
NameHuman-readable identifier
IdentifierUnique tag (i-node number) used by the system
TypeText, executable, directory, etc.
LocationPointer to the device and disk blocks
SizeCurrent size in bytes/blocks
ProtectionPermissions: read, write, execute for owner, group, others
Time, date, user IDCreation, last access and modification, owner
FlagsRead-only, hidden, system, archive, lock flags

File allocation methods

The file allocation method decides which disk blocks belong to a file. The main methods are:

1. Contiguous allocation - each file occupies a set of consecutive blocks. The directory stores the start block and length.

 file A: blocks 0-3   file B: blocks 4-6   free 7-...
 [A][A][A][A][B][B][B][ ][ ]
  • Advantages: simple; very fast sequential and direct access (only one seek); only start and length are stored.
  • Disadvantages: external fragmentation (needs compaction); file size must be known in advance; file growth is difficult.

2. Linked-list allocation - each block contains a pointer to the next block; the directory stores the first block.

 [blk 9 |->2] [blk 2 |->14] [blk 14 |->nil]
  • Advantages: no external fragmentation; files can grow easily; no need to know size.
  • Disadvantages: random access is very slow (must follow the chain); the pointer takes space in each block (so the data size is no longer a power of 2); one lost pointer breaks the file (poor reliability).

3. Linked list with a table in memory (FAT) - the pointers are moved out of the data blocks into a File Allocation Table in memory; entry i gives the block after block i.

  • Advantages: full block available for data; random access is faster (chain followed in memory).
  • Disadvantages: the whole table must be in memory (a 1 TB disk with 1 KB blocks needs 10⁹ entries), so it does not scale.

4. Indexed allocation (i-node) - each file has an index block (i-node) that lists the addresses of all its blocks (UNIX adds indirect blocks for large files).

 i-node: [b1][b2][b3]...[single indirect]-->[b..][b..]
  • Advantages: supports direct access, no external fragmentation, only the i-nodes of open files need to be in memory.
  • Disadvantages: index block overhead (even for a small file); very large files need multiple levels of indirection.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Operating System chapter 5 questions →