Why a file system?
Why a file system There is a general need for long-term and shared data storage: need to store large amount of information persistent storage (outlives process and system reboots) concurrent sharing of information Files meet these requirements The file manager or file system within the OS Set of system software proving services to users and applications in use of files Files are accessed through file management system Q1 2
Concept of a file A named collection of related data stored on secondary storage File name may encode the file type file extensions in UNIX and Windows Abstraction presented to the user Common examples of File types Regular files, directories Executable files special files (block and character) Archives 3
File structure (logical) None - sequence of words, bytes Simple record structure Lines, Fixed length, Variable length Complex Structures Formatted document, multi-media documents Who decides: Operating system Application DBMS 4
File attributes Name only information kept in human-readable form Type needed for systems that support different types Location pointer to file location on device Size current file size Protection controls who can do reading, writing, executing Time, date, and user identification data for protection, security, and usage monitoring. Information about files are kept in the directory structure, which is maintained on the disk. Q2 5
File operations create write read reposition within file file seek delete truncate open(file_i) search the directory structure on disk for entry file_i, and move the content of entry to memory. close (file_i) move the content of entry file_i from memory to directory structure on disk. Q3 6
Examples of file types File Type Usual extension Functiion Executable exe, com, bin or none ready-to-run machinelanguage program Object obj, o complied, machine language, not linked Source code c, p, pas, 177, asm, a source code in various languages Batch bat, sh commands to the command interpreter Text txt, doc textual data documents Word processor wp, tex, rrf, etc. various word-processor formats Library lib, a libraries of routines Print or view ps, dvi, gif ASCII or binary file Archive arc, zip, tar, rar related files grouped into one file, sometimes compressed. 7
Access methods for file data Sequential Access (most common) read next write next, (rewrite) reset no read after last write Direct Access: n = relative block number (on disk) read n write n, rewrite n position to n read next write next 8
Directory structure Directory contains a collection of nodes containing information about all files Both the directory structure and the files reside on disk Backups of these two structures are kept on tapes Directory Files F 1 F 2 F 3 F 4 F n Q4a 9
Information per file in a directory Name Type Address Current length Maximum length Date last accessed (for archival) Date last updated (for dump) Owner ID (who pays) Protection information (discuss later) Q4b10
Directory operations Search for a file Create a file Delete a file List a directory Rename a file Traverse the file system 11
Organize the directory (logically) Efficiency locating a file quickly. Naming convenient to users. Two users can have same name for different files. The same file can have several different names. Grouping logical grouping of files by properties, (e.g., all Java programs, all games, ) Q5 12
Single-level directory A single directory for all users. Naming problem Grouping problem 13
Two-level directory Separate directory for each user. Path name Can have the same file name for different user Efficient searching No grouping capability 14
Tree-structured directories 15
Tree-structured directories Efficient searching Grouping Capability Absolute or relative path name Current directory (working directory) cd /Users/faculty/defoe/Public/ type echo Creating a new file is done in current directory Creating a new subdirectory is done in current directory Q6 16
Protection File owner/creator should be able to control: what can be done by whom Types of access Read Write Execute Append Delete List 17
Access lists and groups Mode of access: read, write, execute Three classes of users RWX a) owner access 7 1 1 1 RWX b) groups access 6 1 1 0 RWX c) public access 1 0 0 1 Ask manager to create a group (unique name), say G, and add some users to the group. For particular file or subdirectory, define an appropriate access. owner group public chmod 761 game Attach a group to a file chgrp G game Q7 18
Filesystem structure Disk divided into one or more partitions independent file system on each partition Sector 0 contains the Master Boot Record (MBR) MBR contains partition table one partition marked as active boot block first block of active partition BIOS reads and executes MBR, which reads boot block of the active partition and executes it program in boot block loads OS and runs it Often file system contains superblock which contains key file system parameters Q8 19
Example disk and filesystem layout Partition Table MBR partition 1 partition 2 (active) partition 3 boot block super block free space management inode list root dir files & dirs 20
File allocation on disk Disk is divided into blocks or sectors Files are stored on secondary storage in blocks or sectors Blocks are the unit of I/O transfer with secondary storage (on LINUX and UNIX, clusters on Windows) Blocks can be of fixed length or variable-length Need file allocation table (FAT) to keep track of files on disk Each file has a FAT entry 21
File allocation methods Keep track of which sectors/blocks on the disk belong to which logical file/directory. Methods include Contiguous allocation Linked (chained) allocation Indexed allocation 22
Contiguous allocation Each file occupies a set of contiguous blocks on the disk Simple FAT entry only starting location (block #) and length (number of blocks) are required Random access Wasteful of space external fragmentation, may use compaction to fix Files cannot grow Pre-allocation of blocks is required Maximum file size is known in advance Q9 23
Contiguous allocation What happens if file F requires 6 blocks? 24
Contiguous allocation 25
Linked allocation Each file is a linked list of disk blocks: blocks may be scattered anywhere on the disk no external fragmentation Dynamic allocation of blocks allocate blocks as needed, link together; e.g., file starts at block 9 File allocation table entry is simple only starting location (block #) is required length or end block can be given Very inefficient with random access files Q10 26
Linked allocation example block pointer 27
Another linked allocation example 28
Example after consolidating file 29
Indexed allocation Brings all pointers together into the index block stores index table Random access is very efficient Can optimize disk reads as all data blocks are known Dynamic access without external fragmentation, but have overhead of index block FAT entry is simple Pointer to index-node (i-node)/index block Used in UNIX Q1130
Indexed allocation example 31