Unix文件类型.ppt_第1页
Unix文件类型.ppt_第2页
Unix文件类型.ppt_第3页
Unix文件类型.ppt_第4页
Unix文件类型.ppt_第5页
已阅读5页,还剩40页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、MODERN OPERATING SYSTEMSThird EditionANDREW S. TANENBAUMChapter 4File Systems,Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639,Essential requirements for long-term information storage: It must be possible to store a very large amount of informat

2、ion. The information must survive the termination of the process using it. Multiple processes must be able to access the information concurrently.,File Systems (1),Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639,Think of a disk as a linear sequ

3、ence of fixed-size blocks and supporting reading and writing of blocks. Questions that quickly arise: How do you find information? How do you keep one user from reading anothers data? How do you know which blocks are free?,File Systems (2),Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-H

4、all, Inc. All rights reserved. 0-13-6006639,files,Processes (threads), address spaces, files are the most important concepts in OS Files are logical units of information created by processes Similar to kind of address space File system Manage files: how they are structured, named, accessed, used, pr

5、otected, implemented, etc,File naming,Files are abstraction mechanism To store information on the disk and read it back When a process creates a file, it gives the file a name; and the file can be accessed by the name Two-part file name File extension: indicating characteristics of file In Unix, fil

6、e extension is just convention In windows, file extensions specify which program “owns” that extension; when double clicking, program assigned to it is launched,Figure 4-1. Some typical file extensions.,File Naming,Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights rese

7、rved. 0-13-6006639,Figure 4-2. Three kinds of files. (a) Byte sequence. (b) Record sequence. (c) Tree.,File Structure,Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639,File Types,Regular Files: ASCII files or binary files ASCII consists of lines

8、of text; can be displayed and printed Binary, have some internal structure known to programs that use them Directory Files to keep track of files Character special files Related to I/O and model serial I/O devices Block special files Mainly to model disks,Unix文件类型,普通文件: 数据是文本还是二进制对Unix而言并无区别;对普通文件内容

9、的解释由处理该文件的应用程序进行 目录文件 包含其他文件的名字以及指向这些文件有关信息的指针 块特殊文件 提供对设备带缓冲的访问 字符特殊文件 所有设别要么是字符特殊文件,要么是块特殊文件,中的文件类型宏,S_ISREG() 普通文件 S_ISDIR() 目录文件 S_ISCHR() 字符特殊文件 S_ISBLK() 块特殊文件,Figure 4-3. (a) An executable file. (b) An archive.,File Types,Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. A

10、ll rights reserved. 0-13-6006639,Figure 4-4a. Some possible file attributes.,File Attributes,Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639,Struct stat,Struct stat mode_t st_mode; / file type and mode (permission) ino_t st_ino; /inode number d

11、ev_t st_dev; /file system dev_tst_rdev; /device number (special) nlink_tst_nlink; /number of links uid_tst_uid; / user ID of owner gid_tst_gid; / group ID of owner off_tst_size; /size in bytes time_tst_atime; /time of last access ,File attributes,drwxr-xr-x 2 root root 4096 Sep 24 2008 Unit2 drwxr-x

12、r-x 2 root root 4096 May 26 19:21 a -rwxr-xr-x 1 root root 10930 Aug 5 22:49 a.out -rwxrwx-T 1 root root 81 Aug 2 2008 a.txt -rwxr-x- 1 root root 81 May 26 19:20 b.txt -rwx- 1 root root 81 Jul 30 19:28 c.txt -rwxr-xr-x 1 root root 11193 Jul 30 19:27 cp,各种许可权限的含义是什么?,File Owner,Group Owner,Everyone E

13、lse,Write Permission,Read Permission,Execute Permission,chmod,u表示该档案的拥有者,g表示与该档案的拥有者属于同一个群体(group)者,o表示其他以外的人,a表示这三者皆是 +表示增加权限、-表示取消权限、=表示唯一设定权限。 r表示可读取,w表示可写入,x表示可执行 Chmod g+rx filename,File Owner,Group Owner,Everyone Else,UNIX 绝对文件权限模式,Chmod:使用数字表示权限,chmodabcfile 其中a,b,c各为一个数字,分别表示User、Group、及Othe

