Chapter 6: File SystemsFile systemsLong-term information storageNaming filesTypical file extensionsFile structuresFile typesAccessing a fileFile attributesFile operationsUsing file system callsUsing file system calls, continuedMemory-mapped filesMore on memory-mapped filesDirectoriesSingle-level directory systemsTwo-level directory systemHierarchical directory systemUnix directory treeOperations on directoriesFile system implementation issuesCarving up the diskContiguous allocation for file blocksContiguous allocationLinked allocationFinding blocks with linked allocationLinked allocation using a RAM-based tableUsing a block index for allocationFinding blocks with indexed allocationLarger files with indexed allocationTwo-level indexed allocationBlock allocation with extentsManaging free space: bit vectorManaging free space: linked listIssues with free space managementWhat’s in a directory?Directory structureHandling long file names in a directorySharing filesSolution: use linksManaging disk spaceDisk quotasBacking up a file systemBitmaps used in a file system dumpChecking the file system for consistencyFile system cacheFile block cache data structuresGrouping data on diskLog-structured file systemsUnix Fast File System indexing schemeMore on Unix FFSDirectories in FFSCD-ROM file systemDirectory entry in MS-DOSMS-DOS File Allocation TableWindows 98 directory entry & file nameStoring a long name in Windows 98Chapter 6: File SystemsChapter 62CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)File systemsFilesDirectories & namingFile system implementationExample file systemsChapter 63CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)Long-term information storageMust store large amounts of dataGigabytes -> terabytes -> petabytesStored information must survive the termination of the process using itLifetime can be seconds to yearsMust have some way of finding it!Multiple processes must be able to access the information concurrentlyChapter 64CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)Naming filesImportant to be able to find files after they’re createdEvery file has at least one nameName can beHuman-accessible: “foo.c”, “my photo”, “Go Panthers!”, “Go Banana Slugs!”Machine-usable: 4502, 33481Case may or may not matterDepends on the file systemName may include information about the file’s contentsCertainly does for the user (the name should make it easy to figure out what’s in it!)Computer may use part of the name to determine the file typeChapter 65CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)Typical file extensionsChapter 66CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)File structuresSequence of bytes Sequence of records1 byte1 record12A 101 111sab wm cm avg ejw sab elm brS02 F01 W02TreeChapter 67CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)File typesExecutablefileArchiveChapter 68CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)Accessing a fileSequential accessRead all bytes/records from the beginningCannot jump aroundMay rewind or back up, howeverConvenient when medium was magnetic tapeOften useful when whole file is neededRandom accessBytes (or records) read in any orderEssential for database systemsRead can be …Move file marker (seek), then read or …Read and then move file markerChapter 69CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)File attributesChapter 610CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)File operationsCreate: make a new fileDelete: remove an existing fileOpen: prepare a file to be accessedClose: indicate that a file is no longer being accessedRead: get data from a fileWrite: put data to a fileAppend: like write, but only at the end of the fileSeek: move the “current” pointer elsewhere in the fileGet attributes: retrieve attribute informationSet attributes: modify attribute informationRename: change a file’s nameChapter 611CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)Using file system callsChapter 612CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)Using file system calls, continuedChapter 613CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)Memory-mapped filesSegmented process before mapping files into its address spaceProcess after mapping Existing file abc into one segment Creating new segment for xyzProgramtextDataBefore mappingProgramtextDataAfter mappingabcxyzChapter 614CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)More on memory-mapped filesMemory-mapped files are a convenient abstractionExample: string search in a large file can be done just as with memory!Let the OS do the buffering (reads & writes) in the virtual memory systemSome issues come up…How long is the file?Easy if read-onlyDifficult if writes allowed: what if a write is past the end of file?What happens if the file is shared: when do changes appear to other processes?When are writes flushed out to disk?Clearly, easier to memory map read-only files…Chapter 615CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)DirectoriesNaming is nice, but limitedHumans like to group things together for convenienceFile systems allow this to be done with directories (sometimes called folders)Grouping makes it easier toFind files in the first place: remember the enclosing directories for the fileLocate related files (or just determine which files are related)Chapter 616CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)Single-level directory systemsOne directory in the file systemExample directoryContains 4 files (foo, bar, baz, blah)owned by 3 different people: A, B, and C (owners shown in red)Problem: what if user B wants to create a file called foo?RootdirectoryAfooAbarBbazCblahChapter 617CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt)Two-level directory systemSolves naming problem: each user has her own directoryMultiple users can use the same file
View Full Document