Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Slide 17Slide 18Slide 19Slide 20Slide 21Slide 22Slide 23Slide 24Slide 25Slide 26Slide 27Slide 28Slide 29Slide 30Slide 31Slide 32Slide 33Slide 3415-410, S’04- 1 -File System (Interface)Mar. 29, 2004Dave EckhardtDave EckhardtBruce MaggsBruce MaggsL25_Filesystem15-410“...RADIX-50??...”15-410, S’04- 1 -SynchronizationCheckpoint 3Checkpoint 3Due midnight tonightSummary – “Where are you now, where will you be”Details – announce bboardTodayTodayChapter 11, File system interfaceOk to skip: remote/distributed (11.5.2!!)Don't forget about Chapter 13Don't forget about Chapter 13Reviewing might help demystify readline() someDon't forget about reading schedule on web siteDon't forget about reading schedule on web site15-410, S’04- 1 -SynchronizationTwo interesting papers about disksTwo interesting papers about diskshttp://www.seagate.com/content/docs/pdf/whitepaper/D2c_More_than_Interface_ATA_vs_SCSI_042003.pdfGoogle for “200 ways to revive a hard drive”15-410, S’04- 1 -What's a file?Abstraction of Abstraction of persistent storagepersistent storageHide details of storage devicessector addressing: CHS vs. LBASCSI vs. IDEHide details of allocation/location on a storage deviceLogicalLogical grouping of data grouping of dataMay be physically scatteredPrograms, dataPrograms, dataSome internal structureSome internal structure15-410, S’04- 1 -Typical file attributesName – 14? 8.3? 255?Name – 14? 8.3? 255?Unicode? ASCII? 6-bit? RADIX-50?Identifier - “file number”Identifier - “file number”Type (or not)Type (or not)Location – device, block listLocation – device, block listSize – real or otherwiseSize – real or otherwiseProtection – Who can do what?Protection – Who can do what?Time, date, last modifier – monitoring, curiousityTime, date, last modifier – monitoring, curiousity15-410, S’04- 1 -“Extended” file attributesBSD UnixBSD Unixarchivednodumpappend-only (by user/by operating system)immutable (by user/by operating system)MacOSMacOSicon color15-410, S’04- 1 -Operations on FilesCreate – locate space, enter into directoryCreate – locate space, enter into directoryWrite, Read – according to position pointer/cursorWrite, Read – according to position pointer/cursorSeek – adjust position pointerSeek – adjust position pointerDelete – remove from directory, release spaceDelete – remove from directory, release spaceTruncateTruncateTrim data from endOften all of itAppend, RenameAppend, Rename15-410, S’04- 1 -Open-file StateExpensive to specify name for each read()/write()Expensive to specify name for each read()/write()String-based operationDirectory look-up““Open-file” structure storesOpen-file” structure storesFile-system / partitionFile-system-relative file numberRead vs. writeCursor position15-410, S’04- 1 -Open files (Unix Model)““In-core”In-core” file state file stateMirror of on-disk structureFile number, size, permissions, modification time, ...Housekeeping infoBack pointer to enclosing file systemPointer to disk device hosting the fileWho holds locks on ranges of fileHow to access file (vector of methods)Pointer to file's type-specific dataSharedShared when file is opened multiple times when file is opened multiple times15-410, S’04- 1 -Open files (Unix Model)““Open file”Open file” state (result of one open() call) state (result of one open() call)Access mode (read vs. write, auto-append, ...)Credentials of process (when it opened the file)Cursor positionPointer to underlying “open file”SharedShared by multiple processes by multiple processes“copied” by fork()inherited across exec()15-410, S’04- 1 -Exampleint fd1, fd2, fd3;off_t pos2, pos3;char buf[10];fd1 = open(“foo.c”, O_RDONLY, 0);fd2 = dup(fd1);fd3 = open(“foo.c”, O_RDONLY, 0);read(fd1, &buf, sizeof (buf));pos2 = lseek(fd2, 0L, SEEK_CUR);/*10*/pos3 = lseek(fd3, 0L, SEEK_CUR);/*0*/15-410, S’04- 1 -“Open File” vs. “In-Core File”Processfd1: 3fd2: 4fd3: 5012345vnode #334readers 2writers 0ttyp5rows: 24cols: 80r/or/wPos 10Pos 015-410, S’04- 1 -File types (or not)GoalGoalAvoid printing a binary executable fileFind program which “understands” a fileFilter file namesFilter file names*.exe are executable, *.c are CTag fileTag fileMacOS: 4-byte type, 4-byte creatorUnix: Both/neither – Leave it (mostly) up to usersUnix: Both/neither – Leave it (mostly) up to users15-410, S’04- 1 -File StructureWhat's What's inin a file? a file?Stream of bytes?What character set? US-ASCII? Roman-1? Unicode?Stream of records?Array of records? Tree of records?Record structure?Record structure?End of “line”CR, LF, CR+LFFixed-length? Varying? Bounded?15-410, S’04- 1 -File Structure - UnixOS OS needs to knowneeds to know about executables about executables“Magic numbers” in first two bytesobsolete A.OUT types - OMAGIC, NMAGIC, ZMAGICELF#! - scriptOtherwise, Otherwise, array of bytesarray of bytesUser/application remembers meaning (hopefully!)For a good time,For a good time,Try the “file” commandRead /usr/share/magicMarvel at the dedication of the masses15-410, S’04- 1 -File Structure – MacOSData forkData forkArray of bytesApplication-dependent structureResource forkResource forkTable of resourcesIcon, Menu, Window, Dialog boxMany resources are widely used & understoodDesktop program displays icons from resource fork15-410, S’04- 1 -Access MethodsProvided by OS or optional program libraryProvided by OS or optional program librarySequentialSequentialLike a taperead() next, write() next, rewind()Sometimes: skip forward/backwardDirect/relativeDirect/relativeArray of fixed-size recordsRead/write any record, by #15-410, S’04- 1 -Access Methods – IndexedFile contains File contains recordsrecordsRecords contain Records contain keyskeysIndexIndex maps keys maps keys records recordsSort data portion by keyBinary search in multi-level listFancy extensionsFancy extensionsMultiple keys, multiple indicesAre we having a database yet?Unix equivalent: dbm/ndbm/gdbm/bdb/...15-410, S’04- 1 -Directory
View Full Document