ce01000-6 operating systems lecture 17 file systems – interface and implementation
TRANSCRIPT
![Page 1: CE01000-6 Operating Systems Lecture 17 File systems – interface and implementation](https://reader036.vdocuments.mx/reader036/viewer/2022062409/5697bf981a28abf838c91489/html5/thumbnails/1.jpg)
CE01000-6 Operating Systems
Lecture 17
File systems – interface and implementation
![Page 2: CE01000-6 Operating Systems Lecture 17 File systems – interface and implementation](https://reader036.vdocuments.mx/reader036/viewer/2022062409/5697bf981a28abf838c91489/html5/thumbnails/2.jpg)
Overview of lecture
In this lecture we will look at: File and directory concept Directory Structure Protection Allocation Methods Free-Space Management
![Page 3: CE01000-6 Operating Systems Lecture 17 File systems – interface and implementation](https://reader036.vdocuments.mx/reader036/viewer/2022062409/5697bf981a28abf838c91489/html5/thumbnails/3.jpg)
Files - User view
As seen by User a File is a named collection of related information held on non-volatile backing storage with a contiguous logical address space. (i.e. it appears to be in one continuous block)
![Page 4: CE01000-6 Operating Systems Lecture 17 File systems – interface and implementation](https://reader036.vdocuments.mx/reader036/viewer/2022062409/5697bf981a28abf838c91489/html5/thumbnails/4.jpg)
Files -Operating Systems view
BUT for Operating System the file is identified by a reference to its location on the hardware store and data in file is held in a number of small blocks
these blocks may be held non-contiguously in hardware store (i.e. sequences of other data blocks that belong to other files or that are empty may exist between some or all of the data blocks of the file)
![Page 5: CE01000-6 Operating Systems Lecture 17 File systems – interface and implementation](https://reader036.vdocuments.mx/reader036/viewer/2022062409/5697bf981a28abf838c91489/html5/thumbnails/5.jpg)
Directories a directory is a link between name of file that the user uses
and the file information and data block location information and is normally maintained in a data structure.
this is simply a table of records where each record has the name of the file, information about the location of the file, and various file property information that is useful, e.g. size, time/date of last modification/access, protection
information (who allowed to use file and how - read only, read/write, etc.)
directories contain entries for files, but may also contain entries for other directories (called sub-directories) - name of directory, location of data block that holds directory information.
![Page 6: CE01000-6 Operating Systems Lecture 17 File systems – interface and implementation](https://reader036.vdocuments.mx/reader036/viewer/2022062409/5697bf981a28abf838c91489/html5/thumbnails/6.jpg)
Directories (Cont.)
using directories allows users to give meaningful names to files and to group files together
in windows systems users normally use the name folder rather than directory - a folder is a directory that has an icon associated with it
directories allow users and application programs to list the information
![Page 7: CE01000-6 Operating Systems Lecture 17 File systems – interface and implementation](https://reader036.vdocuments.mx/reader036/viewer/2022062409/5697bf981a28abf838c91489/html5/thumbnails/7.jpg)
OS Directory support
the operating system provides users and application programs (via API calls) with a number of operations that can be performed on directories e.g. list directory contents, change some file properties like its name and
protection provided, search for given file, delete a file (removes file entry in directory and
free up space used by file on disk), etc.
![Page 8: CE01000-6 Operating Systems Lecture 17 File systems – interface and implementation](https://reader036.vdocuments.mx/reader036/viewer/2022062409/5697bf981a28abf838c91489/html5/thumbnails/8.jpg)
OS File operations
create file - allocate space for file, then create entry in directory for file
write to file - finds location of file from directory entry, then outputs to file at location specified by a current position pointer - points to location in file – location is relative to start of file i.e. logical location not physical) - then updates pointer
read from file - finds location of file from directory entry, then inputs from file at location specified by current position pointer - then updates pointer
file seek - change value of current position pointer to new value
delete file - find directory entry - return space back to O/S, and then delete entry in directory
also getting and setting various file attributes
![Page 9: CE01000-6 Operating Systems Lecture 17 File systems – interface and implementation](https://reader036.vdocuments.mx/reader036/viewer/2022062409/5697bf981a28abf838c91489/html5/thumbnails/9.jpg)
Opening/closing files
instead of repeatedly searching directory for file entry for every operation - O/S usually supplies a method for opening a file
when file opened information about file including location information, are placed in an open file table which is accessed by some index value
alternatively you can have open file tables for each process in which case open file table holds information relevant to process’ use of file e.g. current position pointer and OS has a separate open file table to hold process independent info e.g. file location on disk
![Page 10: CE01000-6 Operating Systems Lecture 17 File systems – interface and implementation](https://reader036.vdocuments.mx/reader036/viewer/2022062409/5697bf981a28abf838c91489/html5/thumbnails/10.jpg)
Opening/closing files (Cont.)
open(Fi) – search the directory structure on disk for
entry Fi, and move the content of entry to open file table - returning a pointer that points to entry in open file table
close (Fi) – move the content of entry Fi in open file
table to directory structure on disk.
![Page 11: CE01000-6 Operating Systems Lecture 17 File systems – interface and implementation](https://reader036.vdocuments.mx/reader036/viewer/2022062409/5697bf981a28abf838c91489/html5/thumbnails/11.jpg)
Directory organisation
need to organise directories to obtain Efficiency – can locate files 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 C programs, all games, …)
![Page 12: CE01000-6 Operating Systems Lecture 17 File systems – interface and implementation](https://reader036.vdocuments.mx/reader036/viewer/2022062409/5697bf981a28abf838c91489/html5/thumbnails/12.jpg)
Directory structure
![Page 13: CE01000-6 Operating Systems Lecture 17 File systems – interface and implementation](https://reader036.vdocuments.mx/reader036/viewer/2022062409/5697bf981a28abf838c91489/html5/thumbnails/13.jpg)
Directory structure (Cont.) General modern directory structure is multi-level in a tree
like structure but one which does allow links between different branches of tree hierarchy
can logically group together related files in subdirectories can allow duplicate file names by placing files in different
directories - use full path names to identify a file uniquely allow search path to be defined to specify directories to
be searched for file references not found in users directory
![Page 14: CE01000-6 Operating Systems Lecture 17 File systems – interface and implementation](https://reader036.vdocuments.mx/reader036/viewer/2022062409/5697bf981a28abf838c91489/html5/thumbnails/14.jpg)
Directory structure (Cont.)
allow concept of current directory (working directory) so that complete pathname does not have to be used if file in current directory
allow relative path names can share subdirectories and files by having links to
file/directory using different file names to refer to same file/directory - prevent deletion of file with multiple links by keeping a count of number of links - only delete when count = 0
![Page 15: CE01000-6 Operating Systems Lecture 17 File systems – interface and implementation](https://reader036.vdocuments.mx/reader036/viewer/2022062409/5697bf981a28abf838c91489/html5/thumbnails/15.jpg)
File Allocation Schemes
File allocation allocates disk blocks to file, but also defines translation of logical file address to physical file address
logical file blocks are numbered from 0 so logical file address specified by:
logical block number + offset within block a number of file allocation schemes -
1. contiguous
2. linked
3. indexed
![Page 16: CE01000-6 Operating Systems Lecture 17 File systems – interface and implementation](https://reader036.vdocuments.mx/reader036/viewer/2022062409/5697bf981a28abf838c91489/html5/thumbnails/16.jpg)
Contiguous Allocation
Each file occupies a set of contiguous blocks on the disk.
Simple to allocate – only starting location (physical block #) and length (number of blocks) are required.
Random access is possible Wasteful of space - external fragmentation of
disk space - similar problem to contiguous memory allocation.
![Page 17: CE01000-6 Operating Systems Lecture 17 File systems – interface and implementation](https://reader036.vdocuments.mx/reader036/viewer/2022062409/5697bf981a28abf838c91489/html5/thumbnails/17.jpg)
Contiguous Allocation (Cont.)
Files cannot grow - without making new copy in new location
mapping from logical address to physical: block to be accessed = starting address of
first block + (logical address / size of block) / is integer division i.e. no fractional part
offset into block = logical address % size of block % is remainder operation
![Page 18: CE01000-6 Operating Systems Lecture 17 File systems – interface and implementation](https://reader036.vdocuments.mx/reader036/viewer/2022062409/5697bf981a28abf838c91489/html5/thumbnails/18.jpg)
Linked Allocation Each file is a linked list of disk blocks; blocks may be scattered
anywhere on the disk.
pointer
File Data
block =
![Page 19: CE01000-6 Operating Systems Lecture 17 File systems – interface and implementation](https://reader036.vdocuments.mx/reader036/viewer/2022062409/5697bf981a28abf838c91489/html5/thumbnails/19.jpg)
Linked Allocation (Cont.)
![Page 20: CE01000-6 Operating Systems Lecture 17 File systems – interface and implementation](https://reader036.vdocuments.mx/reader036/viewer/2022062409/5697bf981a28abf838c91489/html5/thumbnails/20.jpg)
Linked Allocation (Cont.)
Allocate blocks as needed link them together in example in previous slide, file starts at block 9 and
simply follows links for file data Simple to allocate – need only starting address of file
i.e. first physical block id. no waste of space - all free space is available for
allocation to files i.e. no external fragmentation
![Page 21: CE01000-6 Operating Systems Lecture 17 File systems – interface and implementation](https://reader036.vdocuments.mx/reader036/viewer/2022062409/5697bf981a28abf838c91489/html5/thumbnails/21.jpg)
Linked Allocation (Cont.)
But no random access - have to follow linksMapping from logical address to physical:
logical address / size of block specifies the block in the linked chain of blocks
representing file
logical address % size of block specifies offset into block
![Page 22: CE01000-6 Operating Systems Lecture 17 File systems – interface and implementation](https://reader036.vdocuments.mx/reader036/viewer/2022062409/5697bf981a28abf838c91489/html5/thumbnails/22.jpg)
Indexed Allocation
Brings all pointers to disk blocks together into the index block. Logical view.
index table
![Page 23: CE01000-6 Operating Systems Lecture 17 File systems – interface and implementation](https://reader036.vdocuments.mx/reader036/viewer/2022062409/5697bf981a28abf838c91489/html5/thumbnails/23.jpg)
Example of Indexed Allocation
![Page 24: CE01000-6 Operating Systems Lecture 17 File systems – interface and implementation](https://reader036.vdocuments.mx/reader036/viewer/2022062409/5697bf981a28abf838c91489/html5/thumbnails/24.jpg)
Indexed Allocation (Cont.)
Need index table Random access is OK Dynamic access without external
fragmentation and files can grow, but have overhead of index block.
![Page 25: CE01000-6 Operating Systems Lecture 17 File systems – interface and implementation](https://reader036.vdocuments.mx/reader036/viewer/2022062409/5697bf981a28abf838c91489/html5/thumbnails/25.jpg)
Indexed Allocation – Mapping
Mapping from logical to physical address where there is only 1 block to hold index table: logical address / size of block = index into index
table giving address of physical block logical address % size of block = offset into block
block size places upper limit on size of a file = number of indices in block * size of a block in bytes.
![Page 26: CE01000-6 Operating Systems Lecture 17 File systems – interface and implementation](https://reader036.vdocuments.mx/reader036/viewer/2022062409/5697bf981a28abf838c91489/html5/thumbnails/26.jpg)
Indexed Allocation – Mapping using multi-level index (Cont.)
outer-index
index table file
![Page 27: CE01000-6 Operating Systems Lecture 17 File systems – interface and implementation](https://reader036.vdocuments.mx/reader036/viewer/2022062409/5697bf981a28abf838c91489/html5/thumbnails/27.jpg)
Indexed Allocation – Mapping using multi-level index (Cont.)
multi-level indexlowest level gives address of blocks on diskhigher level gives indices into lower level index
blockslogical address / number of indices in a block =
index of next lower index blockthis is repeated until you get index into lowest index
block where address of block is found logical address % size of block = offset into block
![Page 28: CE01000-6 Operating Systems Lecture 17 File systems – interface and implementation](https://reader036.vdocuments.mx/reader036/viewer/2022062409/5697bf981a28abf838c91489/html5/thumbnails/28.jpg)
Free-Space Management Bit vector scheme (n blocks)
bit[j] = 1 => block[j] free
= 0 => block[j] occupied Block number of first free block =
(number of bits per word) *
(number of 0-value words) +
offset of first 1 bit
…
0 1 2 n-1
![Page 29: CE01000-6 Operating Systems Lecture 17 File systems – interface and implementation](https://reader036.vdocuments.mx/reader036/viewer/2022062409/5697bf981a28abf838c91489/html5/thumbnails/29.jpg)
Free-Space Management (Cont.)
Bit map requires extra space. Example:
block size = 212 bytes
disk size = 230 bytes (1 gigabyte)
n = 230/212 = 218 bits (or 32K bytes)
Easy to get contiguous files Linked list scheme of free space management (free
list) - just put free blocks on a linked list Cannot get contiguous space easily No waste of space
![Page 30: CE01000-6 Operating Systems Lecture 17 File systems – interface and implementation](https://reader036.vdocuments.mx/reader036/viewer/2022062409/5697bf981a28abf838c91489/html5/thumbnails/30.jpg)
References
Operating System Concepts. Chapter 11.