Linux MetadataWhere is Metadata Stored?Metadata in the FileMetadata in the DirectoryCrash RecoveryCrash RecoveryRepairing DamageLog-Structured File SystemsModern DisksThe Unix FilesystemThe Unix FilesystemFrom the ProcessDirectoriesFinding a File. and ..I-NodesWhat's in an I-Node?Disk Blocks in the I-NodeMultiple Layers of IndirectionFile OperationsOpening a FileCreating a FileReading a FileWriting a FileSeekClosing a FileLinking to a FileUnlinking a FileUpdating MetadataCreating DirectoriesDeleting DirectoriesRenamingI've Glossed Over StuffFile System LayoutComponents of a File SystemBoot Record and SuperblockThe I-ListData AreaThe Windows FAT File SystemThe Windows FAT File SystemFile Allocation TableSupporting Long NamesDump/RestoreDumping a DiskDump StrategiesMapping a FilesystemDumping a FilesystemLinux MetadataLinux MetadataWhere is MetadataStored?Metadata in the FileMetadata in theDirectoryCrash RecoveryThe Unix FilesystemFile OperationsFile System LayoutThe Windows FATFile SystemDump/Restore1 / 42struct stat {dev_t st_dev; /* device */ino_t st_ino; /* inode */mode_t st_mode; /* protection */nlink_t st_nlink; /* number of hard linksuid_t st_uid; /* user ID of owner */gid_t st_gid; /* group ID of owner */dev_t st_rdev; /* device type (if inodeoff_t st_size; /* total size, in bytesblksize_t st_blksize; /* blocksize for filesystemblkcnt_t st_blocks; /* number of blocks allocatedtime_t st_atime; /* time of last accesstime_t st_mtime; /* time of last modificationtime_t st_ctime; /* time of last status};Where is Metadata Stored?Linux MetadataWhere is MetadataStored?Metadata in the FileMetadata in theDirectoryCrash RecoveryThe Unix FilesystemFile OperationsFile System LayoutThe Windows FATFile SystemDump/Restore2 / 42■ In the file?■ In the directory entry?■ Elsewhere?■ Split?Metadata in the FileLinux MetadataWhere is MetadataStored?Metadata in the FileMetadata in theDirectoryCrash RecoveryThe Unix FilesystemFile OperationsFile System LayoutThe Windows FATFile SystemDump/Restore3 / 42■ (Sort of) done by Apple: resource and dataforks■ Not very portable — when you copy the fileto/from other systems, what happens to themetadata?■ No standardized metadata exchange formatMetadata in the DirectoryLinux MetadataWhere is MetadataStored?Metadata in the FileMetadata in theDirectoryCrash RecoveryThe Unix FilesystemFile OperationsFile System LayoutThe Windows FATFile SystemDump/Restore4 / 42■ Speeds access to metadata■ Makes hard links difficult — need to keepcopies of the metadata synchronized■ Makes directories larger; often, one doesn’tneed the metadata■ Many newer systems keep at least a few bits ofmetadata in the directory, notably file type —knowing if something is or isn’t a directoryspeeds up tree walks considerablyCrash RecoveryLinux MetadataWhere is MetadataStored?Metadata in the FileMetadata in theDirectoryCrash RecoveryCrash RecoveryRepairing DamageLog-Structured FileSystemsModern DisksThe Unix FilesystemFile OperationsFile System LayoutThe Windows FATFile SystemDump/Restore5 / 42■ Must ensure that file systems are in aconsistent state after a system crash■ Example: don’t write out directory entrybefore the metadata■ Example: File systems are generally trees, notgraphs; make sure things always pointsomewhere sane■ What if the file has blocks but the freelisthasn’t been updated?■ Principle: order writes to ensure that the diskis always in a safe stateRepairing DamageLinux MetadataWhere is MetadataStored?Metadata in the FileMetadata in theDirectoryCrash RecoveryCrash RecoveryRepairing DamageLog-Structured FileSystemsModern DisksThe Unix FilesystemFile OperationsFile System LayoutThe Windows FATFile SystemDump/Restore6 / 42■ At boot-time, run a consistency checker exceptafter a clean shutdown■ Example: fsck (Unix) and scandisk(Windows)■ Force things to a safe state; move anyallocated but unreferenced blocks and files to arecovery areaLog-Structured File SystemsLinux MetadataWhere is MetadataStored?Metadata in the FileMetadata in theDirectoryCrash RecoveryCrash RecoveryRepairing DamageLog-Structured FileSystemsModern DisksThe Unix FilesystemFile OperationsFile System LayoutThe Windows FATFile SystemDump/Restore7 / 42■ Instead of overwriting data, append thechanges to a journaling area■ The file system is thus always consistent, aslong as writes are properly ordered.■ Hmm — is that a reasonable assumption?Modern DisksLinux MetadataWhere is MetadataStored?Metadata in the FileMetadata in theDirectoryCrash RecoveryCrash RecoveryRepairing DamageLog-Structured FileSystemsModern DisksThe Unix FilesystemFile OperationsFile System LayoutThe Windows FATFile SystemDump/Restore8 / 42■ Modern disks do a lot of buffering■ Cache size on new Seagate drives: 2-16M bytes■ The drive will reorder writes to optimize seektimes■ If a bad block has been relocated, you can’teven predict when seeks will occur; only thedrive knows■ What if the power fails when data is buffered?The Unix FilesystemLinux MetadataWhere is MetadataStored?Metadata in the FileMetadata in theDirectoryCrash RecoveryThe Unix FilesystemThe Unix FilesystemFrom the ProcessDirectoriesFinding a File. and ..I-NodesWhat’s in anI-Node?Disk Blocks in theI-NodeMultiple Layers ofIndirectionFile OperationsFile System LayoutThe Windows FATFile SystemDump/Restore9 / 42The Unix FilesystemLinux MetadataWhere is MetadataStored?Metadata in the FileMetadata in theDirectoryCrash RecoveryThe Unix FilesystemThe Unix FilesystemFrom the ProcessDirectoriesFinding a File. and ..I-NodesWhat’s in anI-Node?Disk Blocks in theI-NodeMultiple Layers ofIndirectionFile OperationsFile System LayoutThe Windows FATFile SystemDump/Restore10 / 42■ Let’s take a high-level look at the Unix filesystem■ Though details differ (a lot) for, say, Windows,at a high level things are pretty similar■ We’ll discuss the actual code paths next time■ Note: all modern operating systems supportmultiple file system types; differences hiddenby abstraction layer.From the ProcessLinux MetadataWhere is MetadataStored?Metadata in the FileMetadata in theDirectoryCrash RecoveryThe Unix FilesystemThe Unix FilesystemFrom the ProcessDirectoriesFinding a File. and ..I-NodesWhat’s in anI-Node?Disk Blocks in theI-NodeMultiple Layers ofIndirectionFile OperationsFile System LayoutThe Windows FATFile SystemDump/Restore11 / 42■ The process has two crucial directoryattributes, the current root and the currentworking
View Full Document