0% found this document useful (0 votes)
18 views21 pages

Unit 5

css

Uploaded by

Vinaykumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views21 pages

Unit 5

css

Uploaded by

Vinaykumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

UNIT-5

FILE AND I\O MANAGEMENT

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.

Attributes of the File

1.Name

Every file carries a name by which the file is recognized in the file system. One directory cannot have
two files with the same name.

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.

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.

File Access Methods

Let's look at various ways to access files stored in secondary memory.

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.

Modern word systems do provide the concept of direct access and indexed access but the most used
method is sequential access due to the fact that most of the files such as text files, audio files, video
files, etc need to be sequentially accessed.
00:00/04:58

Direct 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.

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.

Indexed Access

If a file can be sorted on any of the filed 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.

Operations on the 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:
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.

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.

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.

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.

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.

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.

Directory Structure

What is a directory?

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.

A directory can be viewed as a file which contains the Meta data of the bunch of files.

Single Level Directory

The simplest method is to have one big list of all the files on the disk. The entire system will contain
only one directory which is supposed to mention all the files present in the file system. The directory
contains one entry per each file present on the file system.
This type of directories can be used for a simple system.

Advantages

1. Implementation is very simple.

2. If the sizes of the files are very small then the searching becomes faster.

3. File creation, searching, deletion is very simple since we have only one directory.

Disadvantages

1. We cannot have two files with the same name.

2. The directory may be very big therefore searching for a file may take so much time.

3. Protection cannot be implemented for multiple users.

4. There are no ways to group same kind of files.

5. Choosing the unique name for every file is a bit complex and limits the number of files in the
system because most of the Operating System limits the number of characters used to construct
the file name.

Two Level Directory

In two level directory systems, we can create a separate directory for each user. There is one master
directory which contains separate directories dedicated to each user. For each user, there is a different
directory present at the second level, containing group of user's file. The system doesn't let a user to
enter in the other user's directory without permission.
Characteristics of two level directory system

1. Each files has a path name as /User-name/directory-name/

2. Different users can have the same file name.

3. Searching becomes more efficient as only one user's list needs to be traversed.

4. The same kind of files cannot be grouped into a single directory for a particular user.

Every Operating System maintains a variable as PWD which contains the present directory name
(present user name) so that the searching can be done appropriately.

Tree Structured Directory

In Tree structured directory system, any directory entry can either be a file or sub directory. Tree
structured directory system overcomes the drawbacks of two level directory system. The similar kind
of files can now be grouped in one directory.

Each user has its own directory and it cannot enter in the other user's directory. However, the user has
the permission to read the root's data but he cannot write or modify this. Only administrator of the
system has the complete access of root directory.

Searching is more efficient in this directory structure. The concept of current working directory is
used. A file can be accessed by two types of path, either relative or absolute.

Absolute path is the path of the file with respect to the root directory of the system while relative path
is the path with respect to the current working directory of the system. In tree structured directory
systems, the user is given the privilege to create the files as well as directories.
Permissions on the file and directory

A tree structured directory system may consist of various levels therefore there is a set of permissions
assigned to each file and directory.

The permissions are R W X which are regarding reading, writing and the execution of the files or
directory. The permissions are assigned to three types of users: owner, group and others.

Acyclic-Graph Structured Directories

The tree structured directory system doesn't allow the same file to exist in multiple directories
therefore sharing is major concern in tree structured directory system. We can provide sharing by
making the directory an acyclic graph. In this system, two or more directory entry can point to the
same file or sub directory. That file or sub directory is shared between the two directory entries.

These kinds of directory graphs can be made using links or aliases. We can have multiple paths for a
same file. Links can either be symbolic (logical) or hard link (physical).

If a file gets deleted in acyclic graph structured directory system, then

1. In the case of soft link, the file just gets deleted and we are left with a dangling pointer.

2. In the case of hard link, the actual file will be deleted only if all the references to it gets deleted.
Device Management in Operating System

Device management in an operating system means controlling the Input/Output devices


like disk, microphone, keyboard, printer, magnetic tape, USB ports, camcorder, scanner,
other accessories, and supporting units like supporting units control channels. A process
may require various resources, including main memory, file access, and access to disk
drives, and others. If resources are available, they could be allocated, and control returned
to the CPU. Otherwise, the procedure would have to be postponed until adequate resources
become available. The system has multiple devices, and in order to handle these physical
or virtual devices, the operating system requires a separate program known as an ad device
controller. It also determines whether the requested device is available.

The fundamentals of I/O devices may be divided into three categories:

1. Boot Device
2. Character Device
3. Network Device

Boot Device

It stores data in fixed-size blocks, each with its unique address. For example- Disks.

Character Device

It transmits or accepts a stream of characters, none of which can be addressed individually.


