Download presentation
Presentation is loading. Please wait.
1
Files Management – The interfacing
The computer applications consists of programs and data. These programs and data must be in the main memory on execution. But when these programs and data are not in use, they will be saved on the secondary memory such as the hard disk, DVD, Flash ,.. etc. The part of the OS that will be responsible for managing the used and unused spaces on these secondary memory, is called the files manager. In this chapter, we will study the followings: The meaning of the file and the methods of naming it. The access methods to the data in these files The structures of the files and the directories How to share the files How to protect the files All these points will be studied from the view of the user, in other words how the users see and use the files. For this reason we call this chapter the interfacing .
2
The file: is a structure that contains information
The file: is a structure that contains information. This information could be any type of data or programs used by the computer system. Each file has a name, and by this name the OS and other processes can deal with that file. File name: The file name is a unique string of characters that identify the file. Most of the operating systems allow the file name to have two parts. The first part is the main name of the file while the second part is the extension of the file. For example, test.java, prg.asm, mesg.doc,...etc. Some OS may allow the file name to be three parts. For example, proc.c.zip. Here the file name is proc and it is of C program type and it is compressed file. The file name may consist of letters , numbers , and special characters, this also depends on the roles of the OS. For example the UNIX recognizes between the upper and lower letters while the WINDOWS not. Also, some OS allow to use different language within the same file name. Figure in slide no. 3 shows different file names types.
3
Examples for Different file names
4
File structure: The structure of the file means how the data is organized within the file. The OS is responsible for how to structure the file and also the operations that implemented on these structures. However, three main types of structures are shown in the figure of slide no. 5. These structures can explained below: Unstructured sequence of bytes : In this type of structures ,the data of the file is organized in just a sequence of bytes without any difference between its parts. It is the responsibility of the application that creates this file to understand the meaning of the contents of the file. Sequence of fixed records: In this type of structures, the file is organized as a sequence of records. And each record consists of fields. The reading and writing operations are done with each record separately. 3) Tree of records: In this type of structures, the file is organized in a tree of variable size records. Each record has a header field called key field. The records in the tree will be arranged according to the key field, that is to make the search operation within the file more easy and more speed.
5
Some types of file structures
6
File Access To use the information stored in the file, we need to bring this information into the main memory. Different methods are used to access the file and deals with it’s contents. Below are some of these methods: Sequential access method Direct access method Indexed access method Sequential access method : This method expresses the simplest way to access the file. The records of the file, in this method can be accessed in sequence from one to the next. For example, if we are in record no. 2 and we want to read record no. 5 then we must move the file pointer from record 2 to 3 to 4 then to 5 and so on. In the same way to write in the file, the pointer is moved in sequence until reaching the end of the file then we add the new data and then the OS defines a new file’s end. Also , in this method the OS can rewind the storage media to return to the beginning of the file. Figure below shows an idea about this method. The tape is typical device that works basing on this method.
7
Direct access method : This method depends on the features of the floppy disk or the hard disk, that works on the principle of the random access. So any record on the disk can be reached directly without the need to move the file pointer in sequence. For example, we can reach from record 6 to record 18 then return to record 2 by moving the read/write head to the locations of these records directly. This access method is more effieceint and faster than the sequence access. The figure below shows a simple structure for the disk storage and how the direct access method is implemented . Surface Truck Sector Read/Write head
8
The indexed access method: In this method, each record in the file has a key. At the same time there is a data structure that contains indexed entries. Each entry consists of a key value and a pointer to the related record .So, when a record is wanted, the OS will search the indexed list according to the key of the record, and then use the pointer to go directly to the record location. Figure below shows the idea behind the indexed access method. .... Record location Key pointer1 Key pointer2 Key pointer3 Keyn pointern search
9
Even the indexed access method is more secure since each record has a key that used to deal with the content of that record, but the problem is size of the indexed list that increases proportionally with the size of the file size. So this will cause burden on the main memory. One solution to solve this problem is to build two lists; a small primary indexed list and a secondary indexed list. The OS will search in three levels to find the location of the wanted record as shown in the figure below. At first level, the OS will bring and search within the primary indexed list to find the address of the part (block) in the secondary indexed list. At the second level, the OS will bring and search within this block to find the address ( location) of the block that contains the wanted record ( actual data). At the third level, the OS will bring and search within the data block to find the wanted record. This method is called Indexed Sequential access method
10
File Attributes : The name of the file is not enough to deal with that file, since there are a lot of attributes which accompany the file in addition to it’s name. Generally, the main attributes can be listed as below: File name File pointer ( some times called Identifier) Data about where the file is stored in the secondary memory File size Protection access information Dates and times of creation and updating the file We must mention here, that to reach to the different attributes and the contents of the file, some OS work as the figure shown below: . File name pointer (Id number) Data Structure containing the attributes Directory structure Location of the file on the secondary storage
11
File operations: The OS offers many operations on the files, such as :
Create a file Open a file Delete a file Read a file Write a file Close a file Seek in a file Append to a file Lock a file others...
12
Directory Structure: the file system may contains millions of files
Directory Structure: the file system may contains millions of files. So, a well organization of these files on the secondary memory must be achieved. The OS does that on two stages. The first stage is to divide the disk into partitions (volumes) . Some OS divide one disk into more than one partition and others allow one than one disk to work as one partition. In the second stage the OS will build a data structure called directory for each partition. This directory contains information ( attributes) such as name, size, location,...etc about the files that stored in the related partition. The figure below shows a typical example for the organization of the disks as partitions.
13
Types of Directory Structures
As we said the directory is used to organize and manage the file system. The OS offers many operations that can be used with the structure of the directory. For example , add an entry for a file when that file is created , delete an entry of a file when that file is deleted , searching for an entry of a file, and so on. Regardless of the operations on the directories, there are different ways to design these directories, below is a list for the important types of the directory structures: Single level directory structure Two level directory structure Tree structured directory Acyclic directory structure
14
Single level directory structure: This type of structures is the simplest one. It
is just a set of entries as shown in the figure below. Each entry belongs to a file and contains the file name , the attributes and the addresses of the file locations on the secondary memory. The disadvantage of this structure is the repetition of the file names. For example two users give their files the same name. Another example, when one user likes to give the same name for two files.
15
Two level directory structure: In this structure there are two levels
Two level directory structure: In this structure there are two levels. The first level which is called the Master File Directory This directory will contain set of entries, where each entry represents one user and has a pointer to a directory in the second level. In the second level, there are a directory dedicated for each user which is called User File Directory. So, the OS needs to know the file and it’s owner, So it can find that file by searching through the two levels as shown in the figure below.
16
Tree structured directory: This structure is the most common today
Tree structured directory: This structure is the most common today. In this structure, there is main directory called the root directory. And from this root, the user can build his own tree structure which consists of subdirectories and files as shown in the figure below. So, each file has it’s own unique path through the tree.
17
Acyclic directory structure: This structure is an extension of the tree structure. Since this structure allows to share directories and files. The shared file is in fact one real copy. And any changes in the file can be seen by all beneficiary users. Also we can see that the shared file may have more than path through the tree. All these principles can be seen in the figure below.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.