Access Methods File store information When it is used it is accessed & read into memory Some systems provide only one access method IBM support many access methods Choosing right one for a particular application
Access Methods Sequential Access read next write next reset no read after last write (rewrite) Direct Access read n write n position to n read next write next rewrite n n = relative block number
Sequential-access File Simplest access method Information accessed- one record after the other Common method – ex: editors & compilers Bulk of operations in file is read & write Read – reads the next portion of the file & advances file pointer Write – appends the end of the file & advances to the newly written material Beginning – reset Forward & backward n records – skip Sequential access is based on the tape model of a file
Sequential-access File
Simulation of Sequential Access on a Direct-access File
Direct Access (relative access) file – fixed length, logical records (allow programs to read & write rapidly), no particular order Random access to any file block Based on disk model of a file File is viewed as a numbered sequence of blocks / records No restrictions – read 24, read 54, write 5 Block number provided by user to OS is normally a relative block number It is an index relative to index of a file Relative blocks – 0,1,… / 1,……….. Use – allows OS to decide where the file should be placed &helps users from accessing file part that is not a part of it Logical record length – L request for record – N turns to I/O request for L bytes starting from location L*(N-1) within the file Logical records are of fixed size – easy to read, write & delete a record
Other access methods They can built on the top of the direct access method Involve the construction of index for a file Contains pointers for various blocks Find a record in a file – search the index – use the pointer to access the file directly – find the desired record Ex: retail price file Large files – index file will be large to be to kept in memory Solution – create an index for the indexed file Primary index file contain pointers to secondary index file which would point actual data item Ex: IBM’s indexed sequential access method (ISAM) uses small master index for secondary index Find a item: binary search in master index for finding the block number in secondary index – block is read – again binary search to find the block containing the desired record – block is searched sequentially Any records can be accessed by this two direct access reads
Example of Index and Relative Files
Directory Structure A collection of nodes containing information about all files F 1 F 2 F 3 F 4 F n Directory Files Both the directory structure and the files reside on disk Backups of these two structures are kept on tapes
The file systems of computer can be extensive Store – millions of files (TB), manage – organize Organization – 2 parts: Disk split into 1/more partitions – minidisks Partition – low level structure – files & directories reside Partition contains information about files in it Information is kept in device directory / volume table of contents Device dir – records name, location, size, type Directory – symbol table – translates file name into directories Insert, delete, search, list all entries
A Typical File-system Organization
Operations Performed on Directory Search for a file – dir struct – entry for a file Create a file – new file created & added to dir Delete a file –no longer needed remove from directory List a directory- list all the files Rename a file – changing the name Traverse the file system – checking the entire directory
Organize the Directory (Logically) to Obtain 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, …)
Single-Level Directory A single directory for all users Naming problem Grouping problem
Two-Level Directory Separate directory for each user Path name Can have the same file name for different user Efficient searching No grouping capability
Tree-Structured Directories
Tree-Structured Directories (Cont) Efficient searching Grouping Capability Current directory (working directory) cd /spell/mail/prog type list
Tree-Structured Directories (Cont) Absolute or relative path name Creating a new file is done in current directory Delete a file rm Creating a new subdirectory is done in current directory mkdir Example: if in current directory /mail mkdir count mail progcopyprtexpcount Deleting “mail” deleting the entire subtree rooted by “mail”
Acyclic-Graph Directories Have shared subdirectories and files
Acyclic-Graph Directories (Cont.) Two different names (aliasing) If dict deletes list dangling pointer Solutions: Backpointers, so we can delete all pointers Variable size records a problem Backpointers using a daisy chain organization Entry-hold-count solution New directory entry type Link – another name (pointer) to an existing file Resolve the link – follow pointer to locate the file
General Graph Directory
General Graph Directory (Cont.) How do we guarantee no cycles? Allow only links to file not subdirectories Garbage collection Every time a new link is added use a cycle detection algorithm to determine whether it is OK