File Manager Flashcards
What is the file manager?
Keeps track of every file in the system, providing an abstracted view of files to the user and maps this onto a disk.
File Manager Tasks
These include:
- organise files into folders
- map file locations
- map logical structures onto physical locations
- enforces restrictions to files
- deal with open, close, read, write and delete operations.
- provides syscalls.
- liaises with device manager to access physical disks within system.
Disk Blocks
Essentially, each disk is split up into blocks of a certain size in which the OS chooses. Files fill up more than one block normally, but there is only one file per block, so space is wasted if a block if not full.
Disk Format
Each partition of a physical disk will be formatted with a particular disk format, splitting these blocks into equal sizes.
File Allocation Methods
The disk format and block usage are both decided by the file allocation method. There are many ways to allocate files to blocks on disks, three being contiguous, linked and indexed.
This also is used for deciding how blocks in a file are accessed.
Freelist
States whether a block is free or not using 1 and 0 (respectively, in use and free). This is stored on a part of a disk which is reserved for such data.
Metadata
Used to store information about a file. This is stored on a part of a disk which is reserved for such data.
File System Parts
Physical Storage On Disk -> FAT, XFS and EXT4.
Logical Naming Scheme -> File/Directory Names.
Permission Model -> Access control such as permissions used by linux.
Syscalls -> System calls, standardised programmatic access to files via kernel.
System calls in the file system
fopen
fclose
fread
fwrite
fseek
fflush
Any program using these system calls can manipulate data in these files.
User programs can see the logical view of the file system via syscalls.
Logical View
- Filenames with extensions, like .txt
- folder hierarchies
- shell with drag and drop and copy/paste in terms of files
For example, file explorer for windows can be considered a logical view of the file management system.
Physical View
- directories and files are just bit patterns stored in blocks of the disk
- OS needs to know which block belongs to which file
- contains metadata and freelist
- arrangement and usage of blocks depends on file allocation method
Inodes and Disk Format with Inodes
Something we use to map logical to physical. Inodes point to physical blocks on disk, with each file having an inode which stores metadata on it. This builds up an inode table, which is then stored on disk in the free allocated space. The parts of the disk then include:
Housekeeping data (contains metadata about the file system)
Freelist
Inode table
Data blocks
Housekeeping Data
This is data that is used for administrative or management purposes, rather than for direct use by end-users or applications. Essentially, metadata about the file system.
Sequential File Access
Start with first block and read each block in order until correct one with wanted data is found.
Direct File Access
Goes directly to the block that contains required data, skipping over other blocks in the meantime.
Contiguous Allocation
Each file is allocated across contiguous blocks on disk (aka all the blocks are together, and each file is side by side)
This inode stores the start block number, and the number of blocks, making it fast for both sequential and direct access.
However, we have fragmentation of free blocks. This is because once one is deleted, we can’t really use up that space again since we put the next file next to the last file added, which then requires frequent defragmentation. Also, we cannot alter the file sizes to grow, since they are side by side and there are no free blocks aside of them until a file next to them is deleted.
Linked Allocation
The files are more spaced out, but the head of each block of a file is kept, with the head of one file pointing to the next file’s head.
This makes it easy to grow and shrink files with no defragmentation, but blocks are widely dispersed, making HDDs read/write head move around a lot. As well as this, sequential access and direct access are affected negatively, since they now have to go to the head block, read it, and then figure out when the next block is (remember, these files are no longer in order, and can be stored anywhere so long as there is space. So it is a lot of jumping around). We also have the danger of pointer corruption.
Indexed Allocation
The first block is reserved to hold the index of all other blocks.
This is very efficient since we have every file’s block information being held in one place, and is very fast for both sequential and direct access.
However, blocks can still be widely dispersed, as well as wasting this one block for small information. We can also, on the other hand, have too much information in this one block, requiring two index blocks, or three etc. The index block(s) could also get corrupted.
File Allocation Table and Disk Format
An alternative to inodes which splits physical disk into distinct sections and uses indexed allocations, but the index blocks are stored in one place. This contains:
Boot Sector -> housekeeping data
FAT -> master copy of index blocks for each file
FAT (copy) -> backup copy of the FAT
Data Region -> contains blocks that store data.
The advantage to this method is that all the pointers are held together and easier to protect, and no need for a separate freelist, with direct access being much more efficient. However, it requires the HDD head to move constantly between FAT area and file area, and FAT will become large for huge disks.
New Technology File System
Another alternative to inodes. This is the defaut disk format for new windows installations, which uses a master file table. Apart from that, the general principle is the same as FAT.
This type of disk format provides useful features such as:
- encryption
- journaling
- file compression
- hard links
- shadow copies
- system compression
Popular File Systems
Below are some popular file systems used:
Windows -> FAT32 and NTFS
MacOS -> APFS
Linux -> EXT4