25
SUBJECT:- Operating System TOPICS:- File Management Chapter-7 1

SUBJECT:-Operating System TOPICS:-File Management

  • Upload
    kerryn

  • View
    43

  • Download
    0

Embed Size (px)

DESCRIPTION

SUBJECT:-Operating System TOPICS:-File Management. From the user’s point of view, one of the most important parts of an operating system is the file system. The file system permits users to create data collections, called files, with desirable properties, such as… - PowerPoint PPT Presentation

Citation preview

Page 1: SUBJECT:-Operating System TOPICS:-File Management

1

SUBJECT:-Operating System

TOPICS:- File Management

Chapter-7

Page 2: SUBJECT:-Operating System TOPICS:-File Management

2

OverviewFrom the user’s point of view, one of the most important parts of an operating system is the file system.The file system permits users to create data collections, called files, with desirable properties, such as…

Long-term existence: Files are stored on disk or other secondary storage and do not disappear when a user logs off.Sharable between processes:-Files have names and can have associated access permission that permit controlled sharing.Structure: Depending on the file system, a file can have an internal structure that is convenient for particular applications. In addition, files can be organized into hierarchical or more complex structure to reflect the relationship among file

Page 3: SUBJECT:-Operating System TOPICS:-File Management

3

File Attributes Name:- User can refer file by its name. A name is

usually a string of characters such as “a.cpp Identifier: This unique item usually in the form of number identifies the file within the file system. It is non-human-readable name for the file.  Type:-This attributes gives the types of file. File can of

different types such as bmp file, text file, word file, excel file, etc.

Location:-This information stores the pointer to location of file on particular device. It generally located the first byte of file.

Size:- The current size of the file either in bytes words, or blocks.

Protection:- Access control information gives the permission for reading, writing, and executing file for different user.  Time, date and user identification:- This

attributes stores the information about the file creation date and time, last modification date and time, user name that has created file, and so on.

Page 4: SUBJECT:-Operating System TOPICS:-File Management

4

File OperationsCreating a file:- Two steps are necessary to create a file. First, space in the file system must be found for the file. Second, an entry for the new file must be made in the directory. The directory entry records the name of the file, the location in the file system, and other information such as length, date and time.Writing a file: - To write a file we have to make system call. System call specifies name of the file on which we want to write and the information to be written to the file. After giving the name, system searches the directory to find the location of the file. System must keep a write pointer to location where the next write is to take place. The write pointer must point to next location when one write operation has been completed.

Page 5: SUBJECT:-Operating System TOPICS:-File Management

5

File OperationsReading a file:-Reading from file operation is generally similar to the write operation. To read from a file, we have to make system call. System call specifies name of the file that we want to read. After giving the name, system searches the directory to find the location of the file. System must keep the read pointer to location where the next read is to take place. The read pointer must point to the next location when one read operation has been completed. In some computer system for read and write operation only one pointer is used that is current-file-position pointer. This saves the space and complexity. 

Page 6: SUBJECT:-Operating System TOPICS:-File Management

6

File OperationsRepositioning with in file:-This operation repositions current-file-position pointer in same file system. It doesn’t involve any I/O operation. 

Deleting a file:-To delete a file, we search the directory for the particular file. After finding desired file, all file space is release so that can be reused by other files. Also the entry for that file is erased from the directory structure. 

Truncating a file:-Sometimes user doesn’t want to delete the file but he erases all the content of the file so the file entry remains as it is in the file system. There is no any change in file attributes except the length of the file. File length becomes zero and the space used by file is released.

Page 7: SUBJECT:-Operating System TOPICS:-File Management

7

File Structure Four terms are in common use when discussing files:

1.Field

2.Record

3.File

4.Database

A field is the basic element of data.

A record is a collection of related fields.

A file is collection of similar records.

The database itself consists of one or more types of files.

Page 8: SUBJECT:-Operating System TOPICS:-File Management

8

Files-Naming The exact rules depends based on the OS

However most of them allows files to be :

1-8 characters

Digits & several selected symbols

Modern ones support up to 255 charactersExample

Osslide,osslide-1 etc.

Some file systems are case sensitive

Dos, Windows : -case insensitive

UNIX, Linux : -case sensitive

ManyOs ssupport two-part filesystemsParts are separated by a period(.)

Example:<filename>.<extension>Test.txt,1.pdf,nature.jpeg

Page 9: SUBJECT:-Operating System TOPICS:-File Management

9

File Organization And Access

We know that disk surface is divided into the tracks, tracks are divided into sector. On the sector data is stored in fixed sized block. This one block is known as the physical record. Here all the blocks are same sized.

Operating system writes the file on the disk that is known as logical record. Logical record size should be match with the physical record size. But logical records may even vary in length. Packing a number of logical records into physical blocks is a common solution to this problem. This packing can be done by user application program or by operating system.

Page 10: SUBJECT:-Operating System TOPICS:-File Management

10

Access Method/Organization

File stores information. When it is used, this information must be accessed and read into computer memory. The information in the file can be accessed in several ways.

Sequential access Direct access The Pile Indexing access method:

Page 11: SUBJECT:-Operating System TOPICS:-File Management

11

Sequential Access It is the simplest access method. Information

