Nothing Special   »   [go: up one dir, main page]

OS Chapter 6

Download as pdf or txt
Download as pdf or txt
You are on page 1of 38

OS Chapter 6: File Management

Chapter Outline


Introduction

Functions of file management

File Attributes

Operations on a file

File Access Methods

Directory Structure

File Protection

Chapter 6 File management 2


Introduction

File management is one of the basic and
important features of operating system.

Operating system is used to manage files
of computer system.

All the files with different extensions are
managed by operating system.

A file is a collection of related information
that is recorded on secondary storage.

Or, a file is a collection of logically related
entities.
Chapter 6 File management 3
Introduction

From the user’s perspective a file is the
smallest allotment of logical secondary
storage.

File management is defined as the
process of manipulating files in computer
system.

Management here includes the process of
creating, modifying and deleting the files.

Chapter 6 File management 4


Functions of File Management
The following are some of the tasks performed
by file management of operating system of any
computer system:

It helps to create new files in computer system
and placing them at the specific locations.

It helps in easily and quickly locating these files
in computer system.

It makes the process of sharing of the files
among different users very easy and user
friendly.

Chapter 6 File management 5


Functions of File Management

It helps to stores the files in separate folders
known as directories. These directories help
users to search file quickly or to manage the
files according to their types or uses.

It helps the user to modify the data of files or to
modify the name of the file in the directories.

Chapter 6 File management 6


File Attributes

What is a File ?

A file can be defined as a data structure which
stores the sequence of records.

Files are stored in a file system, which may
exist on a disk or in the main memory. Files can
be simple (plain text) or complex (specially-
formatted).

The collection of files is known as Directory.

The collection of directories at the different
levels, is known as File System.
Chapter 6 File management 7
File Attributes

Fig: file structure hierarchy

Chapter 6 File management 8


File Attributes

1.Name

Every file carries a name by which the file is
recognized in the file system.

It is the only information which is in human-
readable form.

One directory cannot have two files with the
same name.

Chapter 6 File management 9


File Attributes
2.Identifier

Along with the name, Each File has its own extension
which identifies the type of the file. For example, a text file
has the extension .txt, A video file can have the
extension .mp4.
3.Type

In a File System, the Files are classified in different types
such as video files, audio files, text files, executable files,
etc.

4.Location

In the File System, there are several locations on which,
the files can be stored. Each file carries its location as its
attribute.
Chapter 6 File management 10
File Attributes
5.Size

The Size of the File is one of its most important
attribute. By size of the file, we mean the number of
bytes acquired by the file in the memory.
6.Protection

The Admin of the computer may want the different
protections for the different files. Therefore each file
carries its own set of permissions to the different group
of Users.

7.Time and Date

Every file carries a time stamp which contains the time
and date on which the file is last modified.
Chapter 6 File management 11
Operations on a file

A file is a collection of logically related data that is
recorded on the secondary storage in the form of
sequence of operations.

The content of the files are defined by its creator who
is creating the file.

The various operations which can be implemented on
a file such as read, write, open and close etc. are
called file operations.

These operations are performed by the user by using
the commands provided by the operating system.
Some common operations are as follows:

Chapter 6 File management 12


Operations on a file
1.Create operation:

This operation is used to create a file in the file
system.

It is the most widely used operation performed on the
file system.

To create a new file of a particular type the associated
application program calls the file system.

This file system allocates space to the file. As the file
system knows the format of directory structure, so
entry of this new file is made into the appropriate
directory.
Chapter 6 File management 13
Operations on a file
2. Open operation:

This operation is the common operation performed on
the file.

Once the file is created, it must be opened before
performing the file processing operations.

When the user wants to open a file, it provides a file
name to open the particular file in the file system.

It tells the operating system to invoke the open system
call and passes the file name to the file system.

Chapter 6 File management 14


Operations on a file(a note on sys calls)

A system call is the programmatic way in which a
computer program requests a service from the kernel
of the operating system it is executed on.

A system call is a way for programs to interact with the
operating system.

A computer program makes a system call when it
makes a request to the operating system’s kernel.

System call provides the services of the operating
system to the user programs via Application Program
Interface(API).

Chapter 6 File management 15


Operations on a file(a note on sys calls)
Services Provided by System Calls are listed here:

Process creation and management

Main memory management