For instance, keyboards, printers, etc..5M

Network Device

It is used for transmitting the data packets.


Functions of the device management in the operating system

The operating system (OS) handles communication with the devices via their drivers. The
OS component gives a uniform interface for accessing devices with various physical
features. There are various functions of device management in the operating system. Some
of them are as follows:

1. It keeps track of data, status, location, uses, etc. The file system is a term used to
define a group of facilities.
2. It enforces the pre-determined policies and decides which process receives the
device when and for how long.
3. It improves the performance of specific devices.
4. It monitors the status of every device, including printers, storage drivers, and other
devices.
5. It allocates and effectively deallocates the device. De-allocating differentiates the
devices at two levels: first, when an I/O command is issued and temporarily freed.
Second, when the job is completed, and the device is permanently release

Types of devices

There are three types of Operating system peripheral devices: dedicated, shared, and
virtual. These are as follows:

1. Dedicated Device

In device management, some devices are allocated or assigned to only one task at a time
until that job releases them. Devices such as plotters, printers, tape drivers, and other
similar devices necessitate such an allocation mechanism because it will be inconvenient if
multiple people share them simultaneously. The disadvantage of such devices is the
inefficiency caused by allocating the device to a single user for the whole duration of task
execution, even if the device is not used 100% of the time.

2. Shared Devices

These devices could be assigned to a variety of processes. By interleaving their requests,


disk-DASD could be shared by multiple processes simultaneously. The Device Manager
carefully controls the interleaving, and pre-determined policies must resolve all difficulties.

3. Virtual Devices

Virtual devices are a hybrid of the two devices, and they are dedicated devices that have
been transformed into shared devices. For example, a printer can be transformed into a
shareable device by using a spooling program that redirects all print requests to a disk. A
print job is not sent directly to the printer; however, it is routed to the disk until it is fully
prepared with all of the required sequences and formatting, at which point it is transmitted
to the printers. The approach can transform a single printer into numerous virtual printers,
improving performance and ease of use.

Features of Device Management

Here, you will learn the features of device management in the operating system. Various
features of the device management are as follows:

1. The OS interacts with the device controllers via the device drivers while allocating
the device to the multiple processes executing on the system.
2. Device drivers can also be thought of as system software programs that bridge
processes and device controllers.
3. The device management function's other key job is to implement the API.
4. Device drivers are software programs that allow an operating system to control the
operation of numerous devices effectively.
5. The device controller used in device management operations mainly contains three
registers: command, status, and data.

Android is a complete set of software for mobile devices such as tablet


computers, notebooks, smartphones, electronic book readers, set-top
boxes etc.

It contains a linux-based Operating System, middleware and key


mobile applications.

It can be thought of as a mobile operating system. But it is not limited to


mobile only. It is currently used in various devices such as mobiles,
tablets, televisions etc.

Android is a software package and linux based operating system for


mobile devices such as tablet computers and smartphones.

It is developed by Google and later the OHA (Open Handset Alliance).


Java language is mainly used to write the android code even though
other languages can be used.

The goal of android project is to create a successful real-world product


that improves the mobile experience for end users.
What is Open Handset Alliance (OHA)
It's a consortium of 84 companies such as google, samsung, AKM,
synaptics, KDDI, Garmin, Teleca, Ebay, Intel etc.

It was established on 5th November, 2007, led by Google. It is


committed to advance open standards, provide services and deploy
handsets using the Android Plateform.

Features of Android
After learning what is android, let's see the features of android. The
importantfeatures of android are given below:

1) It is open-source.

2) Anyone can customize the Android Platform.

3) There are a lot of mobile applications that can be chosen by the


consumer.

4) It provides many interesting features like weather details, opening


screen, live RSS (Really Simple Syndication) feeds etc.It provides
support for messaging services(SMS and MMS), web browser, storage
(SQLite), connectivity (GSM, CDMA, Blue Tooth, Wi-Fi etc.), media,
handset layout etc.

Categories of Android applications


There are many android applications in the market. The top categories
are:

o Entertainment
o Tools
o Communication
o Productivity
o Personalization
o Music and Audio
o Social
o Media and Video
o Travel and Local etc.
History of Android

The history and versions of android are interesting to know. The code names of android ranges
from A to J currently, such
as Aestro, Blender, Cupcake, Donut, Eclair, Froyo, Gingerbread, Honeycomb, Ice Cream
Sandwitch, Jelly Bean, KitKat and Lollipop. Let's understand the android history in a
sequence.
1) Initially, Andy Rubin founded Android Incorporation in Palo Alto, California, United
States in October, 2003.
2) In 17th August 2005, Google acquired android Incorporation. Since then, it is in the
subsidiary of Google Incorporation.

