1 / 85

Operating Systems

Operating Systems. 软件学院 高海昌 hchgao@xidian.edu.cn. Contents. 1. Introduction ** 2. Processes and Threads ***** ** 3. Deadlocks ** 4. Memory Management ***** 5. Input/Output *** 6. File Systems **** 8. Multiple Processor Systems * 9. Security **. Chapter 6: File Systems.

jbatiste
Download Presentation

Operating Systems

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. Operating Systems 软件学院 高海昌 hchgao@xidian.edu.cn

  2. Contents 1. Introduction ** 2. Processes and Threads ******* 3. Deadlocks ** 4. Memory Management ***** 5. Input/Output *** 6. File Systems **** 8. Multiple Processor Systems * 9. Security **

  3. Chapter 6: File Systems 6.1 Files 6.2 Directories 6.3 File system implementation 6.4 Example file systems

  4. Long-term Information Storage Three essential requirements: • Must be possible to store a large amount of information • Information stored must survive the termination of the process using it • Multiple processes must be able to access the information concurrently The usual solution to all these problems is to store information on disks and other external media in units called files.

  5. File Naming • The extra rules for naming vary somewhat from system to system. • bruce, device, multimedia • 123, urgent!, fig.2-1 • longlongagotherewasawarbetweentthebirdsandthebeasts (<255) • Some file systems distinguish between upper and lower ease letters (UNIX), whereas others do not (MS-DOS). • Many OS support two-part file names, with the two parts separated by a period, as in prog.c. The part following the period is called the file extension.

  6. File Naming Typical file extensions.

  7. File Structure (a) byte sequence (UNIX and Windows) (b) record sequence (80-character punched card) (c) tree (commercial data processing large mainframe computers) • Three kinds of files

  8. File Types • Sort by usage • system files • user files • library files • Sort by data format • source files • object files • executable files • Sort by access control attribution • executable-only files • read-only files • read/write files

  9. File Types (2) • Sort by file logical structure • structured files • unstructured files • Sort by file physical structure • sequential files • linking files • index files

  10. File Types (3) • UNIX and Windows have regular files and directories. UNIX also has character and block special files. • Regular files: contain user information. • Directories: system files for maintaining the structure of the file system. • Character special files: related to I/O. • Block special files: used to model disks. • Regular files are generally either ASCII files or binary files.

  11. File Types (4) (a) An executable file (b) An archive 存档文件

  12. File Types (exercise) In an executable file, the instructions are usually put into the _______ segment. header, text, data, relocation bits, symbol table text

  13. File Access • Sequential access • read all bytes/records from the beginning • cannot jump around, could rewind or back up • convenient when medium was mag tape • Random access • bytes/records read in any order • essential for data base systems

  14. File Attributes Possible file attributes

  15. Create Delete Open Close Read Write Append Seek Get attributes Set Attributes Rename File Operations

  16. An Example Program Using File System Calls (1/2) copyfile abc xyz argc=3, argv[0]=“copyfile”, argv[1]=“abc”, argv[2]=“xyz”

  17. An Example Program Using File System Calls (2/2)

  18. Memory-Mapped Files (a) Segmented process before mapping files into its address space (b) Process after mapping existing file abc into one segment creating new segment for xyz Access file as above is inconvenient. Map files into the address space of a running process.

  19. Chapter 6: File Systems 6.1 Files 6.2 Directories 6.3 File system implementation 6.4 Example file systems

  20. Single-Level Directory Systems • A single level directory system • contains 4 files • owned by 3 different people, A, B, and C • Problem: different users may accidently use the same names for their files.

  21. Two-level Directory Systems Letters indicate owners of the directories and files open (“x”) open (“nancy/x”) Problem: it is not satisfactory for users with a large number of files.

  22. Hierarchical Directory Systems A hierarchical directory system (a tree of directories)

  23. Path Names A UNIX directory tree • Absolute path name • /usr/ast/mailbox (UNIX) • \usr\ast\mailbox (Win) • Relative path name • mailbox • Working directory ( current directory) • /usr/ast • . , ..

  24. Create Delete Opendir Closedir Readdir Rename Link (hard link/symbol link) Unlink Directory Operations

  25. Exercise • In the file system shown in the following figure, rectangle represents directory, circle represents file, “/” represents the delimiter(分隔符)in the path name which represents the root directory when placed on the head of path name. In the figure (1) . If the present directory is ‘D1’, process A opens the ‘f1’ by the two ways listed blow: ① fd1=open(“(2) /f1”, O_RDONLY) ② fd1=open(“/D1/W1/f1”, O_RDONLY) • ① is more efficient than ②, the reason is (3) :

  26. Exercise • (1)A. f2 in subdirectory W2 is the same as the f2 in subdirectory D2 B. f2 in subdirectory W2 is different from the f2 in subdirectory D2 C. f2 in subdirectory W2 and f2 in subdirectory D2 may be same and may be different D. tree-shaped file system didn’t allow appear the file with same name • (2)A. /D1/W1 B. D1/W1 C. W1 D. f1 • (3)A. ① can directly access the f1 in the root directory B. ① can access the f1 started from searching the present directory C. To get f1, ① needs only one time to access disk, but ② needs 2 times D. To get f1, ① needs only one time to access disk, but ② needs 3 times C. W1

  27. Lesson 2 Operating Systems

  28. Chapter 6: File Systems 6.1 Files 6.2 Directories 6.3 File system implementation 6.4 Example file systems

  29. File System layout 布局 • File system are stored on disk. • Most disks can be divided up into one or more partitions, with independent file systems on each partition. • Sector 0 of the disk is called MBR (Master Boot Record) and is used to boot the computer.

  30. File System layout A possible file system layout Partition table: gives the starting and ending addresses of each partition. Boot block: locate the active partition Superblock: magic number, number of blocks, … Free space mgmt: free blocks in the form of bitmap or a list of pointers. i-nodes: an array of data structure, one per file.

  31. Implementing Files various methods are used in different systems • Contiguous allocation • Linked list allocation • Linked list allocation using a table in memory • i-nodes

  32. Implementing Files (a) Contiguous allocation of disk space for 7 files (b) State of the disk after files D and E have been removed Ad: simple to implement; read performance is excellent. Dis: in time, the disk becomes fragmented. Contiguous allocation is feasible in CD-ROM file system.

  33. Implementing Files (2) Storing a file as a linked list of disk blocks Dis: random access is extremely slow.

  34. Implementing Files (3) Linked list allocation using a file allocation table in RAM Dis: entire table must be in memory all the time to make it work. Such a table in main memory is called a FAT (File Allocation Table)

  35. Implementing Files (4) An example i-node Associate with each file a data structure called an i-node (index-node), which lists the attributes and disk addresses of the file’s blocks. Ad: i-node need only be in memory when the corresponding file is open.

  36. Implementing Directories • The main function of the directory system is to map the ASCII name of the file onto the information needed to locate the data. • Where the attributes should be stored? • Store them directly in the directory entry. • For systems that use i-nodes, store the attributes in the i-nodes.

  37. Implementing Directories (2) (a) A simple directory, fixed size entries, disk addresses and attributes in directory entry (Windows) (b) Directory in which each entry just refers to an i-node (UNIX)

  38. Implementing Directories (3) • So far we have assumed that files have short, fixed-length names. • However, nearly all modern OS support longer, variable-length file names. How can these be implemented? • Simplest way: set a limit on file name length (255), and use one of the designs above for each file name. (Waste) • Second, give up the same size. Each dir entry contains a fixed portion, followed by the actual file name, however long it may be. - dis: when a file is removed, a variable-sized gap is introduced into the dir into which the next file to be entered may not fit. • Third, make the dir entries themselves all fixed length and keep the file names together in a heap at the end of the dir.

  39. Implementing Directories (4) (a) In-line (b) In a heap • Two ways of handling long file names in directory

  40. Shared Files File system containing a shared file

  41. Shared Files (2) • If dir really do contain disk address, then a copy of the disk address will have to be made in B’s dir when the file is linked. • If either B or C subsequently appends to the file, the new blocks will be listed only in the dir of the user doing the append. • Problem can be solved in two ways: • Disk blocks are not listed in dir, but in a little data structure associated with the file itself (i-node in UNIX). • B links to C’s files by having the system create a new file, of type LINK, and entering that file in B’s dir. The new file contains just the path name of the file to which it is linked. (symbolic linking)

  42. Shared Files (3) (a) Situation prior to linking (b) After the link is created (c)After the original owner removes the file

  43. Shared Files (4) • Drawbacks of first solution: • If C tries to remove a file, OS removes the file and clears the i-node, B will have a dir entry pointing to an invalid i-node. If the i-node is later reassigned to another file, B’s link will point to the wrong file. • The system can see from the count in the i-node that the file is still in use, but there is no way for it to find all the dir entries for the file, in order to erase them. • The problem with symbolic links is the extra overhead required. • Drawbacks for both: programs that start at a given dir and find all the files in that dir and its subdir will locate a linked file multiple times.

  44. Disk Space Management • Two general strategies are possible for storing an n byte file: • n consecutive bytes of disk space are allocated • or the file is split up into a number of blocks. • Nearly all file systems chop files up into fixed-size blocks that need not be adjacent.

  45. Block size • The solid curve gives data rate of a disk. (data rate 数据速率 goes up with block size) • The dashed curve gives disk space efficiency. (With small blocks that are powers of two and 2-KB files, no space is wasted in a block) • All files are 2KB. Block size

  46. Keeping track of free blocks (a) Storing the free list on a linked list (b) A bit map Bitmap requires less space, since it uses 1 bit per block, VS 32 bits in the linked list model.

  47. Lesson 3 Operating Systems

  48. Disk Space Management (4) (a) Almost-full block of pointers to free disk blocks in RAM - three blocks of pointers on disk (b) Result of freeing a 3-block file (c) Alternative strategy for handling 3 free blocks - shaded entries are pointers to free disk blocks When the block of pointers is almost empty, a series of short-lived temporary files can cause a lot of disk I/O.

  49. Disk Quotas 磁盘配额 Quotas for keeping track of each user’s disk use

  50. File System Reliability • Backups is very important • It is usually desirable to back up only specific dir and everything in them rather than the entire file system. • Incremental dumps 增量转储 • It may be desirable to compress the data before writing them to tape, but a single bad spot on the backup tape can foil the decompression algorithm and make an entire file unreadable. • It is difficult to perform a backup on an active file system. Making rapid snapshots of the file system state by copying critical data structures. • Backup tapes should be kept off-site.

More Related