CE 01000 6 Operating Systems Lecture 17 File
- Slides: 30
CE 01000 -6 Operating Systems Lecture 17 File systems – interface and implementation
Overview of lecture l In this lecture we will look at: l l l File and directory concept Directory Structure Protection Allocation Methods Free-Space Management
Files - User view l 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)
Files -Operating Systems view l l 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)
Directories l l 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, l l 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.
Directories (Cont. ) l l l 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
OS Directory support l the operating system provides users and application programs (via API calls) with a number of operations that can be performed on directories e. g. l 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.
OS File operations l l 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 l read from file - finds location of file from directory entry, then inputs from file at location specified by current position pointer - then updates pointer l l 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 l also getting and setting various file attributes
Opening/closing files l l l 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
Opening/closing files (Cont. ) l 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 l close (Fi) – move the content of entry Fi in open file table to directory structure on disk.
Directory organisation l need to organise directories to obtain l l Efficiency – can locate files quickly. Naming – convenient to users. l l l 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, …)
Directory structure
Directory structure (Cont. ) l l 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
Directory structure (Cont. ) l l l 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
File Allocation Schemes l l 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
Contiguous Allocation l l 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.
Contiguous Allocation (Cont. ) l l Files cannot grow - without making new copy in new location mapping from logical address to physical: l l block to be accessed = starting address of first block + (logical address / size of block) l / is integer division i. e. no fractional part offset into block = logical address % size of block l % is remainder operation
Linked Allocation l Each file is a linked list of disk blocks; blocks may be scattered anywhere on the disk. block = pointer File Data
Linked Allocation (Cont. )
Linked Allocation (Cont. ) l l l Allocate blocks as needed link them together in example in previous slide, file starts at block 9 and simply follows links for file data l Simple to allocate – need only starting address of file i. e. first physical block id. l no waste of space - all free space is available for allocation to files i. e. no external fragmentation
Linked Allocation (Cont. ) l But no random access - have to follow links l Mapping l logical address / size of block l l from logical address to physical: specifies the block in the linked chain of blocks representing file logical address % size of block l specifies offset into block
Indexed Allocation l l Brings all pointers to disk blocks together into the index block. Logical view. index table
Example of Indexed Allocation
Indexed Allocation (Cont. ) l Need index table l Random access is OK l Dynamic access without external fragmentation and files can grow, but have overhead of index block.
Indexed Allocation – Mapping l l Mapping from logical to physical address where there is only 1 block to hold index table: l logical address / size of block = index into index table giving address of physical block l logical address % size of block = offset into block size places upper limit on size of a file = number of indices in block * size of a block in bytes.
Indexed Allocation – Mapping using multi-level index (Cont. ) � outer-index table file
Indexed Allocation – Mapping using multi-level index (Cont. ) l multi-level index l lowest level gives address of blocks on disk l higher level gives indices into lower level index blocks l logical address / number of indices in a block = index of next lower index block l this is repeated until you get index into lowest index block where address of block is found l logical address % size of block = offset into block
Free-Space Management l Bit vector scheme (n blocks) 0 1 2 n-1 … bit[j] = 1 => block[j] free = 0 => block[j] occupied l Block number of first free block = (number of bits per word) * (number of 0 -value words) + offset of first 1 bit
Free-Space Management (Cont. ) l Bit map requires extra space. Example: block size = 212 bytes disk size = 230 bytes (1 gigabyte) n = 230/212 = 218 bits (or 32 K bytes) l Easy to get contiguous files l Linked list scheme of free space management (free list) - just put free blocks on a linked list l Cannot get contiguous space easily l No waste of space
References l Operating System Concepts. Chapter 11.
- File-file yang dibuat oleh user pada jenis file di linux
- Advanced operating system notes
- Module 4 operating systems and file management
- 01:640:244 lecture notes - lecture 15: plat, idah, farad
- Os file management
- File management in android operating system
- File management in operating system
- File system in operating system
- File system in operating system
- File system in operating system
- Physical image vs logical image
- File sharing management system
- Distributed file system
- Markup tag tells the web browser
- In a file-oriented information system, a transaction file
- Lecture sound systems
- Lecture sound systems
- Operating system examples
- Evolution of operating systems
- Components of an operating system
- Component of operating systems
- Wsn operating systems
- Remzi arpaci-dusseau
- Operating systems lab
- Dual mode in os
- Tanenbaum os
- What are the design issues of distributed operating systems
- Early operating systems
- Real-time operating systems
- Can we make operating systems reliable and secure
- Alternative operating systems