1 / 37

Files

Files. CS 470 - Spring 2002. Overview. Example: FAT File System File Organization File System Organization File Directories and File Sharing Record Blocking Disk space allocation Example: Unix File Systems. Fat Disk Structure. Boot Sector. Reserved Sectors. Other Reserved.

Télécharger la présentation

Files

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Files CS 470 - Spring 2002

  2. Overview • Example: FAT File System • File Organization • File System Organization • File Directories and File Sharing • Record Blocking • Disk space allocation • Example: Unix File Systems

  3. Fat Disk Structure Boot Sector Reserved Sectors Other Reserved Allocation chains and Free List File Allocation Table (FAT) File Allocation Table Copy Redundant Copy Root Directory Fixed size Array of root directory entries File and Directory Area All other directories and files are located here

  4. FAT Boot Sector • Location: First sector of the drive • Contains: • Jump to first level boot code (byte offset 0) • Disk Parameter Block (byte offset 11) which describes the drive • Other identifying information like the volume label (byte offset 43) • First level boot code (typically at offset 0x40)

  5. Geometry BytesPerSector[2] SectorsPerTrack[2] Heads[2] Sectors[2] or LargeSectors[4] Media HiddenSectors[4] Structure Sizes ReservedSectors[2] NumberOfFats SectorsPerFat[2] NbrOfRootEntries[2] SectorsPerCluster Disk Parameter Block Field sizes in bytes are indicated in square brackets

  6. Typedef struct _DIRENT { UCHAR FileName[11]; UCHAR Attributes; UCHAR NtByte; UCHAR CreationCSec; FAT_TIME_STAMP CreationTime; FAT_DATE LastAccessDate; USHORT ExtendedAttributes; FAT_TIME_STAMP LastWriteTime; USHORT FirstClusterOfFile; ULONG FileSize; } DIRENT; FAT Directory Entries

  7. File Allocation Table FAT12 Directory Entry 0xfff 14 8dot3 Name 18 . . . 0 16 First Cluster (15) 0xff7 17 File Size (5a0) 1a 18 0 Dir Entry Bad Cluster 19 FOO BAR 0xfff Free Cluster 1a . . . 1b 14 32f

  8. Fat_Offset to SectorOffset • How to translate FAT tables entries to sector offsets in the disk partition • RootDirSize = NbrRootEntries * sizeof(DIRENT) / SectorSize • FileAreaOffset = NbrReservedSectors + NbrFat*SectorsPerFat + RootDirSize • SectorOffset = FileAreaOffset + (FAT_Offset - 2) * SectorsPerCluster

  9. Long Filename Directory Entry typedef struct _LFN_DIRENT { UCHAR Ordinal; UCHAR Name1[10]; // 5 Unicode chars UCHAR Attributes; // Should be 0x0f UCHAR Type; UCHAR CheckSum; // of 8dot3 name WCHAR Name2[6]; USHORT MustBeZero; WCHAR Name3[2]; } LFN_DIRENT;

  10. DIRENT with LFN Ordinal 0x44 Up to 13 Unicode Chars 3 Characters 26 to 38 All have same Checksum Field 2 Characters 13 to 25 1 First 13 Unicode Chars 8dot3 Name Calculate rotated checksum from this

  11. File Structure CS 470 - Spring 2002 Segment II

  12. File Organization • Vocabulary • Field - basic element of data • Record - collection of related fields • File - collection of similar records • File Organization Choice Criteria • Rapid access • Ease of updates • Economy of storage • Reliability

  13. Some File Types • Pile • Sequential • Indexed Sequential • Indexed • Direct or Hashed

  14. Pile • Variable length records with variable fields • Fields must be self describing • No order to records - exhaustive search Record 1 F1 F2 F3 F5 Record 2 F1 F3 F4 Hdr F4 Data

  15. Sequential File • Fixed length records of fixed format fixed length fields. Distinguished key field. • Records sorted in key field order • Search is typically sequential • Insertions are not easy - so usually accumulated in separate overflow file with periodic update of the master file Record 1 14 F2 F3 F4 F5 Key Record 2 17 F2 F3 F4 F5 24 F2 F3 F4 F5 Record 3 26 F2 F3 F4 F5 Record 4

  16. Indexed Sequential Files • Sequential file with index file and overflow file for updates • Records still in order of key index • Overflow file also accessible through index - Records have Next_Record field which can point into overflow file. • Multiple level so indexing can speed lookups

  17. Indexed Sequential File Key Index 5 Master File 5 9 18 11 35 18 42 35 42 13 Overflow File 38 15

  18. Indexed Files • Index for each searchable field, but each record must have at least one searchable field • Records not sorted, no overflow needed • Allows for variable length fields and records with missing fields • Exhaustive index - one entry per record, versus Partial index - on entry per record containing the indexed field.

  19. Indexed File Indexed File Partial Index Exhaustive Index

  20. Hashed Files • Hashed access with overflow tables to handle collisions • Usually used with fixed length records • Very fast access • No way to sequentially access all records

  21. Hashed File Hashed File 54 Overflow Table 37 8 24 37 87 87 91 23 23 231 43 91 19 14 24 83 14 Pointers calculated via hashing function

  22. File Systems CS 470 - Spring 2002 Segment III

  23. Directories • Contents • Name • File type and organization • Address: Size, location • Access control information • Usage Information - times, current usage • Structure - e.g. directory tree • Operations: Search, Create file, Delete file, and List Directory

  24. File Sharing • Access Rights - Allow various users or groups to share files • Simultaneous Access control - Allow multiple threads to share the same file at the same time

  25. Record Blocking • Three approaches • Fixed Blocking • Variable length records with records restricted to a single block - no spanning • Variable length records which can overlap (span) two blocks • First two may have internal fragmentation • Third is hard to update

  26. Record Blocking Methods Block 1 Rec 1 Rec 2 Rec 3 Rec 4 Rec 5 Rec 6 Block 2 Fragment Block 1 Rec 1 Rec 2 Rec 3 Rec 4 Rec 5 Block 2 Spanning Records Block 1 Rec 1 Rec 2 Rec 3 Rec 4 Rec 4 Rec 5 Rec 6 Rec 6 R7 Block 2

  27. Disk Space Allocation (1 of 2) • Recorded in File Allocation Table • Pre-allocation (at file creation) versus dynamic allocation of space • Allocation size - variable or fixed, large or small, contiguous or not • Allocation Methods • Contiguous - just need address and total size • Chained - pointer to next block • Indexed - index refers to file portions

  28. Allocation Methods Contiguous 3 5 0 1 2 U U 0 1 2 Chained 2 0 1 Indexed 1 2 3 3 4 5

  29. Disk Space Allocation (2 of 2) • Free Space Management (Disk Allocation Table) • Bit maps of Free Blocks • Chained Free Portions • Index of Free Portions • Reliability Problems • Caused by improper shutdown when File and Disk allocation tables kept in memory • Locking is often too expensive

  30. Free List Management Free Allocated Bit Map 0 1 1 1 0 0 1 0 1 1 1 1 14 205 42 Chained Free 2 51 52 Indexed 1 32 3 432 433 434

  31. Unix File System CS 470 - Spring 2002 Segment IV

  32. Classic Unix File System Disk Drive Main Memory Superblock Superblock Inode Table Free Inode List Files and Directories Free Block List File Table Inode Table Buffer Cache

  33. V6 Unix Inode Entries • i_mode - type (dir, char or block special, or ordinary) and file permissions • i_nlink - number of names (hard links) • i_uid, i_gid - user and group owners • i_size0, i_size1 - size of file in bytes • i_ addr[8] - location of file on disk • i_atime, i_mtime - access and modification times

  34. Classic V7 Unix Inode File location part of inode Inode Rest of inode 10 Direct Block Nbrs Block number of Triple Indirect Block 256 More Block Nbrs Single Indirect Block Double Indirect Block 256 More Indirect Block Nbrs 256 Block Nbrs 255 More of these

  35. Unix File Allocation Limits Level Nbr of Blks Nbr of Bytes Direct 10 10 KB Single Indirect 256 256 KB Double Indirect 256 x 256 64 MB = 64 K Triple Indirect 256 x 64 K 16 GB = 16 M

  36. Classic Unix Free Lists Superblock Free Block List 255 Free Block Nbrs One per disk Partition 255 Free Block Nbrs One per disk Partition Superblock Free Disk Inode List

  37. Summary • File Organization • File System Organization • File Directories • File Sharing • Record Blocking • Disk space allocation • Examples: Unix and FAT File Systems

More Related