CS241 System ProgrammingFile System (I)ContentAdministrative AnnouncementsWhy Files?File System RequirementsWhat Makes File-systems Hard?File System ComponentsFile ConceptsFile AttributesFile StructuresFile Structures TodayFile TypesSome DefinitionsKinds of MetadataContent of InodeInode Attributes (Unix Example)The UNIX V7 File System(UNIX i-node)Directories in UnixEffects of CorruptionData Structures for A Typical File SystemFile OperationsOpening A FileInformation in per-process file descriptor tableSystem-wide Open-file Table InformationRelation between fd, open file table and i-node table (UNIX Example)Reading And WritingReading A BlockFile Usage PatternsSummaryCS241 System ProgrammingFile System (I)Klara NahrstedtLecture 203/3/20063/3/2006CS 241, System Programming, Klara Nahrstedt2ContentzAdministrative announcementsz File systems basic concepts–Concept of File–File System ComponentszSummary3/3/2006CS 241, System Programming, Klara Nahrstedt3Administrative AnnouncementszMidterm March 9, 2006 : 7-7:50pmz Students with Last Name A-K will go to 1404SCz Students with Last Name L-Z will go to 1320 DCLz No Discussion Sections during the week of March 6-10, 2006z No Class on Wednesday, March 8, 2006z Optional Midterm Material Review on Wednesday, March 8, 11-11:50am3/3/2006CS 241, System Programming, Klara Nahrstedt4Why Files?zFile system model–Byte oriented–Named files–Users protected from each other–Robust to machine failureszPhysical reality–Block oriented–Physical sector #s–No protection among users of the system–Data might be corrupted if machine crashes3/3/2006CS 241, System Programming, Klara Nahrstedt5File System RequirementszUsers must be able to: –create, modify, and delete files at will. –read, write, and modify file contents with a minimum of fuss about blocking, buffering, etc. –share each other's files with proper authorization –transfer information between files. –refer to files by symbolic names. –retrieve backup copies of files lost through accident or malicious destruction. –see a logical view of their files without concern for how they are stored.3/3/2006CS 241, System Programming, Klara Nahrstedt6What Makes File-systems Hard?z Files grow and shrink in piecesz Little a priori knowledgez 6 orders of magnitude in file sizesz Overcoming disk performance behavior z Desire for efficiencyz Coping with failure3/3/2006CS 241, System Programming, Klara Nahrstedt7File System ComponentszDisk management–Arrange collection of disk blocks into fileszNaming–User gives file name, not track or sector number, to locate datazSecurity–Keep information securezReliability/durability–When system crashes, lose stuff in memory, but want files to be durableUserFileNamingFileaccessDiskmanagementDiskdrivers3/3/2006CS 241, System Programming, Klara Nahrstedt8File Concepts zFiles z Directory structures z Partitions (possible) z File Concept: OS abstracts from the physical properties of its storage device to define a logical storage unit, called file. Files are mapped by the OS onto physical devices.3/3/2006CS 241, System Programming, Klara Nahrstedt9File AttributeszName: symbolic file name, the only information kept in human-readable form. Many OS support two part file names (name.extension) – File.bak (ackup file); file.pdf (pdf file); file jpg (still picture in JPEG format)– Some OS do not enforce extensions (e.g., UNIX), so do (e.g., Windows, MAC OS)zType: needed for systems that support different types. – Regular files - user information, regular files are generally either ASCII or binary files. – Directories - system files for maintaining the structure of the file system – Character special files - related to input/output and used to model serial I/O devices such as terminals, printers, and networks – Block special files - used to model disks zLocation: pointer to a device and to the location of the file on that device. zSize: current size and maximal possible size zProtection: Access-control information. zTime, date, user identification: creation time, last modification, last use.3/3/2006CS 241, System Programming, Klara Nahrstedt10File StructureszByte sequence–Read or write a number of bytes–Unstructured or linearzRecord sequence–Fixed or variable length–Read or write a number of recordszTree–Records with keys–Read, insert, delete a record (typically using B-tree)3/3/2006CS 241, System Programming, Klara Nahrstedt11File Structures TodayzStream of bytes–Simplest to implement in kernel–Easy to manipulate in other forms–Little performance losszMore complicated structures–Hardware-assisted structures fell out of favor–Special-purpose hardware slower, costly3/3/2006CS 241, System Programming, Klara Nahrstedt12File TypeszRegular Files and Directories (in UNIX and Windows)zCharacter-special files (for terminals and other character-based devices)zBlock-based files (for disks and other block-based devices)zExample : A Unix executable file–header: magic number, sizes, entry point, flags–Text (code)–Data–relocation bits–symbol table3/3/2006CS 241, System Programming, Klara Nahrstedt13Some DefinitionszFile descriptor (fd) –an integer used to represent a file – easier than using nameszMetadata –data about data - bookkeeping data used to eventually access the “real” datazOpen file table–system-wide list of descriptors in use3/3/2006CS 241, System Programming, Klara Nahrstedt14Kinds of MetadatazIn UNIX/LINUX –inode – index node, or a specific set of information kept about each file (used in UNIX, LINUX)zTwo forms – on disk and in memory–Directory – names and location information for files and subdirectorieszNote: stored in files in Unix–Superblock – contains information to describe the file system, disk layout–Information about free blocks/inodes on diskzWindows –Master File Table (MFT) in each volume of the NT File System (Windows); each MFT entry zDescribes one file or directoryzContains file attributes (name, time-stamps, list of disk addresses where blocks are located)3/3/2006CS 241, System Programming, Klara Nahrstedt15Content of InodezDisk inode:–File type, size, blocks on disk–Owner, group, permissions (r/w/x)–Reference count–Times: creation, last access, last mod–Inode generation number–Other file attributesz128 bytes on classic Unix3/3/2006CS 241, System Programming, Klara Nahrstedt16Inode Attributes (Unix Example)3/3/2006CS 241, System Programming, Klara
View Full Document