3) The key employees of Android Incorporation are Andy Rubin, Rich Miner, Chris
White and Nick Sears.

4) Originally intended for camera but shifted to smart phones later because of low market for
camera only.

5) Android is the nick name of Andy Rubin given by coworkers because of his love to robots.

6) In 2007, Google announces the development of android OS.

o 7) In 2008, HTC launched the first android mobile.

Let's see the android versions, codenames and API Level provided by
Google.

Version Code name API Level

1.5 Cupcake 3

1.6 Donut 4

2.1 Eclair 7

2.2 Froyo 8

2.3 Gingerbread 9 and 10

3.1 and 3.3 Honeycomb 12 and 13


4.0 Ice Cream Sandwitch 15

4.1, 4.2 and 4.3 Jelly Bean 16, 17 and 18

4.4 KitKat 19

5.0 Lollipop 21

6.0 Marshmallow 23

7.0 Nougat 24-25

8.0 Oreo 26-27

Android Architecture
android architecture or Android software stack is categorized into
five parts:

1. linux kernel
2. native libraries (middleware),
3. Android Runtime
4. Application Framework
5. Applications

Let's see the android architecture first.


1) Linux kernel
It is the heart of android architecture that exists at the root of android
architecture. Linux kernel is responsible for device drivers, power
management, memory management, device management and resource
access.

2) Native Libraries
On the top of linux kernel, their are Native libraries such as WebKit,
OpenGL, FreeType, SQLite, Media, C runtime library (libc) etc.

The WebKit library is responsible for browser support, SQLite is for


database, FreeType for font support, Media for playing and recording
audio and video formats.

3) Android Runtime
In android runtime, there are core libraries and DVM (Dalvik Virtual
Machine) which is responsible to run android application. DVM is like JVM
but it is optimized for mobile devices. It consumes less memory and
provides fast performance.

4) Android Framework
On the top of Native libraries and android runtime, there is android
framework. Android framework includes Android API's such as UI (User
Interface), telephony, resources, locations, Content Providers (data) and
package managers. It provides a lot of classes and interfaces for android
application development.

5) Applications
On the top of android framework, there are applications. All applications
such as home, contact, settings, games, browsers are using android
framework that uses android runtime and libraries. Android runtime and
native libraries are using linux kernal.

How to make android apps


In this page, you will know how to create the simple hello android
application. We are creating the simple example of android using the
Eclipse IDE. For creating the simple example:

1. Create the new android project


2. Write the message (optional)
3. Run the android application

Hello Android Example

You need to follow the 3 steps mentioned above for creating the Hello
android application.

1) Create the New Android project

For creating the new android studio project:

1) Select Start a new Android Studio project


2) Provide the following information: Application name, Company
domain, Project location and Package name of application and click
next.

3) Select the API level of application and click next.


4) Select the Activity type (Empty Activity).

5) Provide the Activity Name and click finish.


After finishing the Activity configuration, Android Studio auto generates
the activity class and other required configuration files.

Now an android project has been created. You can explore the android
project and see the simple program, it looks like this:

2) Write the message


File: activity_main.xml
Android studio auto generates code for activity_main.xml file. You may
edit this file according to your requirement.

1. <?xml version="1.0" encoding="utf-8"?>


2. <android.support.constraint.ConstraintLayout xmlns:android="http://
schemas.android.com/apk/res/android"
3. xmlns:app="http://schemas.android.com/apk/res-auto"
4. xmlns:tools="http://schemas.android.com/tools"
5. android:layout_width="match_parent"
6. android:layout_height="match_parent"
7. tools:context="first.javatpoint.com.welcome.MainActivity">
8.
9. <TextView
10. android:layout_width="wrap_content"
11. android:layout_height="wrap_content"
12. android:text="Hello Android!"
13. app:layout_constraintBottom_toBottomOf="parent"
14. app:layout_constraintLeft_toLeftOf="parent"
15. app:layout_constraintRight_toRightOf="parent"
16. app:layout_constraintTop_toTopOf="parent" />
17.
18. </android.support.constraint.ConstraintLayout>
19. }

File: MainActivity.java

1. package first.javatpoint.com.welcome;
2.
3. import android.support.v7.app.AppCompatActivity;
4. import android.os.Bundle;
5.
6. public class MainActivity extends AppCompatActivity {
7. @Override
8. protected void onCreate(Bundle savedInstanceState) {
9. super.onCreate(savedInstanceState);
10. setContentView(R.layout.activity_main);
11. }
12. }
To understand the first android application, visit the next page (internal details of hello
android example).

3) Run the android application

To run the android application, click the run icon on the toolbar or
simply press Shift + F10.

The android emulator might take 2 or 3 minutes to boot. So please have


patience. After booting the emulator, the android studio installs the
application and launches the activity. You will see something like this:

You might also like