Operating System File System: Session 10 (Chapter 9)
Operating System File System: Session 10 (Chapter 9)
Session 10(Chapter 9)
Data
Complex Structures
Program
Can simulate last two with first method by inserting appropriate control characters Who decides:
OperatingSystems-FileSystem
Attributes of a File
3
Name only information kept in human-readable form Identifier unique tag (number) identifies file within file system 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
OperatingSystems-FileSystem
File Operation
4
File is an abstract data type Create Write Read Reposition within file Delete Truncate Open(Fi) search the directory structure on disk for entry Fi, and move the content of entry to memory Close (Fi) move the content of entry Fi in memory to directory structure on disk
OperatingSystems-FileSystem
File pointer: pointer to last read/write location, per process that has the file open File-open count: counter of number of times a file is open to allow removal of data from open-file table when last processes closes it Disk location of the file: cache of data access information Access rights: per-process access mode information
OperatingSystems-FileSystem
Provided by some operating systems and file systems Mediates access to a file Mandatory or advisory:
Mandatory access is denied depending on locks held and requested Advisory processes can find status of locks and decide what to do
OperatingSystems-FileSystem
OperatingSystems-FileSystem
The file system is a mechanism for storing data and programs. Main characteristics of Secondary storage
Large storage capacity Non-volatile nature. Give raise to the convenience of storing data and programs on secondary storage.
Consequence?
OperatingSystems-FileSystem
Should be flexible, e.g., allow multiple names for same files Support hierarchy for easy of use Want to be sure data has been written to disk in case crash occurs Want to restrict who has access to files Want to share files with other users Sequential access Random access Sequential is most common & Random next Other pattern is Keyed access (not usually provided by OS
Persistence
Sharing/Protection
OperatingSystems-FileSystem
10
Translation scheme should minimize number of additional accesses for a given access pattern Harder than, say page tables where we assumed page tables themselves are not subject to paging!
OperatingSystems-FileSystem
The file system on the disk of an operating system allows data to be stored, searched and retrieved. One part of the file system is the user interface. This interface defines the definition of a file, file attributes, operations allowed on files and a directory structure for organizing files. The other part of the file system has algorithms and data structures to map the logical file system onto the physical storage devices. A file system has a layered design
Each layer uses the features provided by the layer below it to provide features to the layer above it.
It consists of device drivers and interrupt handlers for information transfer between the memory and the disk. A device driver is a translator between the file system and the actual disk hardware. The device driver takes high level instructions as input.
OperatingSystems-FileSystem
The next layer, the basic file system issues generic commands to the appropriate device driver to access (read / write) physical blocks on the disk.
The layer above the basic file system is the file organization module.
This module has information about files, the logical records and the physical blocks.
The file organization module translates / maps logical addresses to physical block addresses for the basic file system.
This module also keeps track of free blocks. The logical file system makes use of the directory structure of the file system and provides information to the file organization module given a file name. Protection and security are also part of the logical file system.
OperatingSystems-FileSystem
OperatingSystems-FileSystem
Over-View
14
OperatingSystems-FileSystem
15
OperatingSystems-FileSystem
16
Look-up (via-directory)
OperatingSystems-FileSystem
at most 1 in-memory instance per unique file #number of openers & other properties
With separate offsets for byte-stream
None of data in OFT is persistent Reflects how processes are currently using files Lifetime of objects determined by open/close
OperatingSystems-FileSystem
1.in-memory inode
Store information about an open file, such as how many openers, corresponds to on-disk file descriptor Region on disk, entry in file descriptor table, that stores persistent information about a file who owns it, where to find its data blocks, etc. A bytewise copy of 2. in memory
2.on-disk inode
OperatingSystems-FileSystem
19
OperatingSystems-FileSystem
These mechanisms looks at how efficiently files are stored and accessed.
OperatingSystems-FileSystem
Contiguous Allocation
21
Idea: allocate files in contiguous blocks File Descriptor = (first block, length) Good sequential & random access Problems:
hard to extend files may require expensive compaction external fragmentation analogous to segmentation-based VM
OperatingSystems-FileSystem
Linked Files
22
lose first block, may lose file Solution: keep linked list in memory
unreliable:
OperatingSystems-FileSystem
23
OperatingSystems-FileSystem
Indexed Allocation
24
Single-index: specify maximum file-size, create index array, then note blocks in index
access ok one translation step Sequential access requires more seeks depending on contiguous allocation
Random
OperatingSystems-FileSystem
Directory Structure
25
OperatingSystems-FileSystem
Disk Structure
26
Disk can be subdivided into partitions Disks or partitions can be RAID protected against failure Disk or partition can be used raw without a file system, or formatted with a file system Partitions also known as minidisks, slices Entity containing file system known as a volume Each volume containing file system also tracks that file systems info in device directory or volume table of contents As well as general-purpose file systems there are many special-purpose file systems, frequently all within the same operating system or computer.
OperatingSystems-FileSystem
Disk Schematics
27
OperatingSystems-FileSystem
OperatingSystems-FileSystem
Disks are big & slow -compared to RAM Access to disk requires
Seek (move arm to track) to cross all tracks anywhere from 20-50ms, on average takes 1/3. Rotational delay (wait for sector to appear under track) 7,200rpm is 8.3ms per rotation, on average takes : 4.15ms rot delay Transfer time (fast: 512 bytes at 998 Mbit/s is about 3.91us)
Consequence:
Avoid seeks Seek to short distances Amortize seeks by doing bulk transfers
OperatingSystems-FileSystem
Disk Scheduling
30
Can use priority scheme Can reduce avg access time by sending requests to disk controller in certain order
Process requests with increasing track numbers until highest reached, then decreasing etc. repeat LOOK dont go all the way to the top without passengers C-SCAN: -only take passengers when going up
Variations:
OperatingSystems-FileSystem
31
OperatingSystems-FileSystem
Search for a file Create a file Delete a file List a directory Rename a file Traverse the file system
OperatingSystems-FileSystem
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, )
OperatingSystems-FileSystem
Single Directory
34
OperatingSystems-FileSystem
Single Directory
35
Path name Can have the same file name for different user Efficient searching No grouping capability
OperatingSystems-FileSystem
OperatingSystems-FileSystem
Absolute or relative path name Creating a new file is done in current directory Delete a file
rm <file-name>
OperatingSystems-FileSystem
Two different names (aliasing) If dict deletes list dangling pointer Solutions:
Back-pointers, so we can delete all pointers Variable size records a problem Back-pointers using a daisy chain organization
Link another name (pointer) to an existing file Resolve the link follow pointer to locate the file
OperatingSystems-FileSystem
OperatingSystems-FileSystem
Directory Implementation
41
Linear List
list of file names with pointers to the data blocks is one way to implement a directory. linear search is necessary to find for a particular file The method is simple but the search is time consuming. To create a file a linear search is made to look for the existence of a file with the same file name and if no such file is found the new file created is added to the directory at the end. To delete a file a linear search for the file name is made and if found allocated space is released. Every time making a linear search consumes time and increases access time that is not desirable since a directory information is frequently used. A sorted list allows for a binary search that is time efficient compared to the linear search.
But maintaining a sorted list is an overhead especially because of file creations and OperatingSystems-FileSystem deletions.
Directory Implementation
42
Hash Table
A linear list is used to store directory entries. A hash table takes a value computed from the file name and returns a pointer to the file name in the linear list. Thus search time is greatly reduced. Insertions are prone to collisions that are resolved. The main problem is the hash function that is dependent on the hash table size. A solution to the problem is to allow for chained overflow with each hash entry being a linked list.
OperatingSystems-FileSystem
A file system must be mounted before it can be accessed A un-mounted file system is mounted at a mount point
(a) Existing.
Mount point
OperatingSystems-FileSystem
File Sharing
44
Sharing of files on multi-user systems is desirable Sharing may be done through a protection scheme On distributed systems, files may be shared across a network Network File System (NFS) is a common distributed filesharing method. Multiple Users
User IDs identify users, allowing permissions and protections to be per-user Group IDs allow users to be in groups, permitting group access rights
OperatingSystems-FileSystem
45
Manually via programs like FTP Automatically, seamlessly using distributed file systems Semi automatically via the world wide web
Client-server model allows clients to mount remote file systems from servers
Server can serve multiple clients Client and user-on-client identification is insecure or complicated NFS is standard UNIX client-server file sharing protocol CIFS is standard Windows protocol Standard operating system file calls are translated into remote calls
Distributed Information Systems (distributed naming services) such as LDAP, DNS, NIS, Active Directory implement unified access to information needed for remote computing
OperatingSystems-FileSystem
Remote file systems add new failure modes, due to network failure, server failure Recovery from failure can involve state information about status of each remote request Stateless protocols such as NFS include all information in each request, allowing easy recovery but less security
OperatingSystems-FileSystem
47
Consistency semantics specify how multiple users are to access a shared file simultaneously
Tend to be less complex due to disk I/O and network latency (for remote file systems
Andrew File System (AFS) implemented complex remote file sharing semantics Unix file system (UFS) implements:
Writes to an open file visible immediately to other users of the same open file Sharing file pointer to allow multiple users to read and write concurrently Writes only visible to sessions starting after the file is closed
OperatingSystems-FileSystem
Protection
48
Types of access
OperatingSystems-FileSystem
Ask manager to create a group (unique name), say G, and add some users to the group. For a particular file (say game) or subdirectory, define an appropriate access.
OperatingSystems-FileSystem
50
OperatingSystems-FileSystem