CS241 System Programming File 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/200601/14/19 CS 241, System Programming, Klara Nahrstedt2ContentAdministrative announcementsFile systems basic concepts–Concept of File–File System ComponentsSummary01/14/19 CS 241, System Programming, Klara Nahrstedt3Administrative AnnouncementsMidterm March 9, 2006 : 7-7:50pm Students with Last Name A-K will go to 1404 SCStudents with Last Name L-Z will go to 1320 DCLNo Discussion Sections during the week of March 6-10, 2006No Class on Wednesday, March 8, 2006Optional Midterm Material Review on Wednesday, March 8, 11-11:50am01/14/19 CS 241, System Programming, Klara Nahrstedt4Why Files?Physical reality–Block oriented–Physical sector #s–No protection among users of the system–Data might be corrupted if machine crashesFile system model–Byte oriented–Named files–Users protected from each other–Robust to machine failures01/14/19 CS 241, System Programming, Klara Nahrstedt5File System RequirementsUsers 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.01/14/19 CS 241, System Programming, Klara Nahrstedt6What Makes File-systems Hard?Files grow and shrink in piecesLittle a priori knowledge6 orders of magnitude in file sizesOvercoming disk performance behavior Desire for efficiencyCoping with failure01/14/19 CS 241, System Programming, Klara Nahrstedt7File System ComponentsDisk management–Arrange collection of disk blocks into filesNaming–User gives file name, not track or sector number, to locate dataSecurity–Keep information secureReliability/durability–When system crashes, lose stuff in memory, but want files to be durableUserFileNamingFileaccessDiskmanagementDiskdrivers01/14/19 CS 241, System Programming, Klara Nahrstedt8File Concepts Files Directory structures Partitions (possible) 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.01/14/19 CS 241, System Programming, Klara Nahrstedt9File AttributesName: 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)Type: 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 Location: pointer to a device and to the location of the file on that device. Size: current size and maximal possible size Protection: Access-control information. Time, date, user identification: creation time, last modification, last use.01/14/19 CS 241, System Programming, Klara Nahrstedt10File StructuresByte sequence–Read or write a number of bytes–Unstructured or linearRecord sequence–Fixed or variable length–Read or write a number of recordsTree–Records with keys–Read, insert, delete a record (typically using B-tree)01/14/19 CS 241, System Programming, Klara Nahrstedt11File Structures TodayStream of bytes–Simplest to implement in kernel–Easy to manipulate in other forms–Little performance lossMore complicated structures–Hardware-assisted structures fell out of favor–Special-purpose hardware slower, costly01/14/19 CS 241, System Programming, Klara Nahrstedt12File TypesRegular Files and Directories (in UNIX and Windows)Character-special files (for terminals and other character-based devices)Block-based files (for disks and other block-based devices)Example : A Unix executable file–header: magic number, sizes, entry point, flags–Text (code)–Data–relocation bits–symbol table01/14/19 CS 241, System Programming, Klara Nahrstedt13Some DefinitionsFile descriptor (fd) –an integer used to represent a file – easier than using namesMetadata –data about data - bookkeeping data used to eventually access the “real” dataOpen file table –system-wide list of descriptors in use01/14/19 CS 241, System Programming, Klara Nahrstedt14Kinds of MetadataIn UNIX/LINUX –inode – index node, or a specific set of information kept about each file (used in UNIX, LINUX)Two forms – on disk and in memory–Directory – names and location information for files and subdirectoriesNote: stored in files in Unix–Superblock – contains information to describe the file system, disk layout–Information about free blocks/inodes on diskWindows –Master File Table (MFT) in each volume of the NT File System (Windows); each MFT entry Describes one file or directoryContains file attributes (name, time-stamps, list of disk addresses where blocks are located)01/14/19 CS 241, System Programming, Klara Nahrstedt15Content of InodeDisk 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 attributes128 bytes on classic Unix01/14/19 CS 241, System
View Full Document