14、r的权限 r=4,w=2,x=1 chmoda=rwxfile chmod777file chmodug=rwx,o=xfile chmod771file chmod4755filename可使此程序具有root的权限,The most common system calls relating to files:,File Operations,Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639,Append Seek Get Attrib

15、utes Set Attributes Rename,Create Delete Open Close Read Write,Figure 4-5. A simple program to copy a file.,Example Program Using File System Calls (1),Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639,. . .,Figure 4-5. A simple program to copy a

16、 file.,Example Program Using File System Calls (2),Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639,Figure 4-6. A single-level directory system containing four files.,Hierarchical Directory Systems (1),Tanenbaum, Modern Operating Systems 3 e, (c

17、) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639,Single-level directory system: The simpliest,Figure 4-7. A hierarchical directory system.,Hierarchical Directory Systems (2),Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639,Figure 4-8

18、. A UNIX directory tree.,Path Names,Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639,Path names,Absolute path name Start from root and are unique Relative path name Current working set: all path names not beginning at the root directory are take

19、n relative to the working directory If current working directory is /usr/ast: then cp /usr/ast/mailbox /usr/ast/mailbox.bak Is: cp mailbox mailbox.bak,Path names,Special Entries: “.” and “.” Dot refers to the current directory; dotdot refers to the parent directory (except root) cp /usr/lib/dictiona

20、ry . cp /usr/lib/dictionary dictionary Cp /usr/lib/dictionary /usr/ast/dictionary,System calls for managing directories:,Directory Operations,Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639,Readdir Rename Link Unlink,Create Delete Opendir Close

21、dir,Directory operation,Hard link Linking allows a file to appear in more than one directory; increments the counter in the files i-node Symbolic link A name is created pointing to a tiny file naming another file,File System Implementation,Users: How files are names, what operations are allowed on t

22、hem, what the directory tree looks like Implementors How files and directories are stored, how disk space is managed and how to make every thing work efficiently and reliably,File System Layout,File system are stored on disks. Most disks are divided up into several partitions Sector 0 is called MBR

23、(master boot record), to boot the computer BIOS reads in and executes MBR, MBR locates the active partition, reads in the boot block, and execute The boot block reads in the OS contained in the partition,Figure 4-9. A possible file system layout.,File System Layout,Tanenbaum, Modern Operating System

24、s 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639,Superblock: contains all the key parameters about a file system; read into memory the booted or the FS is used,Figure 4-10. (a) Contiguous allocation of disk space for 7 files. (b) The state of the disk after files D and F have be

25、en removed.,Contiguous Allocation,Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639,Contiguous Allocation,Advantage: Simple to implement; to record the first block and length Easy to read; only one seek is needed Disadvantage: Fragmentation,Conti

26、guous allocation,One way to eliminate holes in contiguous allocation is to compact the disk every time a file is moved. In this case, copying a file requires a seek and rotational delay, followed by transfer. If seek time is 5ms, rotational delay is 4ms, transfer rate is 8MB/sec, average file size i

27、f 8KB, how long is it to compact half of a 16-GB disk?,Figure 4-11. Storing a file as a linked list of disk blocks.,Linked List Allocation,Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639,Linked list allocation,To keep each file as a linked list

28、 of disk blocks Advantage Only internal fragmentation Disadvantage Random access is difficult Adding a pointer at the head of block; extra overhead while coping,Figure 4-12. Linked list allocation using a file allocation table in main memory.,Linked List Allocation Using a Table in Memory,Tanenbaum,

29、 Modern Operating Systems 3 e, (c) 2008 Prentice-Hall, Inc. All rights reserved. 0-13-6006639,Linked List Allocation Using a Table in Memory,FAT-File Allocation Table Advantage Can take use of the whole block Random access is easy only to store the starting block number Disadvantage To keep the enti

30、re table in memory Cant scale well,?,From MS-DOS to Windows FAT-12, FAT 16, FAT 32 For FAT-12 with 512 bytes blocks, what is the maximum partition size? What is the table size? For FAT-16 with 4KB? In Win95, FAT32 was adopted. Internally, the system tracks sectors of 512 bytes using 32-bit number,Figure 4-32. Maximum partition size for different block siz

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论