Subject Name: Operating Systems Subject Code:10CS53 Prepared By:Mrs.Jisha Jose,Mrs.Thanu Kurian,Mrs.Preethi Sheba Hepsiba Department:Computer Science Date:30/08/2014 11/13/2018
File Concept Access Methods Directory Structure File-System Mounting File Sharing Protection
File Attributes 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
File Operations 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
Open Files Several pieces of data are needed to manage open files: 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
Open File Locking 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
File Types – Name, Extension
Access Methods Sequential Access read next write next reset Direct Access read n write n position to n rewrite n n = relative block number
Sequential-access File
Other access method-Index and Relative Files
A Typical File-system Organization
Directory Structure Operations Performed on Directory Search for a file Create a file Delete a file List a directory Rename a file Traverse the file system
Single-Level Directory -All files are in the same directory Advantages Easy to support and understand Simple Disadvantages When no of files increases,all files must have same names
Two-Level Directory Advantages Separate directory for each user Can have the same file name for different user Efficient searching Disadvantage Structure isolated one user from another
Tree-Structured Directories
Tree-Structured Directories (Cont.) Advantages Efficient searching Allows users to create their own subdirectory Users can access files of other users also by specifying pathnames Disadvantages User have to remember long path names Path names 2 types absolute path name-begins at root relative path name-begins from current directory
Acyclic-Graph Directories
General Graph Directory
File System Mounting A file system must be mounted before it can be accessed A unmounted file system is mounted at a mount point (an empty directory) For eg: on UNIX mount point is /home
(a) Existing (b) Unmounted Partition - Triangles represent subtrees of directories
Mount Point
File Sharing 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 file-sharing method
File Sharing – Multiple Users File owner-controls the file,change attributes, grant access Group-subset of users who can access the file User IDs identify users, allowing permissions and protections to be per-user Group IDs allow users to be in groups, permitting group access rights
Remote File Systems Uses networking to allow file system access between systems Manually via programs like FTP Distributed file systems world wide web 1)Client-server model allows clients to mount remote file systems from servers Server can serve multiple clients NFS is standard UNIX client-server file sharing protocol Standard operating system file calls are translated into remote calls 2)Distributed Information Systems (distributed naming services) such as LDAP(lightweight directory access protocol) DNS, NIS(Network Information systems) implement unified access to information needed for remote computing
3)Failure modes Failure in disk,network or hardware If failure in client server system, client should delay its operations until server recovers Store state information(knowledge of current activities and open files) in both client and server,to recover from failure
Protection Information should be safe from Physical damage(reliablility) Improper access(protection) File owner/creator should be able to control: what can be done by whom Controlled access-limiting the type of file access Types of access Read Write Execute Append Delete List
Access Control Access Control list- specifies user name and type of access allowed for each user Each file and directory associated with an access control list Classification of users Owner-creator of file Group-set of users sharing the file Universe-all other users
Other protection methods Password for each file Disadvantage User has to remember many passwords If only one password for all files,once its is discovered, all files become accessible So password is associated with subdirectory(directory protection)
File-System Structure File system resides on secondary storage (disks) -provides user interface to storage, mapping logical to physical Provides efficient and convenient access to disk by allowing data to be stored, located retrieved easily Disk provides in-place rewrite and random access I/O transfers performed in blocks of sectors (usually 512 bytes) File system is composed of different levels I/O control consists of device drivers Basic file system issues commands to device drivers to read and write physical blocks File organisation module knows about files-type of allocation,location of file etc Logical file system manages the metadata
Layered File System
File-System Implementation Structures and operations used to implement file system operations Boot control block contains info needed by system to boot OS from that volume Needed if volume contains OS, usually first block of volume Volume control block (superblock, master file table) contains volume details Total no of blocks, no. of free blocks, block size, free block pointers or array Directory structure organizes the files Per-file File Control Block (FCB) contains many details about the file permissions, size, dates
A Typical File Control Block
Partitions and Mounting A disk can be sliced into multiple partitions Partition can be raw(contains no file system) or cooked(contains file system) Root partition contains the OS, other partitions can hold other OSes, other file systems, or be raw Mounted at boot time Other partitions can mount automatically or manually
Virtual File System VFS is an abstraction layer on top of the concrete file system It allows client applications to access different types of file systems in a uniform way
Schematic View of Virtual File System
Directory Implementation Linear list of file names with pointer to the data blocks Simple to program Time-consuming to execute Linear search time Could keep ordered alphabetically via linked list or use B+ tree Hash Table – linear list with hash data structure Decreases directory search time Collisions – situations where two file names hash to the same location Only good if entries are fixed size
Allocation Methods - Contiguous An allocation method refers to how disk blocks are allocated for files: Contiguous allocation – each file occupies set of contiguous blocks Best performance in most cases Simple – only starting location (block no) and length (number of blocks) are required Problems include finding space for file, knowing file size, external fragmentation, need for compaction
Contiguous Allocation of Disk Space
Allocation Methods - Linked Linked allocation – each file a linked list of blocks File ends at nil pointer No external fragmentation Each block contains pointer to next block No compaction, external fragmentation
Linked Allocation
Variation of linked allocation-using FAT A section of disk contains the FAT FAT has one entry for each disk block Directory entry contains block number of the first block of the file. Entry indexed by that block number contains block number of next block in file. This continues until last block which contains a special eof value
Allocation Methods - Indexed Indexed allocation Each file has its own index block(s) of pointers to its data blocks Logical view index table
Example of Indexed Allocation
Size of index block Linked scheme-for large files we can link together several index blocks Multilevel index-first level index block points to second level index block, which points to the file blocks Combined scheme-Say,first 12 pointers point to direct blocks( containing addres of blocks containing data files),next three points to indirect blocks
Free Space Management File system maintains free-space list to track available blocks/clusters Bit vector or bit map (n blocks) For eg:consider a disk where blocks 2,3,4,5,8,9,10,11,12,13,17,18,25,26 and 27 are free.The free space bit map would be 001111001111110001100000011100000….
Linked list Another method is to link together all the free disk blocks keeping a pointer to the first free block in a special location in disk
Grouping Store addresses of n free blocks in the first free block.The last block contains addresses of another n free block and so on.. Counting Store address of the first free block and number n of free contiguos blocks that follow in the first block