File Access, Directory and File system management

Device handling(I/O)

Protection

Networking, etc.

Chapter 6 File management 16


Operations on a file(a note on sys calls)
Types of System Calls : There are 5 different
categories of system calls:

Process control: end, abort, create, terminate, allocate
and free memory.

File management: create, open, close, delete, read file
etc.

Device management

Information maintenance

Communication

Chapter 6 File management 17


Examples of Windows and Unix System Calls

Windows Unix
Process Control CreateProcess() fork()
ExitProcess() exit()
WaitForSingleObject() wait()

File Manipulation CreateFile() open()


ReadFile() read()
WriteFile() write()
CloseHandle() close()
Device Manipulation SetConsoleMode() ioctl()
ReadConsole() read()
WriteConsole() write()
Information Maintenance GetCurrentProcessID() getpid()
SetTimer() alarm()
Sleep() sleep()
Communication CreatePipe() pipe()
CreateFileMapping() shmget()
MapViewOfFile() mmap()
Protection SetFileSecurity() chmod()
InitlializeSecurityDescriptor() umask()
SetSecurityDescriptorGroup() chown()

Chapter 6 File management 18


Operations on a file
3. Write operation:

This operation is used to write the information
into a file.

A system call write is issued that specifies the
name of the file and the length of the data has
to be written to the file.

Whenever the file length is increased by
specified value and the file pointer is
repositioned after the last byte written.

Chapter 6 File management 19


Operations on a file
4. Read operation:

This operation reads the contents from a file.

A Read pointer is maintained by the OS, pointing to
the position up to which the data has been read.
5. Re-position or Seek operation:

The seek system call re-positions the file pointers from
the current position to a specific place in the file i.e.
forward or backward depending upon the user's
requirement.

This operation is generally performed with those file
management systems that support direct access files.
Chapter 6 File management 20
Operations on a file
6) Delete Operation:

Deleting the file will not only delete all the data stored
inside the file it is also used so that disk space occupied by
it is freed.

In order to delete the specified file the directory is
searched.

When the directory entry is located, all the associated file
space and the directory entry is released.
7. Truncate operation:

Truncating is simply deleting the file except deleting
attributes.

The file is not completely deleted although the information
stored inside the file gets replaced.
Chapter 6 File management 21
Operations on a file
8. Close operation:

When the processing of the file is complete, it should be
closed so that all the changes made permanent and all the
resources occupied should be released.

On closing it deallocates all the internal descriptors that
were created when the file was opened.
9. Append operation:

This operation adds data to the end of the file.
10. Rename operation:

This operation is used to rename the existing file.

Chapter 6 File management 22


File Access Methods

File access is a process that determines the way that files
are accessed and read into memory.

Generally, a single access method is always supported by
operating systems. Though there are some operating
system which also supports multiple access methods.
The three file access methods are:

Sequential access

Direct or random access

Index sequential access

Chapter 6 File management 23


File Access Methods(Sequential access)

Most of the operating systems access the file sequentially.

In other words, we can say that most of the files need to
be accessed sequentially by the operating system.

In sequential access, the OS read the file word by word.

A pointer is maintained which initially points to the base
address of the file.

If the user wants to read first word of the file then the
pointer provides that word to the user and increases its
value by 1 word.

This process continues till the end of the file.

Chapter 6 File management 24


File Access Methods(Sequential access)

Chapter 6 File management 25


File Access Methods(Sequential access)
Summarily about sequential access;

Data is accessed one record right after another is an order.

Read command cause a pointer to be moved ahead by
one.

Write command allocate space for the record and move
the pointer to the new End Of File.

Such a method is reasonable for tape.

Chapter 6 File management 26


File Access Methods(Direct or random access)

The Direct Access is mostly required in the case of
database systems.

In most of the cases, we need filtered information from
the database. The sequential access can be very slow
and inefficient in such cases.

Suppose every block of the storage stores 4 records
and we know that the record we needed is stored in
10th block.

In that case, the sequential access will not be
implemented because it will traverse all the blocks in
order to access the needed record.

Chapter 6 File management 27


File Access Methods(Direct or random access)

Direct access will give the required result despite of the
fact that the operating system has to perform some
complex tasks such as determining the desired block
number.

However, that is generally implemented in database
applications.

This method is useful for disks.

