CS241 System Programming File System IIContentDirectoryDirectory ContentsSingle Level DirectoryProblems With Single Level DirectoryTwo-level DirectorySlide 8Tree Structured DirectoriesSlide 10Acyclic Graph Structured DirectoriesAcyclic Graph Structured DirectoriesGeneral Graph Structured DirectoriesSlide 14UNIX File System Structure (Example)Path NamesLooking up absolute path nameThe UNIX V7 File SystemDirectory OperationsUNIX Directory EntryUNIX Directory ExampleHard Links and Symbolic LinksHard Link ExampleSymbolic Link ExampleSummaryCS241 System ProgrammingFile System IIKlara NahrstedtLecture 213/10/200601/14/19 CS 241 - System Programming, Klara Nahrstedt2Content File systems basic conceptsSummary01/14/19 CS 241 - System Programming, Klara Nahrstedt3DirectoryTo keep track we need –Directories –FoldersDirectory is a file containing correspondence between filenames and file locations01/14/19 CS 241 - System Programming, Klara Nahrstedt4Directory Contentsfile name symbolic namefile type indicates format of filelocation device and locationsizeprotectioncreation, access, and modification dateowner identification01/14/19 CS 241 - System Programming, Klara Nahrstedt5Single Level Directory01/14/19 CS 241 - System Programming, Klara Nahrstedt6Problems With Single Level Directorymore than one userlarge file systems moving files from one system to anothername clashesmodularity01/14/19 CS 241 - System Programming, Klara Nahrstedt7Two-level Directoryintroduced to remove naming problems between usersfirst level contains list of user directoriessecond level contains user filessystem files kept in separate directory or level 1sharing accomplished by naming other users files01/14/19 CS 241 - System Programming, Klara Nahrstedt8Two-level Directory01/14/19 CS 241 - System Programming, Klara Nahrstedt9Tree Structured Directoriesarbitrary depth of directoriesleaf nodes are filesinterior nodes are directoriespath name lists nodes to traverse to find nodeuse absolute paths from rootuse relative paths from current working directory pointer01/14/19 CS 241 - System Programming, Klara Nahrstedt10Tree Structured Directories01/14/19 CS 241 - System Programming, Klara Nahrstedt11Acyclic Graph Structured DirectoriesAcyclic graphs allow sharingtwo users can name same fileimplementation by links - use logical names of files (file system and file)implementation by symbolic links maps pathname into a new pathnameduplicate paths complicate backup copiesneed reference counts for hard links01/14/19 CS 241 - System Programming, Klara Nahrstedt12Acyclic Graph Structured Directories01/14/19 CS 241 - System Programming, Klara Nahrstedt13General Graph Structured Directoriescyclesmore flexiblemore costlyneed garbage collection (circular structures)must prevent infinite searches01/14/19 CS 241 - System Programming, Klara Nahrstedt14General Graph Structured Directories01/14/19 CS 241 - System Programming, Klara Nahrstedt15UNIX File System Structure (Example)dev etchome optusrvarSpecial filesFor devicesSpecificsFor systemUserdirectoriesApplicationpackagesSharable filesVarying Files(e.g. logs)01/14/19 CS 241 - System Programming, Klara Nahrstedt16Path NamesAbsolute names:•/usr/ast/mailbox•Unique•Start from rootRelative names:•Working/current directory • mailboxExamples:•cp /usr/lib/dictionary .•cp ../lib/dictionary .01/14/19 CS 241 - System Programming, Klara Nahrstedt17Looking up absolute path nameLookup absolute path name /usr/ast/file;System –Locate the root directory –Lookup string ‘usr’ in the root directory, get i-node of the /usr directory–Fetch i-node of /usr and extract disk blocks –Search for the string ‘ast’ in /usr, once the entry is found, the i-node number for /usr/ast directory is taken from it–Read i-node of /user/ast and extract directory blocks–Lookup ‘file’ and find i-node of ‘file’Conclusion: use of a relative path name is not only more convenient, but also saves a substantial amount of work for the system!!!01/14/19 CS 241 - System Programming, Klara Nahrstedt18The UNIX V7 File System The steps in looking up /usr/ast/mbox01/14/19 CS 241 - System Programming, Klara Nahrstedt19Directory Operations1. Create•Direction creation•Empty except . And ..2. Delete•Only empty directory can be deleted in some systems•Directory with . And .. Is considered empty3. Opendir•This program opens the directory to list all files in the directory•Before a directory can be read, it must be opened, analogous to opening and reading a file4. Closedir•When a directory has been read, it should be closed to free up internal table space5. Readdir•Returns the next entry in the open directory6. Rename•Rename directory just like any other file7. Link•Linking is a technique that allows a file to appear in more than one directory•Creates a link between an existing file and the name specified by the path•Link of this kind is called ‘hard link’•Each file which has links pointed to it, includes a reference counter in its i-node to keep track of the number of directory entries containing the file8. Unlink•If the file being unlinked is only present in one directory, it is removed from the file system•If the file is present in multiple directories, only the path name specified is removed.01/14/19 CS 241 - System Programming, Klara Nahrstedt20UNIX Directory Entry A UNIX V7 directory entry01/14/19 CS 241 - System Programming, Klara Nahrstedt21UNIX Directory Example 12345 Name 1inode nameDirectory entry in /dirAInode 1234523567“This is the text in the File.”Block 2356701/14/19 CS 241 - System Programming, Klara Nahrstedt22Hard Links and Symbolic LinksA file may be accessed through multiple paths–Such linking between multiple names is known as link (also known as hard link)UNIX allows users to make a new directory entry that points to an existing file4.3 BSD also supported symbolic links, which are files containing the path name of another file or directory–Soft (symbolic) links, unlike hard links, could point to directories and could cross file-system boundaries01/14/19 CS 241 - System Programming, Klara Nahrstedt23Hard Link ExampleGrand Parent directoryFile inode 12345This is the Text in theFile. 23567Block 2356712345 Name 1Directory entry in /dirADirectory entry in /dirB12345Name 201/14/19 CS 241 - System Programming, Klara
View Full Document