in the file is processed in order, one record after the other. It is most common access method

Sequential access is based on tape model of file.

In sequential access read operations reads the next portion of the file and automatically increment the file pointer to the next position. Similarly, a write operation appends to the end of the file and set the end-of-file pointer to the next position.

Read or writeRewind

Current Position

Beginning End

Sequential Access of File

Page 12: SUBJECT:-Operating System TOPICS:-File Management

12

Direct Access or Hashed File File is made up of fixed length logical records. File consist sequence of blocks or records.

In direct access method any block to be read or write. Thus first we can read block 14, then block 53, then block 7, and so on.

There is no restriction on the order of reading or writing for a direct access file.

This method is based on disk model of file.

Page 13: SUBJECT:-Operating System TOPICS:-File Management

13

The PileThe Least complicated form of file organization may be termed as pile.Data are collected in the order in which they arrive. Each record consists of one burst of data.The purpose of pile is simply to accumulate the mass of data and save it.Record may have different fields, or similar fields in different orders, each fields should self-describing, including a field name as well as value

Page 14: SUBJECT:-Operating System TOPICS:-File Management

14

Indexing Access Method In this method operating system create index for the file.

This index is like the index given in back of book.

Index contains the pointer to the various blocks. To find the particular record in the file, first search the index, and then use that index pointer to access the record from file.

Page 15: SUBJECT:-Operating System TOPICS:-File Management

15

Example of indexing access method For example student records file stores the roll number as index for particular student record. Each student record has roll number having 5 digits maximum (5 bytes), name having maximum 30 characters (30 bytes), address having maximum 200 characters (200 bytes), and course having maximum 30 characters (30 bytes). So total size of one student record is 265 bytes. If our disk contains record for the 2000 students then total bytes occupied by the student records are 5,30,000 bytes. To find the particular record we search for the index (that means roll number). From this index we would know exactly which block contains the desired record and access that block. These index files are generally sorted on the basis of index so we can search particular index key by binary search algorithm.

Page 16: SUBJECT:-Operating System TOPICS:-File Management

16

ExampleRoll Number

(Index)

Logical record number

101

102

…………..

Index File

102 Mahesh Ahmedabad BCA

Data file

Indexing a file

Page 17: SUBJECT:-Operating System TOPICS:-File Management

17

Directory or Disk OrganizationSome system stores millions of files on terabytes of disk. To manage all these files we have to organize the files. This organization is usually performed in two parts. First disk is divided into the multiple parts known as partition, minidisk, volume, or virtual disk.  Each partition contains information about files within it. This information is kept in entries in device directory or volume table of contents or directory. It stores name, location, size, and type for all files on that partition.  

Page 18: SUBJECT:-Operating System TOPICS:-File Management

18

Directory OperationSearch for the file:- To find the entry for the particular file we have to search the directory. All files have symbolic name for searching we have to find out the particular symbol name. Add the file into directory:- New file is created and that file is added to directory.  Delete the file from directory:- When the file is no longer needed, we want to remove it from the directory. Copying a file from one directory to another directory:-When we want the multiple copy of the file, we have to copy the file. We can copy the file into the same directory with different name while we can copy the one file into the different directory with the same name or different name. 

Page 19: SUBJECT:-Operating System TOPICS:-File Management

19

Directory OperationMove file from one directory to another directory:-We can transfer the file from one directory to another directory.  

Display the list of file and other information about file in particular directory:-In directory the different information about the file is stored. Such information is file name, file size, file creation date, file type, etc. When we list a directory the list of all files with its information is displayed on the screen. Back the file of the directory:-We have to make the backup of the files of directory when there is failure of disk. This backup is generally made on magnetic tape or on any other storage device such as floppy, zip floppy, optical disk. When we take backup of directory we are getting the backup of all files within that directory structure.

Page 20: SUBJECT:-Operating System TOPICS:-File Management

20

Directory StructureSingle-level directory structure

Two-level directory structure

Tree-structured (Hierarchical) directory structure

Acyclic graph directory structure

Cyclic graph directory structure

Page 21: SUBJECT:-Operating System TOPICS:-File Management

21

Single level Directory Structure

Single-level directory structure

Root Directory

A B C DDifferent file under root directory

Page 22: SUBJECT:-Operating System TOPICS:-File Management

22

Two Level Directory Structure

Two-level directory structure

User-1 directory

User-2 directory

User-3 directory

MFD

A B CA D Files

Master File Directory

Page 23: SUBJECT:-Operating System TOPICS:-File Management

23

Tree Level Directory Structure

Tree-level directory structure

Root Directory

C

D

User-1 directory

User-2 directory

User-3 directory

A

A

A

Subdirectory Subdirectory-1

Subdirectory-2

Page 24: SUBJECT:-Operating System TOPICS:-File Management

24

Acyclic Graph Directory Structure

A

Acyclic graph directory structure

CA

DA Subdirectory-

1Subdirectory-

2

Sharing

Subdirectory

Root Directory

Sharing

User-1 directory

Sharing

User-3 directoryUser-2 directory

Page 25: SUBJECT:-Operating System TOPICS:-File Management

25

Cyclic Graph Directory Structure

Cycle

Cyclic graph structure

FY

C PCS