The file is viewed as a numbered sequence of blocks or
records.

There are no restrictions on which blocks are read/written,
it can be done in any order.

Chapter 6 File management 28


File Access Methods(Direct or random access)

Chapter 6 File management 29


File Access Methods(Indexed sequential access)

It is built on top of Sequential access.

It uses an Index to control the pointer while accessing
files.

If a file can be sorted on any of the files then an index
can be assigned to a group of certain records.

However, A particular record can be accessed by its
index. The index is nothing but the address of a record
in the file.

In index accessing, searching in a large database
became very quick and easy but we need to have
some extra space in the memory to store the index
value.
Chapter 6 File management 30
Directory Structure

A directory can be defined as the listing of the related files on
the disk.

The directory may store some or the entire file attributes.

To get the benefit of different file systems on the different
operating systems, a hard disk can be divided into the number
of partitions of different sizes.

The partitions are also called volumes or mini disks.

Each partition must have at least one directory in which, all the
files of the partition can be listed.

A directory entry is maintained for each file in the directory
which stores all the information related to that file.

Information about files is maintained by Directories. A directory
can contain multiple files. It can even have directories inside of
them. In Windows we also call these directories as folders.
Chapter 6 File management 31
Directory Structure
A directory can be viewed as a file which contains the Meta data of
the bunch of files. The following is the information maintained in a
directory :

Name : The name visible to user.

Type : Type of the directory.

Location : Device and location on the device where the file header is
located.

Size : Number of bytes/words/blocks in the file.

Position : Current next-read/next-write pointers.

Protection : Access control on read/write/execute/delete.

Usage : Time of creation, access, modification etc.

Mounting : When the root of one file system is "grafted" into the
existing tree of another file system its called Mounting.

Chapter 6 File management 32


File Protection


When information is kept in a computer system, we
want to keep it safe from physical damage (reliability)
and improper access (protection).

Reliability is generally provided by duplicate copies of
files.

Many computers have systems programs that
automatically (or through computer-operator
intervention) copy disk files to tape at regular
intervals (once per day or week or month) to
maintain a copy should a file system be accidentally
destroyed.
Chapter 6 File management 33
File Protection

File systems can be damaged by hardware problems
(such as errors in reading or writing), power surges or
failures, head crashes, dirt, temperature extremes, and
vandalism.

Files may be deleted accidentally. Bugs in the file-system
software can also cause file contents to be lost.

Protection can be provided in many ways.

For a small single-user system, we might provide
protection by physically removing the floppy disks and
locking them in a desk drawer or file cabinet.

In a multi-user system, however, other mechanisms are
needed.
Chapter 6 File management 34
File Protection(Types of Access)

Complete protection is provided by prohibiting access.

Free access is provided with no protection.

Both approaches are too extreme for general use.

What is needed is controlled access.

Protection mechanisms provide controlled access by
limiting the types of file access that can be made.

Access is permitted or denied depending on several
factors, one of which is the type of access requested.
Several different types of operations may be controlled:

Chapter 6 File management 35


File Protection(Types of Access)
The following operations on a file need some form of
control
1. Read: Read from the file.
2. Write: Write or rewrite the file.
3. Execute: Load the file into memory and execute it.
4. Append: Write new information at the end of the file.
5. Delete: Delete the file and free its space for possible
reuse.
6. List: List the name and attributes of the file.

Chapter 6 File management 36


File Protection(Access Control )

Associate with each file and directory an access-control
list (ACL) specifying the user name and the types of
access allowed for each user.

When a user requests access to a particular file, the
operating system checks the access list associated with
that file.

If that user is listed for the requested access, the access is
allowed.

Otherwise, a protection violation occurs and the user job is
denied access to the file. This technique has two
undesirable consequences:

Chapter 6 File management 37


File Protection(Access Control )

Constructing such a list may be a tedious and unrewarding
task, especially if we do not know in advance the list of users in
the system.

The directory entry, previously of fixed size, now needs to be of
variable size, resulting in more complicated space
management.

To condense the length of the access control list, many systems
recognize three classifications of users in connection with each
file:

Owner: The user who created the file is the owner.

Group: A set of users who are sharing the file and need similar
access \is a group, or work group.

Universe: All other users in the system constitute the universe.
Chapter 6 File management 38

You might also like