- Goals:
- Meet the data management needs of the user
- Guarantee that the data in the file are valid
- Optimize performance
- Provide I/O support for a variety of storage device types
- Minimize the potential for lost or destroyed data
- Provide a standardized set of I/O interface routines to user processes
- Provide I/O support for multiple users in the case of multiple-user systems
- Parts:
- Drivers talk directly to the disk
- Basic Filesystem deals with blocks of data, writing to
disk, or buffering in RAM.
- Supervisor selects device, does scheduling, assigns buffers.
- Logical, record access.
- Types of files
- Some operating systems provide support for special file structures.
- Most files are just sequential piles of bits from the OS
perspective. The user applications manage how they're structured.
- This can be inefficient for things like data base servers,
which need to find individual records in a file quickly.
- OSes support this by structuring the files around indexed keys.
- The most common mechanism are B-Trees
- B-Trees
- Balanced tree, NOT A BINARY TREE.
- Made up of keys and records, similar to binary trees.
- Branching factor of \(d \leq b \leq 2d\).
- Every node has at least \(d-1\) keys and \(d\) pointers,
except for the root, which has 1 key.
- Dummy node leaves.
- Search is done like any ordered tree.
- Insertion is done like a 2-3-4 tree. Insert, if too many
keys, split and promote.
- Deletion is also the same. Find, delete, move up a child.
- What we've made is a generalization of a 2-3-4, call it a
d-(d+1)-(d+2)-...-2du tree. B-tree is easier.
- File directories.
- The operating system has to keep a model of the logical
location of files, and map that to the physical location.
This is the directory system.
- You keep the following info:
- Usually the directory is a file itself. Sometimes some of
this info is in the file header.
- Sharing and Access levels
- None
- Knowledge
- Execution
- Reading
- Appending
- Updating
- Change protection
- Deletion
- Simultaneous access?
- File allocation
- Do we allocate a large chunk at creation?
- What size portions to use (groups of blocks).
- How do we keep track of portions?
- Pre-allocation - simple, difficult to estimate size.
- Allocating large portions means more of the file is
contiguous, small tables for where everything is. Simple
block based portions are simple. Small portions waste less space.
- Placement? best fit, first fit, Nearest fit.
- Basic methods of allocation: Contiguous, chained, indexed.
- Contiguous- pre-allocate a contiguous
block. Fragmentation is a problem.
- Chained. No accomodation for locality.
- Indexed. Index entry for each block.
- Free Space management
- In order to quickly find free space, we need some sort of
table of where it is.
- Bit vector. 16G Disk, 512byte blocks, -> 4M. If we don't
have room in RAM, very slow.
- Chained Free portions.
- Indexing. Use index table (hash)
- Free block list. Again large,
- Unix Filesystem
- 6 types of files: regular, directory, special (devices),
named pipes, link, symbolic link.
- Allocation done on block level. Pointers to the blocks
are in the direct and indirect fields in the inode.
- The inode is of small fixed size, can be kept in memory.
- Small files have little indirection.
- Can handle very large files.
- Directories are handled just as above, where the
directiory is a list of pointers to other directories or inodes.
- Volume structure: boot block (boots the system),
superblock (size of partition, inode table size, etc), Inode
table, data blocks.
- Access control: rwx, oga. We know this already.
- We might not know that there are 3 more bits- setUID,
setGID, and sticky. Sticky applies to directory, saying only
owners of files in that directory can move, rename or delete
those files.
- Access control lists
- Another more recent way to control access is with Access
Control Lists.
- Assign a list of user IDs with individual permission
rights with the setfacl command.
- See man page.
- Linux virtual file system
- In its early days, linux had a problem. It's specially
designed filesystem, ext worked will, but lived in a world
where most people used disks with other filesystems, so the
designers needed to support all these others in order to gain
acceptance.
- Thus they developed the virtual filesystem.
- This layer maps between the Linux idea of files to the
other system, e.g. inodes to FATs.