chapter 6 file systems file systems
play

Chapter 6: File Systems File systems Files Directories & - PowerPoint PPT Presentation

Chapter 6: File Systems File systems Files Directories & naming File system implementation Example file systems Chapter 6 CMPS 111, UC Santa Cruz 2 Long-term information storage Must store large amounts of data


  1. Chapter 6: File Systems

  2. File systems � Files � Directories & naming � File system implementation � Example file systems Chapter 6 CMPS 111, UC Santa Cruz 2

  3. Long-term information storage � Must store large amounts of data � Gigabytes -> terabytes -> petabytes � Stored information must survive the termination of the process using it � Lifetime can be seconds to years � Must have some way of finding it! � Multiple processes must be able to access the information concurrently Chapter 6 CMPS 111, UC Santa Cruz 3

  4. Naming files � Important to be able to find files after they’re created � Every file has at least one name � Name can be � Human-accessible: “foo.c”, “my photo”, “Go Slugs!” � Machine-usable: 4502, 33481 � Case may or may not matter � Depends on the file system � Name may include information about the file’s contents � Certainly does for the user (the name should make it easy to figure out what’s in it!) � Computer may use part of the name to determine the file type Chapter 6 CMPS 111, UC Santa Cruz 4

  5. Typical file extensions Chapter 6 CMPS 111, UC Santa Cruz 5

  6. File structures 1 record 1 byte 12A 101 111 sab wm cm avg ejw sab elm br Sequence of bytes Sequence of records S02 F01 W02 Tree Chapter 6 CMPS 111, UC Santa Cruz 6

  7. File types Executable file Archive Chapter 6 CMPS 111, UC Santa Cruz 7

  8. Accessing a file � Sequential access � Read all bytes/records from the beginning � Cannot jump around � May rewind or back up, however � Convenient when medium was magnetic tape � Often useful when whole file is needed � Random access � Bytes (or records) read in any order � Essential for database systems � Read can be … � Move file marker (seek), then read or … � Read and then move file marker Chapter 6 CMPS 111, UC Santa Cruz 8

  9. File attributes Chapter 6 CMPS 111, UC Santa Cruz 9

  10. File operations � Create: make a new file � Append: like write, but only at the end of the file � Delete: remove an existing file � Seek: move the “current” pointer elsewhere in the file � Open: prepare a file to be accessed � Get attributes: retrieve attribute information � Close: indicate that a file is no longer being accessed � Set attributes: modify attribute information � Read: get data from a file � Rename: change a file’s � Write: put data to a file name Chapter 6 CMPS 111, UC Santa Cruz 10

  11. Using file system calls Chapter 6 CMPS 111, UC Santa Cruz 11

  12. Using file system calls, continued Chapter 6 CMPS 111, UC Santa Cruz 12

  13. Memory-mapped files Program Program text text abc Data Data xyz Before mapping After mapping � Segmented process before mapping files into its address space � Process after mapping � Existing file abc into one segment � Creating new segment for xyz Chapter 6 CMPS 111, UC Santa Cruz 13

  14. More on memory-mapped files � Memory-mapped files are a convenient abstraction � Example: string search in a large file can be done just as with memory! � Let the OS do the buffering (reads & writes) in the virtual memory system � Some issues come up… � How long is the file? � Easy if read-only � Difficult if writes allowed: what if a write is past the end of file? � What happens if the file is shared: when do changes appear to other processes? � When are writes flushed out to disk? � Clearly, easier to memory map read-only files… Chapter 6 CMPS 111, UC Santa Cruz 14

  15. Directories � Naming is nice, but limited � Humans like to group things together for convenience � File systems allow this to be done with directories (sometimes called folders ) � Grouping makes it easier to � Find files in the first place: remember the enclosing directories for the file � Locate related files (or just determine which files are related) Chapter 6 CMPS 111, UC Santa Cruz 15

  16. Single-level directory systems Root directory A A B C foo bar baz blah � One directory in the file system � Example directory � Contains 4 files ( foo , bar , baz , blah ) � owned by 3 different people: A, B, and C (owners shown in red) � Problem: what if user B wants to create a file called foo ? Chapter 6 CMPS 111, UC Santa Cruz 16

  17. Two-level directory system Root directory A B C A A B B C C C foo bar foo baz bar foo blah � Solves naming problem: each user has her own directory � Multiple users can use the same file name � By default, users access files in their own directories � Extension: allow users to access files in others’ directories Chapter 6 CMPS 111, UC Santa Cruz 17

  18. Hierarchical directory system Root directory A B C B B C C C A A A foo Papers bar foo blah Papers foo Photos A A A B B os.tex sunset Family foo.tex foo.ps A A A sunset kids Mom Chapter 6 CMPS 111, UC Santa Cruz 18

  19. Unix directory tree Chapter 6 CMPS 111, UC Santa Cruz 19

  20. Operations on directories � Create: make a new � Readdir: read a directory directory entry � Delete: remove a directory � Rename: change the name (usually must be empty) of a directory � Similar to renaming a file � Opendir: open a directory to � Link: create a new entry in allow searching it a directory to link to an � Closedir: close a directory existing file (done searching) � Unlink: remove an entry in a directory � Remove the file if this is the last link to this file Chapter 6 CMPS 111, UC Santa Cruz 20

  21. File system implementation issues � How are disks divided up into file systems? � How does the file system allocate blocks to files? � How does the file system manage free space? � How are directories handled? � How can the file system improve… � Performance? � Reliability? Chapter 6 CMPS 111, UC Santa Cruz 21

  22. Carving up the disk Entire disk Partition table Master Partition 1 Partition 2 Partition 3 Partition 4 boot record Boot Super Free space Index Files & directories block block management nodes Chapter 6 CMPS 111, UC Santa Cruz 22

  23. Contiguous allocation for file blocks A B C D E F A Free C Free E F � Contiguous allocation requires all blocks of a file to be consecutive on disk � Problem: deleting files leaves “holes” � Similar to memory allocation issues � Compacting the disk can be a very slow procedure… Chapter 6 CMPS 111, UC Santa Cruz 23

  24. Contiguous allocation 0 1 2 3 Data in each file is stored in � consecutive blocks on disk Simple & efficient indexing � � Starting location (block #) on disk ( s ta r t ) 4 5 6 7 � Length of the file in blocks ( lengt h ) Random access well-supported � Difficult to grow files � � Must pre-allocate all needed space 8 9 10 11 � Wasteful of storage if file isn’t using all of the space Logical to physical mapping is easy � b locknum = ( pos / 1024 ) + s ta r t ; o f f se t_ i n_b lock = pos % 1024 ; Start=5 Length=2902 Chapter 6 CMPS 111, UC Santa Cruz 24

  25. Linked allocation 0 1 2 3 � File is a linked list of disk 4 6 blocks � Blocks may be scattered around the disk drive 4 5 6 7 � Block contains both pointer x x to next block and data � Files may be as long as needed 8 9 10 11 � New blocks are allocated as 0 needed � Linked into list of blocks in file Start=9 Start=3 � Removed from list (bitmap) End=4 End=6 of free blocks Length=2902 Length=1500 Chapter 6 CMPS 111, UC Santa Cruz 25

  26. Finding blocks with linked allocation � Directory structure is simple � Starting address looked up from directory � Directory only keeps track of first block (not others) � No wasted space - all blocks can be used � Random access is difficult: must always start at first block! � Logical to physical mapping is done by block = start; offset_in_block = pos % 1020; for (j = 0; j < pos / 1020; j++) { block = block->next; } � Assumes that next pointer is stored at end of block � May require a long time for seek to random location in file Chapter 6 CMPS 111, UC Santa Cruz 26

  27. Linked allocation using a RAM-based table 0 4 � Links on disk are slow 1 -1 � Keep linked list in memory 2 -1 3 -2 � Advantage: faster 4 -2 � Disadvantages 5 -1 � Have to copy it to disk at 6 3 B some point 7 -1 � Have to keep in-memory and 8 -1 on-disk copy consistent 9 0 A 10 -1 11 -1 12 -1 13 -1 14 -1 15 -1 Chapter 6 CMPS 111, UC Santa Cruz 27

  28. Using a block index for allocation � Store file block addresses in Name index size an array grades 4 4802 � Array itself is stored in a disk block 0 1 2 3 � Directory has a pointer to this disk block � Non-existent blocks indicated 6 by -1 4 5 6 7 9 � Random access easy 7 � Limit on file size? 0 8 8 9 10 11 Chapter 6 CMPS 111, UC Santa Cruz 28

Recommend


More recommend